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
listlengths
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
69121f23ddf24a31e788c29f54e7af4e
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
/*----------- ---------------* Author : Ryan Ranaut __Hope is a big word, never lose it__ ------------- --------------*/ import java.io.*; import java.util.*; public class Codeforces1 { static PrintWriter out = new PrintWriter(System.out); static final int mod = 1_000_000_007; static long min = (long) (-1e16); 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()); } int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } 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; } } /*--------------------------------------------------------------------------*/ //Try seeing general case //Minimization Maximization - BS..... Connections - Graphs..... //Greedy not worthy - Try DP //Think edge cases public static void main(String[] args) { FastReader s = new FastReader(); int t = s.nextInt(); while(t-->0) { int n = s.nextInt(); int[] a = s.readIntArray(n); out.println(find(n, a)); } out.close(); } public static String find(int n, int[] a) { int ones = 0; int turn = 1; for(int x: a) { if(x == 1) { ones++; continue; } if((x&1) == 0) turn ^= 1; } if(ones == n) return "maomao90"; return (turn == 0 ? "errorgorn" : "maomao90"); } /*----------------------------------End of the road--------------------------------------*/ static class DSU { int[] parent; int[] ranks; int[] groupSize; int size; public DSU(int n) { size = n; parent = new int[n];//0 based ranks = new int[n]; groupSize = new int[n];//Size of each component for (int i = 0; i < n; i++) { parent[i] = i; ranks[i] = 1; groupSize[i] = 1; } } public int find(int x)//Path Compression { if (parent[x] == x) return x; else return parent[x] = find(parent[x]); } public void union(int x, int y)//Union by rank { int x_rep = find(x); int y_rep = find(y); if (x_rep == y_rep) return; if (ranks[x_rep] < ranks[y_rep]) { parent[x_rep] = y_rep; groupSize[y_rep] += groupSize[x_rep]; } else if (ranks[x_rep] > ranks[y_rep]) { parent[y_rep] = x_rep; groupSize[x_rep] += groupSize[y_rep]; } else { parent[y_rep] = x_rep; ranks[x_rep]++; groupSize[x_rep] += groupSize[y_rep]; } size--;//Total connected components } } public static int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } public static long gcd(long x, long y) { return y == 0L ? x : gcd(y, x % y); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static long pow(long a, long b) { if (b == 0L) return 1L; long tmp = 1; while (b > 1L) { if ((b & 1L) == 1) tmp *= a; a *= a; b >>= 1; } return (tmp * a); } public static long modPow(long a, long b, long mod) { if (b == 0L) return 1L; long tmp = 1; while (b > 1L) { if ((b & 1L) == 1L) tmp *= a; a *= a; a %= mod; tmp %= mod; b >>= 1; } return (tmp * a) % mod; } static long mul(long a, long b) { return a * b; } static long fact(int n) { long ans = 1; for (int i = 2; i <= n; i++) ans = mul(ans, i); return ans; } static long fastPow(long base, long exp) { if (exp == 0) return 1; long half = fastPow(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } static void debug(int... a) { for (int x : a) out.print(x + " "); out.println(); } static void debug(long... a) { for (long x : a) out.print(x + " "); out.println(); } static void debugMatrix(int[][] a) { for (int[] x : a) out.println(Arrays.toString(x)); } static void debugMatrix(long[][] a) { for (long[] x : a) out.println(Arrays.toString(x)); } static void reverseArray(int[] a) { int n = a.length; int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void sort(int[] a) { ArrayList<Integer> ls = new ArrayList<>(); for (int x : a) ls.add(x); Collections.sort(ls); for (int i = 0; i < a.length; i++) a[i] = ls.get(i); } static void sort(long[] a) { ArrayList<Long> ls = new ArrayList<>(); for (long x : a) ls.add(x); Collections.sort(ls); for (int i = 0; i < a.length; i++) a[i] = ls.get(i); } static class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
ed2958d4466c65a07050024ca6b8b9eb
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { // Graph // prefix sums //inputs public static void main(String args[])throws Exception{ Input sc=new Input(); precalculates p=new precalculates(); StringBuilder sb=new StringBuilder(); int t=sc.readInt(); for(int f=0;f<t;f++){ int n=sc.readInt(); int a[]=sc.readArray(); int count=0; PriorityQueue<Integer> q=new PriorityQueue<>(Collections.reverseOrder()); for(int i=0;i<n;i++){ q.add(a[i]); } while(q.size()!=0){ count++; int val=q.poll(); if(val==1 && count%2!=0){ count=0; break; }else if(val==1 && count%2==0){ count=1; break; } q.add(val/2); q.add(val/2+val%2); } if(count%2!=0){ sb.append("errorgorn"); }else{ sb.append("maomao90"); } sb.append("\n"); } System.out.print(sb); } } class Input{ BufferedReader br; StringTokenizer st; Input(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public int[] readArray() throws Exception{ st=new StringTokenizer(br.readLine()); int a[]=new int[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Integer.parseInt(st.nextToken()); } return a; } public long[] readArrayLong() throws Exception{ st=new StringTokenizer(br.readLine()); long a[]=new long[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Long.parseLong(st.nextToken()); } return a; } public int readInt() throws Exception{ st=new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public long readLong() throws Exception{ st=new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } public String readString() throws Exception{ return br.readLine(); } public int[][] read2dArray(int n,int m)throws Exception{ int a[][]=new int[n][m]; for(int i=0;i<n;i++){ st=new StringTokenizer(br.readLine()); for(int j=0;j<m;j++){ a[i][j]=Integer.parseInt(st.nextToken()); } } return a; } } class precalculates{ public long gcd(long p, long q) { if (q == 0) return p; else return gcd(q, p % q); } public int[] prefixSumOneDimentional(int a[]){ int n=a.length; int dp[]=new int[n]; for(int i=0;i<n;i++){ if(i==0) dp[i]=a[i]; else dp[i]=dp[i-1]+a[i]; } return dp; } public int[] postSumOneDimentional(int a[]) { int n = a.length; int dp[] = new int[n]; for (int i = n - 1; i >= 0; i--) { if (i == n - 1) dp[i] = a[i]; else dp[i] = dp[i + 1] + a[i]; } return dp; } public int[][] prefixSum2d(int a[][]){ int n=a.length;int m=a[0].length; int dp[][]=new int[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; } } return dp; } public long pow(long a,long b){ long mod=998244353; long ans=1; if(b<=0) return 1; if(b%2==0){ ans=pow(a,b/2)%mod; return ((ans%mod)*(ans%mod))%mod; }else{ ans=pow(a,b-1)%mod; return ((a%mod)*(ans%mod))%mod; } } } class GraphInteger{ HashMap<Integer,vertex> vtces; class vertex{ HashMap<Integer,Integer> children; public vertex(){ children=new HashMap<>(); } } public GraphInteger(){ vtces=new HashMap<>(); } public void addVertex(int a){ vtces.put(a,new vertex()); } public void addEdge(int a,int b,int cost){ if(!vtces.containsKey(a)){ vtces.put(a,new vertex()); } if(!vtces.containsKey(b)){ vtces.put(b,new vertex()); } vtces.get(a).children.put(b,cost); // vtces.get(b).children.put(a,cost); } public boolean isCyclicDirected(){ boolean isdone[]=new boolean[vtces.size()+1]; boolean check[]=new boolean[vtces.size()+1]; for(int i=1;i<=vtces.size();i++) { if (!isdone[i] && isCyclicDirected(i,isdone, check)) { return true; } } return false; } private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){ if(check[i]) return true; if(isdone[i]) return false; check[i]=true; isdone[i]=true; Set<Integer> set=vtces.get(i).children.keySet(); for(Integer ii:set){ if(isCyclicDirected(ii,isdone,check)) return true; } check[i]=false; return false; } } class union_find { int n; int[] sz; int[] par; union_find(int nval) { n = nval; sz = new int[n + 1]; par = new int[n + 1]; for (int i = 0; i <= n; i++) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } boolean find(int a, int b) { return root(a) == root(b); } int union(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return 0; if(a==b) return 0; if (sz[a] > sz[b]) { int temp = ra; ra = rb; rb = temp; } par[ra] = rb; sz[rb] += sz[ra]; return 1; } } /* static int mod=998244353; private static int add(int x, int y) { x += y; return x % MOD; } private static int mul(int x, int y) { int res = (int) (((long) x * y) % MOD); return res; } private static int binpow(int x, int y) { int z = 1; while (y > 0) { if (y % 2 != 0) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } private static int inv(int x) { return binpow(x, MOD - 2); } private static int devide(int x, int y) { return mul(x, inv(y)); } private static int C(int n, int k, int[] fact) { return devide(fact[n], mul(fact[k], fact[n-k])); } */
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
4315b63e3614651e0a9015cecfe261b7
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; public class Forcodechef{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int flag=0; int n; while(t-->0){ n=sc.nextInt(); int [] arr=new int [n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); int sum=0; for(int i=0;i<n;i++){ sum=sum+arr[i]-1; } if(sum%2!=0) System.out.println("errorgorn"); else System.out.println("maomao90"); } }}
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
545510221f6d519e6319aa345223ada5
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; public class d3 { //static boolean[] visited; //static long min; 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; st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); outer : while(t-->0){ st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); ArrayList<Integer> al = new ArrayList<>(); int xor = 0; for(int i = 0;i<n;i++){ al.add(Integer.parseInt(st.nextToken())); xor += (al.get(i)-1); } if(xor%2 == 1){ bw.write("errorgorn\n"); } else{ bw.write("maomao90\n"); } } bw.flush(); } public static int recur(int e){ if(e <= 0){ return 0; } if(e == 1){ return 1; } if(e == 2){ return 2; } if(e == 3){ return 4; } return recur(e-1)+recur(e-2)+recur(e-3); } static class pair{ int a; int b; pair(int a,int b){ this.a = a; this.b = b; } } public static boolean check1(ArrayList<ArrayList<Integer>> graph,boolean[] visited){ for(int i = 0;i<visited.length;i++){ if(!visited[i] && graph.get(i).size() != 0){ if(dfs(i, graph, visited)){ return true; } } print1(visited); } return false; } public static void print1(boolean[] visited){ for(int i = 0;i<visited.length;i++){ System.out.print(visited[i]+" "); } System.out.println(); } public static boolean dfs(int i ,ArrayList<ArrayList<Integer>> g,boolean[] visited){ visited[i] = true; for(int e : g.get(i)){ if(!visited[e]){ // if(dfs(e,g,visited) == true){ // System.out.println("ji"); // return true; // } // dfs(i, g, visited); } else{ return true; } } return false; } public static boolean checksum(int n){ int temp = 0; while(n > 0){ temp += n%10; n /= 10; } return (temp == 10)?true:false; } public static class Node{ int val; int freq; Node(int val,int freq){ this.val = val; this.freq = freq; } } /* public static void dijk(ArrayList<ArrayList<pair>> graph,int i,boolean[] visited){ int[] dist = new int[visited.length]; for(int j = 0;j<dist.length;i++){ dist[j] = Integer.MAX_VALUE; } dist[i] = 0; PriorityQueue<pair> queue = new PriorityQueue<>((pair a1,pair a2)->(a1.dist - a2.dist)); queue.add(new pair(i, 0)); while(!queue.isEmpty()){ pair p1 = queue.poll(); int current = p1.b; if(visited[current]){ continue; } visited[current] = true; for(pair p : graph.get(current)){ int childnode = p.b; int childdist = p.dist; if(!visited[childnode] && dist[childnode] > dist[current]+childdist){ dist[childnode] = dist[current]+childdist; queue.add(p); } } } for(int j = 0;i<visited.length;j++){ System.out.println(dist[j]+" "); } }*/ public static int ceil(ArrayList<Long> al,long val){ int low = 0; int high = al.size()-1; int pos = 0; while(low <= high){ int mid = (low+high)/2; if(al.get(mid) == val){ pos = Math.max(pos,mid); low = mid+1; } else if(al.get(mid) < val){ low = mid+1; } else{ high = mid-1; } } return pos; } public static int floor(ArrayList<Long> al,long val){ int low = 0; int high = al.size()-1; int pos = high; while(low <= high){ int mid = (low+high)/2; if(al.get(mid) == val){ pos = Math.min(pos,mid); high = mid-1; } else if(al.get(mid) < val){ low = mid+1; } else{ high = mid-1; } } return pos; } public static boolean palin(String s){ for(int i = 0;i<s.length()/2;i++){ if(s.charAt(i) == s.charAt(s.length()-i-1)){ continue; } else{ return false; } } return true; } public static long gcd(long a,long b){ if(b == 0L){ return a; } return gcd(b,a%b); } public static boolean check(ArrayList<Long> al,long mid,long m){ long cur = 0L; for(int i = 0;i<al.size();i++){ if(al.get(i) <= mid){ cur++; } else{ cur += (al.get(i)/mid); cur += (al.get(i)%mid != 0)?1L:0L; } } return (cur <= m)?true:false; } // public static int bs(int sum,int low,int high){ // } public static long fin(long n){ return ((long)n)*(n+1)/2; } public static int bceil(ArrayList<Integer> al,int val,int low,int high){ int index = 0; while(low <= high){ int mid = low + (high-low)/2; if(al.get(mid) <= val){ index = Math.max(mid,index); low = mid+1; } else{ high = mid-1; } } return index; } public static int bfloor(ArrayList<Integer> al,int val){ int low = 0; int high = al.size()-1; int index = -1; while(low <= high){ int mid = low + (high-low)/2; int mval = al.get(mid); if(mval >= val){ high = mid-1; index = Math.max(index,mid); } else{ low = mid+1; } } return index; } public static String rev(String s){ StringBuffer sb = new StringBuffer(s); sb.reverse(); return s+sb.toString(); } public static String rev1(String s){ StringBuffer sb = new StringBuffer(s); sb.reverse(); return sb.toString()+s; } public static long fact12(long a){ long l = 1L; for(long i = 1;i<=a;i++){ l *= i; } // System.out.println(l); return l; } public static boolean binary(ArrayList<Integer> al,int a1){ int low = 0; int high = al.size(); while(low <= high){ int mid = (low+high)/2; if(a1 == al.get(mid)){ return true; } else if(a1 > al.get(mid)){ low = mid+1; } else{ high = mid-1; } } return false; } public static void primefact(int n){ for(int i = 2;i*i<=n;i++){ if(n%i == 0){ while(n%i == 0){ n /= i; System.out.println(i); } } } System.out.println(n); } public static boolean prime(long n){ int count = 0; for(long i = 1;i*i <= n;i++){ if(n%i == 0){ if(i*i == n){ count++; } else{ count += 2; } } } if(count == 2){ return true; } return false; } public static boolean bsearch(ArrayList<Integer> al,int low,int high,int req){ if(low > high || low < 0 || high < 0 || low >= al.size() || high >= al.size()){ return false; } int mid = (low+high)/2; if(al.get(mid) == req){ return true; } else if(al.get(mid) > req){ high = mid-1; bsearch(al, low, high, req); } else{ low = mid+1; bsearch(al, low, high, req); } return false; } public static long fact1(int n){ long ans = 1L; for(int i = 2;i<=n;i++){ ans *= i; } return ans; } public static String reverse(String s){ StringBuilder sb = new StringBuilder(s); return sb.reverse().toString(); } public static int find(int n){ return n*(n+1)/2; } public static double calc(int x1,int x2,int y1,int y2){ return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
05cb547962a82493b74aa62ead5e2de7
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.*; import java.nio.Buffer; import java.util.ArrayList; import java.util.StringTokenizer; public class LogChopping { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader( System.in)); PrintWriter pr = new PrintWriter( new OutputStreamWriter( System.out)); int t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); ArrayList<Integer> l = new ArrayList<>(); for(int i =0 ; i< n ; i++){ l.add(Integer.parseInt(st.nextToken())); } int count=0; int flag=0; while(flag==0){ int s=l.size(); int i; int temp=0; for(i=0 ; i<s;i++){ if(l.get(i)>1){ count++; temp=l.get(i); l.remove(i); if(temp%2==0){ l.add(temp/2); l.add(temp/2); }else{ l.add(temp/2); l.add((temp/2)+1); } break; } } //pr.println(l); if(i==s){ flag=1; } } if(count%2==0){ pr.println("maomao90"); }else{ pr.println("errorgorn"); } } pr.close(); } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
8557073fda9b18db3007dc2a769c1d42
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.*; import java.util.*; public class Main { static int mod = 998244353; static boolean[] prime = new boolean[10]; static int[][] dir1 = new int[][]{{0,1},{0,-1},{1,0},{-1,0}}; static int[][] dir2 = new int[][]{{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; static { for (int i = 2; i < prime.length; i++) prime[i] = true; for (int i = 2; i < prime.length; i++) { if (prime[i]) { for (int k = 2; i * k < prime.length; k++) { prime[i * k] = false; } } } } static class JoinSet { int[] fa; JoinSet(int n) { fa = new int[n]; for (int i = 0; i < n; i++) fa[i] = i; } int find(int t) { if (t != fa[t]) fa[t] = find(fa[t]); return fa[t]; } void join(int x, int y) { x = find(x); y = find(y); fa[x] = y; } } static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static long lcm(long a, long b) { return a * b / gcd(a, b); } static int get() throws Exception { String ss = bf.readLine(); if (ss.contains(" ")) ss = ss.substring(0, ss.indexOf(" ")); return Integer.parseInt(ss); } static long getx() throws Exception { String ss = bf.readLine(); if (ss.contains(" ")) ss = ss.substring(0, ss.indexOf(" ")); return Long.parseLong(ss); } static int[] getint() throws Exception { String[] s = bf.readLine().split(" "); int[] a = new int[s.length]; for (int i = 0; i < a.length; i++) { a[i] = Integer.parseInt(s[i]); } return a; } static long[] getlong() throws Exception { String[] s = bf.readLine().split(" "); long[] a = new long[s.length]; for (int i = 0; i < a.length; i++) { a[i] = Long.parseLong(s[i]); } return a; } static String getstr() throws Exception { return bf.readLine(); } static void println() throws Exception { bw.write("\n"); } static void print(int a) throws Exception { bw.write(a + "\n"); } static void print(long a) throws Exception { bw.write(a + "\n"); } static void print(String a) throws Exception { bw.write(a + "\n"); } static void print(int[] a) throws Exception { for (int i : a) { bw.write(i + " "); } println(); } static void print(long[] a) throws Exception { for (long i : a) { bw.write(i + " "); } println(); } static void print(int[][] a) throws Exception { for (int i[] : a) print(i); } static void print(long[][] a) throws Exception { for (long[] i : a) print(i); } static void print(char[] a) throws Exception { for (char i : a) { bw.write(i +""); } println(); } static long pow(long a, long b) { long ans = 1; while (b > 0) { if ((b & 1) == 1) { ans *= a; } a *= a; b >>= 1; } return ans; } static int powmod(long a, long b, int mod) { long ans = 1; while (b > 0) { if ((b & 1) == 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return (int) ans; } static void sort(int[] a) { int n = a.length; Integer[] b = new Integer[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[i]; } static void sort(long[] a) { int n = a.length; Long[] b = new Long[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[i]; } static void resort(int[] a) { int n = a.length; Integer[] b = new Integer[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[n-1-i]; } static void resort(long[] a) { int n = a.length; Long[] b = new Long[n]; for (int i = 0; i < n; i++) b[i] = a[i]; Arrays.sort(b); for (int i = 0; i < n; i++) a[i] = b[n-1-i]; } static int max(int a, int b) { return Math.max(a,b); } static int min(int a, int b) { return Math.min(a,b); } static long max(long a, long b) { return Math.max(a,b); } static long min(long a, long b) { return Math.min(a,b); } static int max(int[] a) { int max = a[0]; for(int i : a) max = max(max,i); return max; } static int min(int[] a) { int min = a[0]; for(int i : a) min = min(min,i); return min; } static long max(long[] a) { long max = a[0]; for(long i : a) max = max(max,i); return max; } static long min(long[] a) { long min = a[0]; for(long i : a) min = min(min,i); return min; } static int abs(int a) { return Math.abs(a); } static long abs(long a) { return Math.abs(a); } static void yes() throws Exception{ print("Yes"); } static void no() throws Exception{ print("No"); } static int[] getarr(List<Integer> list){ int n = list.size(); int[] a = new int[n]; for(int i = 0;i < n;i++) a[i] = list.get(i); return a; } public static void main(String[] args) throws Exception { int t = get(); while (t-- > 0){ int n = get(); int []a = getint(); int c = 0; for(int i : a){ c += i; } c -= n; if(c%2==0){ print("maomao90"); }else{ print("errorgorn"); } } bw.flush(); } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
3c92f8eeb65fcce079bae10405baf545
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; public class C { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException { int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(s[i]); } Arrays.sort(a); boolean e = true; String ans = ""; for (int i = n - 1; i >= 0; i--) { if (a[i] == 1) { if (e) { ans = "maomao90"; } else { ans = "errorgorn"; } break; } if (a[i] % 2 == 0) { if (e) e = false; else e = true; } } if (ans.length() <= 1) { if (e) { ans = "maomao90"; } else { ans = "errorgorn"; } } bw.write(ans + "\n"); } bw.flush(); } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
75b94fb842d2ea5053e24a2e522f9892
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; public class G { static FastScanner fs = new FastScanner(); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(""); static Scanner scn = new Scanner(System.in); public static void main(String[] args) { int t = fs.nextInt(); for (int tt = 0; tt < t; tt++) { int n = fs.nextInt(); int s = 0; for (int i = 0; i < n; i++) { int x = fs.nextInt(); s += (x-1); } if (s % 2 == 0) sb.append("maomao90\n"); else sb.append("errorgorn\n"); } pw.print(sb.toString()); pw.close(); } static void sort(int[] a) { ArrayList<Integer> al = new ArrayList<>(); for (int i : a) al.add(i); Collections.sort(al); for (int i = 0; i < a.length; i++) a[i] = al.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() {while (!st.hasMoreTokens())try {st = new StringTokenizer(br.readLine());} catch (IOException e) {}return st.nextToken();} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble() {return Double.parseDouble(next());} int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) {a[i] = nextInt();} return a;} } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
0f94a17f56a21bfe5a1e1a132c097bcc
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastReader reader = new FastReader(); static int[] nextSame; static int[] nextDiff; static int[][] dp; public static void main(String[] args) { int t = ri(); outerloop: while(t-->0) { int n = ri(); int[] arr = ra(n); int res = 0; Queue<Integer> q = new LinkedList<>(); for(int val: arr) q.add(val); while(!q.isEmpty()) { int val = q.poll(); while(val>1) { q.add(val/2); if((val&1)==1) val = (val+1)/2; else val /=2; res++; } } // System.err.println(res); if((res&1)==1) str.append("errorgorn\n"); else str.append("maomao90\n"); } System.out.println(str.toString()); } static StringBuilder str = new StringBuilder(""); static int MOD = 1000000007; static HashSet<Integer> factors = new HashSet<Integer>(); static HashSet<Integer> primes = new HashSet<Integer>(); static void log(long a, StringBuilder str) { str.append(a+"\n");} static int ri() { return reader.nextInt(); } static String rs() { return reader.nextLine(); } static long rl() { return reader.nextLong(); } static int[] ra(int n) { int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = ri(); return arr; } static class Pair { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } } public static int mex(int[] arr) { int a = -1; for(int val: arr) { if(val-a>1) break; else a = val; } return a+1; } static void seive(int n) { boolean[] composite = new boolean[n + 1]; for (int i = 2; i * i <= n; i++) { if (!composite[i]) { for (int j = i * i; j <= n; j += i) composite[j] = true; } } for (int i = 2; i <= n; i++) { if (!composite[i]) primes.add(i); } } static int sumofdigits(long n) { int sum = 0; while(n>0) { sum += n%10; n /= 10; } return sum; } static void findfactors(int n) { if ((n & 1) == 0) { factors.add(2); while ((n & 1) == 0) n = n >> 1; } for (int i = 3; i * i <= n; i++) { if (n % i == 0) factors.add(i); while ((n % i) == 0) n /= i; } if (n > 1) factors.add(n); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { long lcm = (a * b) / gcd(a, b); return lcm; } static int binarySearch(ArrayList<Integer> list, int n) { int start = 0; int end = list.size() - 1; while (start <= end) { int mid = start + (end - start) / 2; if (list.get(mid) == n) return mid; else if (list.get(mid) > n) end = mid - 1; else start = mid + 1; } if (start == list.size()) return -1; else return start; } // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader(new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); System.setOut(out); } catch (Exception e) { 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; } } // end of fast i/o code }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
a0a835fd822770f4550366d890ee42e8
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; public class B{ public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); for(int tt=0;tt<t;tt++) { int n = fs.nextInt(); int[] arr = fs.readArray(n); int sum = 0; for(int i:arr) { sum += i-1; } // sum -= 1; if(sum%2 == 1) { out.println("errorgorn"); } else out.println("maomao90"); } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long[] sort(long[] arr) { List<Long> temp = new ArrayList(); for(long i:arr)temp.add(i); Collections.sort(temp); int start = 0; for(long i:temp)arr[start++]=i; return arr; } public static String rev(String str) { char[] arr = str.toCharArray(); char[] ret = new char[arr.length]; int start = arr.length-1; for(char i:arr)ret[start--] = i; String ret1 = ""; for(char ch:ret)ret1+=ch; return ret1; } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
256f2d84777c62f6d3acf6a2e9033a68
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
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 A { private static PrintWriter out = new PrintWriter(System.out); public static void solve() { In in = new In(); int tests = in.ni(); while (tests-- > 0) { int n = in.ni(); Integer[] nums = in.nia(n); long total = 0; for (int x : nums) { if (x != 1) total += x - 1; } if (total % 2 == 1) { out.println("errorgorn"); } else { out.println("maomao90"); } } } public static void main(String[] args) throws IOException { // long start = System.nanoTime(); solve(); // System.out.println("Elapsed: " + (System.nanoTime() - start) / 1000000 + // "ns"); out.flush(); } @SuppressWarnings("unused") private static class In { final private static int BUFFER_SIZE = 1024; private byte[] buf; private InputStream is; private int buflen; private int bufptr; public In() { is = System.in; buf = new byte[BUFFER_SIZE]; buflen = bufptr = 0; } public In(String input) { is = new ByteArrayInputStream(input.getBytes()); buf = new byte[BUFFER_SIZE]; buflen = bufptr = 0; } public int readByte() { if (bufptr >= buflen) { try { buflen = is.read(buf); } catch (IOException ioe) { throw new InputMismatchException(); } bufptr = 0; } if (buflen <= 0) return -1; return buf[bufptr++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } /* Next character */ public char nc() { return (char) skip(); } /* Next double */ public double nd() { return Double.parseDouble(ns()); } /* Next string */ public String ns() { final StringBuilder sb = new StringBuilder(); int b = skip(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } /* Next integer */ public int ni() { boolean minus = false; int num = 0; int b; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); b = readByte(); } return minus ? -num : num; } /* Next long */ public long nl() { boolean minus = false; long num = 0; int b; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); b = readByte(); } return minus ? -num : num; } /* Next integer 1D array */ public Integer[] nia(int n) { final Integer[] arr = new Integer[n]; for (int i = 0; i < n; i++) arr[i] = ni(); return arr; } /* Next long 1D array */ public long[] nla(int n) { final long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nl(); return arr; } /* Next string 1D array */ public String[] nsa(int n) { final String[] arr = new String[n]; for (int i = 0; i < n; i++) arr[i] = ns(); return arr; } /* Next char 1D array */ public char[] nca(int n) { final char[] arr = new char[n]; for (int i = 0; i < n; i++) arr[i] = nc(); return arr; } /* Next double 1D array */ public double[] nda(int n) { final double[] arr = new double[n]; for (int i = 0; i < n; i++) arr[i] = nc(); return arr; } /* Next integer matrix */ public int[][] nim(int n, int m) { final int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = ni(); return arr; } /* Next long matrix */ public long[][] nlm(int n, int m) { final long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = nl(); return arr; } /* Next string matrix */ public String[][] nsm(int n, int m) { final String[][] arr = new String[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = ns(); return arr; } /* Next char matrix */ public char[][] ncm(int n, int m) { final char[][] arr = new char[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = nc(); return arr; } /* Next double matrix */ public double[][] ndm(int n, int m) { final double[][] arr = new double[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) arr[i][j] = nd(); return arr; } public static void log(Object... o) { System.out.println(Arrays.deepToString(o)); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
8c15d1bc48cd0c547118624fe53422bd
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.stream.IntStream; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author dauom */ 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); ALogChopping solver = new ALogChopping(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class ALogChopping { public final void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = in.nextIntArray(n); int sum = IntStream.of(a).sum() - n; if (sum % 2 == 1) { out.println("errorgorn"); } else { out.println("maomao90"); } } } static final class InputReader { private final InputStream stream; private final byte[] buf = new byte[1 << 18]; private int curChar; private int numChars; public InputReader() { this.stream = System.in; } public InputReader(final InputStream stream) { this.stream = stream; } private int read() { if (this.numChars == -1) { throw new UnknownError(); } else { if (this.curChar >= this.numChars) { this.curChar = 0; try { this.numChars = this.stream.read(this.buf); } catch (IOException ex) { throw new InputMismatchException(); } if (this.numChars <= 0) { return -1; } } return this.buf[this.curChar++]; } } public final int nextInt() { int c; for (c = this.read(); isSpaceChar(c); c = this.read()) { } byte sgn = 1; if (c == 45) { // 45 == '-' sgn = -1; c = this.read(); } int res = 0; while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9' res *= 10; res += c - 48; // 48 == '0' c = this.read(); if (isSpaceChar(c)) { return res * sgn; } } throw new InputMismatchException(); } public final String next() { int c; while (isSpaceChar(c = this.read())) { } StringBuilder result = new StringBuilder(); result.appendCodePoint(c); while (!isSpaceChar(c = this.read())) { result.appendCodePoint(c); } return result.toString(); } private static boolean isSpaceChar(final int c) { return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t' } public final int[] nextIntArray(final int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
5739d2fd6d3daee2ebda0431547974bd
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.Random; import java.io.FileWriter; import java.io.PrintWriter; /* Solution Created: 17:07:03 23/04/2022 Custom Competitive programming helper. */ public class Main { public static void solve() { int n = in.nextInt(); int cnt = 0; int[] a = in.na(n); for(int i : a) cnt += i-1; if(cnt%2==1) out.println("errorgorn"); else out.println("maomao90"); } public static void main(String[] args) { in = new Reader(); out = new Writer(); int t = in.nextInt(); while(t-->0) solve(); out.exit(); } static Reader in; static Writer out; static class Reader { static BufferedReader br; static StringTokenizer st; public Reader() { this.br = new BufferedReader(new InputStreamReader(System.in)); } public Reader(String f){ try { this.br = new BufferedReader(new FileReader(f)); } catch (IOException e) { e.printStackTrace(); } } public int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nd(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nl(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[] nca() { return next().toCharArray(); } public String[] ns(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int nextInt() { ensureNext(); return Integer.parseInt(st.nextToken()); } public double nextDouble() { ensureNext(); return Double.parseDouble(st.nextToken()); } public Long nextLong() { ensureNext(); return Long.parseLong(st.nextToken()); } public String next() { ensureNext(); return st.nextToken(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); return null; } } private void ensureNext() { if (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } } } static class Util{ private static Random random = new Random(); static long[] fact; public static void initFactorial(int n, long mod) { fact = new long[n+1]; fact[0] = 1; for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod; } public static long modInverse(long a, long MOD) { long[] gcdE = gcdExtended(a, MOD); if (gcdE[0] != 1) return -1; // Inverted doesn't exist long x = gcdE[1]; return (x % MOD + MOD) % MOD; } public static long[] gcdExtended(long p, long q) { if (q == 0) return new long[] { p, 1, 0 }; long[] vals = gcdExtended(q, p % q); long tmp = vals[2]; vals[2] = vals[1] - (p / q) * vals[2]; vals[1] = tmp; return vals; } public static long nCr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nCr(int n, int r) { return (fact[n]/fact[r])/fact[n-r]; } public static long nPr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nPr(int n, int r) { return fact[n]/fact[n-r]; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean[] getSieve(int n) { boolean[] isPrime = new boolean[n+1]; for (int i = 2; i <= n; i++) isPrime[i] = true; for (int i = 2; i*i <= n; i++) if (isPrime[i]) for (int j = i; i*j <= n; j++) isPrime[i*j] = false; return isPrime; } static long pow(long x, long pow, long mod){ long res = 1; x = x % mod; if (x == 0) return 0; while (pow > 0){ if ((pow & 1) != 0) res = (res * x) % mod; pow >>= 1; x = (x * x) % mod; } return res; } public static int gcd(int a, int b) { int tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static long gcd(long a, long b) { long tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static int random(int min, int max) { return random.nextInt(max-min+1)+min; } public static void dbg(Object... o) { System.out.println(Arrays.deepToString(o)); } public static void reverse(int[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { int tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(int[] s) { reverse(s, 0, s.length-1); } public static void reverse(long[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { long tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(long[] s) { reverse(s, 0, s.length-1); } public static void reverse(float[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { float tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(float[] s) { reverse(s, 0, s.length-1); } public static void reverse(double[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { double tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(double[] s) { reverse(s, 0, s.length-1); } public static void reverse(char[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { char tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(char[] s) { reverse(s, 0, s.length-1); } public static <T> void reverse(T[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { T tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static <T> void reverse(T[] s) { reverse(s, 0, s.length-1); } public static void shuffle(int[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); int t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(long[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); long t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(float[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); float t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(double[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); double t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(char[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); char t = s[i]; s[i] = s[j]; s[j] = t; } } public static <T> void shuffle(T[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); T t = s[i]; s[i] = s[j]; s[j] = t; } } public static void sortArray(int[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(long[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(float[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(double[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(char[] a) { shuffle(a); Arrays.sort(a); } public static <T extends Comparable<T>> void sortArray(T[] a) { Arrays.sort(a); } public static int[][] rotate90(int[][] a){ int n = a.length, m = a[0].length; int[][] ans = new int[m][n]; for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) ans[m-j-1][i] = a[i][j]; return ans; } public static char[][] rotate90(char[][] a){ int n = a.length, m = a[0].length; char[][] ans = new char[m][n]; for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) ans[m-j-1][i] = a[i][j]; return ans; } } static class Writer { private PrintWriter pw; public Writer(){ pw = new PrintWriter(System.out); } public Writer(String f){ try { pw = new PrintWriter(new FileWriter(f)); } catch (IOException e) { e.printStackTrace(); } } public void yesNo(boolean condition) { println(condition?"YES":"NO"); } public void printArray(int[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); } public void printlnArray(int[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); pw.println(); } public void printArray(long[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); } public void printlnArray(long[] a) { for(int i = 0; i<a.length; i++) print(a[i]+" "); pw.println(); } public void print(Object o) { pw.print(o.toString()); } public void println(Object o) { pw.println(o.toString()); } public void println() { pw.println(); } public void flush() { pw.flush(); } public void exit() { pw.close(); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
37e7117547a668111f9f7a86a4d45517
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.lang.String; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int k= 0 ; k < t ;k++){ int n = sc.nextInt(); int chop = 0; for(int i = 0 ; i < n ;i++){ int te = sc.nextInt(); chop = chop + te-1; } if(chop % 2 ==0){ System.out.println("maomao90"); }else{ System.out.println("errorgorn"); } } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
e66e8fef42207bafc51081809380b7a7
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class WoodCutting { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } static class Task { public void solve(InputReader in, PrintWriter out) { // Add your code here int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); /* * int[] a = new int[n]; * for (int j = 0; j < n; j++){ * a[j] = in.nextInt(); * } * int count = 0; * for (int k = 0; k < n; k++){ * if (a[k] % 2 == 0){ * count++; * } * } * if (count % 2 == 0){ * out.println("maomao90"); * } * else { * out.println("errorgorn"); * } */ boolean maomao = true; for (int j = 0; j < n; j++) { int v = in.nextInt(); if (v % 2 == 0) { maomao = !maomao; } } out.println(maomao ? "maomao90" : "errorgorn"); } } } 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\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
f806dc0b4c216ed651920fe6f7389e5c
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } static class Task { public void solve(InputReader in, PrintWriter out) { // Add your code here int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int sum = 0; for (int j = 0; j < n; j++) { int l = in.nextInt(); sum += (l - 1); sum %= 2; } System.out.println(sum == 1 ? "errorgorn" : "maomao90"); } } } 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\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
3ba1d763256d4f4e9c54752ae2a41f18
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class A_Log_Chopping { static long mod = Long.MAX_VALUE; public static void main(String[] args) { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); FastReader f = new FastReader(); int t = f.nextInt(); while(t-- > 0){ solve(f, out); } out.close(); } public static void solve(FastReader f, PrintWriter out) { int n = f.nextInt(); int cut = 0; for(int i = 0; i < n; i++) { cut += f.nextInt()-1; } if(cut%2 == 0) { out.println("maomao90"); } else { out.println("errorgorn"); } } // Sort an array public static void sort(int arr[]) { ArrayList<Integer> al = new ArrayList<>(); for(int i: arr) { al.add(i); } Collections.sort(al); for(int i = 0; i < arr.length; i++) { arr[i] = al.get(i); } } // Find all divisors of n public static void allDivisors(int n) { for(int i = 1; i*i <= n; i++) { if(n%i == 0) { System.out.println(i + " "); if(i != n/i) { System.out.println(n/i + " "); } } } } // Check if n is prime or not public static boolean isPrime(int n) { if(n < 1) return false; if(n == 2 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i*i <= n; i += 6) { if(n % i == 0 || n % (i+2) == 0) { return false; } } return true; } // Find gcd of a and b public static long gcd(long a, long b) { long dividend = a > b ? a : b; long divisor = a < b ? a : b; while(divisor > 0) { long reminder = dividend % divisor; dividend = divisor; divisor = reminder; } return dividend; } // Find lcm of a and b public static long lcm(long a, long b) { long lcm = gcd(a, b); long hcf = (a * b) / lcm; return hcf; } // Find factorial in O(n) time public static long fact(int n) { long res = 1; for(int i = 2; i <= n; i++) { res *= res * i; } return res; } // Find power in O(logb) time public static long power(long a, long b) { long res = 1; while(b > 0) { if((b&1) == 1) { res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return res; } // Find nCr public static long nCr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / (fact(r) * fact(n-r)); return ans; } // Find nPr public static long nPr(int n, int r) { if(r < 0 || r > n) { return 0; } long ans = fact(n) / fact(r); return ans; } // sort all characters of a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } // User defined class for fast I/O 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(); } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } boolean nextBoolean() { return Boolean.parseBoolean(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextArray(int n) { int[] a = new int[n]; for(int i=0; i<n; i++) { a[i] = nextInt(); } return a; } } } /** Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k 12 FF (NP form feed, new page) 44 , 76 L 108 l 13 CR (carriage return) 45 - 77 M 109 m 14 SO (shift out) 46 . 78 N 110 n 15 SI (shift in) 47 / 79 O 111 o 16 DLE (data link escape) 48 0 80 P 112 p 17 DC1 (device control 1) 49 1 81 Q 113 q 18 DC2 (device control 2) 50 2 82 R 114 r 19 DC3 (device control 3) 51 3 83 S 115 s 20 DC4 (device control 4) 52 4 84 T 116 t 21 NAK (negative acknowledge) 53 5 85 U 117 u 22 SYN (synchronous idle) 54 6 86 V 118 v 23 ETB (end of trans. block) 55 7 87 W 119 w 24 CAN (cancel) 56 8 88 X 120 x 25 EM (end of medium) 57 9 89 Y 121 y 26 SUB (substitute) 58 : 90 Z 122 z 27 ESC (escape) 59 ; 91 [ 123 { 28 FS (file separator) 60 < 92 \ 124 | 29 GS (group separator) 61 = 93 ] 125 } 30 RS (record separator) 62 > 94 ^ 126 ~ 31 US (unit separator) 63 ? 95 _ 127 DEL */ // (a/b)%mod == (a * moduloInverse(b)) % mod; // moduloInverse(b) = power(b, mod-2);
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
80c917a411e5992d45557fdee6d6b34b
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
// Created By Jefferson Samuel => JeffIsHere import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Math.*; import static java.lang.Double.parseDouble; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.*; public class A { static void solve() throws Exception { int T = 1; T = sint(); tc:for(int t = 1;t<=T;t++) { int N = sint(); int ar[] = iar(N); int ans= 0; for(int k : ar) ans += (k-1); out.println((ans&1)==1 ? "errorgorn":"maomao90"); } } /* -----------------------------------------------------********------------------------------------------------------*/ //Globals static int[] d4 = {-1,1,0,0}; static int[] d8r = {-1,-1,-1,1,1,1,0,0}; static int[] d8c = {-1,1,0,-1,1,0,-1,1}; static final int MOD = (int) 1e9 + 7; static final int IMa = (int) (2e9+5); static final int IMi = (int) (-2e9-5); static final long LMa = Long.MAX_VALUE; static final long LMi = Long.MIN_VALUE; static final double EPS = 1e-9; // Graphs static ArrayList<Integer>[] Gph; static boolean[] vis; static int[][] Grid; static char[][] Crid; // Essentials static int sint() throws IOException {return parseInt(sstr());} static double sdob() throws IOException{return parseDouble(sstr());} static char schar() throws IOException{return sstr().charAt(0);} static long gcd(long a, long b){ return (b == 0) ? a : gcd(b, a % b); } static int[] iar(int N) throws IOException { int[] a = new int[N]; for(int i = 0;i<N;i++)a[i] = sint(); return a; } static String sfull() throws IOException {return in.readLine();} static void revsor(long[] ar){sortAr(ar);revar(ar);} static void revar(long[] ar){for (int i = 0; i < ar.length / 2; i++) { long temp = ar[i]; ar[i] = ar[ar.length - 1 - i]; ar[ar.length - 1 - i] = temp;}} static long[] lar(int N) throws IOException { long[] a = new long[N]; for(int i = 0;i<N;i++)a[i] = slong(); return a; } static String[] sar(int N)throws IOException{ String ar[] = new String[N]; for(int i =0;i<N;i++) ar[i] = sstr(); return ar; } static final Random random=new Random(); static void sortAr(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n);long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static void sortAr(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n);int temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static long slong() throws IOException {return parseLong(sstr());} static String sstr() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in; public static PrintWriter out; static StringTokenizer tok; static class Pair<T,K>{ T F;K S;public Pair(T F, K S) {this.F = F;this.S = S;}} static class Pii{int F,S; public Pii(int F,int S){this.F = F;this.S = S;}} static class Pll{long F;long S; public Pll(long F,long S){this.F=F;this.S=S;}} public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); long startTime = System.currentTimeMillis(); solve(); in.close(); out.close(); long endTime = System.currentTimeMillis(); long timeElapsed = endTime - startTime; err.println("Exec time " + timeElapsed+"ms"); } catch (Throwable e) { e.printStackTrace(); exit(1); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
d715e36b125ae96d8ded957c5c099eaf
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.Scanner; public class Training3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int k = 0; k < t; k++) { int n=sc.nextInt(); int sum=0; for (int i = 0; i < n; i++) { int x=sc.nextInt(); sum+=x-1; } if (sum%2==0) { System.out.println("maomao90"); }else{ System.out.println("errorgorn"); } } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
57aca9d72eda655fa0b460106a0da93d
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.sqrt; import static java.lang.Math.floor; public class Solution { static class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.val = val; this.left = left; this.right = right; } public static int max(int []nums, int s, int e) { int max = Integer.MIN_VALUE; for(int i = s; i <= e; i++) { max = Math.max(max, nums[i]); } return max; } static int depth(TreeNode root) { if(root == null)return 0; int a = 1+ depth(root.left); int b = 1+ depth(root.right); return Math.max(a,b); } static HashSet<Integer>set = new HashSet<>(); static void deepestLeaves(TreeNode root, int cur_depth, int depth) { if(root == null)return; if(cur_depth == depth)set.add(root.val); deepestLeaves(root.left,cur_depth+1,depth); deepestLeaves(root.right,cur_depth+1,depth); } public static void print(TreeNode root) { if(root == null)return; System.out.print(root.val+" "); System.out.println("er"); print(root.left); print(root.right); } public static HashSet<Integer>original(TreeNode root){ int d = depth(root); deepestLeaves(root,0,d); return set; } static HashSet<Integer>set1 = new HashSet<>(); static void leaves(TreeNode root) { if(root == null)return; if(root.left == null && root.right == null)set1.add(root.val); leaves(root.left); leaves(root.right); } public static boolean check(HashSet<Integer>s, HashSet<Integer>s1) { if(s.size() != s1.size())return false; for(int a : s) { if(!s1.contains(a))return false; } return true; } static TreeNode subTree; public static void smallest_subTree(TreeNode root) { if(root == null)return; smallest_subTree(root.left); smallest_subTree(root.right); set1 = new HashSet<>(); leaves(root); boolean smallest = check(set,set1); if(smallest) { subTree = root; return; } } public static TreeNode answer(TreeNode root) { smallest_subTree(root); return subTree; } } static class Key<K1, K2> { public K1 key1; public K2 key2; public Key(K1 key1, K2 key2) { this.key1 = key1; this.key2 = key2; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Key key = (Key) o; if (key1 != null ? !key1.equals(key.key1) : key.key1 != null) { return false; } if (key2 != null ? !key2.equals(key.key2) : key.key2 != null) { return false; } return true; } @Override public int hashCode() { int result = key1 != null ? key1.hashCode() : 0; result = 31 * result + (key2 != null ? key2.hashCode() : 0); return result; } @Override public String toString() { return "[" + key1 + ", " + key2 + "]"; } } public static int sumOfDigits (long n) { int sum = 0; while(n > 0) { sum += n%10; n /= 10; } return sum; } public static void swap(int []ar, int i, int j) { for(int k= j; k >= i; k--) { int temp = ar[k]; ar[k] = ar[k+1]; ar[k+1] = temp; } } public static int findOr(int[]bits){ int or=0; for(int i=0;i<32;i++){ or=or<<1; if(bits[i]>0) or=or+1; } return or; } public static boolean[] getSieve(int n) { boolean[] isPrime = new boolean[n+1]; for (int i = 2; i <= n; i++) isPrime[i] = true; for (int i = 2; i*i <= n; i++) if (isPrime[i]) for (int j = i; i*j <= n; j++) isPrime[i*j] = false; return isPrime; } public static Long gcd(Long a, Long b) { if (a == 0) return b; return gcd(b%a, a); } static long nextPrime(long n) { boolean found = false; long prime = n; while(!found) { prime++; if(isPrime(prime)) found = true; } return prime; } // method to return LCM of two numbers static Long lcm(Long a, Long b) { return (a / gcd(a, b)) * b; } static boolean isPrime(long n) { if(n <= 1)return false; if(n <= 3)return true; if(n%2 == 0 || n%3 == 0)return false; for(int i = 5; i*i <= n; i+= 6) { if(n%i == 0 || n%(i+2) == 0) return false; } return true; } static int countGreater(int arr[], int n, int k){ int l = 0; int r = n - 1; // Stores the index of the left most element // from the array which is greater than k int leftGreater = n; // Finds number of elements greater than k while (l <= r) { int m = l + (r - l) / 2; // If mid element is greater than // k update leftGreater and r if (arr[m] > k) { leftGreater = m; r = m - 1; } // If mid element is less than // or equal to k update l else l = m + 1; } // Return the count of elements greater than k return (n - leftGreater); } static ArrayList<Integer>printDivisors(int n){ ArrayList<Integer>list = new ArrayList<>(); for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { // If divisors are equal, print only one if (n/i == i) list.add(i); else // Otherwise print both list.add(i); list.add(n/i); } } return list; } static void leftRotate(int l, int r,int arr[], int d) { for (int i = 0; i < d; i++) leftRotatebyOne(l,r,arr); } static void leftRotatebyOne(int l, int r,int arr[]) { int i, temp; temp = arr[l]; for (i = l; i < r; i++) arr[i] = arr[i + 1]; arr[r] = temp; } static class pairInPq<F extends Comparable<F>, S extends Comparable<S>> implements Comparable<pairInPq<F, S>> { private F first; private S second; public pairInPq(F first, S second){ this.first = first; this.second = second; } public F getFirst(){return first;} public S getSecond(){return second;} // All the code you already have is fine @Override public int compareTo(pairInPq<F, S> o) { int retVal = getSecond().compareTo(o.getSecond()); if (retVal != 0) { return retVal; } return getFirst().compareTo(o.getFirst()); } } static long modInverse(long a, long m) { long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient long q = a / m; long t = m; // m is remainder now, process // same as Euclid's algo m = a % m; a = t; t = y; // Update x and y y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } static long power(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static TreeNode buildTree(TreeNode root,int []ar, int l, int r){ if(l > r)return null; int len = l+r; if(len%2 != 0)len++; int mid = (len)/2; int v = ar[mid]; TreeNode temp = new TreeNode(v); root = temp; root.left = buildTree(root.left,ar,l,mid-1); root.right = buildTree(root.right,ar,mid+1,r); return root; } static int LIS(int arr[], int n) { int lis[] = new int[n]; int i, j, max = 0; /* Initialize LIS values for all indexes */ for (i = 0; i < n; i++) lis[i] = 1; /* Compute optimized LIS values in bottom up manner */ for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (arr[i] >= arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1; /* Pick maximum of all LIS values */ for (i = 0; i < n; i++) if (max < lis[i]) max = lis[i]; return max; } static void permuteString(String s , String answer) { if (s.length() == 0) { System.out.print(answer + " "); return; } for(int i = 0 ;i < s.length(); i++) { char ch = s.charAt(i); String left_substr = s.substring(0, i); String right_substr = s.substring(i + 1); String rest = left_substr + right_substr; permuteString(rest, answer + ch); } } static boolean isPowerOfTwo(long n) { if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static class Pair1{ long x; long y; public Pair1(long x, long y) { this.x = x; this.y = y; } } static class Pair { int x; int y; // Constructor public Pair(int x, int y) { this.x = x; this.y = y; } } static class Sorting implements Comparator<Pair>{ public int compare(Pair p1, Pair p2){ if(p1.x==p2.x){ return p1.y-p2.y; } return p1.x - p2.x; } } static class Compare1{ static void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.x - p2.x; } }); } } static int min; static int max; static LinkedList<Integer>[]adj; static int n; static void insertlist(int n) { for(int i = 0; i <= n; i++) { adj[i] = new LinkedList<>(); } } static int []ar; static HashMap<Key,Integer>map; static ArrayList<Integer>list; static int dfs(int parent, int child,LinkedList<Integer>[]adj) { list.add(parent); for(int a : adj[parent]) { if(vis[a] == false) { vis[a] = true; return 1+dfs(a,parent,adj); } } return 0; } static StringTokenizer st; static BufferedReader ob; static int [] readarrayInt( int n)throws IOException { st = new StringTokenizer(ob.readLine()); int []ar = new int[n]; for(int i = 0; i < n; i++) { ar[i] = Integer.parseInt(st.nextToken()); } return ar; } static long [] readarrayLong( int n)throws IOException { st = new StringTokenizer(ob.readLine()); long []ar = new long[n]; for(int i = 0; i < n; i++) { ar[i] = Long.parseLong(st.nextToken()); } return ar; } static int readInt()throws IOException { return Integer.parseInt(ob.readLine()); } static long readLong()throws IOException { return Long.parseLong(ob.readLine()); } static int nextTokenInt() { return Integer.parseInt(st.nextToken()); } static long nextTokenLong() { return Long.parseLong(st.nextToken()); } static int root(int u) { if(ar[u] == -1)return -1; if(u == ar[u]) { return u; } return root(ar[u]); } static Pair []pairar; static int numberOfDiv(long num) { int c = 0; for(int i = 1; i <= Math.sqrt(num ); i++) { if(num%i == 0) { long d = num/i; if( d == i)c++; else c += 2; } } return c; } static long ans; static int count; static boolean []computed; static void NoOfWays(int n) { if(n == 0 ) { count++; } if(n <= 0)return; for(int i = 1; i <= n; i++) { if(n+i <= n) NoOfWays(n-i); } } static boolean binarylistsearch( List<Integer>list, int l, int r, int s, int e) { if(s > e)return false; int mid = (s+e)/2; if(list.get(mid) >= l && list.get(mid) < r) { return true; }else if(list.get(mid) > r) { return binarylistsearch(list,l,r,s,mid-1); }else if(list.get(mid) < l) { return binarylistsearch(list,l,r,mid+1,e); } return false; } static int [][] readmatrix(int r, int c)throws IOException{ int [][]mat = new int[r][c]; for(int i = 0; i < r; i++) { st = new StringTokenizer(ob.readLine()); for(int j = 0; j < c; j++) { mat[i][j] = nextTokenInt(); } } return mat; } static HashSet<Integer>set1; static boolean possible; static int c = 0; static void isbeautiful(HashSet<Integer>s,int num, List<Integer>good, int i, int x, int count) { if(c == 2) { possible = true; return; } if(num >x || i == good.size())return; if(num > x)return; if(i >= good.size())return; for(int j = i; j < good.size(); j++) { if(!map.containsKey(new Key(num,good.get(j))) && !map.containsKey(new Key(good.get(j),num))){ if(s.contains(num) && s.contains(good.get(j))) map.put(new Key (num,good.get(j)),1); isbeautiful(s,num*good.get(j),good,i,x,count); } } } static long sum; static long mod; static void recur(HashSet<Integer>set,HashMap<Integer,HashSet<Integer>>map, int n, int j) { if(j > n)return; int v = 0; for(int a : set) { if(map.get(j).contains(a)) { v++; } } long d = map.get(j).size()-v; sum = (sum*d)%mod; HashSet<Integer> temp = map.get(j); for(int num : temp) { if(!set.contains(num)) { set.add(num); recur(set,map,n,j+1); set.remove(num); } } } static int key1; static int key2; static HashSet<Integer>set; public static TreeNode lowestCommonAncestor(TreeNode root) { if(root == null)return null; TreeNode left = lowestCommonAncestor(root.left); TreeNode right =lowestCommonAncestor(root.right); if(left == null && right != null) { System.out.println(right.val); return right; }else if(right == null && left != null) { System.out.println(left.val); return left; }else if(left == null && right == null) { return null; }else { System.out.println(root.val); return root; } } static ArrayList<Integer>res; static boolean poss = false; public static void recur1 (char []ar, int i) { if(i >= ar.length) { boolean isPalindrome = false; for(int k = 0; k < ar.length; k++) { for(int j = 0; j < ar.length; j++) { if(j-k+1 >= 5) { int x = k; int y = j; while(x < y && ar[x] == ar[y]) { x++; y--; } if(x == y || x > y) { isPalindrome = true; } } } } if(!isPalindrome) { poss = true; } } if(i < ar.length && ar[i] == '?' ) { ar[i] = '0'; recur1(ar,i+1); ar[i] = '?'; } if(i < ar.length && ar[i] == '?') { ar[i] = '1'; recur1(ar,i+1); ar[i] = '?'; } if(i < ar.length && ar[i] != '?') { recur1(ar,i+1); } } static int []theArray; static int rotate(int []ar, int element, int i) { int count = 0; while(ar[i] != element) { int last = ar[i]; count++; int prev = ar[1]; for(int j = 2; j <= i; j++) { int temp = ar[j]; ar[j] = prev; prev = temp; } ar[1] = prev; } return count; } static int []A; static long nth(long max, long min, int n){ long mod = 1000000007; if(max%min == 0){ System.out.println(min*n); return (min*n)%mod; }else{ long d = max/min; d++; long e = n/d; long ans = (max*e)%mod; long r = n%d; long div = (ans/min); long temp = (div*min); long f = (temp*r)%mod; ans = f; if(temp == ans){ ans += min; } System.out.println(ans); return ans; } } public static int index(int k, int l, int r) { if(r-l == 1) { if(ar[r] >= k && ar[l] < k) { return l; } }else if(l >= r){ return l; } int mid = (l+r)/2; if(ar[mid] >= k) { return index(k,l,mid-1); }else { return index(k,mid+1,r); } } public static int remSnakes(int start, int end, int k) { int rem = k-ar[end]; if(start+rem > end ) { return 0; }else { return 1+ remSnakes(start+rem,end-1,k); } } static int N; static int []tree = new int[2*N]; static void build(int []arr,boolean odd) { for(int i = 0; i < N; i++) { tree[N+i] = arr[i]; } for(int i = N-1; i > 0; --i) { int left = i << 1; int right = i << 1|1; if(odd) tree[i] = tree[i<<1]|tree[i<<1|1]; else tree[i] = tree[i<<1]^tree[i<<1|1]; } } // function to update a tree node static void updateTreeNode(int p, int value, boolean odd) { // set value at position p tree[p + N] = value; p = p + N; // move upward and update parents for (int i = p; i > 1; i >>= 1) if(odd) tree[i >> 1] = tree[i] | tree[i^1]; else tree[i >> 1] = tree[i]^tree[i^1]; } static int query(int l ,int r) { int res = 0; //loop to build the sum in the range for(l += N, r += N; l < r; l >>= 1, r >>= 1) { if((l&1) > 0) { res += tree[--r]; } if((r&1) > 0) { res += tree[l++]; } } return res; } static int sum1; static void min_line(int u, int min) { for(int i : adj[u]) { min_line(i,min); } System.out.println(u); } static class Key1 { public final int X; public final int Y; public Key1(final int X, final int Y) { this.X = X; this.Y = Y; } public boolean equals (final Object O) { if (!(O instanceof Key1)) return false; if (((Key1) O).X != X) return false; if (((Key1) O).Y != Y) return false; return true; } public int hashCode() { return (X << 16) + Y; } } static void solve() { int []points = new int[26]; int []top_pos = new int[26]; String []ar = {"ABC"}; Arrays.fill(top_pos, Integer.MAX_VALUE); for(int i = 0; i < ar.length; i++) { String s = ar[i]; for(int j = 0; j < s.length(); j++) { int pos = 97-(s.charAt(j)-'0'); points[pos] += (j); if(j < top_pos[pos]) { top_pos[pos] = j; } } } int i = 0; boolean []vis = new boolean[26]; StringBuilder sb = new StringBuilder(); while(true) { int min = Integer.MAX_VALUE; for(int j = 0; j < 26; j++) { if(vis[j] == false) { min = Math.min(min, points[j]); } } if(min == Integer.MAX_VALUE)break; PriorityQueue<pairInPq>pq = new PriorityQueue<>(); for(int j = 0; j < 26; j++) { if(points[j] == min) { vis[j] = true; char c = (char)(j + 'a'); pq.add(new pairInPq(c,top_pos[j])); } } while(pq.size() > 0) { pairInPq p = pq.poll(); char c = (char)p.first; sb.append(c); } } String res = sb.toString(); res = res.toUpperCase(); System.out.println(res); } static boolean al_sub(String s, String a) { int k = 0; for(int i = 0; i < s.length(); i++) { if(k == a.length())break; if(s.charAt(i) == a.charAt(k)) { k++; } } return k == a.length(); } static String result(String s, String a) { char []s_ar = s.toCharArray(); char []a_ar = a.toCharArray(); StringBuilder sb = new StringBuilder(); if(s.length() < a.length()) { for(int i = 0; i < s.length(); i++) { if(s_ar[i] == '?')s_ar[i] = 'a'; } }else { if(al_sub(s,a)) { return "-1"; }else { int k = 0; char element = 'z'; for(char i = 'a'; i <= 'e'; i++) { char []temp = s.toCharArray(); boolean pos = true;; for(int j = 0; j < s.length(); j++) { if(temp[j] == '?') { temp[j] = i; } } boolean sub = false; k = 0; for(int j = 0; j < s.length(); j++) { if(k == a.length()) { pos = false; break; } if(a_ar[k] == temp[j]) { k++; } } if(pos && k < a.length()) { element = i; break; } } if(element == 'z')return "-1"; for(int i = 0; i < s.length(); i++) { if(s_ar[i] == '?') { s_ar[i] = element; } sb.append(s_ar[i]); } return sb.toString(); } } return "-1"; } static void addNodes(ListNode l, int k) { if(k > 10 )return; ListNode temp = new ListNode(k); l.next = temp; addNodes(l.next,k+1); } static ListNode head; static int listnode_recur(ListNode tail) { if(tail == null )return 0; int n = listnode_recur(tail.next); max = Math.max(max, tail.val+head.val); head = head.next; return max; } static void recursion(int []fill, int len, int []valid, int k) { if(k == len) { int num = 0; for(int i = 0; i < fill.length; i++) { num = (num*10)+fill[i]; } System.out.println(num); if(!set.contains(num)) { set.add(num); } return; } for(int i = 0; i < valid.length; i++) { if(fill[k] == 0) { fill[k] = valid[i]; recursion(fill,len,valid,k+1); fill[k] = 0; }else { recursion(fill,len,valid,k+1); } } } static long minans(Long []ar,Long max) { Long one = 0l; Long two = 0l; for(int i = 0; i < ar.length; i++) { Long d = (max-ar[i])/2; two += d; one += (max-ar[i])%2; } Long ans = 0l; if(one >= two) { ans += (two*2); // System.out.println(one+" "+two+" "+ans); one -= two; if(one > 0) ans += (one*2)-1; }else { ans += (one*2); if(two > 0) { two -= one; Long d = two/3; Long temp = d*3; Long r = two%3; ans += temp; ans += d; if(r == 2) { ans += 3; }else if(r == 1){ ans += 2; } } } if(ans < 0)ans = 0l; // System.out.println(one+" "+two+" "+ans); return ans; } static int binarySearch(long []dif,long left, int s, int e) { if(s > e)return s; int mid = (s+e)/2; if(dif[mid] > left) { return binarySearch(dif,left,s,mid-1); }else { return binarySearch(dif,left,mid+1,e); } } public static ListNode addTwoNumbers(ListNode l1, ListNode l2) { int size1 = getLength(l1); int size2 = getLength(l2); ListNode head = new ListNode(1); // make sure length l1 >= length2 head.next = size1 < size2?helper(l2,l1,size2-size1):helper(l1,l2,size1-size2); if(head.next.val > 9) { head.next.val = head.next.val%10; return head; } return head.next; } public static int getLength(ListNode l1) { int count = 0; while(l1 != null) { l1 = l1.next; count++; } return count; } public static ListNode helper(ListNode l1, ListNode l2, int offset) { if(l1 == null)return null; ListNode result = offset == 0?new ListNode(l1.val+l2.val):new ListNode(l1.val); System.out.println(l1.val+" "+l2.val); ListNode post = offset == 0?helper(l1.next,l2.next,0):helper(l1.next,l2,offset-1); if(post != null && post.val > 9) { result.val += 1; post.val = post.val%10; } result.next = post; return result; } public static ListNode arrayToLinkedList(int []ar, ListNode head) { head = new ListNode(0); head.next = null; ListNode h = head; for(int i = 0; i < ar.length; i++) { ListNode cur = new ListNode(ar[i]); if(h == null) { h = cur; }else{ h.next = cur; h = h.next; } } return head.next; } static Long numLessThanN(Long n, int s, int e,Long []powerful) { if(s >= e) { if(powerful[s] > n)return powerful[s-1]; return powerful[s]; } int mid = (s+e)/2; if(powerful[mid] == n) { return powerful[mid]; }else if(powerful[mid] > n && powerful[mid-1] < n) { return powerful[mid-1]; }else if(powerful[mid] > n){ return numLessThanN(n,0,mid-1,powerful); }else { return numLessThanN(n,mid+1,e,powerful); } } static Long minimumX; static void minX(Long x, Long c) { Long p = 2l; Long a = x; if(x > minimumX)return; if(x == 1)return; while(p*p <= x) { int count = 0; Long num = (long)Math.pow(p, c); Long minx = lcm(num,x); minx = minx/(gcd(num,x)); minimumX = Math.min(minimumX, minx); // System.out.println(minimumX+" "+x+" "+p+" "+num); //System.out.println(minx+" "+"df"+" "+p); if(minx < x) { minX(minx,c); } p++; } } static boolean isConsecutive (List<Integer>list) { for(int i : list) { if(i > 3)return false; } int x = 0; int y = 0; for(int i = 0; i < list.size(); i++) { if(list.get(i) == 2) { x++; }else if(list.get(i) == 3)y++; } if(y >= 2 || x >= 3)return false; if(x > 0 && y > 0)return false; return true; } static int []ismean(int []ar, int one, int minusone, int []temp){ int n = ar.length; for(int i = 1; i < n-1; i++) { if(temp[i] == 1 && temp[i-1] == -1 && one > 0) { one--; temp[i+1] = 1; }else if(temp[i-1] == -1 && temp[i] == -1 && one > 0) { temp[i+1] = 1; one--; }else if(temp[i] == -1 && temp[i-1] == 1 && minusone > 0) { minusone--; temp[i+1] = -1; }else if(temp[i] == 1 && temp[i-1] == 1 && minusone > 0) { minusone--; temp[i+1] = -1; }else { return temp; } } return temp; } static boolean isnottwo(int []ar, int one, int minusone,int temp[]) { int n = ar.length; int []ans = ismean(ar,one,minusone,temp); if(ans[n-1] != -2)return true; return false; } public static long findClosest(long arr[], long target) { int n = arr.length; // Corner cases if (target <= arr[0]) return arr[0]; if (target >= arr[n - 1]) return arr[n - 1]; // Doing binary search int i = 0, j = n, mid = 0; while (i < j) { mid = (i + j) / 2; if (arr[mid] == target) return arr[mid]; /* If target is less than array element, then search in left */ if (target < arr[mid]) { // If target is greater than previous // to mid, return closest of two if (mid > 0 && target > arr[mid - 1]) return getClosest(arr[mid - 1], arr[mid], target); /* Repeat for left half */ j = mid; } // If target is greater than mid else { if (mid < n-1 && target < arr[mid + 1]) return getClosest(arr[mid], arr[mid + 1], target); i = mid + 1; // update i } } // Only single element left after search return arr[mid]; } // Method to compare which one is the more close // We find the closest by taking the difference // between the target and both values. It assumes // that val2 is greater than val1 and target lies // between these two. public static long getClosest(long val1, long val2, long target) { if (target - val1 >= val2 - target) return val2; else return val1; } static int gain(int i) { if(i == 0 || i == n) { return 0; } if(ar[i] > ar[i-1] && ar[i] > ar[i+1] || ar[i] < ar[i-1] && ar[i] < ar[i+1])return 1; return 0; } static int number_of_theif(String s ) { int c = 0; int n = s.length(); int zero = 0; for(char i : s.toCharArray()) { if(i == '?')c++; if(i == '0')zero++; } if(c == n)return n; if(zero == n)return 1; int index = -1; for(int i = 0; i < n; i++) { if(s.charAt(i) == '1') { index = i; } } if(index != -1) { int zero_index = -1; for(int j = index+1; j < n; j++) { if(s.charAt(j) == '0') { zero_index = j; break; } } if(zero_index == -1) { return n-index; }else { return zero_index-index+1; } }else { for(int i = 0; i < n; i++) { if(s.charAt(i) == '0') { return i+1; } } } return 1; } static List<List<Integer>>res0; static int minpath; static void recursion(List<Integer>l, int parent, LinkedList<Integer>[]adj) { if(adj[parent].size() == 0) { l.add(parent); res0.add(new ArrayList(l)); minpath++; return; }else { l.add(parent); recursion(l,adj[parent].get(0),adj); for(int i = 1; i < adj[parent].size(); i++) { recursion(new ArrayList<>(), adj[parent].get(i),adj); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();} } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str = ""; try {str = br.readLine();} catch (IOException e) {e.printStackTrace();} return str; } } static class Node{ int source; int target; int time; public Node(int source, int target) { this.source = source; this.target = target; } } static HashMap<Node,Integer>map1; static void makeSet(int source, int target, int time) { Node node = new Node(source,target); node.source = source; node.target = target; map1.put(node, time); } static class pairForPq implements Comparable<pairForPq>{ Integer value; Integer index; public pairForPq(Integer value, Integer index) { this.value = value; this.index = index; } public int compareTo(pairForPq o) { return value-o.value; } } static long max_score; static boolean []vis; public static void longJump(long []ar,int index, long cur_max, int n) { // System.out.println(cur_max); if(index > n) { max_score = Math.max(max_score,cur_max); return; } if(vis[index] == true) { return; } vis[index] = true; cur_max += ar[index]; int k = (int)ar[index]; int next = index+k; longJump(ar,next,cur_max,n); } static boolean even_sum; static void check_even_sum(int lower_odd, int upper_odd) { if(lower_odd%2 == 0 && upper_odd%2 == 0) { even_sum = true; } } public static void main(String args[])throws IOException { ob = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedOutputStream out = new BufferedOutputStream(System.out); FastReader sc = new FastReader(); FileOutputStream out1 = new FileOutputStream("output.txt"); // BufferedReader ob1 = new BufferedReader(new FileReader("input.txt")); PrintWriter writer = new PrintWriter("output.txt", "UTF-8"); int t = Integer.parseInt(ob.readLine()); while(t --> 0) { int n = Integer.parseInt(ob.readLine()); int sum = 0; StringTokenizer st = new StringTokenizer(ob.readLine()); for(int i = 0; i < n; i++) { int e = Integer.parseInt(st.nextToken()); sum += e-1; } System.out.println(sum%2 != 0?"errorgorn":"maomao90"); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
561dd3995b9c83856c9adf2057889e4b
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static int n; public static void main(String[] args) throws IOException { t = in.iscan(); while (t-- > 0) { n = in.iscan(); long sum = 0; for (int i = 0; i < n; i++) { sum += in.iscan() - 1; } if (sum % 2 == 1) { out.println("errorgorn"); } else { out.println("maomao90"); } } out.close(); } static INPUT in = new INPUT(System.in); static PrintWriter out = new PrintWriter(System.out); private static class INPUT { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar, numChars; public INPUT (InputStream stream) { this.stream = stream; } public INPUT (String file) throws IOException { this.stream = new FileInputStream (file); } public int cscan () throws IOException { if (curChar >= numChars) { curChar = 0; numChars = stream.read (buf); } if (numChars == -1) return numChars; return buf[curChar++]; } public int iscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } int res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public String sscan () throws IOException { int c = cscan (); while (space (c)) c = cscan (); StringBuilder res = new StringBuilder (); do { res.appendCodePoint (c); c = cscan (); } while (!space (c)); return res.toString (); } public double dscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } double res = 0; while (!space (c) && c != '.') { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); res *= 10; res += c - '0'; c = cscan (); } if (c == '.') { c = cscan (); double m = 1; while (!space (c)) { if (c == 'e' || c == 'E') return res * UTILITIES.fast_pow (10, iscan ()); m /= 10; res += (c - '0') * m; c = cscan (); } } return res * sgn; } public long lscan () throws IOException { int c = cscan (), sgn = 1; while (space (c)) c = cscan (); if (c == '-') { sgn = -1; c = cscan (); } long res = 0; do { res = (res << 1) + (res << 3); res += c - '0'; c = cscan (); } while (!space (c)); return res * sgn; } public boolean space (int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } public static class UTILITIES { static final double EPS = 10e-6; public static void sort(int[] a, boolean increasing) { ArrayList<Integer> arr = new ArrayList<Integer>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(long[] a, boolean increasing) { ArrayList<Long> arr = new ArrayList<Long>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static void sort(double[] a, boolean increasing) { ArrayList<Double> arr = new ArrayList<Double>(); int n = a.length; for (int i = 0; i < n; i++) { arr.add(a[i]); } Collections.sort(arr); for (int i = 0; i < n; i++) { if (increasing) { a[i] = arr.get(i); } else { a[i] = arr.get(n-1-i); } } } public static int lower_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound (int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } public static void updateMap(HashMap<Integer, Integer> map, int key, int v) { if (!map.containsKey(key)) { map.put(key, v); } else { map.put(key, map.get(key) + v); } if (map.get(key) == 0) { map.remove(key); } } public static long gcd (long a, long b) { return b == 0 ? a : gcd (b, a % b); } public static long lcm (long a, long b) { return a * b / gcd (a, b); } public static long fast_pow_mod (long b, long x, int mod) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod; return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod; } public static long fast_pow (long b, long x) { if (x == 0) return 1; if (x == 1) return b; if (x % 2 == 0) return fast_pow (b * b, x / 2); return b * fast_pow (b * b, x / 2); } public static long choose (long n, long k) { k = Math.min (k, n - k); long val = 1; for (int i = 0; i < k; ++i) val = val * (n - i) / (i + 1); return val; } public static long permute (int n, int k) { if (n < k) return 0; long val = 1; for (int i = 0; i < k; ++i) val = (val * (n - i)); return val; } // start of permutation and lower/upper bound template public static void nextPermutation(int[] nums) { //find first decreasing digit int mark = -1; for (int i = nums.length - 1; i > 0; i--) { if (nums[i] > nums[i - 1]) { mark = i - 1; break; } } if (mark == -1) { reverse(nums, 0, nums.length - 1); return; } int idx = nums.length-1; for (int i = nums.length-1; i >= mark+1; i--) { if (nums[i] > nums[mark]) { idx = i; break; } } swap(nums, mark, idx); reverse(nums, mark + 1, nums.length - 1); } public static void swap(int[] nums, int i, int j) { int t = nums[i]; nums[i] = nums[j]; nums[j] = t; } public static void reverse(int[] nums, int i, int j) { while (i < j) { swap(nums, i, j); i++; j--; } } static int lower_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= cmp) high = mid; else low = mid + 1; } return low; } static int upper_bound (int[] arr, int hi, int cmp) { int low = 0, high = hi, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > cmp) high = mid; else low = mid + 1; } return low; } // end of permutation and lower/upper bound template } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
daca30c5f21ea5efa9f4958fb752d38e
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Solution{ public static void main(String[] args) { TaskA solver = new TaskA(); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(i, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n= in.nextInt(); int ans=-1*n; for(int i=0;i<n;i++) { ans+=in.nextInt(); } if(ans%2==0) { println("maomao90"); } else { println("errorgorn"); } } } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static int len(long x) { String s=String.valueOf(x); return s.length(); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void printArr(int[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static void printArr(long[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static int[]input(int n){ int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } static int[]input(){ int n= in.nextInt(); int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } //////////////////////////////////////////////////////// static class Pair { int first; int second; Pair(int x, int y) { this.first = x; this.second = y; } } static void sortS(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.second - p2.second; } }); } static void sortF(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.first - p2.first; } }); } ///////////////////////////////////////////////////////////// static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static void println(long c) { out.println(c); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } 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\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
8843249b23ea80f3e0b7e764002a8a48
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.*; import java.io.*; // you can compare with output.txt and expected out public class RoundGlobal20A { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void initIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); RoundGlobal20A sol = new RoundGlobal20A(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; boolean hasMultipleTests = true; initIO(isFileIO); int t = hasMultipleTests? in.nextInt() : 1; for (int i = 1; i <= t; ++i) { int n = in.nextInt(); int[] a = in.nextIntArray(n); if(isDebug){ out.printf("Test %d\n", i); } boolean ans = solve(a); if(ans) out.println("errorgorn"); else out.println("maomao90"); if(isDebug) out.flush(); } in.close(); out.close(); } private boolean solve(int[] a) { // return true if first player wins // ai -> need ai-1 cutting int n = a.length; int sum = 0; for(int i=0; i<n; i++) { sum += a[i]-1; } return (sum&1) == 1; } int[] solve(){ return null; } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[][] nextTreeEdges(int n, int offset){ int[][] e = new int[n-1][2]; for(int i=0; i<n-1; i++){ e[i][0] = nextInt()+offset; e[i][1] = nextInt()+offset; } return e; } int[][] nextMatrix(int n, int m) { return nextMatrix(n, m, 0); } int[][] nextMatrix(int n, int m, int offset) { int[][] mat = new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[i][j] = nextInt()+offset; } } return mat; } int[][] nextPairs(int n){ return nextPairs(n, 0); } int[][] nextPairs(int n, int offset) { int[][] xy = new int[2][n]; for(int i=0; i<n; i++) { xy[0][i] = nextInt() + offset; xy[1][i] = nextInt() + offset; } return xy; } int[][] nextGraphEdges(){ return nextGraphEdges(0); } int[][] nextGraphEdges(int offset) { int m = nextInt(); int[][] e = new int[m][2]; for(int i=0; i<m; i++){ e[i][0] = nextInt()+offset; e[i][1] = nextInt()+offset; } return e; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } public void printlnAns(boolean ans) { if(ans) println(YES); else println(NO); } public void printAns(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(long[] arr){ printAns(arr); println(); } public void printAns(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(int[] arr){ printAns(arr); println(); } public <T> void printAns(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void printlnAns(ArrayList<T> arr){ printAns(arr); println(); } public void printAns(int[] arr, int add){ if(arr != null && arr.length > 0){ print(arr[0]+add); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]+add); } } } public void printlnAns(int[] arr, int add){ printAns(arr, add); println(); } public void printAns(ArrayList<Integer> arr, int add) { if(arr != null && arr.size() > 0){ print(arr.get(0)+add); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)+add); } } } public void printlnAns(ArrayList<Integer> arr, int add){ printAns(arr, add); println(); } public void printlnAnsSplit(long[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public void printlnAnsSplit(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void printlnAnsSplit(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private void permutateAndSort(int[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); int temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][][] constructDirectedNeighborhood(int n, int[][] e){ int[] inDegree = new int[n]; int[] outDegree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outDegree[u]++; inDegree[v]++; } int[][] inNeighbors = new int[n][]; int[][] outNeighbors = new int[n][]; for(int i=0; i<n; i++) { inNeighbors[i] = new int[inDegree[i]]; outNeighbors[i] = new int[outDegree[i]]; } int[] inIdx = new int[n]; int[] outIdx = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outNeighbors[u][outIdx[u]++] = v; inNeighbors[v][inIdx[v]++] = u; } return new int[][][] {inNeighbors, outNeighbors}; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; int[] idx = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][idx[u]++] = v; neighbors[v][idx[v]++] = u; } return neighbors; } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
82db113ee26ce432cee020759de0546a
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
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; import java.util.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int testNum = in.nextInt(); solver.solve(testNum, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { for (int z = 0; z < testNumber; z++) { int n = in.nextInt(); int[] a = new int[n]; long sum = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); sum += a[i] - 1; } if (sum % 2== 1) { out.println("errorgorn"); } else { out.println("maomao90"); } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
6fc6ba851d0e047deffcac741b6be02f
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-- > 0) { int n = scanner.nextInt(), sum = 0; for(int i = 0; i < n; ++i) sum += scanner.nextInt()-1; if(sum%2 == 1) System.out.println("errorgorn"); else System.out.println("maomao90"); } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
272ca90c6eb24404989d8a462fb79881
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
256 megabytes
//Some of the methods are copied from GeeksforGeeks Website import java.util.*; import java.lang.*; import java.io.*; public class Main { //static Scanner sc=new Scanner(System.in); static Reader sc=new Reader(); // static FastReader sc=new FastReader(System.in); static long mod = (long)(1e9)+ 7; static int max_num=(int)1e5+5; public static void main (String[] args) throws java.lang.Exception { try{ /* Collections.sort(al,(a,b)->a.x-b.x); Collections.sort(al,Collections.reverseOrder()); long n=sc.nextLong(); String s=sc.next(); char a[]=s.toCharArray(); StringBuilder sb=new StringBuilder(); map.put(a[i],map.getOrDefault(a[i],0)+1); out.println("Case #"+tt+": "+ans ); */ int t = sc.nextInt(); for(int tt=1;tt<=t;tt++) { int n=sc.nextInt(); PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder()); for(int i=0;i<n;i++) { int x=sc.nextInt(); if(x!=1) pq.add(x); } boolean f=false; while(!pq.isEmpty()) { int top=pq.poll(); int now=top-1; if(now>1) pq.add(now); f=!f; } flag(f); } out.flush(); out.close(); } catch(Exception e) {} } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static void flag(boolean flag) { out.println(flag ? "errorgorn" : "maomao90"); out.flush(); } /* Map<Long,Long> map=new HashMap<>(); for(int i=0;i<n;i++) { if(!map.containsKey(a[i])) map.put(a[i],1); else map.replace(a[i],map.get(a[i])+1); } Set<Map.Entry<Long,Long>> hmap=map.entrySet(); for(Map.Entry<Long,Long> data : hmap) { } Iterator<Integer> itr = set.iterator(); while(itr.hasNext()) { int val=itr.next(); } */ // static class Pair // { // int x,y; // Pair(int x,int y) // { // this.x=x; // this.y=y; // } // } // Arrays.sort(p, new Comparator<Pair>() // { // @Override // public int compare(Pair o1,Pair o2) // { // if(o1.x>o2.x) return 1; // else if(o1.x==o2.x) // { // if(o1.y>o2.y) return 1; // else return -1; // } // else return -1; // }}); static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static void DFS(ArrayList<Integer> graph[],boolean[] visited, int u) { visited[u]=true; int v=0; for(int i=0;i<graph[u].size();i++) { v=graph[u].get(i); if(!visited[v]) DFS(graph,visited,v); } } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long nCr(long a,long b,long mod) { return (((fact[(int)a] * modInverse(fact[(int)b],mod))%mod * modInverse(fact[(int)(a - b)],mod))%mod + mod)%mod; } static long fact[]=new long[max_num]; static void fact_fill() { fact[0]=1l; for(int i=1;i<max_num;i++) { fact[i]=(fact[i-1]*(long)i); if(fact[i]>=mod) fact[i]%=mod; } } static long modInverse(long a, long m) { return power(a, m - 2, m); } static long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (long)((p * (long)p) % m); if (y % 2 == 0) return p; else return (long)((x * (long)p) % m); } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } // Thank You !
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
1ed39e6003338ddee26a9769817572af
train_108.jsonl
1650722700
There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
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) throws Exception { Reader reader = new Reader(); int t = reader.nextInt(); while(t-- > 0){ var n = reader.nextInt(); PriorityQueue<Integer> q = new PriorityQueue<>((a,b) -> b - a); while(n-- > 0) q.offer(reader.nextInt()); solve(q); } } private static void solve(PriorityQueue<Integer> q) { boolean err = true; while(!q.isEmpty() && q.peek() != 1){ var poll = q.poll(); var res = poll / 2; q.offer(res); if(poll % 2 == 0){ q.offer(res); }else{ q.offer(poll - res); } err = !err; } System.out.println(!err ? "errorgorn" : "maomao90"); } static class Reader{ BufferedReader bufferedReader; StringTokenizer stringTokenizer; Reader(){ bufferedReader = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(stringTokenizer == null || !stringTokenizer.hasMoreElements()){ try{ stringTokenizer = new StringTokenizer(bufferedReader.readLine()); }catch (Exception e){ System.out.println(e.getMessage()); } } return stringTokenizer.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String s = ""; try{ s = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } }
Java
["2\n\n4\n\n2 4 2 1\n\n1\n\n1"]
1 second
["errorgorn\nmaomao90"]
NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
Java 11
standard input
[ "games", "implementation", "math" ]
fc75935b149cf9f4f2ddb9e2ac01d1c2
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.
800
For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).
standard output
PASSED
30fd6ef9fadeced1f10a2dc286f9f0b7
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class file { public static void main(String args[]) { long t;int i,a=0,b=0; String s; Scanner x=new Scanner(System.in); t=x.nextLong(); while(t>0) { t--; s=x.next(); for(i=0;i<s.length();i++) { if(s.charAt(i)=='A') a++; else b++; if(b>a) break; } if(a>=b && s.charAt(0)=='A' && s.charAt(s.length()-1)=='B') System.out.println("YES"); else System.out.println("NO"); a=0; b=0; }}}
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
48c19120787be343bf77f06d44ed2235
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc > 0){ tc--; String s = sc.next(); int ca = 0; int cb = 0; int n = s.length(); boolean got = true; if(n == 1 || s.charAt(0)=='B' || s.charAt(n-1) == 'A') System.out.println("NO"); else{ for(int i = 0; i < n; i++){ if(s.charAt(i) == 'A'){ ca++; }else{ cb++; } if(cb > ca){ got = false; } } if(got) System.out.println("YES"); else System.out.println("NO"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
88d36051c8a1b148a5dc77ac644158a4
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.*; public class OptimalReduction { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); while(t>0){ tinh(); t=t-1; } } public static void tinh(){ String s = sc.next(); int check =1; int demA=0; int demB=0; for(int i =0; i<s.length(); i++){ if(s.charAt(i)=='A'){ demA++; } if(s.charAt(i)=='B'){ demB++; } } int demA1=0; int demB1 =0; for(int i=0; i<s.length(); i++){ if(s.charAt(i)=='A'){ demA1++; } if(s.charAt(i)=='B'){ demB1++; } if(demA1 < demB1){ check=0; break; } } if(demA == 0 || demB==0 || demB > demA || s.charAt(0) == 'B' || s.charAt(s.length()-1) == 'A' || check ==0){ System.out.println("NO"); }else{ System.out.println("YES"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
abfb44cf362effa2d3d147409d8e46f3
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class Testing { public static void main(String[] args) { Scanner s = new Scanner (System.in); int t=s.nextInt(); for(int i=0;i<t;i++){ StringBuilder input = new StringBuilder (s.next()); if(input.length()==1||input.charAt(0)=='B'||input.charAt(input.length()-1)=='A'){ System.out.println("NO"); } else { for(int j=1;j<input.length();j++){ if(input.charAt(j)=='B'&&input.charAt(j-1)=='A') { input.delete(j-1, j+1); //System.out.println(input); j-=2; if (j<0) j=0; } } if (input.toString().contains("B")) System.out.println("NO"); else System.out.println("yes"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
ceea775427ec0795d7ba37e0aefeb191
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); int tc = fs.nextInt(); while (tc > 0) { stack<Character> s = new stack<>(); String t = fs.next(); for (int i = 0; i < t.length(); i++) { if (!s.isEmpty() && t.charAt(i) == 'B' && s.top() == 'A') { s.pop(); continue; } s.push(t.charAt(i)); } int c = 0, x = 0; while (!s.isEmpty()) { if (s.top() == 'A') c++; x++; s.pop(); } if (c == x && t.length() > 1 && t.charAt(t.length() - 1) == 'B') System.out.println("YES"); else System.out.println("NO"); tc--; } } static class node<T> { public T val; public node<T> next; } static class stack<T> { private node<T> tp; private int s; public stack() { } public void push(T x) { if (s == 0) { tp = new node<>(); tp.val = x; } else { node<T> n = new node<>(); n.val = x; n.next = tp; tp = n; } s++; } public void pop() { if (s == 0) { return; } else { tp = tp.next; } s--; } public boolean isEmpty() { return s == 0; } public T top() { return tp.val; } } static class Pair<K, V> { private K first; private V second; Pair() { } public void put(K first, V second) { this.first = first; this.second = second; } public K getFirst() { return this.first; } public V getSecond() { return this.second; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public FastScanner() { try { String filename = this.getClass().getEnclosingClass().getSimpleName(); br = new BufferedReader(new FileReader(new File(filename + ".in"))); } catch (Exception e) { System.err.println("Using standard input instead."); br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
34f1802f487c5e503aa00800cae457ce
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class Solution { static int mod=(int)998244353; public static void main(String[] args) { Copied io = new Copied(System.in, System.out); // int k=1; int t = 1; t = io.nextInt(); for (int i = 0; i < t; i++) { // io.print("Case #" + k + ": "); solve(io); // k++; } io.close(); } public static void solve(Copied io) { String s = io.next(); int nA = 0, nB = 0; boolean ans = true; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == 'A') { nA++; }else { nB++; } ans &= (nA >= nB); } binaryOutput(ans && s.charAt(s.length() - 1) == 'B' && s.charAt(0) == 'A', io); } static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static void binaryOutput(boolean ans, Copied io){ String a=new String("YES"), b=new String("NO"); if(ans){ io.println(a); } else{ io.println(b); } } static int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void printArr(int[] arr,Copied io) { for (int x : arr) io.print(x + " "); io.println(); } static void printArr(long[] arr,Copied io) { for (long x : arr) io.print(x + " "); io.println(); } static int[] listToInt(ArrayList<Integer> a){ int n=a.size(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=a.get(i); } return arr; } static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} } class Pair implements Cloneable, Comparable<Pair> { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+101*Math.abs(y); } @Override public String toString() { return "("+x+" "+y+")"; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } } class byY implements Comparator<Pair>{ // @Override public int compare(Pair o1,Pair o2){ // -1 if want to swap and (1,0) otherwise. int t= o1.y-o2.y; if(t!=0) return t; else return o1.x-o2.x; } } class byX implements Comparator<Pair>{ // @Override public int compare(Pair o1,Pair o2){ // -1 if want to swap and (1,0) otherwise. int t= o1.x-o2.x; if(t!=0) return t; else return o1.y-o2.y; } } class DescendingOrder<T> implements Comparator<T>{ @Override public int compare(Object o1,Object o2){ // -1 if want to swap and (1,0) otherwise. int addingNumber=(Integer) o1,existingNumber=(Integer) o2; if(addingNumber>existingNumber) return -1; else if(addingNumber<existingNumber) return 1; else return 0; } } class Copied extends PrintWriter { public Copied(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Copied(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public String next() { return nextToken(); } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 17
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
759351a1ed2d72bd372f77fa5dbb67d9
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class AAAB{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); for(int c=0;c<t;c++){ String s = sc.nextLine(); boolean b = true; int sum = 0; if(s.charAt(s.length()-1)=='B'){ for(int i = 0;i<s.length();i++){ if(s.charAt(i) == 'B'){ sum--; }else { sum++; } if (sum<0) b = false; } }else{ b = false; } if(b){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
28827ac42c20d9a4f97095b8bc25ef58
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class AAAB{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); for(int c=0;c<t;c++){ String s = sc.nextLine(); boolean b; int sum = 0; if(s.charAt(s.length()-1)=='B'){ b = true; }else{ b = false; } for(int i = 0;i<s.length();i++){ if(s.charAt(i) == 'B'){ sum--; }else sum ++; if (sum<0) b = false; } if(b){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
57afa97031caa4574c50b1fea3a4f3ea
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class c { public static void main(String[] args) { int a = 0, b = 0; long t; String str; Scanner sc = new Scanner(System.in); t = sc.nextLong(); while (t != 0) { t--; str = sc.next(); // reads string for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'A') a++; else b++; if(b>a) break; } if (a >= b && str.charAt(0) == 'A' && str.charAt(str.length() - 1) == 'B') System.out.println("YES"); else System.out.println("NO"); a =b = 0; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
39a8351ca90f3153b14d505f6d71822b
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class c { public static void main(String[] args) { int a = 0, b = 0; long t; String str; Scanner sc = new Scanner(System.in); t = sc.nextLong(); while (t != 0) { t--; str = sc.next(); // reads string for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'A') a++; else b++; if(b>a) break; } if (a >= b && str.charAt(0) == 'A' && str.charAt(str.length() - 1) == 'B') System.out.println("YES"); else System.out.println("NO"); a = 0; b = 0; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
79a2ce015c6c7e2c84762b5ba2221e0c
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class c { public static void main(String[] args) { int a = 0, b = 0, i = 0; long t; String str; Scanner sc = new Scanner(System.in); t = sc.nextLong(); while (t != 0) { str = sc.next(); // reads string t--; for (i = 0; i < str.length(); i++) { if (str.charAt(i) == 'A') a++; else b++; if(b>a) break; } if (a >= b && str.charAt(0) == 'A' && str.charAt(str.length() - 1) == 'B') System.out.println("YES"); else System.out.println("NO"); a = 0; b = 0; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
26af107b9b239d2c891e5b6eb2571f2a
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class c { public static void main(String[] args) { int a = 0, b = 0, i = 0; long t; String str; Scanner sc = new Scanner(System.in); t = sc.nextLong(); while (t != 0) { t--; str = sc.next(); // reads string for (i = 0; i < str.length(); i++) { if (str.charAt(i) == 'A') a++; else b++; if(b>a) break; } if (a >= b && str.charAt(0) == 'A' && str.charAt(str.length() - 1) == 'B') System.out.println("YES"); else System.out.println("NO"); a = 0; b = 0; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
6d23afbeea13fbc1856cda807d273c66
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class b { public static void main(String args[]) { long t;int i,a=0,b=0; String s; Scanner x=new Scanner(System.in); t=x.nextLong(); while(t>0) { t--; s=x.next(); for(i=0;i<s.length();i++) { if(s.charAt(i)=='A') a++; else b++; if(b>a) break; } if(a>=b && s.charAt(0)=='A' && s.charAt(s.length()-1)=='B') System.out.println("YES"); else System.out.println("NO"); a=0; b=0; }}}
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
00fc67a3d72e4348c3020b452bcd5a0f
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Solution { /* public static void main(String[]args){ Scanner sc= new Scanner(System.in); String s=sc.nextLine(); String[]arr=s.split("W+"); System.out.println(arr.length); for (int i = 0 ; i < arr.length;i++){ System.out.println(arr[i].length()); System.out.println(arr[i]); } }*/ /* public static void main(String [] args){ Scanner sc= new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while (t>0) { t--; String s=sc.nextLine(); char arr[]=s.toCharArray(); boolean As=false; boolean Bs=false; if(arr[0]=='B'){ System.out.println("NO"); continue; } if(arr[arr.length-1]=='A'){ System.out.println("NO"); continue; } int counta=0; int countb=0; boolean error=false; Stack<Integer>stack=new Stack<>(); for (int i = 0 ; i < arr.length;i++){ if(arr[i]=='A'){ As=true; counta++; if(arr[i+1]=='B'){ stack.push(counta); counta=0; } } if(arr[i]=='B'){ Bs=true; countb++; if(i+1==arr.length||(i+1<arr.length && arr[i+1]=='A')){ stack.push(countb); countb=0; } } } while(!stack.empty()){ int x=stack.pop(); int y=stack.pop(); if(x>y){ error=true; break; } } if(As^Bs){ System.out.println("NO"); }else if(error){ System.out.println("NO"); }else{ System.out.println("YES"); } } }*/ public static void main(String [] args){ Scanner sc= new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while (t>0) { t--; String s=sc.nextLine(); char ar[]=s.toCharArray(); boolean ok=true; int a=0; int b=0; for (int i = 0 ; i < ar.length ; i++){ if(ar[i]=='A')a++; else if(ar[i]=='B')b++; if(b>a)ok=false; } if(ar[ar.length-1]!='B')ok =false; if(ok) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
e345ec487535cd8154d7ce12e46f9398
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class loveAAB { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t, ca = 0; boolean kq; t = Integer.parseInt(sc.nextLine()); String a; String b; while (t-- != 0) { a = sc.nextLine(); kq = true; ca = 0; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) == 'A') { ca++; } if (a.charAt(i) == 'B') { ca--; if (ca < 0) { kq = false; } } } if (a.charAt(0) == 'B') { kq = false; } if (a.charAt(a.length() - 1) == 'A') { kq = false; } if (kq == false) { System.out.println("NO"); } else { System.out.println("YES"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
5cecbb78c4cb738c8567a4c449e4f01c
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class B_I_love_AAAB { static Scanner in = new Scanner(); static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans = new StringBuilder(); static int testCases, n; static char a[]; static int count[]; static boolean ok = false; static void solve(int i, char a[], int t) { if (i >= n) { return; } /*if (a[i] == 'B' && i != 0) { if ((i - 1 >= 0 && a[i - 1] == 'B') || (i + 1 < n && a[i + 1] == 'B')) { ans.append("NO"); return; } }*/ count[(a[i] - 'A')]++; if (count[1] > count[0]) { //ans.append("NO"); ok = false; return; } solve(i + 1, a, t); } static void solve(int t) { if (n == 1) { ans.append("NO"); count = new int[2]; } else { ok = true; /*if (a[0] == 'B') { ok = false; }*/ if (a[n - 1] == 'A') { ok = false; } /*boolean ok1 = true; for (int i = n - 2; i >= 0; --i) { if (a[i] == 'B') { ok1 = false; break; } } if (ok1) { ans.append("YES"); if (t != testCases) { ans.append("\n"); } return; }*/ count = new int[2]; int prev = ans.length(); solve(0, a, t); int present = ans.length(); if (ok) { ans.append("YES"); } else { ans.append("NO"); } /*else if (!ok && present == prev) { ans.append("NO"); }*/ } if (t != testCases) { ans.append("\n"); } } public static void main(String[] priya) throws IOException { testCases = in.nextInt(); for (int t = 0; t < testCases; ++t) { a = in.next().toCharArray(); n = a.length; solve(t + 1); } out.print(ans.toString()); out.flush(); in.close(); } static boolean isSmaller(String str1, String str2) { int n1 = str1.length(), n2 = str2.length(); if (n1 < n2) { return true; } if (n2 < n1) { return false; } for (int i = 0; i < n1; i++) { if (str1.charAt(i) < str2.charAt(i)) { return true; } else if (str1.charAt(i) > str2.charAt(i)) { return false; } } return false; } static String sub(String str1, String str2) { if (isSmaller(str1, str2)) { String t = str1; str1 = str2; str2 = t; } String str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n1 - n2; int carry = 0; for (int i = n2 - 1; i >= 0; i--) { int sub = (((int) str1.charAt(i + diff) - (int) '0') - ((int) str2.charAt(i) - (int) '0') - carry); if (sub < 0) { sub = sub + 10; carry = 1; } else { carry = 0; } str += String.valueOf(sub); } for (int i = n1 - n2 - 1; i >= 0; i--) { if (str1.charAt(i) == '0' && carry > 0) { str += "9"; continue; } int sub = (((int) str1.charAt(i) - (int) '0') - carry); if (i > 0 || sub > 0) { str += String.valueOf(sub); } carry = 0; } return new StringBuilder(str).reverse().toString(); } static String sum(String str1, String str2) { if (str1.length() > str2.length()) { String t = str1; str1 = str2; str2 = t; } String str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n2 - n1; int carry = 0; for (int i = n1 - 1; i >= 0; i--) { int sum = ((int) (str1.charAt(i) - '0') + (int) (str2.charAt(i + diff) - '0') + carry); str += (char) (sum % 10 + '0'); carry = sum / 10; } for (int i = n2 - n1 - 1; i >= 0; i--) { int sum = ((int) (str2.charAt(i) - '0') + carry); str += (char) (sum % 10 + '0'); carry = sum / 10; } if (carry > 0) { str += (char) (carry + '0'); } return new StringBuilder(str).reverse().toString(); } static long detect_sum(int i, long a[], long sum) { if (i >= a.length) { return sum; } return detect_sum(i + 1, a, sum + a[i]); } static String mul(String num1, String num2) { int len1 = num1.length(); int len2 = num2.length(); if (len1 == 0 || len2 == 0) { return "0"; } int result[] = new int[len1 + len2]; int i_n1 = 0; int i_n2 = 0; for (int i = len1 - 1; i >= 0; i--) { int carry = 0; int n1 = num1.charAt(i) - '0'; i_n2 = 0; for (int j = len2 - 1; j >= 0; j--) { int n2 = num2.charAt(j) - '0'; int sum = n1 * n2 + result[i_n1 + i_n2] + carry; carry = sum / 10; result[i_n1 + i_n2] = sum % 10; i_n2++; } if (carry > 0) { result[i_n1 + i_n2] += carry; } i_n1++; } int i = result.length - 1; while (i >= 0 && result[i] == 0) { i--; } if (i == -1) { return "0"; } String s = ""; while (i >= 0) { s += (result[i--]); } return s; } static class Node<T> { T data; Node<T> next; public Node() { this.next = null; } public Node(T data) { this.data = data; this.next = null; } public T getData() { return data; } public void setData(T data) { this.data = data; } public Node<T> getNext() { return next; } public void setNext(Node<T> next) { this.next = next; } @Override public String toString() { return this.getData().toString() + " "; } } static class ArrayList<T> { Node<T> head, tail; int len; public ArrayList() { this.head = null; this.tail = null; this.len = 0; } int size() { return len; } boolean isEmpty() { return len == 0; } int indexOf(T data) { if (isEmpty()) { throw new ArrayIndexOutOfBoundsException(); } Node<T> temp = head; int index = -1, i = 0; while (temp != null) { if (temp.getData() == data) { index = i; } i++; temp = temp.getNext(); } return index; } void add(T data) { Node<T> newNode = new Node<>(data); if (isEmpty()) { head = newNode; tail = newNode; len++; } else { tail.setNext(newNode); tail = newNode; len++; } } void see() { if (isEmpty()) { throw new ArrayIndexOutOfBoundsException(); } Node<T> temp = head; while (temp != null) { out.print(temp.getData().toString() + " "); out.flush(); temp = temp.getNext(); } out.println(); out.flush(); } void inserFirst(T data) { Node<T> newNode = new Node<>(data); Node<T> temp = head; if (isEmpty()) { head = newNode; tail = newNode; len++; } else { newNode.setNext(temp); head = newNode; len++; } } T get(int index) { if (isEmpty() || index >= len) { throw new ArrayIndexOutOfBoundsException(); } Node<T> temp = head; int i = 0; T data = null; while (temp != null) { if (i == index) { data = temp.getData(); } i++; temp = temp.getNext(); } return data; } void addAt(T data, int index) { if (index >= len) { throw new ArrayIndexOutOfBoundsException(); } Node<T> newNode = new Node<>(data); int i = 0; Node<T> temp = head; while (temp.next != null) { if (i == index) { newNode.setNext(temp.next); temp.next = newNode; } i++; temp = temp.getNext(); } // temp.setNext(temp); len++; } void popFront() { if (isEmpty()) { throw new ArrayIndexOutOfBoundsException(); } if (head == tail) { head = null; tail = null; } else { head = head.getNext(); } len--; } void removeAt(int index) { if (index >= len) { throw new ArrayIndexOutOfBoundsException(); } if (index == 0) { this.popFront(); return; } Node<T> temp = head; int i = 0; Node<T> n = new Node<>(); while (temp != null) { if (i == index) { n.next = temp.next; temp.next = n; break; } i++; n = temp; temp = temp.getNext(); } tail = n; --len; } void clearAll() { this.head = null; this.tail = null; } } static void merge(long a[], int left, int right, int mid) { int n1 = mid - left + 1, n2 = right - mid; long L[] = new long[n1]; long R[] = new long[n2]; for (int i = 0; i < n1; i++) { L[i] = a[left + i]; } for (int i = 0; i < n2; i++) { R[i] = a[mid + 1 + i]; } int i = 0, j = 0, k1 = left; while (i < n1 && j < n2) { if (L[i] <= R[j]) { a[k1] = L[i]; i++; } else { a[k1] = R[j]; j++; } k1++; } while (i < n1) { a[k1] = L[i]; i++; k1++; } while (j < n2) { a[k1] = R[j]; j++; k1++; } } static void sort(long a[], int left, int right) { if (left >= right) { return; } int mid = (left + right) / 2; sort(a, left, mid); sort(a, mid + 1, right); merge(a, left, right, mid); } static class Scanner { BufferedReader in; StringTokenizer st; public Scanner() { in = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } String nextLine() throws IOException { return in.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } void close() throws IOException { in.close(); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
52cb9b068e367b82c5c2e6930185dc36
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.lang.*; import java.io.FileReader; import java.io.IOException; import java.math.BigInteger; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.util.*; import java.util.LinkedList; public class A_769 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void sort(long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- > 0) { char[] ch = sc.next().toCharArray(); boolean ans = true; if(ch.length == 1){ System.out.println("NO"); } else if(ch.length == 2 ){ if(ch[1] == 'B' && ch[0] == 'A'){ System.out.println("YES"); }else System.out.println("NO"); }else if(ch[ch.length-1] != 'B' || ch[0] != 'A'){ System.out.println("NO"); } else{ long a = 0, b = 0; for(char c:ch){ if(c == 'A'){ a++; } if(c == 'B'){ b++; } if(b > a){ ans = false; } } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
22d3c00bedbc2caa5d61fa732d4b6507
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class IloveAAAB { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while (n-- > 0) { String str = sc.next(); boolean f = true; int ifBs = 0; if (str.length() <= 1 || str.charAt(0) == 'B' || str.charAt(str.length()-1) != 'B') f = false; else { for (int i = 0 ; i < str.length() ;i++) { if (str.charAt(i) == 'A') { ifBs++; }else ifBs--; if (ifBs < 0) f = false; } } System.out.println(f ? "YES" : "NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
66e1087e51e31a442c43dd96a92146b2
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class ss { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0) { String s = sc.next(); int a = 0,b = 0; for (int i = 0;i<s.length();i++) { if (s.charAt(i) == 'A') { a+=1; }else { b+=1; } if (b>a) break; } if (a == 0 || b == 0 || b>a || s.charAt(0) == 'B' || s.charAt(s.length()-1) == 'A') { out.println("NO"); }else { out.println("YES"); } } out.close(); } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public 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(); } int[] readArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
e6e8397ef39dafddaf61992a87271a70
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { // Graph // prefix sums //inputs public static void main(String args[])throws Exception{ Input sc=new Input(); precalculates p=new precalculates(); StringBuilder sb=new StringBuilder(); int t=sc.readInt(); for(int f=0;f<t;f++){ String str=sc.readString(); int a=0; int b=0; int n=str.length(); for(int i=0;i<str.length();i++){ if(str.charAt(i)=='A') a++; else b++; if(a<b){ break; } } if(a<b || (b==0) || a==0 || str.charAt(0)=='B' || str.charAt(n-1)=='A') sb.append("NO\n"); else sb.append("YES\n"); } System.out.print(sb); } /* ABBAAB ABABAAABBAABBB AABABAABBB AAABABBAABBB AAABABB */ } class Input{ BufferedReader br; StringTokenizer st; Input(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public int[] readArray() throws Exception{ st=new StringTokenizer(br.readLine()); int a[]=new int[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Integer.parseInt(st.nextToken()); } return a; } public long[] readArrayLong() throws Exception{ st=new StringTokenizer(br.readLine()); long a[]=new long[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Long.parseLong(st.nextToken()); } return a; } public int readInt() throws Exception{ st=new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public long readLong() throws Exception{ st=new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } public String readString() throws Exception{ return br.readLine(); } public int[][] read2dArray(int n,int m)throws Exception{ int a[][]=new int[n][m]; for(int i=0;i<n;i++){ st=new StringTokenizer(br.readLine()); for(int j=0;j<m;j++){ a[i][j]=Integer.parseInt(st.nextToken()); } } return a; } } class precalculates{ public long gcd(long p, long q) { if (q == 0) return p; else return gcd(q, p % q); } public int[] prefixSumOneDimentional(int a[]){ int n=a.length; int dp[]=new int[n]; for(int i=0;i<n;i++){ if(i==0) dp[i]=a[i]; else dp[i]=dp[i-1]+a[i]; } return dp; } public int[] postSumOneDimentional(int a[]) { int n = a.length; int dp[] = new int[n]; for (int i = n - 1; i >= 0; i--) { if (i == n - 1) dp[i] = a[i]; else dp[i] = dp[i + 1] + a[i]; } return dp; } public int[][] prefixSum2d(int a[][]){ int n=a.length;int m=a[0].length; int dp[][]=new int[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; } } return dp; } public long pow(long a,long b){ long mod=998244353; long ans=1; if(b<=0) return 1; if(b%2==0){ ans=pow(a,b/2)%mod; return ((ans%mod)*(ans%mod))%mod; }else{ ans=pow(a,b-1)%mod; return ((a%mod)*(ans%mod))%mod; } } } class GraphInteger{ HashMap<Integer,vertex> vtces; class vertex{ HashMap<Integer,Integer> children; public vertex(){ children=new HashMap<>(); } } public GraphInteger(){ vtces=new HashMap<>(); } public void addVertex(int a){ vtces.put(a,new vertex()); } public void addEdge(int a,int b,int cost){ if(!vtces.containsKey(a)){ vtces.put(a,new vertex()); } if(!vtces.containsKey(b)){ vtces.put(b,new vertex()); } vtces.get(a).children.put(b,cost); // vtces.get(b).children.put(a,cost); } public boolean isCyclicDirected(){ boolean isdone[]=new boolean[vtces.size()+1]; boolean check[]=new boolean[vtces.size()+1]; for(int i=1;i<=vtces.size();i++) { if (!isdone[i] && isCyclicDirected(i,isdone, check)) { return true; } } return false; } private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){ if(check[i]) return true; if(isdone[i]) return false; check[i]=true; isdone[i]=true; Set<Integer> set=vtces.get(i).children.keySet(); for(Integer ii:set){ if(isCyclicDirected(ii,isdone,check)) return true; } check[i]=false; return false; } } class union_find { int n; int[] sz; int[] par; union_find(int nval) { n = nval; sz = new int[n + 1]; par = new int[n + 1]; for (int i = 0; i <= n; i++) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } boolean find(int a, int b) { return root(a) == root(b); } int union(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return 0; if(a==b) return 0; if (sz[a] > sz[b]) { int temp = ra; ra = rb; rb = temp; } par[ra] = rb; sz[rb] += sz[ra]; return 1; } } /* static int mod=998244353; private static int add(int x, int y) { x += y; return x % MOD; } private static int mul(int x, int y) { int res = (int) (((long) x * y) % MOD); return res; } private static int binpow(int x, int y) { int z = 1; while (y > 0) { if (y % 2 != 0) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } private static int inv(int x) { return binpow(x, MOD - 2); } private static int devide(int x, int y) { return mul(x, inv(y)); } private static int C(int n, int k, int[] fact) { return devide(fact[n], mul(fact[k], fact[n-k])); } */
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
518f741ee2f990b1a9ed36b0cbef35f1
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); outer : while (t-- > 0) { char[] c = sc.next().toCharArray(); int n = c.length; if (c[0] == 'B' || n == 1 || c[n-1] == 'A') { out.println("NO"); continue outer; } int sum = 0; for (char x : c) { if (x == 'A') sum++; else sum--; if (sum < 0) { out.println("NO"); continue outer; } } out.println("YES"); } out.close(); } static int INF = Integer.MAX_VALUE; public static int min(int[] a){ int min = INF; int n = a.length; for(int i = 0; i < n; i++) min = Math.min(min, a[i]); return min; } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public 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();} int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
333af11e2e37e617c67c73a787539e69
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/* !!!!Hello World,Prakhar here!!!! codechef handle prakhar_3011 codeforces handle prakhar_30 trying to get good at CP PEACE OUT......... */ /* */ import java.io.*; import java.util.*; public class AAAB { public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { char c[] = sc.next().toCharArray();int sum=0; String ans="YES"; if(c[c.length-1]=='A'){ ans="NO"; } for(int i=0;i<c.length;i++){ if(c[i]=='A') sum++; else sum--; if(sum<0){ ans="NO"; } } System.out.println(ans); } } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void revsort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } /* ......FAST SCANNER template taken from secondthread...... */ static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextdouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
76f0e37513db1e32d0f8b6842f1e2a56
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/* !!!!Hello World,Prakhar here!!!! codechef handle prakhar_3011 codeforces handle prakhar_30 trying to get good at CP PEACE OUT......... */ /* */ import java.io.*; import java.util.*; public class AAAB { public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { char c[] = sc.next().toCharArray();int sum=0; String ans="YES"; if(c[c.length-1]=='A'){ System.out.println("NO"); continue; } for(int i=0;i<c.length;i++){ if(c[i]=='A') sum++; else sum--; if(sum<0){ ans="NO"; } } System.out.println(ans); } } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void revsort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } /* ......FAST SCANNER template taken from secondthread...... */ static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextdouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
33e888813a5851068dd95566784cf6a3
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; import java.util.*; public class B_april{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=Integer.parseInt(sc.nextLine()); while(t-->0) { char[] ch=sc.next().toCharArray(); boolean ans=true; if(ch[0]=='B' || ch[ch.length-1]=='A') ans=false; Stack<Character> st = new Stack<Character>(); if(ch[0]=='A'){ st.push('A'); } for(int i=1;i<ch.length;i++){ if(ch[i] == 'A') st.push('A'); else if(ch[i] == 'B' && st.isEmpty() != true) st.pop(); else if(ch[i] == 'B' && st.isEmpty() == true){ ans = false; break; } } System.out.println(ans?"YES":"NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
60e311af1b5bf012ec0e8509fd7bf497
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class B_1672 { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=Integer.parseInt(sc.nextLine()); while(t-->0) { char[] ch=sc.next().toCharArray(); boolean ans=true; int a=0; int b=0; if(ch[0]=='B' || ch[ch.length-1]=='A') ans=false; for(int i=0;i<ch.length && ans;i++ ) { if(ch[i]=='A') a++; else b++; if(a<b) ans=false; } System.out.println(ans?"YES":"NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
1a8fbce821671d5c446399e44e33765a
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class GoodString { private static boolean solve(String str) { int a = 0; int strLen = str.length(); if(strLen <= 1 || str.charAt(strLen-1) == 'A') { return false; } for(int i=0; i<strLen; i++) { if(str.charAt(i) == 'A') { a++; } else if(a == 0) { return false; } else { a--; } } return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testcases = sc.nextInt(); String s2 = ""; for(int i=0; i<testcases; i++) { s2 = sc.next(); System.out.println(solve(s2) ? "YES" : "NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
e61f3e003b2500021c672bf0be9d343b
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Round20B{ public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while(t-- > 0){ String s = br.readLine(); //1) cant have s.length == 1 //2) cant have s starts with B //3) cant have s contains only with b or a //4) cant have s b more than a long count_a = 0, count_b = 0; String ans = "YES"; for(char c : s.toCharArray()){ if(c == 'A'){ count_a++; } else{ count_b++; } if(count_b > count_a){ ans = "NO"; break; } } if(s.length() == 1){ ans = "NO"; } else if(s.charAt(0) == 'B' || s.charAt(s.length() - 1) == 'A'){ ans = "NO"; } else if(s.length() > 2){ if(s.charAt(0) == 'A' && s.charAt(1) == 'B' && s.charAt(2) == 'B'){ ans = "NO"; } } pw.println(ans); } pw.close(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
8ec41c629a5a0d013cf4e04b5fe842b3
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class Demo4 { public static void main(String[] args) { try { FastReader in = new FastReader(); int testCases = in.nextInt(); while (testCases-- > 0) { String x = in.next(); int acount = 0; int bcount = 0; boolean flag = false; for (int i=0; i<x.length(); i++) { if (x.charAt(i)=='A') { acount++; } else { acount--; } if (acount<0) { flag = true; break; } } if (flag == true || x.length() < 2 || x.charAt(x.length()-1) == 'A' || x.charAt(0) == 'B') { System.out.println("NO"); } else { System.out.println("YES"); } // int acount = 0; // int bcount = 0; // if (x.charAt(0) == 'B' || x.charAt(x.length()-1) == 'A') { // System.out.println("NO"); // continue; // } // boolean prevb = false; // boolean preva = true; // boolean flag = false; // acount++; // int ac = 1; // int bc = 0; // for (int i=1; i<x.length(); i++) { // if (x.charAt(i)=='B') { // preva = false; // prevb = true; // bc++; // bcount++; // } else { // if (prevb == true) { // prevb = false; // preva = true; // ac = 0; // bc = 0; // } // ac++; // acount++; // } // if (bc>ac) { // flag = true; // break; // } // } // if (flag==true) { // System.out.println("NO"); // } else if (bcount==0 || acount==0) { // System.out.println("NO"); // } else if (bcount > acount) { // System.out.println("NO"); // } else { // System.out.println("YES"); // } } } catch (Exception e) { e.printStackTrace(); } } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in));; } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
0292b88edef0e82b2087064921ed05ed
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class amd{ public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { String str=s.next(); int n=str.length(); if(str.charAt(n-1)!='B') { System.out.println("NO"); continue; } int sum=0; boolean p=true; for(int i=0; i<n;i++) { char c=str.charAt(i); if(c=='A') { sum++; }else { sum--; } if(sum<0) { p=false; System.out.println("NO"); break; } } if(p) { System.out.println("YES"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
5ed5e92f3f45a6a752a040ee302e765c
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.*; public class B { 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 swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void main(String[] args) { // TODO Auto-generated method stub FastReader t = new FastReader(); PrintWriter o = new PrintWriter(System.out); int test = t.nextInt(); while (test-- > 0) { String s = t.next(); long max = Integer.MIN_VALUE, min = Integer.MAX_VALUE; int n = s.length(); long a = 0, b = 0; boolean can = true; for (int i = 0; i < n; ++i) { char c = s.charAt(i); if (c == 'A') { // if (i-1>=0 && s.charAt(i-1) == 'B') // { // a = 0; // b = 0; // } a++; } else { a--; } if(a<0) { can = false; break; } } if (can && s.charAt(n-1) == 'B' && s.charAt(0) == 'A') o.println("YES"); else o.println("NO"); } o.flush(); o.close(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
fafb2452b04d1c8d3e1c15cf96207c41
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0) { String s=sc.next(); int f=1; int as=0; int bs=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='B') { as--; if(as==-1) { f=-1; break; } } else { as++; } // System.out.println(i+" "+as); } if(as>=0 && s.charAt(s.length()-1)=='B') { System.out.println("Yes"); } else { System.out.println("No"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
9ebaacdbfcbcba43dc187661778f071c
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] argv) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { String s = sc.next(); if (s.charAt(0) != 'A' || s.charAt(s.length()-1) != 'B') { System.out.println("NO"); continue; } int c = 0; String ans = "YES"; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'A') { c++; } else { c--; if (c < 0) { ans = "NO"; break; } } } System.out.println(ans); } sc.close(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
f9cc5df35c7da87f5b09bfc977cf59c4
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class p1672B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); outer: while (t-- > 0) { char[] in = scan.next().toCharArray(); if (in[0] == 'B' || in[in.length - 1] == 'A') { System.out.println("No"); continue; } int[] dp = new int[in.length]; dp[0] = 1; for (int i = 1; i < in.length; i++) { if (in[i] == 'A') dp[i] = dp[i - 1] + 1; else dp[i] = dp[i - 1] - 1; if (dp[i] < 0) { System.out.println("No"); continue outer; } } System.out.println("Yes"); } } } /* * 20 BBABAAABBABA BBAABBBABABA AABABBBBA AABBABAAAABABABAABAB BBABABABAA * AAABBBBABBBA BBAAAAABBBAA AABBABABBAAB BBABBBBAABAABBAABBAA AABBAABAABBB * AAABBBBABBB BBBAABBBAABB ABBBBABBABA ABBAAAABABBA BAAAABAABAB ABABBAABABA * BABBABABAAAA AAAABABBBBBA AABBAABAAABB BABAAAABAAA BABABBABBBABBBBABBAA * BBBBABBBAAA BAAABABBBABBBAABAAAB AAAAABABBBBB AAAABAAABA AABABAAABBB * BBBBAAAABAA BAAAAABAABBBAAABABBB BABABABBBB ABABBBBAAAAA BAAABBABBABA * BAAAAABBBBBBBAAABAAB BABAAAABABBB */
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
430af94d33a12593616d0350c0b9da67
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class global_20_a { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); loop:while(t-->0) { char ch[]=in.next().toCharArray(); if(ch.length<2 || ch[0]=='B' || ch[ch.length-1]=='A') { out.println("NO"); continue loop; } Stack<Character> s=new Stack<>(); for(char c:ch) { if(!s.isEmpty() && c=='B' && s.peek()=='A') { s.pop(); } else { s.push(c); } } if(s.isEmpty()) out.println("YES"); else{ while(!s.isEmpty()){ if(s.peek()=='B') { out.println("NO"); continue loop; } s.pop(); } out.println("YES"); } } out.close(); } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
a4432d4476bfd7ec6c39789a99b40795
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class B_1672 { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=Integer.parseInt(sc.nextLine()); while(t-->0) { char[] ch=sc.next().toCharArray(); boolean ans=true; int a=0; int b=0; if(ch[0]=='B' || ch[ch.length-1]=='A') ans=false; for(int i=0;i<ch.length && ans;i++ ) { if(ch[i]=='A') a++; else b++; if(a<b) ans=false; } System.out.println(ans?"YES":"NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
df48f30be1895d7ebba7eae087675776
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
//Author : -crazy_coder- import static java.lang.Math.*; import static java.lang.System.out; import java.io.*; import java.util.*; public class Main{ public static void readArray(int[] arr,int st,int length,BufferedReader br)throws Exception{String[] str=br.readLine().split(" "); for(int i=st;i<length;i++){arr[i]=Integer.parseInt(str[i]);}} public static void printArray(int[] arr){for(int i=0;i<arr.length;i++){out.print(arr[i]+" ");}out.println();} public static void primeUsingBits(BitSet bit,int n){bit.flip(0,n+1);bit.set(0,false);bit.set(1,false);for(int i=2;i*i<=n;i++){if(bit.get(i)){for(int j=i*i;j<=n;j+=i){bit.set(j,false);}}}} public static int Gcd(int a,int b){if(b==0)return a;return Gcd(b,a%b);} public static int Lcm(int a,int b){return a*b/Gcd(a,b);} //<---------------------------------------Main Function----------------------------------------> public static void main(String[] args)throws Exception{ BufferedReader br=new BufferedReader(new BufferedReader(new InputStreamReader(System.in))); int t=Integer.parseInt(br.readLine()); // int t=1; while(t-->0){ //write your code here String str=br.readLine(); boolean flag=true; int a=0,b=0; int currB=(str.charAt(0)=='B'?0:-1),prevB=0; int i=0,j=0; for(i=0;i<str.length();i++){ if(str.charAt(i)=='A')a++; else b++; if(a<b){flag=false;break;} } if(str.charAt(str.length()-1)!='B')flag=false; if(str.charAt(0)=='B')flag=false; if(flag)out.println("YES"); else out.println("NO"); } } public static void manupulate(char[][] ch,int r,int c,int cnt){ for(int j=r-1;j>=0;j--){ if(ch[j][c]=='.'&&cnt>0){ ch[j][c]='*'; cnt--; } } } // <----------------------------------------XXXXXXXXXXXXXXXXXXXXX-----------------------------------------> ////////////////////////********fastModExpo********///////////////////////// public static long fastModExpo(long a,long n,long mod){ if(n==0)return 1; long ans=1; while(n>1){ if((n&1)==1){ ans=ans*a%mod; } a=a*a%mod; n>>=1; } ans=ans*a%mod; return ans; } // ****** next permutation================= public static int[] swap(int arr[], int start, int end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; return arr; } public static int[] reverse(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start++] = arr[end]; arr[end--] = temp; } return arr; } public static boolean next_permutation(int arr[]) { if (arr.length <= 1) return false; int last = arr.length - 2; while (last >= 0) { if (arr[last] < arr[last + 1]) { break; } last--; } if (last < 0) return false; int nextGreater = arr.length - 1; for (int i = arr.length - 1; i > last; i--) { if (arr[i] > arr[last]) { nextGreater = i; break; } } arr = swap(arr, nextGreater, last); arr = reverse(arr, last + 1, arr.length - 1); return true; } ////////////////////////////*******FastReader********////////////////////////////////// static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } 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()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try{ str=br.readLine().trim(); }catch(Exception e){ e.printStackTrace(); } return str; } } ////////////////////////////*******FastWriter********////////////////////////////////// static class FastWriter { private final BufferedWriter bw; public FastWriter(){ this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object)throws IOException{ bw.append(""+object); } public void println(Object object)throws IOException{ print(object); bw.append("\n"); } public void close()throws IOException{ bw.close(); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
e7d64e267717f254b016f2ec2b79db30
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.awt.image.ImageProducer; import java.util.*; public class Solution { static boolean prime[] = new boolean[1000001]; static Set<Long> cubes=new HashSet<>(); static { long N = 1000000000000L; // // // for(int i=1;i*i<=n;i++) // { // long x=i*i; // set.add(x); // } for (long i = 1; i * i * i <= N; i++) { cubes.add(i * i * i); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); while(t-->0) { String str=sc.nextLine(); int cb=0; if(str.length()<=1) { System.out.println("No"); continue; } int mbc=0; int ca=0; boolean flag=false; for(int i=0;i<str.length();i++) { if(str.charAt(i)=='B') { cb++; } else { ca++; } if(ca<cb) { flag=true; break; } } mbc=Math.max(mbc,cb); if(str.charAt(str.length()-1)=='A' || flag || str.charAt(0)=='B') { System.out.println("no"); } else { System.out.println("yes"); } } } public static boolean isPal(String str) { for(int i=0;i<str.length()/2;i++) { if (str.charAt(i) != str.charAt(str.length() - 1 - i)) return false; } return true; } // public static int[] reverse(int arr[],int start,int end) // { // for(int i=start;i<=end;i++) // { // int temp=arr[i]; // arr[i]=arr[i+1]; // arr[i+1]=temp; // } // return arr; // } static boolean checkPerfectSquare(double number) { //calculating the square root of the given number double sqrt=Math.sqrt(number); //finds the floor value of the square root and comparing it with zero return ((sqrt - Math.floor(sqrt)) == 0); } static void sieveOfEratosthenes(int n) { for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers // for(int i = 2; i <= n; i++) // { // if(prime[i] == true) // System.out.print(i + " "); // } } public static boolean isPrime(int n) { for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } public static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
2ac472046178e09a9a1a44e52874905f
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.*; //import java.math.BigInteger; public class code2{ public static class Pair{ int a; int b; Pair(int i,int j){ a=i; b=j; } } public static int GCD(int a, int b) { if (b == 0) return a; return GCD(b, a % b); } public static void shuffle(int a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; } } public static void shuffle(long a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index long x = a[t]; a[t] = a[i]; a[i] = x; } } public static PrintWriter out = new PrintWriter(System.out); public static long[][] dp; //@SuppressWarnings("unchecked") public static void main(String[] arg) throws IOException{ //Reader in=new Reader(); //PrintWriter out = new PrintWriter(System.out); //Scanner in = new Scanner(System.in); FastScanner in=new FastScanner(); int t=in.nextInt(); while(t-- > 0){ String s=in.next(); if(s.charAt(0)=='B'){ out.println("NO"); continue; } if(s.charAt(s.length()-1)!='B'){ out.println("NO"); continue; } boolean flag=false; for(int i=0;i<s.length();i++){ if(s.charAt(i)=='B'){ flag=true; break; } } if(!flag){ out.println("NO"); } else{ int a=0; int b=0; for(int i=0;i<s.length();i++){ if(s.charAt(i)=='A') a++; else b++; if(b>a){ flag=false; break; } } if(flag) out.println("YES"); else out.println("NO"); } } out.flush(); } } class Fenwick{ int[] bit; public Fenwick(int n){ bit=new int[n]; //int sum=0; } public void update(int index,int val){ index++; for(;index<bit.length;index += index&(-index)) bit[index]+=val; } public int presum(int index){ int sum=0; for(;index>0;index-=index&(-index)) sum+=bit[index]; return sum; } public int sum(int l,int r){ return presum(r+1)-presum(l); } } class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
bae03267d9c4b3b7b741342603916749
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) { new B().run(); } BufferedReader br; PrintWriter out; long mod = (long) (1e9 + 7), inf = (long) (3e18); class pair { int F, S; pair(int f, int s) { F = f; S = s; } } // ---------------------- solve -------------------------- void solve() { int t=1; t = ni(); // comment for no test cases tc: while(t-- > 0) { //TODO: char[] s= ns().toCharArray(); int n=s.length; int a=0, b=0; for(int i=0; i<n; i++){ if(s[i]=='B'){ b++; } else{ a++; } if(b>a){ out.println("NO"); continue tc; } } if(s[n-1]!='B'){ out.println("NO"); continue tc; } out.println("YES"); } } // -------- I/O Template ------------- public long pow(long A, long B, long C) { if(A==0) return 0; if(B==0) return 1; long n=pow(A, B/2, C); if(B%2==0){ return (long)((n*n)%C + C )%C; } else{ return (long)(((n*n)%C * A)%C +C)%C; } } 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()); } int[] na(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } long[] nal(int n) { long a[] = new long[n]; for(int i = 0; i < n; i++) a[i] = nl(); return a; } StringTokenizer ip; String ns() { if(ip == null || !ip.hasMoreTokens()) { try { ip = new StringTokenizer(br.readLine()); if(ip == null || !ip.hasMoreTokens()) ip = new StringTokenizer(br.readLine()); } catch(IOException e) { throw new InputMismatchException(); } } return ip.nextToken(); } void run() { try { if (System.getProperty("ONLINE_JUDGE") == null) { br = new BufferedReader(new FileReader("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt")); out = new PrintWriter("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt"); } else { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } catch (FileNotFoundException e) { System.out.println(e); } solve(); out.flush(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
a442fb72f1c3ca7b0a8f6fa798eb79d5
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeSet; public class Solving { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tk = new StringTokenizer(in.readLine()); int t = Integer.parseInt(tk.nextToken()); while(t-- > 0) { String exp = in.readLine(); if(exp.charAt(0) != 'A' || exp.charAt(exp.length() - 1) != 'B') { System.out.println("No"); continue; } int a = 1; boolean flag = true; for(int i=1;i<exp.length();i++) { if(exp.charAt(i) == 'A') { a++; } else { if(--a < 0) { System.out.println("NO"); flag = false; break; } } } if(flag) System.out.println("YES"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
06383ec109113329e50664d279d0ee27
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class IloveAAAB { public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); for(int c=0;c<t;c++){ String s = sc.nextLine(); boolean b = true; int sum = 0; if(s.charAt(s.length()-1)=='B'){ for(int i = 0;i<s.length();i++){ if(s.charAt(i) == 'B'){ sum--; }else { sum++; } if (sum<0) b = false; } }else{ b = false; } if(b){ System.out.println("YES"); }else{ System.out.println("NO"); } } } } /* public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0) { String s2 = sc.next(); if(s2.charAt(s2.length()-1)=='B'){ int c=0; for (int i = 0; i < s2.length(); i++) { if(s2.charAt(i)=='B'){ --c; } else { ++c; } } if(c<=0){ System.out.println("NO"); } else { System.out.println("YES"); } } else { System.out.println("NO"); } } } } */
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
28ce002cf9d67374b5874fca84d43a74
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testCases = sc.nextInt(); for(int testCase = 0 ; testCase<testCases ; testCase++) { String s2 = sc.next(); int a = 0; boolean isOk = true; for(int i=0 ; i<s2.length() ; i++) { if(s2.charAt(i) == 'B' ) { if(a <= 0 ) { isOk = false; break; }else { a--; } }else { a++; } } if(isOk && s2.charAt(s2.length()-1) == 'B' ) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
d7d0c7572972703bfa63560fe0555a29
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class ILoveAAAB { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 0; i < t; i++) { String s = in.next(); if (s.length() == 1) { out.println("NO"); } else { char[] sArr = s.toCharArray(); if ((sArr[0] == 'B') || (sArr[sArr.length - 1] == 'A')) { out.println("NO"); } else { boolean can = true; int numA = 0; int numB = 0; for (int j = 0; j < sArr.length; j++) { if (sArr[j] == 'A') { numA++; } else { numB++; } if (numB > numA) { can = false; break; } } if (can) { out.println("YES"); } else { out.println("NO"); } } } } out.close(); } 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) { // noop } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
609cc4570051ff861194fb84d7b77b2b
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class class1 { public static void main(String arg[]) { Scanner input=new Scanner(System.in); int t=input.nextInt(); while(t-->0) { String s=input.next(); int n=s.length(); char c[]=s.toCharArray(); int x=0; if(c[0]=='B') { x++; } if(c[n-1]=='A') { x++; } int b=0,a=0,flag=0; for(int i=0;i<n;i++) { if(c[i]=='A') { a++; } else { b++; if(b>a) { x++; break; } } } if(x==0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
99622cbf6a74cf61b4724845e905b43e
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
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 q1 { static HashSet<Long> hs; static int[][] dp; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.next()); while (t-- > 0) { String str= sc.next();boolean flag= false; if(str.length()==1 || str.charAt(0)!='A' || str.charAt(str.length()-1)!='B') { System.out.println("NO"); continue; } int curr=0; for(int i=0;i<str.length();i++) { if(str.charAt(i)=='A') { curr++; } else { curr--; } if(curr<0) { flag=true; break; } } if(flag) { System.out.println("NO"); } else { System.out.println("YES"); } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
cd755d4a0fd9e3226205d02ccddb5a09
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { String s2=sc.next(); int count=0; int n=s2.length(); boolean flag=s2.charAt(n-1)=='B'; for(int i=0; i<s2.length(); i++) { if(s2.charAt(i)=='B'){ count--; } else { count++; } if(count<0) { flag=false; } } // if((s2.length()-count)>0) { // for(int i=0; i<s2.length(); i++) { // if(s2.charAt(i)=='B' && s2.charAt(i-1)=='A') { // flag=true; // } // else { // flag=false; // } // } // } if(flag==true) { System.out.println("YES"); } else { System.out.println("NO"); } } } catch(Exception e) { } // your code goes here } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
2d3e127c84bfbc6335b637edda3430e2
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { String s2=sc.next(); int count=0; int n=s2.length(); boolean flag=s2.charAt(n-1)=='B'; for(int i=0; i<s2.length(); i++) { if(s2.charAt(i)=='B'){ count--; } else { count++; } if(count<0) { flag=false; } } // if((s2.length()-count)>0) { // for(int i=0; i<s2.length(); i++) { // if(s2.charAt(i)=='B' && s2.charAt(i-1)=='A') { // flag=true; // } // else { // flag=false; // } // } // } if(flag==true) { System.out.println("YES"); } else { System.out.println("NO"); } } } catch(Exception e) { } // your code goes here } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
eeae84e8ec1c68cbf4d88144433da438
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Contest_yandexA{ //static final int MAXN = (int)1e6; public static void main(String[] args) throws IOException{ Scanner input = new Scanner(System.in); /*int n = input.nextInt(); int k = input.nextInt(); k = k%4; int[] a = new int[n]; for(int i = 0;i<n;i++){ a[i] = input.nextInt(); } int[] count = new int[n]; int sum = 0; for(int tt = 0;tt<k;tt++){ for(int i = 0;i<n;i++){ count[a[i]-1]++; } for(int i = 0;i<n;i++){ sum+= count[i]; } for(int i = 0;i<n;i++){ a[i] = sum; sum-= count[i]; } } for(int i = 0;i<n;i++){ System.out.print(a[i] + " "); }*/ int t = input.nextInt(); for(int tt = 0;tt<t;tt++){ String s2 = input.next(); if (s2.charAt(s2.length()-1)=='A') { System.out.println("NO"); continue; } int ac = 0; String ans = "YES"; for (int i = 0; i < s2.length(); ++i) { if (s2.charAt(i)=='A') ++ac; else --ac; if (ac<0) ans = "NO"; } System.out.println(ans); } } public static long gcd(long a,long b){ if(b == 0){ return a; } return gcd(b,a%b); } /*public static int lcm(int a,int b){ return (a / gcd(a, b)) * b; }*/ } class Pair implements Comparable<Pair>{ int x; int y; Pair(int x,int y){ this.x = x; this.y = y; } @Override public int compareTo(Pair p){ return this.x-p.x; } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
903f88915390dcbced0aa1821e613747
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; /** * * @author Acer */ public class NewClass_B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); k: while(T-- > 0){ String s = sc.next(); if(s.charAt(0) == 'B' || s.charAt(s.length()-1) == 'A'){ System.out.println("NO"); continue; } boolean flag = true; int a = 0, b = 0; for (int i = 0; i < s.length(); i++) { if(s.charAt(i) == 'A'){ if(b > 0){ if(b > a){ flag = false; } if(a == b){ b = 0; a = 0; } } a++; } if(s.charAt(i) == 'B'){ b++; } } if(b > a) flag = false; if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
5d873e7b77eb02c4455773116c44ccf6
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
//package Global20; import java.io.*; import java.math.*; import java.util.*; public class Q2 { //Solution static int INF = (int)(1e9); static long mod = (long)(1e9)+7; static long mod2 = 998244353; static long[] segtree; static char[] curans; static long ans; static String S; static ArrayList<Integer>[] graph; static boolean[] vis; static int[] a; static int N; static long K; static long[] fact; static ArrayList<Long> pos; static ArrayList<Long> neg; static long[] max; static int[] dp; static long mx; static long[] fun; public static void main(String[] args) { //Cash out /*(Notes) * * * */ FastScanner I = new FastScanner(); //Input OutPut O = new OutPut(); //Output int T = I.nextInt(); while (T-- > 0) { String S = I.next(); int M = S.length(); int a = 0; int b = 0; boolean good = true; for (int i = 0; i < M; i++) { if (S.charAt(i) == 'B') { b++; }else { a++; } if (b > a) { good = false; } } if (S.charAt(M - 1) == 'A') { good = false; } O.pln(good? "YES" : "NO"); } } public static ArrayList<String> perms(int N, int upper){ if (N==1) { ArrayList<String> ret = new ArrayList<String>(); for (int i = 1; i<=upper; i++) ret.add(Integer.toString(i)+" "); return ret; } ArrayList<String> prev = perms(N-1,upper); ArrayList<String> ret = new ArrayList<String>(); for (int i = 0; i < prev.size(); i++) { boolean[] vis = new boolean[upper+1]; String cur = prev.get(i); String[] parts = cur.split(" "); for (int j = 0; j < parts.length; j++) { vis[Integer.parseInt(parts[j])]=true; } for (int j = 1; j <= upper; j++) { if (!vis[j]) { String curans = cur; curans+=Integer.toString(j)+" "; ret.add(curans); } } } return ret; } public static void DFS(int start) { if (start == 0) { return; } vis[start] = true; mx = Math.max(mx, fun[start]); int next = graph[start].get(0); // We only ever point to one node at a time if (vis[next]) { return; } DFS(next); } public static long C(int N, int K) { long ans = fact[N]; ans *= FastExp(fact[K], mod - 2); ans %= mod; ans *= FastExp(fact[N - K], mod - 2); ans %= mod; return ans; } public static double[][] matrix_exp(double[][] a, long exp, long mod) { int R = a.length; int C = a[0].length; double[][] ans = new double[R][C]; boolean mult_yet = false; while (exp > 0) { if (exp % 2 == 1) { if (!mult_yet) { mult_yet = true; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { ans[i][j] = a[i][j]; } } }else { double[][] new_ans = mult(ans, a, mod); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { ans[i][j] = new_ans[i][j]; } } } } double[][] new_a = mult(a, a, mod); // a = a^2 (binary exponentiation on matrices) for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { a[i][j] = new_a[i][j]; } } exp /= 2; } return ans; } public static double[][] mult(double[][] a, double[][] b, long mod) { int r1 = a.length; int c1 = a[0].length; int r2 = b.length; int c2 = b[0].length; //Requires: c1 = r2 double[][] ans = new double[r1][c2]; for (int r = 0; r < r1; r++) { for (int c = 0; c < c2; c++) { //Dot product of (a[r])^T and b[c] (as vectors in R^n (n = c1 = r2)) double[] col_vector = new double[r2]; double[] row_vector = new double[c1]; for (int i = 0; i < r2; i++) { col_vector[i] = b[i][c]; } for (int i = 0; i < c1; i++) { row_vector[i] = a[r][i]; } ans[r][c] = dot_product(row_vector, col_vector, mod); } } return ans; } public static double dot_product(double[] a, double[] b, long mod) { double ans = 0; int N = a.length; //Requires: a and b are both vectors in R^n for (int i = 0; i < N; i++) { ans += a[i] * b[i]; } return ans; } public static double max(double a, double b) {return Math.max(a, b);} public static double min(double a, double b) {return Math.min(a, b);} public static long min(long a, long b) {return Math.min(a,b);} public static long max(long a, long b) {return Math.max(a,b);} public static int min(int a, int b) {return Math.min(a,b);} public static int max(int a, int b) {return Math.max(a,b);} public static long abs(long x) {return Math.abs(x);} public static long abs(int x) {return Math.abs(x);} public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) ans++; return ans;} public static long GCD(long a, long b) { if (a==0||b==0) return max(a,b); return GCD(min(a,b),max(a,b)%min(a,b)); } public static long FastExp(long base, long exp) { long ans=1; while (exp>0) { if (exp%2==1) ans*=base; exp/=2; base*=base; base%=mod; ans%=mod; } return ans; } public static long ModInv(long num,long mod) {return FastExp(num,mod-2);} public static int pop(long x) { //Returns number of bits within a number int cnt = 0; while (x>0) { if (x%2==1) cnt++; x/=2; } return cnt; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());}; double nextDouble() {return Double.parseDouble(next());} } static class OutPut{ PrintWriter w = new PrintWriter(System.out); void pln(double x) {w.println(x);w.flush();} void pln(boolean x) {w.println(x);w.flush();} void pln(int x) {w.println(x);w.flush();} void pln(long x) {w.println(x);w.flush();} void pln(String x) {w.println(x);w.flush();} void pln(char x) {w.println(x);w.flush();} void pln(StringBuilder x) {w.println(x);w.flush();} void pln(BigInteger x) {w.println(x);w.flush();} void p(int x) {w.print(x);w.flush();} void p(long x) {w.print(x);w.flush();} void p(String x) {w.print(x);w.flush();} void p(char x) {w.print(x);w.flush();} void p(StringBuilder x) {w.print(x);w.flush();} void p(BigInteger x) {w.print(x);w.flush();} void p(double x) {w.print(x);w.flush();} void p(boolean x) {w.print(x);w.flush();} } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
f652e837b974aa43373345c215d5e179
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.*; public class Main { static long mod=(long)1e18+7; static long[]fac=new long[1002]; static int n, x=0,me,op; static int[]pe,a,aa, prime=new int[(int)1e7+1]; static int[][]perm; static long[][]memo; static Integer[]ps; static TreeSet<Long>p=new TreeSet<Long>(); public static void main(String[] args) throws Exception{ int t =sc.nextInt(); while(t-->0) { String s = sc.next(); boolean f = true; int b =0; int a = 0; for (int i = 0; i < s.length(); i++) { if(s.charAt(i)=='B') { b++; }else a++; if(a<b) { f=false; break; } } if(f&&a>=b) { pw.println(s.charAt(0)=='A'&&s.charAt(s.length()-1)=='B'?"YES":"NO"); }else { pw.println("NO"); } } pw.close(); } public static long solFul(int m, int o) { if(o<m)return 0; if(o == op)return 1; if(memo[m][o]!=-1) { return memo[m][o]; } return memo[m][o] = (solFul(m+1,o)+solFul(m, o+1))%mod; } public static long solFree(int m, int o) { if(m<=o)return 0; if(m == me)return 1; if(o == op&&m>op)return 1; if(memo[m][o]!=-1)return memo[m][o]; return memo[m][o] = (solFree(m+1,o)+solFree(m, o+1))%mod; } public static String rev(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { sb.append(s.charAt(s.length()-1-i)); } return sb.toString(); } public static int divNum(int n) { int total = 1; while(n>1) { int p=prime[n]; int count =1; while(n%p==0) { n/=p; count++; } total*=count; } return total; } public static void sieve() { for (int i = 2; i < prime.length; i++) { if(prime[i]==0) { p.add((long)i); for (int j = i; j < prime.length; j+=i) { prime[j]++; } } } } public static long[] Extended(long p, long q) { if (q == 0) return new long[] { p, 1, 0 }; long[] vals = Extended(q, p % q); long d = vals[0]; long a = vals[2]; long b = vals[1] - (p / q) * vals[2]; return new long[] { d, a, b }; } public static int LIS(int[] a) { int n = a.length; int[] ser = new int[n]; Arrays.fill(ser, Integer.MAX_VALUE); int cur = -1; for (int i = 0; i < n; i++) { int low = 0; int high = n - 1; int mid = (low + high) / 2; while (low <= high) { if (ser[mid] < a[i]) { low = mid + 1; } else { high = mid - 1; } mid = (low + high) / 2; } cur = Math.max(cur, high + 1); ser[high + 1] = Math.min(ser[high + 1], a[i]); } return cur + 1; } public static void permutation(int idx,int v) { if(v==(1<<n)-1) { perm[x++]=pe.clone(); return ; } for (int i = 0; i < n; i++) { if((v&1<<i)==0) { pe[idx]=aa[i]; permutation(idx+1, v|1<<i); } } return ; } public static void sort(int[]a) { mergesort(a, 0, a.length-1); } public static void sortIdx(long[]a,long[]idx) { mergesortidx(a, idx, 0, a.length-1); } public static long C(int a,int b) { long x=fac[a]; long y=fac[a-b]*fac[b]; return x*pow(y,mod-2)%mod; } public static long pow(long a,long b) { long ans=1;a%=mod; for(long i=b;i>0;i/=2) { if((i&1)!=0) ans=ans*a%mod; a=a*a%mod; } return ans; } public static void pre(){ fac[0]=1; fac[1]=1; fac[2]=2; for (int i = 3; i < fac.length; i++) { fac[i]=fac[i-1]*i%mod; } } public static long eval(String s) { long p=1; long res=0; for (int i = 0; i < s.length(); i++) { res+=p*(s.charAt(s.length()-1-i)=='1'?1:0); p*=2; } return res; } public static String binary(long x) { String s=""; while(x!=0) { s=(x%2)+s; x/=2; } return s; } public static boolean allSame(String s) { char x=s.charAt(0); for (int i = 0; i < s.length(); i++) { if(s.charAt(i)!=x)return false; } return true; } public static boolean isPalindrom(String s) { int l=0; int r=s.length()-1; while(l<r) { if(s.charAt(r--)!=s.charAt(l++))return false; } return true; } public static boolean isSubString(String s,String t) { int ls=s.length(); int lt=t.length(); boolean res=false; for (int i = 0; i <=lt-ls; i++) { if(t.substring(i, i+ls).equals(s)) { res=true; break; } } return res; } public static boolean isSorted(long[]a) { for (int i = 0; i < a.length-1; i++) { if(a[i]>a[i+1])return false; } return true; } public static long evaln(String x,int n) { long res=0; for (int i = 0; i < x.length(); i++) { res+=Long.parseLong(x.charAt(x.length()-1-i)+"")*Math.pow(n, i); } return res; } static void mergesort(int[] arr,int b,int e) { if(b<e) { int m=b+(e-b)/2; mergesort(arr,b,m); mergesort(arr,m+1,e); merge(arr,b,m,e); } return; } static void merge(int[] arr,int b,int m,int e) { int len1=m-b+1,len2=e-m; int[] l=new int[len1]; int[] r=new int[len2]; for(int i=0;i<len1;i++)l[i]=arr[b+i]; for(int i=0;i<len2;i++)r[i]=arr[m+1+i]; int i=0,j=0,k=b; while(i<len1 && j<len2) { if(l[i]<r[j])arr[k++]=l[i++]; else arr[k++]=r[j++]; } while(i<len1)arr[k++]=l[i++]; while(j<len2)arr[k++]=r[j++]; return; } static void mergesortidx(long[] arr,long[]idx,int b,int e) { if(b<e) { int m=b+(e-b)/2; mergesortidx(arr,idx,b,m); mergesortidx(arr,idx,m+1,e); mergeidx(arr,idx,b,m,e); } return; } static void mergeidx(long[] arr,long[]idx,int b,int m,int e) { int len1=m-b+1,len2=e-m; long[] l=new long[len1]; long[] lidx=new long[len1]; long[] r=new long[len2]; long[] ridx=new long[len2]; for(int i=0;i<len1;i++) { l[i]=arr[b+i]; lidx[i]=idx[b+i]; } for(int i=0;i<len2;i++) { r[i]=arr[m+1+i]; ridx[i]=idx[m+1+i]; } int i=0,j=0,k=b; while(i<len1 && j<len2) { if(l[i]<=r[j]) { arr[k++]=l[i++]; idx[k-1]=lidx[i-1]; } else { arr[k++]=r[j++]; idx[k-1]=ridx[j-1]; } } while(i<len1) { idx[k]=lidx[i]; arr[k++]=l[i++]; } while(j<len2) { idx[k]=ridx[j]; arr[k++]=r[j++]; } return; } static long mergen(int[] arr,int b,int m,int e) { int len1=m-b+1,len2=e-m; int[] l=new int[len1]; int[] r=new int[len2]; for(int i=0;i<len1;i++)l[i]=arr[b+i]; for(int i=0;i<len2;i++)r[i]=arr[m+1+i]; int i=0,j=0,k=b; long c=0; while(i<len1 && j<len2) { if(l[i]<r[j])arr[k++]=l[i++]; else { arr[k++]=r[j++]; c=c+(long)(len1-i); } } while(i<len1)arr[k++]=l[i++]; while(j<len2)arr[k++]=r[j++]; return c; } static long mergesortn(int[] arr,int b,int e) { long c=0; if(b<e) { int m=b+(e-b)/2; c=c+(long)mergesortn(arr,b,m); c=c+(long)mergesortn(arr,m+1,e); c=c+(long)mergen(arr,b,m,e); } return c; } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static long sumd(long x) { long sum=0; while(x!=0) { sum+=x%10; x=x/10; } return sum; } public static ArrayList<Integer> findDivisors(int n){ ArrayList<Integer>res=new ArrayList<Integer>(); for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { // If divisors are equal, print only one if (n/i == i) res.add(i); else { res.add(i); res.add(n/i); } } } return res; } public static void sort2darray(Integer[][]a){ Arrays.sort(a,Comparator.<Integer[]>comparingInt(x -> x[0]).thenComparingInt(x -> x[1])); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws FileNotFoundException { 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 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(); } public int[] nextArrint(int size) throws IOException { int[] a=new int[size]; for (int i = 0; i < a.length; i++) { a[i]=sc.nextInt(); } return a; } public long[] nextArrlong(int size) throws IOException { long[] a=new long[size]; for (int i = 0; i < a.length; i++) { a[i]=sc.nextLong(); } return a; } public int[][] next2dArrint(int rows,int columns) throws IOException{ int[][]a=new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j]=sc.nextInt(); } } return a; } public long[][] next2dArrlong(int rows,int columns) throws IOException{ long[][]a=new long[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j]=sc.nextLong(); } } return a; } } static class Segment{ long x; long y; long m; public Segment(long x,long y, long m) { this.x=x; this.y=y; this.m=m; } @Override public String toString() { return x+" "+y+" "+m; } } static Scanner sc=new Scanner(System.in); static PrintWriter pw=new PrintWriter(System.out); }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
0fdc9c0a724121dbe8e03d4721da93fb
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // try { // System.setIn(new FileInputStream("input.txt")); // System.setOut(new PrintStream(new FileOutputStream("output.txt"))); // } catch (Exception e) { // System.err.println("Error"); // } Scanner in = new Scanner(System.in); int t = in.nextInt(); in.nextLine(); while(t-- > 0) { String s = in.nextLine(); System.out.println(solve(s)); } } static String solve(String s) { Stack<Character> st = new Stack<>(); if(s.charAt(s.length() -1) == 'A') return "NO"; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == 'B') { if(!st.isEmpty() && st.peek() == 'A') { st.pop(); } else { st.push('B'); } } else { st.push(s.charAt(i)); } } while(!st.isEmpty()) { if(st.pop() == 'B') return "NO"; } return "YES"; } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
a59f1f5309967f140913dfe3cfa6f541
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
//package b; import java.util.*; import java.io.*; public class B { public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int cases=Integer.parseInt(br.readLine()); for(int d=0;d<cases;d++){ String target=br.readLine(); int b=0; int a=0; boolean fail=target.length()<=1; if(target.charAt(target.length()-1)=='A'){ fail=true; } for(int i=0;i<target.length();i++){ if(target.charAt(i)=='B'){ b++; }else{ a++; } if(b>a){ fail=true; } } if(fail){ pw.println("NO"); }else{ pw.println("YES"); } } pw.close(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
2d18cd90dea0e20874a7bf57c0dc96d0
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/* Author:Farhan Shaikh */ 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 Pupil { static FastReader sc = new FastReader(); public static void main (String[] args) throws java.lang.Exception { // your code goes here int t=sc.nextInt(); while(t>0){ String s=sc.next(); if(s.length()==1) { no(); } else { int a=0; int b=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='A') { a++; } else { b++; } } boolean b1=true; if(s.charAt(s.length()-1)=='A' || s.charAt(0)=='B' ||a==0 ||b==0) { b1=false; } a=0; b=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='B') { b++; } else { a++; } if(a<b) { b1=false; break; } } if(b1) { yes(); } else { no(); } } t--; } } // FAST I/O 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 boolean two(int n)//power of two { if((n&(n-1))==0) { return true; } else{ return false; } } public static boolean isPrime(long n){ for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } public static int digit(int n) { int n1=(int)Math.floor((int)Math.log10(n)) + 1; return n1; } public static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } public static long highestPowerof2(long x) { // check for the set bits x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; // Then we remove all but the top bit by xor'ing the // string of 1's with that string of 1's shifted one to // the left, and we end up with just the one top bit // followed by 0's. return x ^ (x >> 1); } public static void yes() { System.out.println("YES"); return; } public static void no() { System.out.println("NO"); return ; } public static void al(long arr[],int n) { for(int i=0;i<n;i++) { arr[i]=sc.nextLong(); } return ; } public static void ai(int arr[],int n) { for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } return ; } } //CAAL THE BELOW FUNCTION IF PARING PRIORITY IS NEEDED // // PriorityQueue<pair> pq = new PriorityQueue<>(); **********declare the syntax in the main function****** // pq.add(1,2)/////// // class pair implements Comparable<pair> { // int value, index; // pair(int v, int i) { index = i; value = v; } // @Override // public int compareTo(pair o) { return o.value - value; } // } // User defined Pair class // class Pair { // int x; // int y; // // Constructor // public Pair(int x, int y) // { // this.x = x; // this.y = y; // } // } // Arrays.sort(arr, new Comparator<Pair>() { // @Override public int compare(Pair p1, Pair p2) // { // return p1.x - p2.x; // } // }); // class Pair { // int height, id; // // public Pair(int i, int s) { // this.height = s; // this.id = i; // } // } //Arrays.sort(trips, (a, b) -> Integer.compare(a[1], b[1])); // ArrayList<ArrayList<Integer>> connections = new ArrayList<ArrayList<Integer>>(); // for(int i = 0; i<n;i++) // connections.add(new ArrayList<Integer>());
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
409b3395e6b19066addc6815ad7f2186
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.*; import java.util.*; public class B { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { String s=sc.next(); int n=s.length(); boolean ans=true; int b=0; int a=0; for(int i=0;i<n;i++) { if(s.charAt(i)=='B') { b++; }else { a++; } if(b>a) { ans=false; } } if(s.charAt(n-1)=='A') { ans=false; } if(s.charAt(0)=='B') { ans=false; } if(s.length()==1) { ans=false; } out.println(ans?"YES":"NO"); } out.close(); } public static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { 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
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
1343228e2dc66f70ebf1391306bf5920
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.nio.charset.MalformedInputException; import java.util.StringTokenizer; import java.util.Arrays; public class Cv { //==========================Solution============================// public static void main(String[] args) { FastScanner in = new FastScanner(); Scanner sc = new Scanner(System.in); PrintWriter o = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { String s = sc.next(); boolean bool = true; int b = 0; int f = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (i == 0 && c == 'B') { bool = false; break; } if (c == 'A') { if (b > f) { bool = false; break; } else { f++; } } if (c == 'B') { b++; if (b > f) { bool = false; break; } } } char g = s.charAt(s.length() - 1); if (s.length() == 1 || g == 'A') { bool = false; } if (bool) { o.println("YES"); } else { o.println("NO"); } } o.close(); } //==============================================================// static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } byte nextByte() { return Byte.parseByte(next()); } short nextShort() { return Short.parseShort(next()); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return java.lang.Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
139219491d507c619bfbd991f847c84d
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.StringTokenizer; public class I_love_AAAB { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } } public static void main(String Args[]) throws java.lang.Exception { try { Scanner obj = new Scanner (System.in); int t = obj.nextInt(); while (t > 0) { t--; String str = obj.next(); int n = str.length(), i = 0, cA = 0, cB= 0; boolean b = true; if (n == 1 || str.charAt(n-1) == 'A' || str.charAt(0) == 'B') { System.out.println ("NO"); continue; } while (i < n) { char ch = str.charAt(i); if (ch == 'A') { cA++; } else { cB++; } if (cB > cA) { b = false; } i++; } if (cA >= cB && b) { System.out.println ("YES"); } else { System.out.println ("NO"); } } }catch(Exception e){ return; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
abeb8294fb494c9ba3a81e8ab4893c73
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class AAB { public static void main(String aegs[]){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); while(n-->0){ int q = 0, b = 0; String a = scanner.next(); for(int i=0;i<a.length();i++){ if(a.charAt(i)=='A') q++; else b++; if(b>q){ System.out.println("NO"); break; } else if(a.charAt(a.length()-1)=='A'){ System.out.println("NO"); break; } else if(i==a.length()-1){ System.out.println("YES"); break; } } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
dc3159800205643e3109430fe1923f5a
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.IOException; import java.util.Scanner; public class draft { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String[] ansList = new String[n]; int index = 0; scan.nextLine(); for (int i = 0; i < n; i++) { String str = scan.nextLine(); boolean flag = true; int cntA = 0; int cntB = 0; if (str.length() < 2) { flag = false; } else { if (str.charAt(str.length() - 1) != 'B') { flag = false; } else { for (int j = 0; j < str.length(); j++) { if (str.charAt(j)== 'A') { cntA++; } if (str.charAt(j) == 'B') { cntB++; } if (cntA + (-1) * cntB < 0) { flag = false; break; } } } } if (flag) { ansList[index] = "yes"; // System.out.println("yes"); } else { ansList[index] = "no"; // System.out.println("no"); } index++; } for (String str : ansList) { System.out.println(str); } } } //AABBABABBAAB
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
10df63394f178cb274f7e4af963b9a7a
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
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 * * @author Roy */ 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); BILoveAAAB solver = new BILoveAAAB(); solver.solve(1, in, out); out.close(); } static class BILoveAAAB { public void solve(int testNumber, InputReader in, OutputWriter out) { int tCases = in.readInteger(); for (int cs = 1; cs <= tCases; ++cs) { String s = in.readString(); boolean possible = true; int countA = 0, countB = 0, i = 0, l = s.length(); while (i < l && possible) { boolean foundA = false, foundB = false; while (i < l && s.charAt(i) == 'A') { i++; countA++; foundA = true; } while (i < l && s.charAt(i) == 'B') { i++; countB++; foundB = true; } if (foundA && foundB && countA != 0 && countB != 0 && countA >= countB) ; else possible = false; } if (possible) out.printLine("YES"); else out.printLine("NO"); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { this.print(objects); writer.println(); } public void close() { writer.flush(); writer.close(); } } static class InputReader { private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private final InputStream stream; private final byte[] buf = new byte[1024]; public InputReader(InputStream stream) { this.stream = stream; } private long readWholeNumber(int c) { long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res; } 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 readInteger() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = (int) readWholeNumber(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 interface SpaceCharFilter { boolean isSpaceChar(int ch); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
c7ce3c6d0d65c2c8b60a14ab3bb3f381
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.io.*; public class codeforces1672B { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int rep = 0; rep<numCases;rep++) { String str = br.readLine(); if (str.length()==1) { System.out.println("NO"); } else { boolean bo = true; int numA = 0; int numB = 0; for (int i = 0; i<str.length();i++) { if (str.charAt(i)=='B') { numB++; } else { numA++; } if (numB>numA) { bo = false; } } if (str.charAt(0)=='B' || str.charAt(str.length()-1)=='A') { System.out.println("NO"); } else { if (bo) { System.out.println("YES"); } else { System.out.println("NO"); } } } } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
cd5d5c802b0c2b63cce685bc727a76f6
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.*; public class Codeforces { static long mod= Long.MAX_VALUE; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); // DecimalFormat formatter= new DecimalFormat("#0.000000"); int t=fs.nextInt(); // int t=1; outer:for(int time=1;time<=t;time++) { char arr[]=fs.next().toCharArray(); int a=0,b=0; for(char c:arr) { if(c=='A') a++; else b++; if(b>a) { out.println("NO"); continue outer; } } if(b==0||arr[arr.length-1]=='A') out.println("NO"); else out.println("YES"); } out.close(); } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); int temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } static void sort(long[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); long temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } String nextLine() { String str=""; try { str= (br.readLine()); } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long[] readArrayL(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
1f40ac7049a383b6f516225f6862ba88
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static FastReader in=new FastReader(); static final Random random=new Random(); static long mod=1000000007L; static long[] fact = new long[16]; static void init() { fact[0] = 1; for(int i=1; i<16; i++) fact[i] = (i*fact[i-1]); } public static void main (String[] args) throws java.lang.Exception { int t=in.nextInt(); while(t-->0) solve(); // ArrayList<Pair> al = new ArrayList<>(); // for(int i=0; i<5; i++) { // al.add(new Pair(in.nextLong(), in.nextLong())); // } // for(int i=0; i<5; i++) { // System.out.println(al.get(i).a + " " + al.get(i).b); // } // Compare obj = new Compare(); // obj.compare(al, 5); // for(int i=0; i<5; i++) { // System.out.println(al.get(i).a + " " + al.get(i).b); // } } static void solve() { String s = in.nextLine(); int n = s.length(); if(n<2) { System.out.println("NO"); return; } else if(s.charAt(0)=='B') { System.out.println("NO"); return; } else if(s.charAt(n-1)=='A') { System.out.println("NO"); return; } else { int cnt = 0; for(int i=0; i<n; i++) { if(s.charAt(i)=='A') cnt++; else cnt--; if(cnt<0) { System.out.println("NO"); return; } } System.out.println("YES"); } } static long cntSetBit(long num) { long ans = 0; while(num>0) { if(num%2==1) ans++; num /= 2; } return ans; } static int max(int a, int b) { if(a<b) return b; return a; } static void ruffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static < E > void print(E res) { System.out.println(res); } static int gcd(int a,int b) { if(b==0) { return a; } return gcd(b,a%b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if(a<0) return -1*a; return a; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int [] readintarray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] readlongarray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
0369b4cfba20fe857dda2013a06a27ba
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; public class ILoveAAB { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int tests = scn.nextInt(); scn.nextLine(); for(int t=0;t<tests;t++){ String str = scn.nextLine(); boolean flag = true; int a = 0; for(int i=0;i<str.length();i++){ if(str.charAt(i) == 'B'){ if(a == 0){ flag = false; break; }else{ a--; } }else{ a++; } } if(flag && str.charAt(str.length()-1) == 'B'){ System.out.println("YES"); }else{ System.out.println("NO"); } } scn.close(); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
93f472d75b9bb21375cc1b0c67d039bb
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
// package faltu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class Main { public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(long[] a, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(a[mid]<m) l=mid+1; else r=mid-1; } return l; } public static long getClosest(long val1, long val2,long target) { if (target - val1 >= val2 - target) return val2; else return val1; } static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } public static int findIndex(long arr[], long t) { if (arr == null) { return -1; } int len = arr.length; int i = 0; while (i < len) { if (arr[i] == t) { return i; } else { i = i + 1; } } return -1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a,long b) { return (a / gcd(a, b)) * b; } public static int[] swap(int a[], int left, int right) { int temp = a[left]; a[left] = a[right]; a[right] = temp; return a; } public static void swap(long x,long max1) { long temp=x; x=max1; max1=temp; } public static int[] reverse(int a[], int left, int right) { // Reverse the sub-array while (left < right) { int temp = a[left]; a[left++] = a[right]; a[right--] = temp; } return a; } static int lowerLimitBinarySearch(ArrayList<Integer> A,int B) { int n =A.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(A.get(mid) > B) { second = mid; }else { first = mid+1; } } if(first < n && A.get(first) < B) { first++; } return first; //1 index } 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; } } // *******----segement tree implement---***** // -------------START-------------------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode) { if(start==end) { tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value) { if(start==end) { arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid) { updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); } else { updateTree(arr,tree,start,mid,2*treeNode,idx,value); } tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } // disjoint set implementation --start static void makeSet(int n) { parent=new int[n]; rank=new int[n]; for(int i=0;i<n;i++) { parent[i]=i; rank[i]=0; } } static void union(int u,int v) { u=findpar(u); v=findpar(v); if(rank[u]<rank[v])parent[u]=v; else if(rank[v]<rank[u])parent[v]=u; else { parent[v]=u; rank[u]++; } } private static int findpar(int node) { if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } static int parent[]; static int rank[]; // *************end static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } public static int[] sort(int[] arr) { ArrayList<Integer> al = new ArrayList<>(); for(int i=0;i<arr.length;i++) al.add(arr[i]); Collections.sort(al); for(int i=0;i<arr.length;i++) arr[i]=al.get(i); return arr; } static ArrayList<String>powof2s; static void powof2S() { long i=1; while(i<(long)2e18) { powof2s.add(String.valueOf(i)); i*=2; } } static boolean coprime(int a, long l){ return (gcd(a, l) == 1); } static int[][] dirs = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; static Long MOD=(long) (1e9+7); static int prebitsum[][]; static ArrayList<Integer>arr; static boolean[] vis; static ArrayList<ArrayList<Integer>>adj; public static void main(String[] args) throws IOException { // sieve(); // prebitsum=new int[200001][18]; // presumbit(prebitsum); // powof2S(); FastReader s = new FastReader(); int tt = s.nextInt(); while(tt-->0) { char[]ch=s.next().toCharArray(); solver(ch); } } static void solver(char[]ch) { int n=ch.length; int cnta=0,cntb=0; boolean f=true; for(char c:ch) { if(c=='A')cnta++; else { ++cntb; if(cntb>cnta) { f=false; break; } } } if(cnta==0||cntb==0)System.out.println("NO"); else if(cntb>cnta||!f||ch[n-1]!='B')System.out.println("NO"); else System.out.println("YES"); } static void pc2d(char[][]a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void pi2d(int[][]a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void DFSUtil(int v, boolean[] vis) { vis[v] = true; Iterator<Integer> it = adj.get(v).iterator(); while (it.hasNext()) { int n = it.next(); if (!vis[n]) DFSUtil(n, vis); } } static long DFS(int n) { vis = new boolean[n+1]; long cnt=0; for (int i = 1; i <= n; i++) { if (!vis[i]) { DFSUtil(i, vis); cnt++; } } return cnt; } public static String revStr(String str){ String input = str; StringBuilder input1 = new StringBuilder(); input1.append(input); input1.reverse(); return input1.toString(); } public static String sortString(String inputString){ char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static long myPow(long n, long i){ if(i==0) return 1; if(i%2==0) return (myPow(n,i/2)%MOD * myPow(n,i/2)%MOD)%MOD; return (n%MOD* myPow(n,i-i)%MOD)%MOD; } static void palindromeSubStrs(String str) { HashSet<String>set=new HashSet<>(); char[]a =str.toCharArray(); int n=str.length(); int[][]dp=new int[n][n]; for(int g=0;g<n;g++){ for(int i=0,j=g;j<n;j++,i++){ if(!set.contains(str.substring(i,i+1))&&g==0) { dp[i][j]=1; set.add(str.substring(i,i+1)); } else { if(!set.contains(str.substring(i,j+1))&&isPalindrome(str,i,j)) { dp[i][j]=1; set.add(str.substring(i,j+1)); } } } } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(dp[i][j]+" "); if(dp[i][j]==1)ans++; } System.out.println(); } System.out.println(ans); } static boolean isPalindrome(String str,int i,int j) { while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean sign(long num) { return num>0; } static boolean isSquare(long x){ if(x==1)return true; long y=(long) Math.sqrt(x); return y*y==x; } static long power1(long a,long b) { if(b == 0){ return 1; } long ans = power(a,b/2); ans *= ans; if(b % 2!=0){ ans *= a; } return ans; } static void swap(StringBuilder sb,int l,int r) { char temp = sb.charAt(l); sb.setCharAt(l,sb.charAt(r)); sb.setCharAt(r,temp); } // function to reverse the string between index l and r static void reverse(StringBuilder sb,int l,int r) { while(l < r) { swap(sb,l,r); l++; r--; } } // function to search a character lying between index l and r // which is closest greater (just greater) than val // and return it's index static int binarySearch(StringBuilder sb,int l,int r,char val) { int index = -1; while (l <= r) { int mid = (l+r)/2; if (sb.charAt(mid) <= val) { r = mid - 1; } else { l = mid + 1; if (index == -1 || sb.charAt(index) >= sb.charAt(mid)) index = mid; } } return index; } // this function generates next permutation (if there exists any such permutation) from the given string // and returns True // Else returns false static boolean nextPermutation(StringBuilder sb) { int len = sb.length(); int i = len-2; while (i >= 0 && sb.charAt(i) >= sb.charAt(i+1)) i--; if (i < 0) return false; else { int index = binarySearch(sb,i+1,len-1,sb.charAt(i)); swap(sb,i,index); reverse(sb,i+1,len-1); return true; } } private static int lps(int m ,int n,String s1,String s2,int[][]mat) { for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(s1.charAt(i-1)==s2.charAt(j-1))mat[i][j]=1+mat[i-1][j-1]; else mat[i][j]=Math.max(mat[i-1][j],mat[i][j-1]); } } return mat[m][n]; } static int lcs(String X, String Y, int m, int n) { int[][] L = new int[m+1][n+1]; // Following steps build L[m+1][n+1] in bottom up fashion. Note // that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] for (int i=0; i<=m; i++) { for (int j=0; j<=n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (X.charAt(i-1) == Y.charAt(j-1)) L[i][j] = L[i-1][j-1] + 1; else L[i][j] = Math.max(L[i-1][j], L[i][j-1]); } } return L[m][n]; // Following code is used to print LCS // int index = L[m][n]; // int temp = index; // // // Create a character array to store the lcs string // char[] lcs = new char[index+1]; // lcs[index] = '\u0000'; // Set the terminating character // // // Start from the right-most-bottom-most corner and // // one by one store characters in lcs[] // int i = m; // int j = n; // while (i > 0 && j > 0) // { // // If current character in X[] and Y are same, then // // current character is part of LCS // if (X.charAt(i-1) == Y.charAt(j-1)) // { // // Put current character in result // lcs[index-1] = X.charAt(i-1); // // // reduce values of i, j and index // i--; // j--; // index--; // } // // // If not same, then find the larger of two and // // go in the direction of larger value // else if (L[i-1][j] > L[i][j-1]) // i--; // else // j--; // } // return String.valueOf(lcs); // Print the lcs // System.out.print("LCS of "+X+" and "+Y+" is "); // for(int k=0;k<=temp;k++) // System.out.print(lcs[k]); } static long lis(long[] aa2, int n) { long lis[] = new long[n]; int i, j; long max = 0; for (i = 0; i < n; i++) lis[i] = 1; for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (aa2[i] >= aa2[j] && lis[i] <= lis[j] + 1) lis[i] = lis[j] + 1; for (i = 0; i < n; i++) if (max < lis[i]) max = lis[i]; return max; } static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean issafe(int i, int j, int r,int c, char ch) { if (i < 0 || j < 0 || i >= r || j >= c|| ch!= '1')return false; else return true; } static long power(long a, long b) { a %=MOD; long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static long[] sieve; public static void sieve() { int nnn=(int) 1e6+1; long nn=(int) 1e6; sieve=new long[(int) nnn]; int[] freq=new int[(int) nnn]; sieve[0]=0; sieve[1]=1; for(int i=2;i<=nn;i++) { sieve[i]=1; freq[i]=1; } for(int i=2;i*i<=nn;i++) { if(sieve[i]==1) { for(int j=i*i;j<=nn;j+=i) { if(sieve[j]==1) { sieve[j]=0; } } } } } } class decrease implements Comparator<Long> { // Used for sorting in ascending order of // roll number public int compare(long a, long b) { return (int) (b - a); } @Override public int compare(Long o1, Long o2) { // TODO Auto-generated method stub return (int) (o2-o1); } } class pair{ long x; long y; long c; char ch; public pair(long x,long y) { this.x=x; this.y=y; } public pair(long x,char ch) { this.x=x; this.ch=ch; } public pair(long x,long y,long c) { this.x=x; this.y=y; this.c=c; } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
ded4da3db198579d00b87255430f07f3
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
// package faltu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class Main { public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(long[] a, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(a[mid]<m) l=mid+1; else r=mid-1; } return l; } public static long getClosest(long val1, long val2,long target) { if (target - val1 >= val2 - target) return val2; else return val1; } static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } public static int findIndex(long arr[], long t) { if (arr == null) { return -1; } int len = arr.length; int i = 0; while (i < len) { if (arr[i] == t) { return i; } else { i = i + 1; } } return -1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a,long b) { return (a / gcd(a, b)) * b; } public static int[] swap(int a[], int left, int right) { int temp = a[left]; a[left] = a[right]; a[right] = temp; return a; } public static void swap(long x,long max1) { long temp=x; x=max1; max1=temp; } public static int[] reverse(int a[], int left, int right) { // Reverse the sub-array while (left < right) { int temp = a[left]; a[left++] = a[right]; a[right--] = temp; } return a; } static int lowerLimitBinarySearch(ArrayList<Integer> A,int B) { int n =A.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(A.get(mid) > B) { second = mid; }else { first = mid+1; } } if(first < n && A.get(first) < B) { first++; } return first; //1 index } 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; } } // *******----segement tree implement---***** // -------------START-------------------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode) { if(start==end) { tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value) { if(start==end) { arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid) { updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); } else { updateTree(arr,tree,start,mid,2*treeNode,idx,value); } tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } // disjoint set implementation --start static void makeSet(int n) { parent=new int[n]; rank=new int[n]; for(int i=0;i<n;i++) { parent[i]=i; rank[i]=0; } } static void union(int u,int v) { u=findpar(u); v=findpar(v); if(rank[u]<rank[v])parent[u]=v; else if(rank[v]<rank[u])parent[v]=u; else { parent[v]=u; rank[u]++; } } private static int findpar(int node) { if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } static int parent[]; static int rank[]; // *************end static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } public static int[] sort(int[] arr) { ArrayList<Integer> al = new ArrayList<>(); for(int i=0;i<arr.length;i++) al.add(arr[i]); Collections.sort(al); for(int i=0;i<arr.length;i++) arr[i]=al.get(i); return arr; } static ArrayList<String>powof2s; static void powof2S() { long i=1; while(i<(long)2e18) { powof2s.add(String.valueOf(i)); i*=2; } } static boolean coprime(int a, long l){ return (gcd(a, l) == 1); } static int[][] dirs = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; static Long MOD=(long) (1e9+7); static int prebitsum[][]; static ArrayList<Integer>arr; static boolean[] vis; static ArrayList<ArrayList<Integer>>adj; public static void main(String[] args) throws IOException { // sieve(); // prebitsum=new int[200001][18]; // presumbit(prebitsum); // powof2S(); FastReader s = new FastReader(); int tt = s.nextInt(); while(tt-->0) { char[]ch=s.next().toCharArray(); solver(ch); } } static void solver(char[]ch) { int n=ch.length; int sum=0; boolean f=true; for(char c:ch) { if(c=='A')sum++; else sum--; if(sum<0) { f=false; break; } } if(!f||ch[n-1]!='B')System.out.println("NO"); else System.out.println("YES"); } static void pc2d(char[][]a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void pi2d(int[][]a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void DFSUtil(int v, boolean[] vis) { vis[v] = true; Iterator<Integer> it = adj.get(v).iterator(); while (it.hasNext()) { int n = it.next(); if (!vis[n]) DFSUtil(n, vis); } } static long DFS(int n) { vis = new boolean[n+1]; long cnt=0; for (int i = 1; i <= n; i++) { if (!vis[i]) { DFSUtil(i, vis); cnt++; } } return cnt; } public static String revStr(String str){ String input = str; StringBuilder input1 = new StringBuilder(); input1.append(input); input1.reverse(); return input1.toString(); } public static String sortString(String inputString){ char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static long myPow(long n, long i){ if(i==0) return 1; if(i%2==0) return (myPow(n,i/2)%MOD * myPow(n,i/2)%MOD)%MOD; return (n%MOD* myPow(n,i-i)%MOD)%MOD; } static void palindromeSubStrs(String str) { HashSet<String>set=new HashSet<>(); char[]a =str.toCharArray(); int n=str.length(); int[][]dp=new int[n][n]; for(int g=0;g<n;g++){ for(int i=0,j=g;j<n;j++,i++){ if(!set.contains(str.substring(i,i+1))&&g==0) { dp[i][j]=1; set.add(str.substring(i,i+1)); } else { if(!set.contains(str.substring(i,j+1))&&isPalindrome(str,i,j)) { dp[i][j]=1; set.add(str.substring(i,j+1)); } } } } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(dp[i][j]+" "); if(dp[i][j]==1)ans++; } System.out.println(); } System.out.println(ans); } static boolean isPalindrome(String str,int i,int j) { while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean sign(long num) { return num>0; } static boolean isSquare(long x){ if(x==1)return true; long y=(long) Math.sqrt(x); return y*y==x; } static long power1(long a,long b) { if(b == 0){ return 1; } long ans = power(a,b/2); ans *= ans; if(b % 2!=0){ ans *= a; } return ans; } static void swap(StringBuilder sb,int l,int r) { char temp = sb.charAt(l); sb.setCharAt(l,sb.charAt(r)); sb.setCharAt(r,temp); } // function to reverse the string between index l and r static void reverse(StringBuilder sb,int l,int r) { while(l < r) { swap(sb,l,r); l++; r--; } } // function to search a character lying between index l and r // which is closest greater (just greater) than val // and return it's index static int binarySearch(StringBuilder sb,int l,int r,char val) { int index = -1; while (l <= r) { int mid = (l+r)/2; if (sb.charAt(mid) <= val) { r = mid - 1; } else { l = mid + 1; if (index == -1 || sb.charAt(index) >= sb.charAt(mid)) index = mid; } } return index; } // this function generates next permutation (if there exists any such permutation) from the given string // and returns True // Else returns false static boolean nextPermutation(StringBuilder sb) { int len = sb.length(); int i = len-2; while (i >= 0 && sb.charAt(i) >= sb.charAt(i+1)) i--; if (i < 0) return false; else { int index = binarySearch(sb,i+1,len-1,sb.charAt(i)); swap(sb,i,index); reverse(sb,i+1,len-1); return true; } } private static int lps(int m ,int n,String s1,String s2,int[][]mat) { for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(s1.charAt(i-1)==s2.charAt(j-1))mat[i][j]=1+mat[i-1][j-1]; else mat[i][j]=Math.max(mat[i-1][j],mat[i][j-1]); } } return mat[m][n]; } static int lcs(String X, String Y, int m, int n) { int[][] L = new int[m+1][n+1]; // Following steps build L[m+1][n+1] in bottom up fashion. Note // that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] for (int i=0; i<=m; i++) { for (int j=0; j<=n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (X.charAt(i-1) == Y.charAt(j-1)) L[i][j] = L[i-1][j-1] + 1; else L[i][j] = Math.max(L[i-1][j], L[i][j-1]); } } return L[m][n]; // Following code is used to print LCS // int index = L[m][n]; // int temp = index; // // // Create a character array to store the lcs string // char[] lcs = new char[index+1]; // lcs[index] = '\u0000'; // Set the terminating character // // // Start from the right-most-bottom-most corner and // // one by one store characters in lcs[] // int i = m; // int j = n; // while (i > 0 && j > 0) // { // // If current character in X[] and Y are same, then // // current character is part of LCS // if (X.charAt(i-1) == Y.charAt(j-1)) // { // // Put current character in result // lcs[index-1] = X.charAt(i-1); // // // reduce values of i, j and index // i--; // j--; // index--; // } // // // If not same, then find the larger of two and // // go in the direction of larger value // else if (L[i-1][j] > L[i][j-1]) // i--; // else // j--; // } // return String.valueOf(lcs); // Print the lcs // System.out.print("LCS of "+X+" and "+Y+" is "); // for(int k=0;k<=temp;k++) // System.out.print(lcs[k]); } static long lis(long[] aa2, int n) { long lis[] = new long[n]; int i, j; long max = 0; for (i = 0; i < n; i++) lis[i] = 1; for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (aa2[i] >= aa2[j] && lis[i] <= lis[j] + 1) lis[i] = lis[j] + 1; for (i = 0; i < n; i++) if (max < lis[i]) max = lis[i]; return max; } static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean issafe(int i, int j, int r,int c, char ch) { if (i < 0 || j < 0 || i >= r || j >= c|| ch!= '1')return false; else return true; } static long power(long a, long b) { a %=MOD; long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static long[] sieve; public static void sieve() { int nnn=(int) 1e6+1; long nn=(int) 1e6; sieve=new long[(int) nnn]; int[] freq=new int[(int) nnn]; sieve[0]=0; sieve[1]=1; for(int i=2;i<=nn;i++) { sieve[i]=1; freq[i]=1; } for(int i=2;i*i<=nn;i++) { if(sieve[i]==1) { for(int j=i*i;j<=nn;j+=i) { if(sieve[j]==1) { sieve[j]=0; } } } } } } class decrease implements Comparator<Long> { // Used for sorting in ascending order of // roll number public int compare(long a, long b) { return (int) (b - a); } @Override public int compare(Long o1, Long o2) { // TODO Auto-generated method stub return (int) (o2-o1); } } class pair{ long x; long y; long c; char ch; public pair(long x,long y) { this.x=x; this.y=y; } public pair(long x,char ch) { this.x=x; this.ch=ch; } public pair(long x,long y,long c) { this.x=x; this.y=y; this.c=c; } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
0a6a6a3222a6cccf2b71f6aebf6efb0f
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class CF_1672B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while (t-- > 0) { String s2 = sc.nextLine(); int aCount = 0; int bCount = 0; boolean isGood = true; for (int i = 0; i < s2.length(); i++) { if (s2.charAt(i) == 'A') aCount++; else { bCount++; if (bCount > aCount) { isGood = false; break; } } } if (aCount == 0 || bCount == 0 || s2.charAt(s2.length()-1) == 'A') isGood = false; System.out.println(isGood ? "YES" : "NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
a6c48b99f29886e30dc6b0c17ce4de09
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
/** * @Jai_Bajrang_Bali * @Har_Har_Mahadev */ import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class practice2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while (t-- > 0) { String str=sc.next(); int len=str.length(); boolean check=true; int a=0; int b=0; if(str.charAt(0)=='B'|| str.charAt(len-1)=='A') check=false; for (int i = 0; i < str.length(); i++) { if(str.charAt(i)=='A') a++; else b++; if(a<b) { check=false; } } if(check) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
db088e94ed0aa89550d0f493db8bfd70
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); StringBuilder sb = new StringBuilder(); while(t-->0) { String s = scn.next(); int countA = 0; int countB = 0; for(int i = 0 ; i<s.length() ; i++) { if (s.charAt(i) == 'A') countA++; else countB++; if(countA<countB) break; } if(countA<countB || countB==0 || countA==0 ||s.charAt(0)=='B' || s.charAt(s.length()-1)=='A') System.out.println("No"); else System.out.println("Yes"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
325e5824d87a07871cd1c979736a0665
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
//package codeforces.globalround20; import java.io.*; import java.util.*; import static java.lang.Math.*; public class B { static InputReader in; static PrintWriter out; public static void main(String[] args) { //initReaderPrinter(true); initReaderPrinter(false); solve(in.nextInt()); //solve(1); } /* General tips 1. It is ok to fail, but it is not ok to fail for the same mistakes over and over! 2. Train smarter, not harder! 3. If you find an answer and want to return immediately, don't forget to flush before return! */ /* Read before practice 1. Set a timer based on a problem's difficulty level: 45 minutes at your current target practice level; 2. During a problem solving session, focus! Do not switch problems or even worse switch to do something else; 3. If fail to solve within timer limit, read editorials to get as little help as possible to get yourself unblocked; 4. If after reading the entire editorial and other people's code but still can not solve, move this problem to to-do list and re-try in the future. 5. Keep a practice log about new thinking approaches, good tricks, bugs; Review regularly; 6. Also try this new approach suggested by um_nik: Solve with no intention to read editorial. If getting stuck, skip it and solve other similar level problems. Wait for 1 week then try to solve again. Only read editorial after you solved a problem. 7. Remember to also submit in the original problem link (if using gym) so that the 1 v 1 bot knows which problems I have solved already. 8. Form the habit of writing down an implementable solution idea before coding! You've taken enough hits during contests because you rushed to coding! */ /* Read before contests and lockout 1 v 1 Mistakes you've made in the past contests: 1. Tried to solve without going through given test examples -> wasting time on solving a different problem than asked; 2. Rushed to coding without getting a comprehensive sketch of your solution -> implementation bugs and WA; Write down your idea step by step, no need to rush. It is always better to have all the steps considered before hand! Think about all the past contests that you have failed because slow implementation and implementation bugs! This will be greatly reduced if you take your time to get a thorough idea steps! 3. Forgot about possible integer overflow; When stuck: 1. Understand problem statements? Walked through test examples? 2. Take a step back and think about other approaches? 3. Check rank board to see if you can skip to work on a possibly easier problem? 4. If none of the above works, take a guess? */ static void solve(int testCnt) { for (int testNumber = 0; testNumber < testCnt; testNumber++) { char[] s = in.next().toCharArray(); boolean ans = (s[0] == 'A' && s[s.length - 1] == 'B'); if(ans) { int cnta = 0; for(int i = 0; i < s.length; i++) { if(s[i] == 'A') cnta++; else { ans &= (cnta > 0); cnta--; } } } out.println(ans ? "YES" : "NO"); } out.close(); } static void initReaderPrinter(boolean test) { if (test) { try { in = new InputReader(new FileInputStream("src/input.in")); out = new PrintWriter(new FileOutputStream("src/output.out")); } catch (IOException e) { e.printStackTrace(); } } else { in = new InputReader(System.in); out = new PrintWriter(System.out); } } static class InputReader { BufferedReader br; StringTokenizer st; InputReader(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream), 32768); } 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()); } 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; } Integer[] nextIntArray(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitive(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitiveOneIndexed(int n) { int[] a = new int[n + 1]; for (int i = 1; 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; } long[] nextLongArrayPrimitive(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long[] nextLongArrayPrimitiveOneIndexed(int n) { long[] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextLong(); return a; } String[] nextStringArray(int n) { String[] g = new String[n]; for (int i = 0; i < n; i++) g[i] = next(); return g; } List<Integer>[] readGraphOneIndexed(int n, int m) { List<Integer>[] adj = new List[n + 1]; for (int i = 0; i <= n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt(); int v = nextInt(); adj[u].add(v); adj[v].add(u); } return adj; } List<Integer>[] readGraphZeroIndexed(int n, int m) { List<Integer>[] adj = new List[n]; for (int i = 0; i < n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; adj[u].add(v); adj[v].add(u); } return adj; } /* A more efficient way of building an undirected graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildUndirectedGraph(int nodeCnt, int edgeCnt) { int[] end1 = new int[edgeCnt], end2 = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(); edgeCntForEachNode[u]++; edgeCntForEachNode[v]++; end1[i] = u; end2[i] = v; } int[][] adj = new int[nodeCnt + 1][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]]; } for (int i = 0; i < edgeCnt; i++) { adj[end1[i]][idxForEachNode[end1[i]]] = end2[i]; idxForEachNode[end1[i]]++; adj[end2[i]][idxForEachNode[end2[i]]] = end1[i]; idxForEachNode[end2[i]]++; } return adj; } /* A more efficient way of building a directed graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildDirectedGraph(int nodeCnt, int edgeCnt) { int[] from = new int[edgeCnt], to = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; //from u to v: u -> v for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(); edgeCntForEachNode[u]++; from[i] = u; to[i] = v; } int[][] adj = new int[nodeCnt + 1][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]]; } for (int i = 0; i < edgeCnt; i++) { adj[from[i]][idxForEachNode[from[i]]] = to[i]; idxForEachNode[from[i]]++; } return adj; } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
c70cae23dc6a8f9751cb478f19993edc
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class solution{ public static void main (String[] args) { int t=sc.nextInt(); while(t--!=0) { String s=sc.next(); int a = 0 , b = 0 , flag = 1; for(int i=0 ; i<s.length() ; i++){ if(s.charAt(i)== 'B'){ b++ ; }else{ a++; } if(a<b){ flag = 0 ; } } if(s.charAt(s.length()-1) != 'B'){ flag = 0; } if(flag==1){ out.println("YES"); }else{ out.println("NO"); } } //////////////////////////////////////////////////////////////////// out.flush();out.close(); }//*END OF MAIN METHOD* static final Random random = new Random(); static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] readArrayL(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static FastScanner sc = new FastScanner(); }//*END OF MAIN CLASS*
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
8779ec69ebe95eaeb74872460ada9a01
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.*; import java.util.Random; import java.util.StringTokenizer; import static java.lang.Long.*; public class RandomClass { static final Random random = new Random(); public static class Node implements Comparable<Node> { int x; int y; public Node(int a, int b) { x = a; y = b; } @Override public int compareTo(Node o) { if (this.x > o.x) { return +1; } else if (this.x == o.x) { return 0; } else { return -1; } } } public static class Node1 { int number; int count; public Node1(int num, int c) { number = num; count = c; } } public static void main(String args[]) throws Exception { FastReader fs = new FastReader(); StringBuilder sb = new StringBuilder(); int t = fs.nextInt(); while (t-- > 0) { String s2 = fs.nextLine(); if (s2.length() == 1) { sb.append("NO\n"); } else { char prev = s2.charAt(0); if (prev == 'B') { sb.append("NO\n"); continue; } if (s2.charAt(s2.length() - 1) != 'B') { sb.append("NO\n"); continue; } int flag = 0; ArrayList<Integer> positionOfBs = new ArrayList<>(); for (int i = 1; i < s2.length(); i++) { char curr = s2.charAt(i); if (curr == 'B') { positionOfBs.add(i); } } if (positionOfBs.size() == 1) { sb.append("YES\n"); } else { int prevBPosition = positionOfBs.get(0); int breakFlag = 0; for (int i = 0; i < positionOfBs.size(); i++) { int currBPosition = positionOfBs.get(i); if (currBPosition - prevBPosition == 1) { // int lengthOfStringBeforePrevBPosition = prevBPosition; // int numberOfBsBeforePrevBPosition = (i-1); int lengthOfStringTillNow = currBPosition+1; int numberOfBsTillNow = (i+1); if(lengthOfStringTillNow < numberOfBsTillNow*2) { sb.append("NO\n"); breakFlag = 1; break; } } prevBPosition = currBPosition; } if (breakFlag != 1) { sb.append("YES\n"); } } } } System.out.println(sb); } static int gcd(int a, int b) { return (a % b == 0) ? Math.abs(b) : gcd(b, a % b); } static boolean isPossible(int a, int b, int c) { return (c % gcd(a, b) == 0); } //Fast Reader static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void ruffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output
PASSED
24b3cce7a47f0507596a916856d1aacd
train_108.jsonl
1650722700
Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$\texttt{A}$$$ except for the last character which is $$$\texttt{B}$$$. The good strings are $$$\texttt{AB},\texttt{AAB},\texttt{AAAB},\ldots$$$. Note that $$$\texttt{B}$$$ is not a good string.You are given an initially empty string $$$s_1$$$.You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?
256 megabytes
//package com.codeforces.GlobalRound20; import java.io.*; import java.util.StringTokenizer; public class Div2B { 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) { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); FastReader fsr = new FastReader(); int T = fsr.nextInt(); for (int i = 1; i <= T; i++) { String s2 = fsr.nextLine(); isBuildableByGoodStrings(s2, out); } out.flush(); out.close(); } private static void isBuildableByGoodStrings(String s2, PrintWriter out) { int n = s2.length(); if (n < 2) { out.println("NO"); return; } int numA = 0; for (int i = 0; i < s2.length(); i++) { if (s2.charAt(i) == 'A') { numA++; } else if (numA == 0) { out.println("NO"); return; } else { numA--; } } if (s2.charAt(n - 1) == 'B') { out.println("YES"); } else { out.println("NO"); } } }
Java
["4\n\nAABAB\n\nABB\n\nAAAAAAAAB\n\nA"]
1 second
["YES\nNO\nYES\nNO"]
NoteIn the first test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAB}} \to \texttt{A}\color{red}{\texttt{AB}}\texttt{AB}$$$.In the third test case, we transform $$$s_1$$$ as such: $$$\varnothing \to \color{red}{\texttt{AAAAAAAAB}}$$$.In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0b9be2f076cfa13cdc76c489bf1ea416
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 \leq |s_2| \leq 2 \cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$\texttt{A}$$$ and $$$\texttt{B}$$$. It is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
800
For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
standard output