filename_1,filename_2,code_1,code_2,labels,notes 0df4050e,6f02c6d9,"import java.io.*; import java.util.*; public class MainClass { public static void main(String[] args) { Reader in = new Reader(System.in); int t = in.nextInt(); StringBuilder stringBuilder = new StringBuilder(); while (t-- > 0) { ArrayList reds = new ArrayList<>(); ArrayList blue = new ArrayList<>(); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt() - 1; } char[] s = in.next().toCharArray(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { reds.add(a[i]); } else { blue.add(a[i]); } } Collections.sort(reds, Collections.reverseOrder()); Collections.sort(blue); boolean ff = true; int start = 0; for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < start) { ff = false; break; } start++; } start = n - 1; for (int i = 0; i < reds.size(); i++) { if (reds.get(i) > start) { ff = false; break; } start--; } stringBuilder.append(ff?""YES"":""NO"").append(""\n""); } System.out.println(stringBuilder); } } class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader(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()); } }"," import java.io.*; import java.util.*; public class Main { static long mod = 1000000007; static long inv(long a, long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } static long mi(long a) { return inv(a, mod); } static InputReader sc = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] A = new int[n]; for (int i = 0; i < A.length; i++) { A[i] = sc.nextInt(); } String word = sc.next(); ArrayList blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < word.length(); i++) { if (word.charAt(i) == 'R') { red.add(A[i]); } else { blue.add(A[i]); } } Collections.sort(blue); Collections.sort(red); boolean possible = true; int a = 1; for (int i = 0; i < blue.size(); i++, a++) { if (blue.get(i) < a) { possible = false; break; } } for (int i = 0; i < red.size(); i++, a++) { if (red.get(i) > a) { possible = false; break; } } if (possible) out.println(""YES""); else out.println(""NO""); } out.flush(); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } public static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } public static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } } ",1,"(L6) similar main code with variable change, changing the order of few lines, in a slightly larger code, additional code. Unused functions. Different Logic." 3dd65549,c1638a45,"import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); char[] a=sc.next().toCharArray(); char[] b=sc.next().toCharArray(); int e0=0; int e1=0; int o0=0; int o1=0; for(int i=0;i { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }","import java.io.*; import java.util.*; public class qC { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while(T-- > 0) { int N = Integer.parseInt(br.readLine()); char[] curr = br.readLine().toCharArray(); char[] sol = br.readLine().toCharArray(); // int oddP = 0; // int evenP = 0; // int even1 = 0; // int odd1 = 0; // int even0 = 0; // int odd0 = 0; // boolean alreadySolved = true; // for(int i = 0;i < N;i++) { // if(curr[i] == sol[i]) { // evenP++; // if(curr[i] == '1') even1++; // else even0++; // } // else { // oddP++; // if(curr[i] == '1') odd1++; // else odd0++; // alreadySolved = false; // } // } // // if(alreadySolved) { // System.out.println(0); // continue; // } // int minSwaps = Integer.MAX_VALUE; // if(N % 2 == 1) { // if(evenP % 2 == 1 && Math.abs(odd1 - odd0) <= 1 && odd1 > 0 && odd0 > 0) { // minSwaps = Math.min(minSwaps, oddP); // } // if(oddP % 2 == 0 && Math.abs(even1 - even0) <= 1 && even1 > 0 && even1 > 0) { // minSwaps = Math.min(minSwaps, evenP); // } // } // else { // if(evenP % 2 == 0 && Math.abs(odd1 - odd0) <= 1 && odd1 > 0 && odd0 > 0) { // minSwaps = Math.min(minSwaps, oddP); // } // if(oddP % 2 == 1 && Math.abs(even1 - even0) <= 1 && even1 > 0 && even1 > 0) { // minSwaps = Math.min(minSwaps, evenP); // } // } // System.out.println((minSwaps == Integer.MAX_VALUE) ? -1: minSwaps); int curr1 = 0; int sol1 = 0; int mismatch = 0; for(int i = 0;i < N;i++) { if(curr[i] == '1') curr1++; if(sol[i] == '1') sol1++; if(curr[i] != sol[i]) mismatch++; } int minAns = Integer.MAX_VALUE; //even operations if(curr1 == sol1 && mismatch % 2 == 0) { minAns = Math.min(mismatch, minAns); } //odd operations for(int i = 0;i < N;i++) { if(curr[i] == '1') { int tempcurr1 = N - curr1 + 1; int tempmismatch; if(sol[i] == '0') { tempmismatch = N - mismatch; } else { tempmismatch = N - mismatch - 1; } if(tempcurr1 == sol1 && tempmismatch % 2 == 0) { minAns = Math.min(minAns, tempmismatch + 1); } } } System.out.println((minAns == Integer.MAX_VALUE) ? -1 : minAns); } } } ",0,Non-Plagiarised 53196443,e496d229,"import java.lang.*; import java.util.*; import java.io.*; public class Main { static FastScanner in = new FastScanner(); static void solve() { int n = in.nextInt(); long[] a = new long[n], odd = new long[n], even = new long[n]; long[] sum = new long[n]; long m1 = Long.MAX_VALUE, m2 = Long.MAX_VALUE; long st = 0; for (int i = 0; i < n; ++i) { a[i] = in.nextLong(); if (i % 2 == 0 && a[i] < m1) m1 = a[i]; if (i % 2 == 1 && a[i] < m2) m2 = a[i]; st += a[i]; odd[i] = m1; even[i] = m2; sum[i] = st; } long ans = Long.MAX_VALUE; for (int i = 1; i < n; ++i) { long aux = sum[i] + odd[i] * (n - i - 1 + (i + 1) / 2) + even[i] * (n - (i + 1) / 2); if (aux < ans && aux > 0) ans = aux; } System.out.println(ans); } public static void main(String[] args) { int T = in.nextInt(); while (T-- > 0) solve(); } static class Pair { X x; Y y; public Pair(X x, Y y) { this.x = x; this.y = y; } } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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; } } ","import java.util.*; //import java.util.Stack; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); long[] a=new long[n]; long[] odd=new long[n]; long[] even=new long[n]; long[] sum=new long[n]; long m1=Long.MAX_VALUE; long m2=Long.MAX_VALUE; long st=(long)0; for(int i=0;ia[i]) m1=a[i]; if(i%2==1&&m2>a[i]) m2=a[i]; st+=a[i]; odd[i]=m1; even[i]=m2; sum[i]=st; } long minc=Long.MAX_VALUE; for(int i=1;i0) minc=c; } System.out.println(minc); } } } ",1,(L4) Similar code with variable name change within a slightly larger code. New function. 05f939b3,e647bef7," //package cf; import java.io.*; import java.util.*; public class D_668 { static int p=1000000007; static int dia=Integer.MIN_VALUE; public static void main(String[] args) throws Exception{ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), ""ASCII""), 512); FastReader sc=new FastReader(); int t=sc.nextInt(); StringBuilder sb=new StringBuilder(); while(t-->0) { int n=sc.nextInt(); int a=sc.nextInt(); int b=sc.nextInt(); int da=sc.nextInt(); int db=sc.nextInt(); dia=Integer.MIN_VALUE; int dp[]=new int[(int) n+1]; List adj[]=new ArrayList[n+1]; for(int i=0;i<=n;i++) { adj[i]=new ArrayList<>(); } Set s=new HashSet<>(); for(int i=1;i=db||2*da>=dia||da>=dp[b]) sb.append(""Alice\n""); else sb.append(""Bob\n""); } System.out.println(sb.toString()); out.flush(); } public static int dfs(int dp[],List adj[],int i,int p,int d) { dp[i]=d; int last_max=0; for(int v:adj[i]) { if(p!=v&&dp[v]==0) { int max=1+dfs(dp,adj,v,i,d+1); dia=Math.max(dia,max+last_max); last_max=Math.max(last_max,max); } } return last_max; } public static int binary_Search_upper(int ar[],int x) { int res=-1; int l=0;int r=ar.length-1; while(l<=r) { int mid=(l+r)>>1; if(ar[mid]==x) { res=mid; l=mid+1; } else if(ar[mid]>x) { r=mid-1; } else { l=mid+1; } } return res; } public static int binary_Search_lower(int ar[],int x) { int res=-1; int l=0;int r=ar.length-1; while(l<=r) { int mid=(l+r)>>1; if(ar[mid]==x) { res=mid; r=mid-1; } else if(ar[mid]>x) { r=mid-1; } else { l=mid+1; } } return res; } int bit[]=new int[(int)1e6]; public void update(int n,int val,int i) { i++; while(i0) { sum+=bit[i]; i-=(i)&(-i); } return sum; } /////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// 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; } } } "," import java.io.*; import java.util.*; public class Main { private static final boolean N_CASE = true; private List> g; private int a; private int b; private int da; private int db; private int max; private int ab; private int dfs(int u, int fa, int depth) { if (u == a) { ab = depth; } int m1 = 0, m2 = 0; for (int v : g.get(u)) { if (v != fa) { int m = dfs(v, u, depth + 1) + 1; if (m > m1) { m2 = m1; m1 = m; } else if (m > m2) { m2 = m; } } } max = Math.max(max, m1 + m2); int cmax = Math.max(m1, m2); max = Math.max(max, cmax + depth); return cmax; } private void solve() { int n = sc.nextInt(); a = sc.nextInt() - 1; b = sc.nextInt() - 1; da = sc.nextInt(); db = sc.nextInt(); g = createGraph(n); for (int i = 0; i < n - 1; ++i) { int u = sc.nextInt() - 1, v = sc.nextInt() - 1; g.get(u).add(v); g.get(v).add(u); } max = 0; dfs(b, -1, 0); db = Math.min(max, db); boolean win = true; if (ab > da) { if (db > da * 2) { win = false; } } out.println(win ? ""Alice"" : ""Bob""); } private void run() { int T = N_CASE ? sc.nextInt() : 1; for (int t = 0; t < T; ++t) { solve(); } } private static MyWriter out; private static MyScanner sc; private static class MyScanner { BufferedReader br; StringTokenizer st; private MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[][] nextIntArray(int n, int m) { int[][] a = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = sc.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[][] nextLongArray(int n, int m) { long[][] a = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextLong(); } } return a; } List nextList(int n) { List list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(nextInt()); } return list; } List nextLongList(int n) { List list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(nextLong()); } return list; } char[] nextCharArray(int n) { return sc.next().toCharArray(); } char[][] nextCharArray(int n, int m) { char[][] c = new char[n][m]; for (int i = 0; i < n; i++) { String s = sc.next(); for (int j = 0; j < m; j++) { c[i][j] = s.charAt(j); } } return c; } } private static class MyWriter extends PrintWriter { private MyWriter(OutputStream outputStream) { super(outputStream); } void printArray(int[] a) { for (int i = 0; i < a.length; ++i) { print(a[i]); print(i == a.length - 1 ? '\n' : ' '); } } void printArray(long[] a) { for (int i = 0; i < a.length; ++i) { print(a[i]); print(i == a.length - 1 ? '\n' : ' '); } } void println(int[] a) { for (int v : a) { println(v); } } void print(List list) { for (int i = 0; i < list.size(); ++i) { print(list.get(i)); print(i == list.size() - 1 ? '\n' : ' '); } } void println(List list) { list.forEach(this::println); } } private List> createGraph(int n) { List> g = new ArrayList<>(); for (int i = 0; i < n; ++i) { g.add(new ArrayList<>()); } return g; } private void fill(int[][] a, int value) { for (int[] row : a) { fill(row, value); } } private void fill(int[] a, int value) { Arrays.fill(a, value); } public static void main(String[] args) { out = new MyWriter(new BufferedOutputStream(System.out)); sc = new MyScanner(); new Main().run(); out.close(); } }",0,Non-Plagiarised ac121776,eb6cfca7,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Solution { static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class HashMultiSet implements Iterable { private final HashMap map; private int size; public HashMultiSet(){map=new HashMap<>(); size=0;} public void clear(){map.clear(); size=0;} public int size(){return size;} public int setSize(){return map.size();} public boolean contains(T a){return map.containsKey(a);} public boolean isEmpty(){return size==0;} public Integer get(T a){return map.getOrDefault(a,0);} public void add(T a, int count) { int cur=get(a);map.put(a,cur+count); size+=count; if(cur+count==0) map.remove(a); } public void addOne(T a){add(a,1);} public void remove(T a, int count){add(a,Math.max(-get(a),-count));} public void removeOne(T a){remove(a,1);} public void removeAll(T a){remove(a,Integer.MAX_VALUE-10);} public Iterator iterator() { return new Iterator<>() { private final Iterator iter = map.keySet().iterator(); private int count = 0; private T curElement; public boolean hasNext(){return iter.hasNext()||count>0;} public T next() { if(count==0) { curElement=iter.next(); count=get(curElement); } count--; return curElement; } }; } } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) { // Initially, all elements are in // their own set. parent[i] = i; } } // Returns representative of x's set int find(int x) { // Finds the representative of the set // that x is an element of if (parent[x] != x) { // if x is not the parent of itself // Then x is not the representative of // his set, parent[x] = find(parent[x]); // so we recursively call Find on its parent // and move i's node directly under the // representative of this set } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { // Find representatives of two sets int xRoot = find(x), yRoot = find(y); // Elements are in the same set, no need // to unite anything. if (xRoot == yRoot) return; // If x's rank is less than y's rank if (rank[xRoot] < rank[yRoot]) // Then move x under y so that depth // of tree remains less parent[xRoot] = yRoot; // Else if y's rank is less than x's rank else if (rank[yRoot] < rank[xRoot]) // Then move y under x so that depth of // tree remains less parent[yRoot] = xRoot; else // if ranks are the same { // Then move y under x (doesn't matter // which one goes where) parent[yRoot] = xRoot; // And increment the result tree's // rank by 1 rank[xRoot] = rank[xRoot] + 1; } } } private static boolean try1(String s, int index,int prev){ int n = s.length(); for(int i = index;i= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static void main(String[] args) throws FileNotFoundException { new Main(); } } ",0,Non-Plagiarised 089b7f00,fb20d298,"import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while(t>0){ int n=scan.nextInt(); int[] a=new int[n]; for(int i=0;iset=new TreeSet<>(); set.add(a[0]); boolean flag=false; for(int i=1;i0) { int n = sc.nextInt(); int b[] = sc.readArray(n); TreeSet set = new TreeSet<>(); boolean f = true; set.add(b[0]); for(int i=1 ; i{ int i, w; public Tower(int a, int b) { i=a; w=b; } public int compareTo(Tower o) {return w - o.w;} } static class Block implements Comparable{ int i, w; public Block(int a, int b) { i=a; w=b; } public int compareTo(Block o) {return o.w-w;} } static PriorityQueue towers; static PriorityQueue blocks; static int[] par; static void solve() { while (!blocks.isEmpty()) { Block h = blocks.poll(); Tower t = towers.poll(); par[h.i] = t.i; t.w += h.w; towers.add(t); } List res = new ArrayList(towers); Collections.sort(res); boolean works = true; for (int i =1 ; i < m; i++) { if (Math.abs(res.get(i-1).w - res.get(i).w) > x) works = false; } if (works) { out.println(""YES""); for (int i = 0; i < n; i++) out.print(par[i] + 1 + "" ""); out.println(); } else out.println(""NO""); } static int n,m,x; public static void readInput() throws IOException { // br = new BufferedReader(new FileReader("".in"")); // out = new PrintWriter(new FileWriter("".out"")); int t = Integer.parseInt(br.readLine()); while (t-->0) { StringTokenizer st= new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); x = Integer.parseInt(st.nextToken()); towers = new PriorityQueue(); blocks = new PriorityQueue(); par = new int[n]; st = new StringTokenizer(br.readLine()); for (int i= 0 ; i < n; i++) { blocks.add(new Block(i,Integer.parseInt(st.nextToken()))); } for (int i =0 ; i < m; i++) { towers.add(new Tower(i, 0)); } solve(); } } } ","/* bts songs to dance to: I need U Run ON Filter I'm fine */ 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 x1515C { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int X = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); ArrayList ls = new ArrayList(); for(int i=0; i < N; i++) ls.add(new Unit(arr[i], i)); Collections.sort(ls); int[] res = new int[N]; PriorityQueue pq = new PriorityQueue(Comparator.reverseOrder()); for(int i=1; i <= M; i++) pq.add(new Unit(0, i)); for(Unit add: ls) { Unit tower = pq.poll(); tower.height += add.height; res[add.id] = tower.id; pq.add(tower); } int min = pq.poll().height; int max = min; while(pq.size() > 0) max = max(max, pq.poll().height); if(max-min > X) sb.append(""NO\n""); else { sb.append(""YES\n""); for(int x: res) sb.append(x+"" ""); sb.append(""\n""); } } System.out.print(sb); } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } } class Unit implements Comparable { public int id; public int height; public Unit(int h, int i) { height = h; id = i; } public int compareTo(Unit oth) { return oth.height-height; } }",0,Non-Plagiarised 9291ca83,b185d034,"import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Practice { static HashMap map = new HashMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); int[][] occurances = new int[5][n]; for(int i=0;i=0;j--){ tmpSum+=occurances[i][j]; if(tmpSum>0) tmpAns++; else break; } ans = Math.max(ans, tmpAns); } System.out.println(ans); } } } ","import java.io.*; import java.util.*; public class A734C { public static void main(String[] args) { JS scan = new JS(); int t = scan.nextInt(); loop:while(t-->0){ int n = scan.nextInt(); String[] arr= new String[n]; Integer[][] counts = new Integer[5][n]; for(int i = 0;i<5;i++){ for(int j = 0;j=0;j--){ extra+=counts[i][j]; if(extra>0)curr++; } best = Math.max(best,curr); } System.out.println(best); } } static class JS { public int BS = 1 << 16; public char NC = (char) 0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar() { 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 long nextLong() { num = 1; boolean neg = false; if (c == NC) c = nextChar(); for (; (c < '0' || c > '9'); c = nextChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; num *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / num; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c > 32) { res.append(c); c = nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c != '\n') { res.append(c); c = nextChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = nextChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ",1,"(L4) Variable name change, switch the location of lines, change single while for for, within a slightly larger code. New class of FastScanner and its functions. " 28c2d81a,48c5f745," import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class D { public static void main(String[] args) { FastScanner fs = new FastScanner(); int cases = fs.nextInt(); while(cases-->0){ int n = fs.nextInt(), k = fs.nextInt(); int[] positions = fs.readArray(k), temps = fs.readArray(k); int[] forced = new int[n]; Arrays.fill(forced, Integer.MAX_VALUE/2); for(int i=0; i=0; i--) forced[i] = Math.min(forced[i], forced[i+1]+1); for(int i=0; i ""+a); } public static void debug(long a, long b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(char a, char b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(int[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(char[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(HashMap map){ System.out.print(""Map--> ""+map.toString()); } } } "," import java.io.*; import java.util.*; public class E { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Reader sc=new Reader(); PrintWriter pw=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); int[] idxes=new int[k]; int[] temps=new int[k]; for(int i=0;i=0;i--) { ans[i]=Math.min(ans[i], ans[i+1]+1); } for(int i=0;i= '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(); } } } ",1,"(L4) Similar main function, variable renaming, splitting/combining lines, slightly larger file, different imports. Additional unused class/functions. FastScanner class and its functions." 1ea771ea,ee270b2a," import java.io.*; import java.util.*; public class CODECHEF { 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(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static long MOD=1000000000; static class Pair{ long a; int b; Pair(long i,int j){ a=i; b=j; } } static long[] solve(int[] pos,long[] arr,int n,int k){ long[] ans=new long[n]; long[] left=new long[n]; long[] right=new long[n]; long min=Integer.MAX_VALUE; for(int i=0;i=0;i--){ min=Math.min(min+1,arr[i]); right[i]=min; } for(int i=0;i0){ int n=fs.nextInt(); int k=fs.nextInt(); int[] pos=new int[k]; for(int i=0;i 0){ int n = scanner.nextInt(), k = scanner.nextInt(); int[] a = new int[k]; for(int i=0;i=0;i--){ R[i] = Math.min(min+1,R[i]); min = R[i]; } for(int i=0;i0) { int n = sc.nextInt(); char[] s = new char[n]; char[] t = new char[n]; s = sc.next().toCharArray(); t = sc.next().toCharArray(); int a = 0, b = 0, c = 0, d = 0; for(int i = 0; i < n; i++) { if(s[i] == '0' && t[i] == '0') a++; if(s[i] == '1' && t[i] == '0') b++; if(s[i] == '0' && t[i] == '1') c++; if(s[i] == '1' && t[i] == '1') d++; } int res = Integer.MAX_VALUE; if(b == c || b+1 == c) { if((b + c) % 2 == 0) { res = Math.min(res, b + c); } } if(a == d || a+1 == d) { if((a + d) % 2 == 1) { res = Math.min(res, a + d); } } if(res == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(res); } } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } } ","import java.util.*; import java.io.*; public class C { public static void main(String[] args) { FastScanner sc = new FastScanner(); int T = sc.nextInt(); while(T-->0) { int n = sc.nextInt(); char[] s = new char[n]; char[] t = new char[n]; s = sc.next().toCharArray(); t = sc.next().toCharArray(); int a = 0, b = 0, c = 0, d = 0; for(int i = 0; i < n; i++) { if(s[i] == '0' && t[i] == '0') a++; if(s[i] == '1' && t[i] == '0') b++; if(s[i] == '0' && t[i] == '1') c++; if(s[i] == '1' && t[i] == '1') d++; } int res = Integer.MAX_VALUE; if(b == c || b+1 == c) { if((b + c) % 2 == 0) { res = Math.min(res, b + c); } } if(a == d || a+1 == d) { if((a + d) % 2 == 1) { res = Math.min(res, a + d); } } if(res == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(res); } } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } } ",1,EM 3380fa52,8a39dbf5,"import java.util.*; import java.io.*; import java.math.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Coder { static int n, k; static long a[]; static int pos[]; static int temp[]; static StringBuilder str = new StringBuilder(""""); static int cnt[][] = new int[(int)1e5+5][2]; static void solve() { long []l = new long[n]; long []r = new long[n]; long p = Integer.MAX_VALUE; for(int i=0;i=0;i--){ p = Math.min(p+1, a[i]); r[i] = p; } for(int i=0;i 0) { bf.readLine(); String s[] = bf.readLine().trim().split(""\\s+""); n = Integer.parseInt(s[0]); k = Integer.parseInt(s[1]); s = bf.readLine().trim().split(""\\s+""); pos = new int[k]; temp = new int[k]; a = new long[n]; for(int i=0;i=0;j--) { if(arr[j]==0) { right[j]=right[j+1]+1; } else { right[j]=Math.min(right[j+1]+1,arr[j]); } } for(int j=0;j 0) { int n = Integer.parseInt(br.readLine()); String source = br.readLine(); String destination = br.readLine(); int sameStatusOnes = 0; int sameStatusZeros = 0; int diffStatusOnes = 0; int diffStatusZeros = 0; for (int i = 0; i < n; i++) { char c1 = source.charAt(i); char c2 = destination.charAt(i); if (c1 == c2) { if (c1 == '0') { sameStatusZeros += 1; } else { sameStatusOnes += 1; } } else { if (c1 == '0') { diffStatusZeros += 1; } else { diffStatusOnes += 1; } } } int sameStatus = sameStatusOnes + sameStatusZeros; int diffStatus = diffStatusOnes + diffStatusZeros; //first case if (sameStatus == n) { System.out.println(0); } else if (diffStatus == n) { //second case if (diffStatus % 2 == 0 && diffStatusOnes == (n + 1) / 2) System.out.println(n); else System.out.println(-1); } else { int op1 = -1; int op2 = -1; if (sameStatus % 2 != 0 && sameStatusOnes == (sameStatus + 1) / 2) op1 = sameStatus; if (diffStatus % 2 == 0 && diffStatusOnes == (diffStatus + 1) / 2) op2 = diffStatus; if (op1 != -1 && op2 != -1) System.out.println(Integer.min(op1, op2)); else if (op1 != -1) System.out.println(op1); else if (op2 != -1) System.out.println(op2); else System.out.println(-1); } t--; } } } ","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 Template { static int mod = 1000000007; public static void main(String[] args){ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int yo = sc.nextInt(); while (yo-- > 0) { int n = sc.nextInt(); String s = sc.next(); String t = sc.next(); int op1 = cal(s,t,n); int op2 = helper(s,t,n,'0'); int op3 = helper(s,t,n,'1'); int ans = min(min(op1,op2),op3); if(ans == Integer.MAX_VALUE){ out.println(""-1""); } else { out.println(ans); } } out.close(); } static int helper(String str1, String str2, int n, int ch){ char[] s = str1.toCharArray(); char[] t = str2.toCharArray(); int idx = -1; for(int i = 0; i < n; i++){ if(s[i] == '1' && t[i] == ch){ idx = i; break; } } if(idx == -1){ return Integer.MAX_VALUE; } for(int i = 0; i < n; i++){ if(i == idx) continue; if(s[i] == '1') s[i] = '0'; else s[i] = '1'; } int ans = cal(String.valueOf(s),String.valueOf(t),n); if(ans == Integer.MAX_VALUE) return ans; return 1 + ans; } static int cal(String s, String t, int n){ int op01 = 0; int op10 = 0; for(int i = 0; i < n; i++){ if(s.charAt(i) != t.charAt(i)){ if(s.charAt(i) == '1') op10++; else op01++; } } if(op10 != op01){ return Integer.MAX_VALUE; } return op01 + op10; } /* Source: hu_tao Random stuff to try when stuck: - use bruteforcer - check for n = 1, n = 2, so on -if it's 2C then it's dp -for combo/probability problems, expand the given form we're interested in -make everything the same then build an answer (constructive, make everything 0 then do something) -something appears in parts of 2 --> model as graph -assume a greedy then try to show why it works -find way to simplify into one variable if multiple exist -treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them) -find lower and upper bounds on answer -figure out what ur trying to find and isolate it -see what observations you have and come up with more continuations -work backwards (in constructive, go from the goal to the start) -turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements) -instead of solving for answer, try solving for complement (ex, find n-(min) instead of max) -draw something -simulate a process -dont implement something unless if ur fairly confident its correct -after 3 bad submissions move on to next problem if applicable -do something instead of nothing and stay organized -write stuff down Random stuff to check when wa: -if code is way too long/cancer then reassess -switched N/M -int overflow -switched variables -wrong MOD -hardcoded edge case incorrectly Random stuff to check when tle: -continue instead of break -condition in for/while loop bad Random stuff to check when rte: -switched N/M -long to int/int overflow -division by 0 -edge case for empty list/data structure/N=1 */ public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList ls = new ArrayList(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + "" ""); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } public static long ceil(long x, long y){ return (x + 0l + y - 1) / y; } static 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[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(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[] readDoubles(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; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream(""input.txt""); // FileOutputStream out = new FileOutputStream(""output.txt""); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }",0,Non-Plagiarised 0c0af0ff,d6a8d884,"import java.util.*; import java.lang.*; import java.io.*; public class Main { PrintWriter out = new PrintWriter(System.out); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(""""); String next() throws IOException { if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(next()); } long nl() throws IOException { return Long.parseLong(next()); } long mod=1000000007; void solve() throws IOException { for (int tc=ni();tc>0;tc--) { int n=ni(); int[]A=new int[n]; long[]T=new long[n]; A[0]=ni(); T[0]=A[0]; long total=0; for (int i=1;i0) { if ((p&1)==1) r=(r*a)%mod; p>>=1; a=(a*a)%mod; } return r; } public static void main(String[] args) throws IOException { new Main().solve(); } }","//Praise our lord and saviour qlf9 //DecimalFormat f = new DecimalFormat(""##.00""); import java.util.*; import java.io.*; import java.math.*; import java.text.*; public class C{ public static void main(String[] omkar) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); StringBuilder sb = new StringBuilder(); int cases = Integer.parseInt(st.nextToken()); for(int i = 0; i < cases; i++) { solve(in, st, sb); } System.out.println(sb); } public static void solve(BufferedReader in, StringTokenizer st, StringBuilder sb) throws Exception { st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int[] arr = readArr(n, in, st); int[] mins = new int[n]; mins[0] = arr[0]; mins[1] = arr[1]; for(int i = 2; i < n; i++) { mins[i] = Math.min(arr[i], mins[i-2]); } long[] sums = new long[n]; sums[0] = (long)(arr[0]); for(int i = 1; i < n; i++) { sums[i] = sums[i-1]+(long)(arr[i]); } long minc = Long.MAX_VALUE; long temp; for(int i = 1; i < n; i++) { temp = sums[i]; temp += (long)(mins[i])*(long)(n-(i+2)/2); temp += (long)(mins[i-1])*(long)(n-(i+1)/2); minc = Math.min(minc, temp); } sb.append(minc+""\n""); } public static int[] readArr(int N, BufferedReader in, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(in.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }",0,Non-Plagiarised 1230c43e,2bbf754b,"//package com.company; import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static boolean[] primecheck = new boolean[1000002]; public static void main(String[] args) throws IOException { OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); PROBLEM solver = new PROBLEM(); int t = 1; t = in.nextInt(); for (int i = 0; i < t; i++) { solver.solve(in, out); } out.close(); } static class PROBLEM { public void solve(FastReader in, PrintWriter out) { int n = in.nextInt(); int[] a = in.readArray(n); char[] c = in.nextLine().toCharArray(); int cur = 1; ArrayList p = new ArrayList<>(); for (int i = 0; i < n; i++) { p.add(new Pair(c[i], a[i])); } Collections.sort(p); // for (int i = 0; i < n; i++) { // out.println(p.get(i).x + "" "" + p.get(i).y); // } for (int i = 0; i < n; i++) { if(p.get(i).x == 'B' && p.get(i).y < i+1){ out.println(""NO""); return; } if(p.get(i).x == 'R' && p.get(i).y > i+1){ out.println(""NO""); return; } } out.println(""YES""); // int n = in.nextInt(), m = in.nextInt(); // char[] s = in.nextLine().toCharArray(); // // int rl = 0, ud = 0, r = 0 , l = 0, rlf = 0, udf = 0; // int lmax = 0, rmax = 0, umax = 0, dmax = 0; // // for (int i = 0; i < s.length; i++) { // if(s[i] == 'L'){ // if(rlf == 0) rlf = -1; // rl--; // l--; // if(rl == 0) l = 0; // if(rl < 0 && lmax+rmax <= m) lmax = Math.max(Math.abs(l), lmax); // } // if(s[i] == 'R'){ // if(rlf == 0) rlf = 1; // rl++; // r++; // // if(rl > 0 && lmax+rmax <= m) rmax = Math.max(r, rmax); // } // if(s[i] == 'U'){ // if(udf == 0) udf = 1; // ud++; // r = Math.max(Math.abs(ud), r); // if(ud > 0 && umax+dmax <= n) umax = Math.max(Math.abs(ud), umax); // } // if(s[i] == 'D'){ // if(udf == 0) udf = -1; // ud--; // r = Math.max(Math.abs(ud), r); // if(ud < 0 && umax+dmax <= n) dmax = Math.max(Math.abs(ud), dmax); // } // } // // int ansc = 0, ansr = 0; // // out.println(rlf + "" lmx = "" + lmax + "" rmax"" + rmax); // // if(rlf == 1) ansc = m-rmax; // else if(rlf == -1) ansc = 1+lmax; // else ansc = 1; // // if(udf == 1) ansr = 1+umax; // else if(udf == -1) ansr = m-dmax; // else ansr = 1; // // out.println(ansr + "" "" + ansc); } } static HashMap initializeMap(int n){ HashMap hm = new HashMap<>(); for (int i = 0; i <= n; i++) { hm.put(i, 0); } return hm; } static boolean isRegular(char[] c){ Stack s = new Stack<>(); for (char value : c) { if (s.isEmpty() && value == ')') return false; if (value == '(') s.push(value); else s.pop(); } return s.isEmpty(); } static ArrayList> createAdj(int n, int e){ FastReader in = new FastReader(); ArrayList> adj = new ArrayList<>(); for (int i = 0; i < n + 1; i++) { adj.add(new ArrayList<>()); } for (int i = 0; i < e; i++) { int a = in.nextInt(), b = in.nextInt(); System.out.println(a); adj.get(a).add(b); adj.get(b).add(a); } return adj; } static int binarySearch(int[] a, int l, int r, int x){ if(r>=l){ int mid = l + (r-l)/2; if(a[mid] == x) return mid; if(a[mid] > x) return binarySearch(a, l, mid-1, x); else return binarySearch(a,mid+1, r, x); } return -1; } static boolean isPalindromeI(int n){ int d = 0; int y = n; while(y>0){ d++; y/=10; } int[] a = new int[d]; for (int i = 0; i < d; i++) { a[i] = n%10; n/=10; } System.out.println(Arrays.toString(a)); for (int i = 0; i < d / 2; i++) { if(a[i] != a[d-i-1]) return false; } return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static int exponentMod(int A, int B, int C) { // Base cases if (A == 0) return 0; if (B == 0) return 1; // If B is even long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } // If B is odd else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int) ((y + C) % C); } static class Pair implements Comparable{ char x; int y; Pair(char x, int y){ this.x = x; this.y = y; } public int compareTo(Pair o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } static class Tuple implements Comparable{ int x, y, id; Tuple(int x, int y, int id){ this.x = x; this.y = y; this.id = id; } public int compareTo(Tuple o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } // public static class Pair, V extends Comparable> implements Comparable> { // public U x; // public V y; // // public Pair(U x, V y) { // this.x = x; // this.y = y; // } // // public int hashCode() { // return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); // } // // public boolean equals(Object o) { // if (this == o) // return true; // if (o == null || getClass() != o.getClass()) // return false; // Pair p = (Pair) o; // return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); // } // // public int compareTo(Pair b) { // int cmpU = x.compareTo(b.x); // return cmpU != 0 ? cmpU : y.compareTo(b.y); // } // // public int compareToY(Pair b) { // int cmpU = y.compareTo(b.y); // return cmpU != 0 ? cmpU : x.compareTo(b.x); // } // // public String toString() { // return String.format(""(%s, %s)"", x.toString(), y.toString()); // } // // } 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()); } char nextChar() { return next().charAt(0); } boolean nextBoolean() { return !(nextInt() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } private static int[] mergeSort(int[] array) { //array.length replaced with ctr int ctr = array.length; if (ctr <= 1) { return array; } int midpoint = ctr / 2; int[] left = new int[midpoint]; int[] right; if (ctr % 2 == 0) { right = new int[midpoint]; } else { right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } int[] result = new int[array.length]; left = mergeSort(left); right = mergeSort(right); result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right) { int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while (leftPointer < left.length || rightPointer < right.length) { if (leftPointer < left.length && rightPointer < right.length) { if (left[leftPointer] < right[rightPointer]) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } else if (leftPointer < left.length) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } return result; } public static void Sieve(int n) { Arrays.fill(primecheck, true); primecheck[0] = false; primecheck[1] = false; for (int i = 2; i * i < n + 1; i++) { if (primecheck[i]) { for (int j = i * 2; j < n + 1; j += i) { primecheck[j] = false; } } } } } ","import java.util.*; /** __ __ ( _) ( _) / / \\ / /\_\_ / / \\ / / | \ \ / / \\ / / |\ \ \ / / , \ , / / /| \ \ / / |\_ /| / / / \ \_\ / / |\/ _ '_| \ / / / \ \\ | / |/ 0 \0\ / | | \ \\ | |\| \_\_ / / | \ \\ | | |/ \.\ o\o) / \ | \\ \ | /\\`v-v / | | \\ | \/ /_| \\_| / | | \ \\ | | /__/_ `-` / _____ | | \ \\ \| [__] \_/ |_________ \ | \ () / [___] ( \ \ |\ | | // | [___] |\| \| / |/ /| [____] \ |/\ / / || ( \ [____ / ) _\ \ \ \| | || \ \ [_____| / / __/ \ / / // | \ [_____/ / / \ | \/ // | / '----| /=\____ _/ | / // __ / / | / ___/ _/\ \ | || (/-(/-\) / \ (/\/\)/ | / | / (/\/\) / / // _________/ / / \____________/ ( */ public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- >0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i plist=new ArrayList<>(); for(int i=0;icounter) { flag=true; break; } } counter++; } System.out.println(flag?""NO"":""YES""); } } public static class Pair implements Comparable{ int number; char color; Pair(int number,char color){ this.number=number; this.color=color; } @Override public int compareTo(Pair o) { if(o.color==this.color) { return this.number-o.number; } else { return this.color-o.color; } } public String toString() { return number+""-""+color+"".""; } } } ",0,Non-Plagiarised 7686c854,abd16ff0,"import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.IntToLongFunction; import java.lang.*; import java.io.*; import java.math.*; public final class CF { public static void main(String[]args)throws IOException { FastReader ob=new FastReader(); int t=ob.nextInt(); StringBuffer sb=new StringBuffer(); while(t-->0) { int n=ob.nextInt(); PriorityQueue a=new PriorityQueue<>(); PriorityQueue b=new PriorityQueue<>(); long ans=Long.MAX_VALUE; long sum=0; for(int i=0;i { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair a) { return a.y-y; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String s=""""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } ","import java.util.*; public class Solve{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long ans=Long.MAX_VALUE; long pre=0; PriorityQueue epq=new PriorityQueue<>(); PriorityQueue opq=new PriorityQueue<>(); for(int i=0;i0) ans=Math.min(ans,pre+opq.peek()*(n-opq.size())+epq.peek()*(n-epq.size())); } System.out.println(ans); } } }",1,"(L4) Similar main with variable renaming, additional lines, different imports, within a slightly larger code. Additional unused class. FastReader class instead of scanner." cdb801a1,ed610dc9,"//package codeforces; import java.io.*; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws java.lang.Exception { FastReader fr = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = fr.ni(); while(t-->0) { int n = fr.ni(); long arr [] = new long[n]; for(int i = 0 ; i < n ; i++) arr[i]= fr.nl(); long even = arr[0]; long odd = arr[1]; long minEven = arr[0]; long minOdd = arr[1]; long ans = (minEven*n) + (minOdd*n); for(int i = 2 ; i < n ; i++) { if((i&1) == 0) { even += arr[i]; minEven = Math.min(minEven, arr[i]); long a = (i+2)/2; long b = (i+1)-a; long temp = (even + (minEven*(n - a))); temp += (odd + (minOdd*(n - b))); ans = Math.min(ans, temp); }else { odd += arr[i]; minOdd = Math.min(minOdd, arr[i]); long a = (i+2)/2; long b = (i+1)-a; long temp = (even + (minEven*(n - a))); temp += (odd + (minOdd*(n - b))); ans = Math.min(ans, temp); } } out.println(ans); } out.close(); } }","/* * akshaygupta26 */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.Random; import java.util.Arrays; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Collections; import java.util.*; public class C { public static void main(String[] args) { FastReader sc=new FastReader(); StringBuffer ans=new StringBuffer(); int test=sc.nextInt(); while(test-->0) { int n=sc.nextInt(); long arr[]=new long[n]; for(int i=0;i0){ int n = Integer.parseInt(br.readLine()); ArrayList lst = new ArrayList<>(); for(int i = 0; i vals = new ArrayList<>(); for(int j = 0; j0){ sum+=vals.get(++pt); } ans = max(ans, pt+1); } sb.append(ans).append('\n'); } System.out.println(sb); } } /** * min deletions * for each letter calc max len of words * Its desirable to add someting that has more of x and less of other letters -> f(x, s)=>fx-sum(fz) */ ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class Comprog { static FastReader fr = new FastReader(); private static void testCase() { int n = fr.nextInt(); int [][] scoreChanges = new int [5][n]; int [] totalScores = new int [5]; // initialize for (int i = 0; i < 5; i++) totalScores[i] = 0; for (int i = 0; i < 5; i++) for (int j = 0; j < n; j++) scoreChanges[i][j] = 0; for (int wordIndex = 0; wordIndex < n; wordIndex++) { String nextWord = fr.nextLine(); for (int charIndex = 0; charIndex < 5; charIndex++) { // How many more of the current char ('a' or 'b' or etc.) are in nextWord than // the total number of chars in it int change = 2 * countCharsInString(nextWord, (char) ('a' + charIndex)) - nextWord.length(); totalScores[charIndex] += change; scoreChanges[charIndex][wordIndex] = change; } } for (int charIndex = 0; charIndex < 5; charIndex++) Arrays.sort(scoreChanges[charIndex]); int round = 0; boolean done = false; while (round < n && !done) { for (int charIndex = 0; charIndex < 5; charIndex++) { if (totalScores[charIndex] > 0) { System.out.println(n - round); done = true; break; } totalScores[charIndex] -= scoreChanges[charIndex][round]; } round++; } if (!done) System.out.println(0); } public static int countCharsInString(String str, char c) { int cnt = 0; for (int i = 0; i < str.length(); i++) if (str.charAt(i) == c) cnt++; return cnt; } public static void main(String[] args) { int t; t = fr.nextInt(); for (int i = 0; i < t; i++) testCase(); } static class NumberFrequency { int number; int frequency; public NumberFrequency(int number, int frequency) { this.number = number; this.frequency = frequency; } public void incrementFrequency() { this.frequency++; } } static class SortByFrequency implements Comparator { public int compare(NumberFrequency nf1, NumberFrequency nf2) { return nf2.frequency - nf1.frequency; } } 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; } } }",0,Non-Plagiarised 3088ca9c,a2cf5634,"import java.util.*; import java.io.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int n = sc.nextInt(); sc.nextLine(); String [] str = new String[n]; int res = 0; for(int i=0;i=0;p--) { sum+=arr[p]; if(sum>0) { count++; } else { break; } } res=Math.max(count , res); } System.out.println(res); t--; } } }"," /* Author : Kartikey Rana from MSIT New Delhi */ import java.util.*; import javax.sql.rowset.serial.SerialArray; import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction; import java.io.*; import java.math.*; import java.sql.Array;; public class Main { static class FR { BufferedReader br; StringTokenizer st; public FR() { 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; } // NEXT INT ARRAY int[] NIA(int n) { int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } // NEXT DOUBLE ARRAY double[] NDA(int n) { double arr[] = new double[n]; for (int i = 0; i < n; i++) arr[i] = nextDouble(); return arr; } // NEXT LONG ARRAY long[] NLA(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } // NEXT STRING ARRAY String[] NSA(int n) { String[] arr = new String[n]; for (int i = 0; i < n; i++) arr[i] = next(); return arr; } // NEXT CHARACTER ARRAY char[] NCA(int n) { char[] arr = new char[n]; String s = sc.nextLine(); for (int i = 0; i < n; i++) arr[i] = s.charAt(i); return arr; } } //************************* FR CLASS ENDS ********************************** static long mod = (long) (1e9 + 7); public static int[] sieve(int n) { int[] primes = new int[n + 1]; for (int i = 0; i <= n; i++) { primes[i] = i; } for (int i = 2; i < n; i++) { if (primes[i] < 0) continue; if ((long) i * (long) i > n) break; for (int j = i * i; j < n; j++) { if (primes[j] > 0 && primes[j] % primes[i] == 0) primes[j] = -primes[j]; } } return primes; } static int lcm(int a, int b) { return (int) ((a / gcd(a, b)) * b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long[][] ncr(int n, int k) { long C[][] = new long[n + 1][k + 1]; int i, j; // Calculate value of Binomial // Coefficient in bottom up manner for (i = 0; i <= n; i++) { for (j = 0; j <= Math.min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using // previously stored values else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; } } return C; } static long modInverse(long a, long m) { long g = gcd(a, 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 = (int) ((p * (long) p) % m); if (y % 2 == 0) return p; else return (int) ((x * (long) p) % m); } static int XOR(int n) { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } // ----------------------------------DSU-------------------------------- static int parent[]; static int rank[]; public static int find(int x) { if(x == parent[x]) { return x; } int temp = find(parent[x]); parent[x] = temp; return temp; } public static void union(int x, int y) { int lx = find(x); int ly = find(y); if(parent[x] == parent[y]) return; if(rank[lx] < rank[ly]) { parent[lx] = ly; } else if(rank[lx] >rank[ly]) { parent[ly] = lx; } else { parent[lx] = ly; rank[ly]++; } find(x); find(y); } /* ***************************************************************************************************************************************************/ static class Pair implements Comparable { int x; int y; public Pair(int x, int y) { super(); this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return this.x - o.x; } } static FR sc = new FR(); static StringBuilder sb = new StringBuilder(); public static void main(String args[]) throws IOException { int tc = sc.nextInt(); // int tc = 1; while (tc-- > 0) { TEST_CASE(); } sb.setLength(sb.length() - 1); System.out.println(sb); } static void TEST_CASE() throws IOException { // BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = sc.nextInt(); String[] strs = new String[n]; for(int i = 0; i < n; i++) { strs[i] = sc.next(); } int max = -1; for(int i = 0; i < 5; i++) { ArrayList arr = new ArrayList<>(); for(int j = 0; j < n; j++) { String s = strs[j]; char letter = (char)(97+i); int val = 0; for(int k = 0; k < s.length(); k++) { if(s.charAt(k) == letter) val++; else val--; } arr.add(val); } Collections.sort(arr, Collections.reverseOrder()); int val = 0; int ans = 0; for(int x : arr) { val += x; if(val <= 0) break; else ans++; } max = Math.max(ans, max); } sb.append(max + ""\n""); } } ",0,Non-Plagiarised 752ea9a5,b2ec0eff,"//package Codeforces; import java.io.*; import java.util.*; public class PheonixAndTowers { public static void main(String[] args)throws Exception{ new PheonixAndTowers().run();} long mod=1000000000+7; // int[][] ar; void solve() throws Exception { for(int tt=ni();tt>0;tt--){ //int n = ni(); int n = ni(); int m =ni(); int x =ni(); int[] a = new int[n]; for(int i=0;i pq = new PriorityQueue<>(); for(int i=1;i<=m;i++) pq.add(new Pair(i)); out.println(""YES""); for(int i:a){ Pair r = pq.remove(); r.sum+=i; pq.add(r); out.print(r.id+"" ""); } out.println(); } } class Pair implements Comparable{ int id; long sum=0; public Pair(int i){ this.id=i; } @Override public int compareTo(Pair o) { return Long.compare(this.sum, o.sum); } } boolean issubset(int[] a,int k){ int n = a.length; boolean[][]dp = new boolean[n+1][k+1]; for(int i=0;i<=n;i++){ for(int j=0;j<=k;j++){ if(i==0) {dp[i][j] = false;continue;} if(j==0){dp[i][j]= true; continue;} if(a[i-1]<=j){ dp[i][j] = dp[i][j-a[i-1]] || dp[i-1][j]; }else{ dp[i][j] = dp[i-1][j]; } } } return dp[n][k]; } void ruffleSort(int[] a) { //ruffle int n=a.length; Random r=new Random(); for (int i=0; i al = new ArrayList<>(); for(int i=0;i use expo to calc -->(a^(mod-2)) */ long expo(long p,long q) /* (p^q)%mod */ { long z = 1; while (q>0) { if (q%2 == 1) { z = (z * p)%mod; } p = (p*p)%mod; q >>= 1; } return z; } void run()throws Exception { in=System.in; out = new PrintWriter(System.out); solve(); out.flush(); } private int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } private int ni() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); int sgn = 1; if (c == '-') { sgn = -1; c = scan(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = scan(); } while (!isSpaceChar(c)); return res * sgn; } private long nl() throws IOException { long num = 0; int b; boolean minus = false; while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = scan(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = scan(); } } private double nd() throws IOException{ return Double.parseDouble(ns()); } private String ns() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = scan(); } while (!isSpaceChar(c)); return res.toString(); } private String nss() throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); return br.readLine(); } private char nc() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); return (char) c; } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } private boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhiteSpace(c); } private interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } ","//Implemented By Aman Kotiyal Date:-02-May-2021 Time:-7:58:39 pm import java.io.*; import java.util.*; public class ques3 { public static void main(String[] args)throws Exception{ new ques3().run();} long mod=1000000000+7; void solve() throws Exception { for(int ii=ni();ii>0;ii--) { int n=ni(); int m=ni(); int x=ni(); long h[]=new long[n]; for (int i = 0; i pq=new PriorityQueue(new Comparator() { public int compare(long[] x, long[] y) { if(x[1]-y[1]>0)return 1; if(x[1]-y[1]<0)return -1; return 0; } }); for (int i = 1; i <=m; i++) pq.add(new long[] {i,0}); for(int i=0;ix) { out.println(""NO""); } else { out.println(""YES""); for (int i = 0; i < dp.length; i++) { out.print(dp[i]+"" ""); } out.println(); } } } /*FAST INPUT OUTPUT & METHODS BELOW*/ private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; private SpaceCharFilter filter; PrintWriter out; int min(int... ar){int min=Integer.MAX_VALUE;for(int i:ar)min=Math.min(min, i);return min;} long min(long... ar){long min=Long.MAX_VALUE;for(long i:ar)min=Math.min(min, i);return min;} int max(int... ar) {int max=Integer.MIN_VALUE;for(int i:ar)max=Math.max(max, i);return max;} long max(long... ar) {long max=Long.MIN_VALUE;for(long i:ar)max=Math.max(max, i);return max;} void reverse(int a[]){for(int i=0;i>1;i++){int tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}} void reverse(long a[]){for(int i=0;i>1;i++){long tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}} String reverse(String s){StringBuilder sb=new StringBuilder(s);sb.reverse();return sb.toString();} void shuffle(int a[]) { ArrayList al = new ArrayList<>(); for(int i=0;i use expo to calc -->(a^(mod-2)) */ long expo(long p,long q) /* (p^q)%mod */ { long z = 1; while (q>0) { if (q%2 == 1) { z = (z * p)%mod; } p = (p*p)%mod; q >>= 1; } return z; } void run()throws Exception { in=System.in; out = new PrintWriter(System.out); solve(); out.flush(); } private int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } private int ni() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); int sgn = 1; if (c == '-') { sgn = -1; c = scan(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = scan(); } while (!isSpaceChar(c)); return res * sgn; } private long nl() throws IOException { long num = 0; int b; boolean minus = false; while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = scan(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = scan(); } } private double nd() throws IOException{ return Double.parseDouble(ns()); } private String ns() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = scan(); } while (!isSpaceChar(c)); return res.toString(); } private String nss() throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); return br.readLine(); } private char nc() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); return (char) c; } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } private boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhiteSpace(c); } private interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } ",0,Non-Plagiarised 0588b869,9028caf7,"import java.util.*; import java.io.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static final long mod=(long)1e9+7; public static long pow(long a,int p) { long res=1; while(p>0) { if(p%2==1) { p--; res*=a; res%=mod; } else { a*=a; a%=mod; p/=2; } } return res; } static class Pair { int u,v,w; Pair(int u,int v,int w) { this.u=u; this.v=v; this.w=w; } } /*static class Pair implements Comparable { int v,l; Pair(int v,int l) { this.v=v; this.l=l; } public int compareTo(Pair p) { return l-p.l; } }*/ static int gcd(int a,int b) { if(b%a==0) return a; return gcd(b%a,a); } public static void dfs(int u,int dist[],int sub[],int mxv[],int par[],ArrayList edge[]) { sub[u]=1; for(int v:edge[u]) { if(dist[v]==-1) { par[v]=u; dist[v]=dist[u]+1; dfs(v,dist,sub,mxv,par,edge); if(sub[v]+1>sub[u]) { sub[u]=sub[v]+1; mxv[u]=v; } } } } public static void main(String args[])throws Exception { FastReader fs=new FastReader(); PrintWriter pw=new PrintWriter(System.out); //int tc=fs.nextInt(); int n=fs.nextInt(); int a[]=new int[n]; for(int i=0;i o=new ArrayList<>(); ArrayList z=new ArrayList<>(); for(int i=0;i0) { int n=input.nextInt(); int a[]=new int[n]; ArrayList list=new ArrayList<>(); ArrayList space=new ArrayList<>(); for(int i=0;i zeros, List ones) { if (ones.size() == 0) return 0; int oneSize = ones.size(); int zeroSize = zeros.size(); int [][] time = new int [oneSize + 1][zeroSize + 1]; for (int i=1; i<=oneSize; i++) { time[i][i] = time[i - 1][i - 1] + Math.abs(ones.get(i - 1) - zeros.get(i - 1)); for (int j=i+1; j<=zeroSize; j++) { time[i][j] = Math.min(time[i][j - 1], time[i - 1][j - 1] + Math.abs(ones.get(i - 1) - zeros.get(j - 1))); } } return time[oneSize][zeroSize]; } public static void main (String [] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List zeros = new ArrayList<>(); List ones = new ArrayList<>(); for (int i=0; ia; static ArrayListb; static int dp[][]; public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); arr=new int[n]; for(int i=0;i(); b =new ArrayList<>(); for(int i=0;i 0) { int n = in.nextInt(); Integer[] k = intInput(n, in), h = intInput(n, in); long ans = 0; int a = k[n - 1]; int current = k[n - 1]; for (int i = n - 1; i >= 0; i--) { if (current > k[i]) { ans += sum(a - current + 1); a = k[i]; current = k[i]-h[i]+1; }else { current = Math.min(current, k[i] - h[i]+1); } } ans += sum(a - current + 1); out.println(ans); } out.flush(); } static long sum(long a) { return a * (a + 1) / 2; } static boolean prime(long k) { for (int i = 2; i * i <= k; i++) { if (k % i == 0) { return false; } } return true; } static long gcd(long a, long b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } static void reverseArray(Integer[] a) { for (int i = 0; i < (a.length >> 1); i++) { Integer temp = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = temp; } } static Integer[] intInput(int n, InputReader in) { Integer[] a = new Integer[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextInt(); return a; } static Long[] longInput(int n, InputReader in) { Long[] a = new Long[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextLong(); return a; } static String[] strInput(int n, InputReader in) { String[] a = new String[n]; for (int i = 0; i < a.length; i++) a[i] = in.next(); return a; } // static void sieve() { // for (int i = 2; i * i < prime.length; i++) { // if (prime[i]) // continue; // for (int j = i * i; j < prime.length; j += i) { // prime[j] = true; // } // } // } } class Data { int val; int ind; boolean positive; Data(int val, int ind) { this.val = Math.abs(val); this.ind = ind; this.positive = val >= 0; } } class compareVal implements Comparator { @Override public int compare(Data o1, Data o2) { // return (o1.val - o2.val == 0 ? o1.ind - o2.ind : o1.val - o2.val); return (o1.val - o2.val); } } class compareInd implements Comparator { @Override public int compare(Data o1, Data o2) { return o1.ind - o2.ind == 0 ? o1.val - o2.val : o1.ind - o2.ind; } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }","import java.util.*; import java.io.*; public class hmm { static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws Exception { int t =sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int []k = sc.nextIntArray(n); int h[]=sc.nextIntArray(n); long mana = 0; pair cur = new pair(k[n-1]-h[n-1]+1,k[n-1]); for(int i=n-1;i>=0;i--) { int s = k[i]; int start = s-h[i]+1; if(s>=cur.x) { cur.x = Math.min(start, cur.x); } else { long x = cur.y - cur.x +1; mana += x*(x+1)/2; cur.x = start; cur.y = s; } } long x = cur.y - cur.x +1; mana += x*(x+1)/2; pw.println(mana); } pw.close(); } // -------------- stuff ------------------------------ static class pair { int x ; int y; public pair(int n,int c) { x= n; y = c; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }",0,Non-Plagiarised bdf7bfb2,d92c5342,"import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); String[] s = new String[n]; for(int i=0; i pq = new PriorityQueue<>(Collections.reverseOrder()); //Big comes in top; for(int i=0; i 0){ cur += pq.poll(); numberOfWords++; }else{ break; } } MAX = Math.max(MAX, numberOfWords); } pw.println(MAX); } pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.*; public class Main{ 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[] nextArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextArray(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static class FastWriter extends PrintWriter { FastWriter(){ super(System.out); } void println(int[] array) { for(int i=0; i0){ int n=in.nextInt(); String[] ar=new String[n]; for (int i = 0; i < n; i++) { ar[i]=in.next(); } int ans=0; for(char ch='a';ch<='e';ch++){ int[] res=new int[n]; for (int i = 0; i < n; i++) { String ss=ar[i]; for (int j = 0; j < ss.length(); j++) { if(ss.charAt(j)==ch){ res[i]++; }else { res[i]--; } } } Arrays.sort(res);int max=0,nn=0; for (int i = n-1; i>=0; i--) { max+=res[i]; if(max>0){ nn++; }else { break; } } ans=Math.max(ans,nn); } out.println(ans); } out.close(); } //Arrays.sort(a, (o1, o2) -> (o1[0] - o2[0])); static int totalPrimeFactors(int n) { int cnt=0; while (n%2==0) { cnt++; n /= 2; } int num= (int) Math.sqrt(n); for (int i = 3; i <= num; i+= 2) { while (n%i == 0) { cnt++; n /= i; num=(int)Math.sqrt(n); } } if (n > 2){ cnt++; } return cnt; } static char get(int i){ return (char)(i+'a'); } static boolean distinct(int num){ HashSet set=new HashSet<>(); int len=String.valueOf(num).length(); while (num!=0){ set.add(num%10); num/=10; } return set.size()==len; } static int maxSubArraySum(int a[],int st,int en) { int max_s = Integer.MIN_VALUE, max_e = 0,ind=0,ind1=1; for (int i = st; i <= en; i++) { max_e+= a[i]; if (max_s < max_e){ max_s = max_e; ind=ind1; } if (max_e < 0){ max_e = 0; ind1=i+1; } } if(st==0){ return max_s; } if(ind==1){ return a[0]+2*max_s; }else { return 2*max_s+maxSubArraySum(a,0,ind-1); } //return max_s; } static void segmentedSieve(ArrayList res,int low, int high) { if(low < 2){ low = 2; } ArrayList prime = new ArrayList<>(); sS2(high, prime); boolean[] mark = new boolean[high - low + 1]; Arrays.fill(mark, true); for (int i = 0; i < prime.size(); i++) { int loLim = (low / prime.get(i)) * prime.get(i); if (loLim < low){ loLim += prime.get(i); } if (loLim == prime.get(i)){ loLim += prime.get(i); } for (int j = loLim; j <= high; j += prime.get(i)) { mark[j - low] = false; } } for (int i = low; i <= high; i++) { if (mark[i - low]){ System.out.println(i); res.add(i); } } } static void sS2(int limit, ArrayList prime) { int bound = (int)Math.sqrt(limit); boolean[] mark = new boolean[bound + 1]; for (int i = 0; i <= bound; i++){ mark[i] = true; } for (int i = 2; i * i <= bound; i++) { if (mark[i]) { for (int j = i * i; j <= bound; j += i){ mark[j] = false; } } } for (int i = 2; i <= bound; i++) { if (mark[i]){ prime.add(i); } } } static boolean[] sieveOfEratosthenes(int n){ boolean[] prime = new boolean[n + 1]; Arrays.fill(prime,true); prime[0]=false;prime[1]=false; for (int p = 2; p * p <= n; p++) { if(prime[p]){ for (int i = p * p; i <= n; i += p){ prime[i] = false; } } } return prime; } static int highestPowerOf2(int n) { if (n < 1){ return 0; } int res = 1; for (int i = 0; i < 8 * Integer.BYTES; i++) { int curr = 1 << i; if (curr > n){ break; } res = curr; } return res; } static int reduceFraction(int x, int y) { int d= gcd(x, y); return x/d+y/d; } static boolean subset(int[] ar,int n,int sum){ if(sum==0){ return true; } if(n<0||sum<0){ return false; } return subset(ar,n-1,sum)||subset(ar,n-1,sum-ar[n]); } static boolean isPrime(int n){ if(n<=1) return false; for(int i = 2;i<=Math.sqrt(n);i++){ if (n % i == 0) return false; } return true; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static int lcm(int a, int b) { return (a * b) / gcd(a, b); } static boolean isPowerOfTwo(long n) { if(n==0){ return false; } while (n%2==0){ n/=2; } return n==1; } static boolean isPerfectSquare(int x){ if (x >= 0) { int sr = (int)Math.sqrt(x); return ((sr * sr) == x); } return false; } static int lower_bound(int[] arr, int x) { int low_limit = 0, high_limit = arr.length, mid; while (low_limit < high_limit) { mid = (low_limit + high_limit) / 2; if (arr[mid] >= x){ high_limit = mid; }else{ low_limit = mid + 1; } } return low_limit; } static int upper_bound(int[] arr, int x) { int low_limit = 0, high_limit = arr.length, mid; while (low_limit < high_limit) { mid = (low_limit + high_limit) / 2; if (arr[mid] > x){ high_limit = mid; }else{ low_limit = mid + 1; } } return low_limit; } static int binarySearch(int[] ar,int n,int num){ int low=0,high=n-1; while (low<=high){ int mid=(low+high)/2; if(ar[mid]==num){ return mid; }else if(ar[mid]>num){ high=mid-1; }else { low=mid+1; } } return -1; } static int fib(int n) { long[][] F = new long[][]{{1,1},{1,0}}; if (n == 0){ return 0; } power(F, n-1); return (int)F[0][0]; } static void multiply(long F[][], long M[][]) { long x = (F[0][0]*M[0][0])%1000000007 + (F[0][1]*M[1][0])%1000000007; long y = (F[0][0]*M[0][1])%1000000007 + (F[0][1]*M[1][1])%1000000007; long z = (F[1][0]*M[0][0])%1000000007 + (F[1][1]*M[1][0])%1000000007; long w = (F[1][0]*M[0][1])%1000000007 + (F[1][1]*M[1][1])%1000000007; F[0][0] = x%1000000007; F[0][1] = y%1000000007; F[1][0] = z%1000000007; F[1][1] = w%1000000007; } static void power(long F[][], int n) { if( n == 0 || n == 1){ return; } long M[][] = new long[][]{{1,1},{1,0}}; power(F, n/2); multiply(F, F); if (n%2 != 0){ multiply(F, M); } } static int binaryExponentiation(int x,int n){ int ans=1; while (n>0){ if(n%2!=0){ ans=(ans*x)%MOD; } x=(x*x)%MOD; n/=2; } return ans; } static void bfs(ArrayList[] ar,int node){ boolean[] visited=new boolean[ar.length]; Queue queue=new LinkedList<>(); visited[node]=true; queue.add(node); while(!queue.isEmpty()){ int nn=queue.poll(); System.out.print(nn+"" ""); for(int n : ar[nn]) { if (!visited[n]) { visited[n] = true; queue.add(n); } } } System.out.println(); } static void dfs(ArrayList[] ar,int node){ boolean[] visited=new boolean[ar.length]; dfsUtil(ar,node,visited); System.out.println(); } static void dfsUtil(ArrayList[] ar,int node,boolean[] visited){ visited[node]=true; //System.out.print(node+"" ""); for(Integer n:ar[node]){ if(!visited[n]){ dfsUtil(ar,n,visited); } } } }",0,Non-Plagiarised 317a209c,9ab3c0e1,"import java.io.*; import java.util.*; public class D_Java { public static final int MOD = 998244353; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } int[] f; int[] rf; public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }","//package CF672; /** * @version 1.0 * @Package_Name: CF672 * @Author: Redorain * @Date: 2020/9/25 8:47 */ import java.util.*; public class d { public static Scanner sc = new Scanner(System.in); public static final int MOD = 998244353; int []f; int [] lf; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } public static int ksm(int a, int n) { int ans = 1; while(n > 0) { if((n & 1) == 1) ans = mul(a, ans); a = mul(a, a); n >>= 1; } return ans; } public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(lf[n - k], lf[k])); } public static int inv(int a) { return ksm(a, MOD - 2); } public void solve() { int n = sc.nextInt(); int k = sc.nextInt(); f = new int[n + 42]; lf = new int[n + 42]; f[0] = lf[0] = 1; for(int i = 1; i < f.length; i++) { f[i] = mul(f[i - 1], i); lf[i] = mul(lf[i - 1], inv(i)); } int[] events = new int[2 * n]; for(int i = 0; i < n; i++) { int le = sc.nextInt(); int ri = sc.nextInt(); events[i] = le * 2; events[i + n] = ri * 2 + 1; } Arrays.sort(events); int ans = 0, balance = 0; for(int r = 0; r < 2 * n;) { int l = r; while(r < 2 * n && events[l] == events[r]) ++r; int added = r - l; if(events[l] % 2 == 0) { ans += C(balance + added, k); if(ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if(ans >= MOD) ans -= MOD; balance += added; } else balance -= added; } sc.close(); System.out.println(ans); } public static void main(String[] args) { (new d()).solve(); } }",1,"(L4) Similar code with variable renaming, function renaming. Function creations." 0fd5b95a,41e72d4f,"//package codeforces; import java.io.PrintWriter; import java.util.*; public class codeforces { static int dp[][]=new int[5001][5001]; public static void main(String[] args) { Scanner s=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=1; for(int tt=0;tt z=new ArrayList<>(); ArrayList o=new ArrayList<>(); for(int i=0;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i { if (x[c] != y[c]) return(int)( x[c] - y[c]); return (int)-(x[1]+x[2] - y[1]-y[2]); }); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static int sol(int i,int j,ArrayList z,ArrayList o) { if(j==o.size()) { return 0; } int h=z.size()-i; int l=o.size()-j; if(i==z.size()) { return 10000000; } if(dp[i][j]!=-1) { //System.out.println(i+"" ""+j); return dp[i][j]; } int ans1=sol(i+1,j,z,o); int ans2=sol(i+1,j+1,z,o)+Math.abs(z.get(i)-o.get(j)); dp[i][j]=Math.min(ans1, ans2); return dp[i][j]; } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.StringTokenizer; public class ProblemD { public static void main(String[] args) throws IOException { final int INF = 20000000; InputStream in = System.in; InputReader scan = new InputReader(in); int n = scan.nextInt(); int occ = 0; List occPos = new ArrayList<>(); HashSet occPosSet = new HashSet<>(); for(int i=1;i<=n;i++) { int num = scan.nextInt(); if(num==1) { occ++; occPos.add(i); occPosSet.add(i); } } int[][] dp = new int[n+1][occ+1]; for(int i=0;i<=n;i++) { for(int j=0;j<=occ;j++) { dp[i][j] = 20000000; } } for(int i=1;i<=n;i++) { int k=1; for(int pos: occPos) { if(occPosSet.contains(i)) { dp[i][k] = dp[i-1][k]; } else { dp[i][k] = Math.min(dp[i-1][k], dp[i-1][k-1]+Math.abs(pos-i)); if(k==1) dp[i][k]=Math.min(dp[i][k],Math.abs(pos-i)); } k++; } } if(dp[n][occ]==INF) { System.out.println(0); } else { System.out.println(dp[n][occ]); } } static class InputReader { BufferedReader br; StringTokenizer st; InputReader(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException ioe) { ioe.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } } ",0,Non-Plagiarised 3380fa52,f28b8cb4,"import java.util.*; import java.io.*; import java.math.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Coder { static int n, k; static long a[]; static int pos[]; static int temp[]; static StringBuilder str = new StringBuilder(""""); static int cnt[][] = new int[(int)1e5+5][2]; static void solve() { long []l = new long[n]; long []r = new long[n]; long p = Integer.MAX_VALUE; for(int i=0;i=0;i--){ p = Math.min(p+1, a[i]); r[i] = p; } for(int i=0;i 0) { bf.readLine(); String s[] = bf.readLine().trim().split(""\\s+""); n = Integer.parseInt(s[0]); k = Integer.parseInt(s[1]); s = bf.readLine().trim().split(""\\s+""); pos = new int[k]; temp = new int[k]; a = new long[n]; for(int i=0;i= 0; j--) { p = Math.min(p + 1, c[j]); right[j] = p; } for (int j = 0; j < n; j++) { System.out.print(Math.min(left[j], right[j]) + "" ""); } System.out.println(); } } } ",1,"(L5) similar main code with variable renaming, combing/splitting lines. Within a large code. Many comments. Change for with while." 80881cae,ad4c7a20,"//package Codeforces; import java.io.*; import java.util.*; public class CP { static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException, CloneNotSupportedException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { 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)+500*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) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } // public void swap() // { // this.y=this.y+this.x; // this.x=this.y-this.x; // this.y=this.y-this.x; // } } }","import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); // static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException, CloneNotSupportedException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); for(int i=1;i<=t;i++) solve(i); out.close(); out.flush(); // System.out.flush(); // System.exit(0); } static void solve(int CASENO) throws IOException, CloneNotSupportedException { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { 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)+500*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) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a,Comparator.reverseOrder()); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; Node(int ver) { vertex=ver; dis=-1; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res%mod; } static long binomialCoeff(long n, long k) { if(n n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } 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') { 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 void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ",1,(L4) Code reuse with variable renaming in a function. More comments. 4241f473,4685c420,"import java.io.*; import java.util.*; public class C { public static void main(String[] args)throws IOException { FastScanner scan = new FastScanner(); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = scan.nextInt(); for(int tt = 0;tt arr = new ArrayList<>(); for(int i = 0;i list = new ArrayList<>(); char ch = (char)('a'+cases); for(int i = 0;i=0;i--) { sum+=list.get(i); if(sum>0) count++; else break; } max = Math.max(max, count); } output.write(max+""\n""); } output.flush(); } public static int[] sort(int arr[]) { List list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); for(int i = 0;i stories[]=new ArrayList[5]; for(int i=0;i<5;i++){ stories[i]=new ArrayList<>(); } for(int i=1;i<=n;i++){ char c[]=br.readLine().toCharArray(); int freq[]=new int[5]; for(int j=0;j{ int x,y,diff; public Story(int x,int y){ this.x=x; this.y=y; this.diff=this.x-this.y; } @Override public int compareTo(Story o) { return -this.diff+o.diff; } }",0,Non-Plagiarised 3e93b259,a60fba84,"import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable { int f,s; Pair(int f,int s) { this.f=f; this.s=s; } public int compareTo(Pair p) { return this.f-p.f; } } public static void main(String args[]) { FastReader fs=new FastReader(); PrintWriter pw=new PrintWriter(System.out); int tc=fs.nextInt(); while(tc-->0) { int n=fs.nextInt(); long a[]=new long[n]; for(int i=0;i0){ int n = ni(); long arr[] = new long[n]; lIA(arr); long ans = (long)(n*(arr[0] + arr[1])); long sum = arr[0] + arr[1]; long emin = arr[0], omin = arr[1]; for(int i=2; i 0){ int n= s.nextInt(); long [] time= new long [n]; long [] health= new long [n]; for(int i=0; i=0; i--) { if(currtime-time[i]>= currhealth) { ans+= (currhealth*(currhealth+1))/2; currhealth= health[i]; currtime= time[i]; } else if(currtime-time[i]>currhealth-health[i]) currhealth+= (currtime-time[i]-currhealth+health[i]); } ans+= (currhealth*(currhealth+1))/2; System.out.println(ans); } s.close(); } }","import java.util.*; import java.io.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long k[]=new long[n]; long h[]=new long[n]; for(int i=0;i=1;i--){ if(k[i]-k[i-1]>=length){ curr=curr+length; ans=ans+(curr*(curr+1))/2; length=h[i-1]; curr=0; } else{ length=Math.max(length-(k[i]-k[i-1]),h[i-1]); curr=curr+k[i]-k[i-1]; } } curr=curr+length; ans=ans+(curr*(curr+1))/2; System.out.println(ans); } } } ",0,Non-Plagiarised cc9230d3,ec558d69,"import java.io.BufferedReader; import java.util.StringTokenizer; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; public class C { static int[][] lr = new int[2][(int)2e5+10]; static long[][] dp = new long[2][(int)2e5+10]; static ArrayList> g; public static void main(String[] args) { FastReader fr = new FastReader(); PrintWriter out = new PrintWriter(System.out, true); int cases = fr.nextInt(); for(int c = 0; c < cases; c++) { int nodes = fr.nextInt(); g = new ArrayList>(); for(int i = 1; i <= nodes; i++) { lr[0][i] = fr.nextInt(); lr[1][i] = fr.nextInt(); } for(int i = 0; i <= nodes; i++) { g.add(new ArrayList()); } for(int i = 0; i < nodes-1; i++) { int f = fr.nextInt(); int t = fr.nextInt(); g.get(f).add(t); g.get(t).add(f); } DFS(1, -1); out.write(Math.max(dp[0][1], dp[1][1]) + ""\n""); } out.close(); } static void DFS(int v, int p) { dp[0][v] = dp[1][v] = 0; for(Integer u : g.get(v)) { if (u == p) continue; DFS(u, v); dp[0][v] += Math.max(Math.abs(lr[0][v] - lr[1][u]) + dp[1][u], dp[0][u] + Math.abs(lr[0][v] - lr[0][u])); dp[1][v] += Math.max(Math.abs(lr[1][v] - lr[1][u]) + dp[1][u], dp[0][u] + Math.abs(lr[1][v] - lr[0][u])); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { this.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; } } } ","import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { static int N=(int)2e5+10; static int[][] A=new int[2][N]; static long[][] dp=new long[2][N]; static ArrayList> links=new ArrayList<>(N); static { for (int i=0;i()); } static void dfs(int v,int p) { dp[0][v]=dp[1][v]=0; for (Integer link :links.get(v)) { if (link==p) continue; dfs(link,v); dp[0][v]+=Math.max(Math.abs(A[0][v]-A[0][link])+dp[0][link],Math.abs(A[0][v]-A[1][link])+dp[1][link]); dp[1][v]+=Math.max(Math.abs(A[1][v]-A[0][link])+dp[0][link],Math.abs(A[1][v]-A[1][link])+dp[1][link]); } } public static void main (String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()),n,i; while (t-->0) { n=Integer.parseInt(br.readLine()); for (i=1;i<=n;i++) { String[] in=br.readLine().split("" ""); A[0][i]=Integer.parseInt(in[0]); A[1][i]=Integer.parseInt(in[1]); links.set(i,new ArrayList<>()); } for (i=1;i=Integer.MAX_VALUE){ ans=-1; } res.append(ans+"" \n""); } } } p++; } System.out.println(res); } private static long solve( long correct1, long correct0, long wrong1, long wrong0,long a) { long op1=Integer.MAX_VALUE; long op2=Integer.MAX_VALUE; if(wrong1==0 && wrong0==0){ return 0; } if(a==1){ { // using correct1 if(correct1>0){ long newcorrect1=1+wrong0; long newcorrect0=wrong1; long newwrong1=correct0; long newwrong0=correct1-1; op1=(1+solve(newcorrect1,newcorrect0,newwrong1,newwrong0,0)); } } } else{ { //using wrong1 { if(wrong1>0){ long newcorrect1=wrong0; long newcorrect0=wrong1-1; long newwrong1=1+correct0; long newwrong0=correct1; op2=(1+solve(newcorrect1,newcorrect0,newwrong1,newwrong0,1)); } } } } long ans=Math.min(op1,op2); return ans; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static long modpower(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; } // SIMPLE POWER FUNCTION=> static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } }","import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 0; i < t; i++) { int n = scan.nextInt(); String a = scan.next(); String b = scan.next(); int[] cChet = new int[n]; int[] cNech = new int[n]; int sumChet = 0; int sumNechet = 0; int numOnesA = 0; int numOnesB = 0; boolean soluble = true; for (int j = 0; j < n; j++) { cChet[j] = (a.charAt(j) - 48) ^ (b.charAt(j) - 48); cNech[j] = cChet[j] ^ 1; sumChet += cChet[j]; sumNechet += cNech[j]; } int INF = 100000000; int ans = INF; if (((sumChet % 2 == 1) && (sumNechet % 2 == 0)) || !(numOnesB == numOnesA || numOnesB == (n - numOnesA + 1))) { ans = -1; } else { if (sumChet % 2 == 0) { int ones = 0; int zeroes = 0; for (int j = 0; j < n; j++) { if (cChet[j] == 1) { if (a.charAt(j) == '1') { ones++; } else { zeroes++; } } } if ((ones - zeroes) == 0 || (ones - zeroes) == 1) { ans = Math.min(sumChet, ans); } } if (sumNechet % 2 == 1) { int ones = 0; int zeroes = 0; for (int j = 0; j < n; j++) { if (cNech[j] == 1) { if (a.charAt(j) == '1') { ones++; } else { zeroes++; } } } if ((ones - zeroes) == 0 || (ones - zeroes) == 1) { ans = Math.min(sumNechet, ans); } } } if (ans != INF) { System.out.println(ans); } else { System.out.println(-1); } } } public static int find(int x, int log) { int pow = (int)Math.pow(2, log); int ans = (x / (pow * 2)) * pow; if (x % (pow * 2) > pow) { ans += pow; } else { ans += (x % (pow * 2)); } return ans; } } ",0,Non-Plagiarised 11c2ab99,4f7af821,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { FastScanner fs=new FastScanner(); int T=fs.nextInt(); PrintWriter out=new PrintWriter(System.out); for (int tt=0; tt=0; i--) forced[i]=Math.min(forced[i], forced[i+1]+1); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i0){ int n = scanner.nextInt(); int k = scanner.nextInt(); int[] c = new int[n]; Arrays.fill(c,inf); int[] a = new int[k]; int[] b = new int[k]; for(int i=0;i=0;--i){ c[i] = Math.min(c[i],c[i+1]+1); } for(int i=0;i=0; i--) forced[i]=Math.min(forced[i], forced[i+1]+1); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (char i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i { if(x[c]>y[c]) { return 1; }else { return -1; } }); } public static void printb(boolean ans) { if(ans) { System.out.println(""Yes""); }else { System.out.println(""No""); } } 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(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i{ int a , b; Pair(int x , int y){ a=x; b=y; } public int compareTo(Pair o) { return a != o.a ? a - o.a : b - o.b; } } } ",1,"(L3) Similar code reuse in main and sort function, with additional code in a larger code. Variable renaming. Different imports. Changing the order of variable declaration." 9e7551da,f0e13442,"import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; // نورت الكود يا كبير اتفضل // يا رب Accepted public class InterestingStory { private static int[] freq; private static String[] strs; private static int[] countAlpha(char alpha) { int[] count = new int[strs.length]; for (int i = 0; i < strs.length; i++) for (char c : strs[i].toCharArray()) count[i] += c == alpha ? -1 : 1; return count; } private static int solve(char alpha) { int[] res = countAlpha(alpha); Arrays.sort(res); int freqSum = 0; for (int j : freq) freqSum += j; freqSum -= freq[alpha - 'a']; int k = res.length - 1; //System.out.println(freq[alpha - 'a'] + "" "" + freqSum); while (k >= 0 && freq[alpha - 'a'] <= freqSum) { //System.out.println(freq[alpha - 'a'] + "" "" + freqSum); freqSum -= res[k--]; } return k + 1; } public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); freq = new int[7]; strs = new String[n]; for (int i = 0; i < n; i++) strs[i] = in.nextLine(); for (String str : strs) for (char c : str.toCharArray()) freq[c - 'a']++; int max = 0; // int x = solve('d'); // out.println(x); for (char c = 'a'; c < 'f'; c++) max = Math.max(max, solve(c)); // int[] arr = countAlpha('d'); // Arrays.sort(arr); // // for (int i : arr) // out.println(i); out.println(max); } out.close(); } private static class FastReader { BufferedReader br; StringTokenizer st; FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; // نورت الكود يا كبير اتفضل // يا رب Accepted public class InterestingStory { private static int[] freq; private static String[] strs; private static int[] countAlpha(char alpha) { int[] count = new int[strs.length]; for (int i = 0; i < strs.length; i++) for (char c : strs[i].toCharArray()) count[i] += c == alpha ? -1 : 1; return count; } private static int solve(char alpha) { int[] res = countAlpha(alpha); Arrays.sort(res); int freqSum = 0; for (int j : freq) freqSum += j; freqSum -= freq[alpha - 'a']; int k = res.length - 1; while (k >= 0 && freq[alpha - 'a'] <= freqSum) freqSum -= res[k--]; return k + 1; } public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); freq = new int[5]; strs = new String[n]; for (int i = 0; i < n; i++) strs[i] = in.nextLine(); for (String str : strs) for (char c : str.toCharArray()) freq[c - 'a']++; int max = 0; for (char c = 'a'; c < 'f'; c++) max = Math.max(max, solve(c)); out.println(max); } out.close(); } private static class FastReader { BufferedReader br; StringTokenizer st; FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }",1,EM 3c74c140,732c98a0," //package com.company; import java.math.*; import java.util.*; import java.lang.*; import java.io.*; public final class Main { FastReader s; public static void main (String[] args) throws java.lang.Exception { new Main().run(); } void run() { s = new FastReader(); solve(); } StringBuffer sb; // int counter; void solve() { sb = new StringBuffer(); for(int T = s.nextInt();T > 0;T--) { start(); } // System.out.print(sb); } void start() { int n = s.nextInt(); int mat[][] = new int[n][5]; for(int i = 0; i x = new ArrayList<>(); for(int j = 0; j=0) { int u = x.get(l); if(s+u>0) { s+=u; cnt++; } else break; l--; } return cnt; } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } long power(long x, long y, long p) { long res = 1; // Initialize result // Update x if it is more // than or equal to p x = x % p; while (y > 0) { // If y is odd, multiply // x with the 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; } int lower_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; //if(arr[i] > key)return -1; if(arr[j] < key)return -1; while(i0;t--) solve(); out.print(sb); } void solve(){ int n = in.nextInt(); int[][] mat = new int[n][5]; for(int i = 0; i x = new ArrayList<>(); for(int j = 0; j=0) { int u = x.get(l); if(s+u>0) { s+=u; cnt++; } else break; l--; } return cnt; } long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int upper_bound(long[] arr, int key) { int i=0, j=arr.length-1; if (arr[j]<=key) return j+1; if(arr[i]>key) return i; while (i arr, long n) { arr.sort(new Comparator() { @Override public int compare(Pair p1, Pair p2) { return (int) (p2.first - p1.first); } }); } } public 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 (Exception e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ String str=""""; try{ str=br.readLine(); }catch (Exception e){ e.printStackTrace(); } return str; } } }",1,"(L5) Similar code within functions of different names, in two large codes. Extra spacing, different imports. Some conditions have been changed. " 00c0b82a,1ea771ea,"import java.util.*; public class E1547 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int q = sc.nextInt(); for(int i = 0; i < q; i++){ int n = sc.nextInt(); int k = sc.nextInt(); int[][] t = new int[k][2]; for(int j = 0; j < k; j++){ t[j][0] = sc.nextInt();//room } for(int j = 0; j < k; j++){ t[j][1] = sc.nextInt();//air } long[] left = new long[n]; long[] right = new long[n]; long tmp = Integer.MAX_VALUE; long[] max =new long[n]; for(int j = 0; j < n; j++){ max[j] = Integer.MAX_VALUE; } for (int j = 0; j < k; j++) { max[t[j][0]-1] = t[j][1]; } for (int j = 1; j <= n; j++) { tmp = Math.min(tmp+1, max[j-1]); left[j-1] = tmp; } for(int j = n; j >= 1; j--){ tmp = Math.min(tmp+1, max[j-1]); right[j-1] = tmp; } for(int j = 0; j < n; j++){ System.out.print(Math.min(left[j], right[j]) + "" ""); } System.out.println(); } } } "," import java.io.*; import java.util.*; public class CODECHEF { 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(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static long MOD=1000000000; static class Pair{ long a; int b; Pair(long i,int j){ a=i; b=j; } } static long[] solve(int[] pos,long[] arr,int n,int k){ long[] ans=new long[n]; long[] left=new long[n]; long[] right=new long[n]; long min=Integer.MAX_VALUE; for(int i=0;i=0;i--){ min=Math.min(min+1,arr[i]); right[i]=min; } for(int i=0;i0){ int n=fs.nextInt(); int k=fs.nextInt(); int[] pos=new int[k]; for(int i=0;i blue = new ArrayList<>(); List red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (s.charAt(i) == 'B') { blue.add(a[i]); } else { red.add(a[i]); } } Collections.sort(blue); Collections.sort(red); for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < i + 1) { result.append(""NO""); return; } } for (int i = 0; i < red.size(); i++) { if (red.get(i) > i + 1 + blue.size()) { result.append(""NO""); return; } } result.append(""YES""); } static class WithIdx implements Comparable { int val, idx; public WithIdx(int val, int idx) { this.val = val; this.idx = idx; } @Override public int compareTo(WithIdx o) { if (val == o.val) { return Integer.compare(idx, o.idx); } return Integer.compare(val, o.val); } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } String[] nextStringArray(int n) { String[] res = new String[n]; for (int i = 0; i < n; i++) res[i] = nextToken(); return res; } } static class PrefixSums { long[] sums; public PrefixSums(long[] sums) { this.sums = sums; } public long sum(int fromInclusive, int toExclusive) { if (fromInclusive > toExclusive) throw new IllegalArgumentException(""Wrong value""); return sums[toExclusive] - sums[fromInclusive]; } public static PrefixSums of(int[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } public static PrefixSums of(long[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } } static class ADUtils { static void sort(int[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } static void reverse(int[] arr) { int last = arr.length / 2; for (int i = 0; i < last; i++) { int tmp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = tmp; } } static void sort(long[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } } static class MathUtils { static long[] FIRST_PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051}; static long[] primes(int to) { long[] all = new long[to + 1]; long[] primes = new long[to + 1]; all[1] = 1; int primesLength = 0; for (int i = 2; i <= to; i++) { if (all[i] == 0) { primes[primesLength++] = i; all[i] = i; } for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) { all[(int) (i * primes[j])] = primes[j]; } } return Arrays.copyOf(primes, primesLength); } static long modpow(long b, long e, long m) { long result = 1; while (e > 0) { if ((e & 1) == 1) { /* multiply in this bit's contribution while using modulus to keep * result small */ result = (result * b) % m; } b = (b * b) % m; e >>= 1; } return result; } static long submod(long x, long y, long m) { return (x - y + m) % m; } static long modInverse(long a, long m) { long g = gcdF(a, m); if (g != 1) { throw new IllegalArgumentException(""Inverse doesn't exist""); } else { // If a and m are relatively prime, then modulo // inverse is a^(m-2) mode m return modpow(a, m - 2, m); } } static public long gcdF(long a, long b) { while (b != 0) { long na = b; long nb = a % b; a = na; b = nb; } return a; } } } /* 5 3 2 3 8 8 2 8 5 10 1 */","import java.util.*; public class mentor1 { public static boolean solve(int n, String color, int[] arr){ List Barr = new ArrayList(); List Rarr = new ArrayList(); for (int i = 0; i < n; i++) { if(color.charAt(i) == 'B')Barr.add(arr[i]); else Rarr.add(arr[i]); } Barr.sort(Comparator.naturalOrder()); Rarr.sort(Comparator.reverseOrder()); for (int i = 0; i < Barr.size(); i++) { if(Barr.get(i)< i + 1)return false; } for (int i = 0; i < Rarr.size(); i++) { int expect = n-i; if(Rarr.get(i) > expect)return false; } return true; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); for (int i = 0; i < n; i++) { int m = input.nextInt(); int[] arr = new int[m]; for(int j = 0;j0;i--) { long dif = d[i] - d[i-1]; long nxt = 0; if(i+1= cur) { req[i] = 0; } else { req[i] = cur-dif; } // System.out.println(i+"" ""+req[i]); } long ans = 0, prev = 0; for(int i=0;iprev) { ans = ans + sumFrom(prev, req[i]); ans = ans + sumFrom(req[i], req[i] + (d[i]-d[i-1])); prev = req[i] + d[i] - d[i-1]; } else { ans = ans + sumFrom(prev, prev + (d[i]-d[i-1])); prev = prev + d[i] - d[i-1]; } } } } out.write(ans+""\n""); } out.close(); } private static long sumFrom(long l, long cur) { long is1 = (cur*(cur+1))/2; long is2 = (l*(l+1))/2; return is1 - is2; } static long pow(long a, long b){long ret = 1;while(b>0){if(b%2 == 0){a = (a*a)%mod;b /= 2;}else{ret = (ret*a)%mod;b--;}}return ret%mod;} static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b); } private static void sort(int[] a) {List k = new ArrayList<>();for(int val : a) k.add(val);Collections.sort(k);for(int i=0;i[] tre2){for(int i=0;i();}} private static void init(List[] tre2){for(int i=0;i();}} private static void sort(long[] a) {List k = new ArrayList<>();for(long val : a) k.add(val);Collections.sort(k);for(int i=0;i0) { int n = sc.nextInt(); long dsasds[] = new long[n]; for(int i=0;i0;i--) { long dif = dsasds[i] - dsasds[i-1]; long nxt = 0; if(i+1= cur) { dsasdsuyuiyubtrtr[i] = 0; } else { dsasdsuyuiyubtrtr[i] = cur-dif; } // System.out.println(i+"" ""+dsasdsuyuiyubtrtr[i]); } long dsasdscsacsauyuiyubtrtr = 0, kokopmom = 0; for(int i=0;ikokopmom) { dsasdscsacsauyuiyubtrtr = dsasdscsacsauyuiyubtrtr + sumFrom(kokopmom, dsasdsuyuiyubtrtr[i]); dsasdscsacsauyuiyubtrtr = dsasdscsacsauyuiyubtrtr + sumFrom(dsasdsuyuiyubtrtr[i], dsasdsuyuiyubtrtr[i] + (dsasds[i]-dsasds[i-1])); kokopmom = dsasdsuyuiyubtrtr[i] + dsasds[i] - dsasds[i-1]; } else { dsasdscsacsauyuiyubtrtr = dsasdscsacsauyuiyubtrtr + sumFrom(kokopmom, kokopmom + (dsasds[i]-dsasds[i-1])); kokopmom = kokopmom + dsasds[i] - dsasds[i-1]; } } } } System.out.println(dsasdscsacsauyuiyubtrtr); } } private static long sumFrom(long l, long cur) { long is1 = (cur*(cur+1))/2; long is2 = (l*(l+1))/2; return is1 - is2; } private static long solve(int i, int k, int pre, int a[], int dsasds[]) { if(i == a.length) { int dsasdsuyuiyubtrtr = pre*(l-dsasds[i-1]); return dsasdsuyuiyubtrtr; } if(dp[i][k]!=-1) return dp[i][k]; long cans = Integer.MAX_VALUE; if(k>0) { cans = 1L*pre*(dsasds[i]-dsasds[i-1]) + solve(i+1, k-1, pre, a, dsasds); } cans = Math.min(cans, 1L*pre*(dsasds[i]-dsasds[i-1]) + solve(i+1, k, a[i], a, dsasds)); return dp[i][k] = cans; } private static boolean same(char[] a, char[] b) { for(int i=0;i val, long mid) { for(int i=0;i=mid) return false; mid = mid + 1; } } return true; } static long fac[] = new long[100006]; static void precompute() { int n = 100005; fac[0] = 1; for(int i=1;i<=n;i++) fac[i] = (i * fac[i-1])%mod; } static long power(long base, long p, long mod2) { long dsasdscsacsauyuiyubtrtr = 1; while(p!=0) { if(p%2==0) { base = (base*base)%mod2; p/=2; } else { dsasdscsacsauyuiyubtrtr = (dsasdscsacsauyuiyubtrtr*base)%mod2; p-=1; } } return (int) (dsasdscsacsauyuiyubtrtr%mod2); } private static boolean checkl(char[] s, char t[]) { int i=0, j =0; while(im) { dsasdsuyuiyu = mid-1; } else { ret = mid; l = mid+1; } } return ret; } private static int find(int[] a, int l, int dsasdsuyuiyu, long m) { int ret = -1; while(l<=dsasdsuyuiyu) { int mid = (l+dsasdsuyuiyu)/2; if(a[mid]>=m) { ret = mid; dsasdsuyuiyu = mid-1; } else l = mid+1; } return ret; } private static boolean find(String ini, String a) { return !KMPSearch(ini,a); } static boolean KMPSearch(String pat, String txt) { int M = pat.length(); int N = txt.length(); int lps[] = new int[M]; int j = 0; computeLPSArray(pat, M, lps); int i = 0; while (i < N) { if (pat.charAt(j) == txt.charAt(i)) { j++; i++; } if (j == M) { j = lps[j - 1]; return true; } else if (i < N && pat.charAt(j) != txt.charAt(i)) { if (j != 0) j = lps[j - 1]; else i = i + 1; } } return false; } static void computeLPSArray(String pat, int M, int lps[]) { int len = 0; int i = 1; lps[0] = 0; // lps[0] is always 0 // the loop calculates lps[i] for i = 1 to M-1 while (i < M) { if (pat.charAt(i) == pat.charAt(len)) { len++; lps[i] = len; i++; } else // (pat[i] != pat[len]) { // This is tricky. Consider the example. // AAACAAAA and i = 7. The idea is similar // to search step. if (len != 0) { len = lps[len - 1]; // Also, note that we do not increment // i here } else // if (len == 0) { lps[i] = len; i++; } } } } // private static boolean check(long n,long val) { // if(n == 0) return true; // // while(val<=n) { //// if(check(n-val,)) // } // } private static int find(int[] a, TreeMap ts, int lp) { int ret = 1; int idx = -1; for(int i=a.length-1;i>=0;i--) { if(a[i] == lp) { idx = i; break; } } idx--; int kokopmom = lp; while(idx>=0) { if((kokopmom - a[idx]) >= lp) { ret++; kokopmom = a[idx]; } idx--; } return ret; } private static void reverse(char[] s) { char a[] = new char[s.length]; for(int i=0;isize[fv]) { par[fv] = fu; size[fu] += size[fv]; } else { par[fu] = fv; size[fv] += size[fu]; } return true; } else return false; } } class pair{ long val; char c; pair(long val, char c){ this.val = val; this.c = c; } }",1,(L5) Similar function code with variable renaming within a large code. Combining and splitting lines. Different spacing. Change for with while 13441e8f,2ebeae13,"import java.util.*; public class Armchairs { public static int findMinTime(List zeros, List ones) { if (ones.size() == 0) return 0; int oneSize = ones.size(); int zeroSize = zeros.size(); int [][] time = new int [oneSize + 1][zeroSize + 1]; for (int i=1; i<=oneSize; i++) { time[i][i] = time[i - 1][i - 1] + Math.abs(ones.get(i - 1) - zeros.get(i - 1)); for (int j=i+1; j<=zeroSize; j++) { time[i][j] = Math.min(time[i][j - 1], time[i - 1][j - 1] + Math.abs(ones.get(i - 1) - zeros.get(j - 1))); } } return time[oneSize][zeroSize]; } public static void main (String [] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); List zeros = new ArrayList<>(); List ones = new ArrayList<>(); for (int i=0; i list1,list0; public static void main(String args[]){ FastReader sc=new FastReader(); int n=sc.nextInt(); list1=new ArrayList<>(); list0=new ArrayList<>(); for(int i=0;i=list1.size()){return 0;} if(j>=list0.size()){return Integer.MAX_VALUE;} if(dp[i][j]!=-1){return dp[i][j];} dp[i][j]=Math.min(check(i+1,j+1)+(long)Math.abs(list1.get(i)-list0.get(j)),check(i,j+1)); return dp[i][j]; } } ",0,Non-Plagiarised 9028caf7,a4e39423,"import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1; while(T-->0) { int n=input.nextInt(); int a[]=new int[n]; ArrayList list=new ArrayList<>(); ArrayList space=new ArrayList<>(); for(int i=0;i a = new ArrayList<>(); ArrayList b = new ArrayList<>(); for(int i = 0; i < n; i++){ if(arr[i] == 1){ a.add(i); }else{ b.add(i); } } if(a.size() == 0){ System.out.println(""0""); return; } int [][] dp = new int[a.size()][b.size()]; for(int i = 0; i < a.size(); i++){ for(int j = i; j < b.size(); j++) { if (j == 0) { dp[i][j] = Math.abs(a.get(i) - b.get(j)); } else if (i == 0) { dp[i][j] = Math.min(dp[i][j - 1], Math.abs(a.get(i) - b.get(j))); } else if (i == j) { dp[i][j] = dp[i - 1][j - 1] + Math.abs(a.get(i) - b.get(j)); } else { dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j - 1] + Math.abs(a.get(i) - b.get(j))); } } } System.out.println(dp[a.size() - 1][b.size() - 1]); } static int readInt() throws IOException { return Integer.parseInt(br.readLine()); } static long readLong() throws IOException { return Long.parseLong(br.readLine()); } static int[] readIntarray() throws IOException { String[] _a = br.readLine().split("" ""); int[] _res = new int[_a.length]; for (int i = 0; i < _a.length; i++) { _res[i] = Integer.parseInt(_a[i]); } return _res; } static long[] readLongarray() throws IOException { String[] _a = br.readLine().split("" ""); long[] _res = new long[_a.length]; for (int i = 0; i < _a.length; i++) { _res[i] = Long.parseLong(_a[i]); } return _res; } } ",0,Non-Plagiarised 14b0fb8e,6490bbe8,"import java.io.*; import java.util.*; public class Solution { static long res; public static void main(String[] args) throws Exception { FastReader fr=new FastReader(); int n=fr.nextInt(); ArrayList oc=new ArrayList<>(); ArrayList em=new ArrayList<>(); res=Long.MAX_VALUE; for(int i=0;i oc,ArrayList em,int idx,int j,long dp[][]) { if(idx==oc.size()) return 0; long available=em.size()-j; long req=oc.size()-idx; if(available0&&j>0) { if(a.charAt(i-1)==b.charAt(j-1)) { lcs=a.charAt(i-1)+lcs; i--; j--; } else { if(dp[i-1][j]>dp[i][j-1]) i--; else j--; } } return lcs; } public static long facto(long n) { if(n==1||n==0) return 1; return n*facto(n-1); } public static long gcd(long n1,long n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } public static boolean isPali(String s) { int i=0; int j=s.length()-1; while(i<=j) { if(s.charAt(i)!=s.charAt(j)) return false; i++; j--; } return true; } public static String reverse(String s) { String res=""""; for(int i=0;i[] adj; // static void getAdj(int n,int q, FastReader sc){ // adj = new ArrayList[n+1]; // for(int i=1;i<=n;i++){ // adj[i] = new ArrayList<>(); // } // for(int i=0;i 0) { // output.append(solver()).append(""\n""); // } // out.println(output); // _______________________________ int n = sc.nextInt(); int arr[] = new int[n]; for(int i=0;i a = new ArrayList<>(); ArrayList b = new ArrayList<>(); for(int i=0;i0) { br.readLine(); int n =readInt(); int k =readInt(); int[] ans = new int[n]; Arrays.fill(ans, (int)2e9+1); int[] a = new int[k]; int[] t = new int[k]; int mini = 0, maxi = 0; for (int i = 0 ;i a[maxi]) maxi = i; } for (int j = 0; j = 0; i--) { r[i] = temp = min(temp+1,ans[i]); } for (int i = 0; i < n; i++) out.print(min(l[i],r[i]) + "" ""); out.println(); } out.close(); } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static StringTokenizer st = new StringTokenizer(""""); static String read() throws IOException{return st.hasMoreTokens() ? st.nextToken():(st = new StringTokenizer(br.readLine())).nextToken();} static int readInt() throws IOException{return Integer.parseInt(read());} static long readLong() throws IOException{return Long.parseLong(read());} static double readDouble() throws IOException{return Double.parseDouble(read());} }","import java.util.*; import java.io.*; public class AirConditioner{ public static void main(String[] args) throws Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ br.readLine(); StringTokenizer st=null; st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int k=Integer.parseInt(st.nextToken()); int[] idx=new int[k]; int[] temp=new int[k]; st=new StringTokenizer(br.readLine()); for(int i=0;i=0;i--){ right[i]=Math.min(right[i+1]+1,arr[i]); } for(int i=0;i= '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 int mod = (int) (1e9 + 7); public static class pair implements Comparator { int x; int y; public pair() { } public pair(int x, int y) { this.x = x; this.y = y; } @Override public int compare(pair o1, pair o2) { return o1.y - o2.y; } } public static long modularpow(long a, long b) { long res = 1; if (b == 0) return res; else { while (b > 0) { if (b % 2 == 1) { res *= a; res %= mod; } a = a * a; a %= mod; b /= 2; } return res % mod; } } public static int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } public static String binary(int a) { String s1 = """"; while (a > 0) { s1 = a % 2 + s1; a /= 2; } return s1; } public static int Lower_Bound(long a[], int l, int r, long k) { while (r - l > 1) { int mid = l + (r - l) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l; } public static int Upper_Bound(int a[], int l, int r, int k) { while (r - l > 1) { int mid = (l + r) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l + 1; } public static void main(String arg[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { br.readLine(); String s[]=br.readLine().split("" ""); int n=Integer.parseInt(s[0]); int k=Integer.parseInt(s[1]); long a[]=new long[n]; long b[]=new long[n]; long c[]=new long[n]; Arrays.fill(c,Integer.MAX_VALUE); String s1[]=br.readLine().split("" ""); s=br.readLine().split("" ""); for(int i=0;i=0;i--){ p=Math.min(p+1,c[i]); b[i]=p; } for(int i=0;i> dp= new HashMap<>(); // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) public void sieve() { spf[1] = 1; for (int i=2; i getFactorization(int x) { if(dp.containsKey(x)) return dp.get(x); Set ret = new HashSet<>(); while (x != 1) { if(spf[x]!=2) ret.add(spf[x]); x = x / spf[x]; } dp.put(x,ret); return ret; } // function to find first index >= x public int lowerIndex(List arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y public int upperIndex(List arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } // function to count elements within given range public int countInRange(List arr, int n, int x, int y) { // initialize result int count = 0; count = upperIndex(arr, n, y) - lowerIndex(arr, n, x) + 1; return count; } public int add(int a, int b){ a+=b; if(a>=MOD) a-=MOD; else if(a<0) a+=MOD; return a; } public int mul(int a, int b){ long res= (long)a*(long)b; return (int)(res%MOD); } public int power(int a, int b) { int ans=1; while(b>0){ if((b&1)!=0) ans= mul(ans,a); b>>=1; a= mul(a,a); } return ans; } int[] fact= new int[MAXN]; int[] inv= new int[MAXN]; public int Ckn(int n, int k){ if(k<0 || n<0) return 0; return mul(mul(fact[n],inv[k]),inv[n-k]); } public int inverse(int a){ return power(a,MOD-2); } public void preprocess() { fact[0]=1; for(int i=1;i=0;i--){ inv[i]= mul(inv[i+1],i+1); } } public void solve(InputReader in, PrintWriter out) { int test= in.nextInt(); while(test-->0){ int n= in.nextInt(), k= in.nextInt(); int[] a= new int[k]; int[] t= new int[k]; for(int i=0;i=0;i--){ p= Math.min(p+1,c[i]); R[i]=(int)p; } for(int i=0;i{ // @Override // public int compare(Tuple t1, Tuple t2) { // return t2.l - t1.l; // } // } public int _gcd(int a, int b) { if(b == 0) { return a; } else { return _gcd(b, a % b); } } } static class Venice{ public Map m= new HashMap<>(); public long base=0; public long totalValue=0; private int M= 1000000007; private long addMod(long a, long b){ a+=b; if(a>=M) a-=M; return a; } public void reset(){ m= new HashMap<>(); base=0; totalValue=0; } public void update(long add){ base= base+ add; } public void add(long key, long val){ long newKey= key-base; m.put(newKey, addMod(m.getOrDefault(newKey,(long)0),val)); } } static class Tuple implements Comparable{ int x, y, z; public Tuple(int x, int y, int z){ this.x= x; this.y= y; this.z=z; } @Override public int compareTo(Tuple o){ return this.x-o.x; } } static class Pair implements Comparable{ public int x; public int y; public Pair(int x, int y){ this.x= x; this.y= y; } @Override public int compareTo(Pair o) { return this.x-o.x; } } // fast input reader class; static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { String line = null; try { line = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble(){ return Double.parseDouble(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } } }",1,(L4) similar function code with variable renaming within a large code. New Function. 04ed33a5,7ea34254,"import java.util.Scanner; public class Subsequence { private static Scanner sc = new Scanner(System.in); public static void main(String args[]) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i=0;i0){ int n= scan.nextInt(); long a[] = new long[n]; for(int i=0;i{ // public int compare(Pair p1,Pair p2){ // return p1.x-p2.x; // } //} ",0,Non-Plagiarised 49b94994,d8654140,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main1582D { public static void main(String[] args) { final FastScanner in = new FastScanner(System.in); final PrintWriter out = new PrintWriter(System.out); 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[] b = solution(a, n); for (int j = 0; j < n; j++) { out.print(b[j]); out.print("" ""); } out.println(); } out.flush(); out.close(); in.close(); } private static int[] solution(int[] a, int n) { int[] b = new int[n]; int start = 0; if (n % 2 == 1) { if (a[0] + a[1] != 0) { b[0] = -a[2]; b[1] = -a[2]; b[2] = a[0] + a[1]; } else if (a[0] + a[2] != 0) { b[0] = -a[1]; b[1] = a[0] + a[2]; b[2] = -a[1]; } else { b[0] = a[1] + a[2]; b[1] = -a[0]; b[2] = -a[0]; } start = 3; } else { b[0] = -a[1]; b[1] = a[0]; int gcd = gcd(b[0], b[1]); b[0] /= gcd; b[1] /= gcd; start = 2; } for (int i = start; i < n; i += 2) { b[i] = -a[i + 1]; b[i + 1] = a[i]; } return b; } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readIntArr(int n) { int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = Integer.parseInt(next()); } return result; } long[] readLongArr(int n) { long[] result = new long[n]; for (int i = 0; i < n; i++) { result[i] = Long.parseLong(next()); } return result; } void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } long nextLong() { return Long.parseLong(next()); } } } ","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 int mod=1000000007 ; static List[] adj; static boolean vst[]; static int dp[]; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); while(t-->0) { int n=fs.nextInt(); int arr[]=fs.readArray(n); int ans[]=new int[n]; if(n%2==0) { for(int i=0;i>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 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+""ms""); } private static boolean oj = System.getProperty(""ONLINE_JUDGE"") != null; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } 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]; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap map, int k, int v) { //map[k] += v; if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } // compress Big value to Time Limit public static int[] compress(int[] arr) { ArrayList ls = new ArrayList(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap map = new HashMap(); int boof = 1; //min value for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } // Fast Writer public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException(""FastWriter""); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("""" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("".""); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException(""innerflush""); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException(""flush""); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } // Fast Inputs static class FastScanner { //I don't understand how this works lmao 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[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = 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[] readArrayDouble(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; } } } } ","import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; int t = Integer.parseInt(br.readLine()); while (t --> 0) { int n = Integer.parseInt(br.readLine()); String a = br.readLine(); String b = br.readLine(); int alit = 0; int blit = 0; int ans = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if (a.charAt(i) == '1') alit++; if (b.charAt(i) == '1') blit++; } if (alit == blit) { int count = 0; for (int i = 0; i < n; i++) if (a.charAt(i) != b.charAt(i)) count++; ans = Math.min(count, ans); } if (alit == n - blit + 1) { int count = 0; for (int i = 0; i < n; i++) if (a.charAt(i) == b.charAt(i)) count++; ans = Math.min(ans, count); } if (ans == Integer.MAX_VALUE) { pw.println(""-1""); } else { pw.println(ans); } } pw.close(); } }",1,"(L3) Small code reuse with variable change in a huge code, different imports. Extra comments. Changing the order of declarations." ccc8ef27,f7a0ea6d,"import java.util.*; public class Sol { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int a[][]=new int[n][5]; int tot[]=new int[n]; for(int i=0;i0) res+=ans[j++]; return j; } }","import java.util.*; public class Solution { private static Scanner in = new Scanner(System.in); public static void main(String args[]) { int t = in.nextInt(); while(t-->0) { solution(); } } private static void solution() { int ans=0; int n = in.nextInt(); String s[] = new String[n]; int occurance[][] = new int[n][5]; for(int i=0;i n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }","import java.io.*; import java.util.*; public class D_Java { public static final int MOD = 998244353; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } int[] f; int[] rf; public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }",1,EM 76ad805a,f229aa7f,"import java.util.Arrays; import java.util.Scanner; public class First { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); String a = sc.next(); String b = sc.next(); char ch1[] = a.toCharArray(); char ch2[] = b.toCharArray(); int zz = 0; int oz = 0; int zo = 0; int oo = 0; for (int i = 0; i < n; i++) { if (ch1[i] == '0') { if (ch2[i] == '0') { zz += 1; } else { oz += 1; } } else { if (ch2[i] == '0') { zo += 1; } else { oo += 1; } } } int ans = -1; if ((oo - zz) == 1 || zo == oz) { int s1 = (int) 1e7; int s2 = (int) 1e7; if ((oo - zz) == 1) { s1 = oo + zz; } if (zo == oz) s2 = zo + oz; ans = Math.min(s1, s2); } System.out.println(ans); } } } //9 //001011011 //011010101 3 2 2 2 //9 //100010111 //101101100 2 1 3 3","import java.util.*; import java.io.*; import java.math.*; public class cf { static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); char[] a = sc.next().toCharArray(); char[] b = sc.next().toCharArray(); int x = 0, y = 0, lit = 0,lit2 = 0; for (int i = 0; i < n; i++) { if (a[i] == '1') lit++; if (b[i] == '1') lit2++; if (a[i] == b[i]) x++; else y++; } if(lit == lit2 || n - lit + 1 == lit2) { if (lit == lit2 && n - lit + 1 == lit2) { pw.println(Math.min(x,y)); }else if(lit == lit2) { pw.println(y); }else { pw.println(x); } }else { pw.println(-1); } } pw.close(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }",0,Non-Plagiarised 0e68e463,2120328e,"import java.io.*; import java.util.*; import static java.lang.Math.*; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = in.nextInt(); for(int tt = 0; tt < t; tt++) { int n = in.nextInt(); long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = in.nextLong(); char[] s = in.next().toCharArray(); if (solve(arr, n, s))pw.println(""YES""); else pw.println(""NO""); } pw.close(); } static boolean solve(long[] arr, int n, char[] s) { ArrayList B = new ArrayList<>(); ArrayList R = new ArrayList<>(); for(int i = 0; i < n; i++) { if (s[i] == 'B') B.add(arr[i]); else R.add(arr[i]); } Collections.sort(B); Collections.sort(R); // debug(B); long last = n; for (int i = R.size() - 1; i >= 0; i--) { long v = R.get(i); if (v > last) { return false; } last--; } long first = 1; int size = B.size(); for (int i = 0; i < size; i++) { long v = B.get(i); // debug(v, first); if (v < first) return false; first++; } return true; } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } } ","/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static int mod=10000007; static StringBuilder sb=new StringBuilder(); /* start */ public static void main(String [] args) { int t = i(); while(t-->0) { int n = i(); int a[] = input(n); char c[] = inputC(); ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); for(int i=0;in-i) { is = false; break; } } out.println(is==true?""YES"":""NO""); } out.close(); } /* end */ 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 int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static char[] inputC() { String s = sc.nextLine(); return s.toCharArray(); } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } //pair class private static class Pair implements Comparable { int first, second; public Pair(int f, int s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }",0,Non-Plagiarised b56ebada,b95a75a7,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class First { 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 a = 1; int t; t = in.nextInt(); //t = 1; while (t > 0) { //out.print(""Case #""+(a++)+"": ""); solver.call(in, out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); int[] arr = new int[n]; Integer[] lower = new Integer[n]; Integer[] higher = new Integer[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } TreeSet set = new TreeSet<>(); for (int i = 0; i < n; i++) { set.add(arr[i]); lower[i] = set.lower(arr[i]); higher[i] = set.higher(arr[i]); } for (int i = 1; i < n; i++) { if(arr[i]>arr[i-1]){ if(higher[i-1] != null && higher[i-1]arr[i]){ out.println(""NO""); return; } } } out.println(""YES""); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a; int b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class answer1 implements Comparable{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { return this.a - o.a; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;icur) { if(head.right==null) { Node next=new Node(arr[i]); head.right=next; next.left=head; head=head.right; } else if(head.right.valarr[i]) { cond=true; break; } else if(head.left.val==arr[i]) { head=head.left; } else { Node next=new Node(arr[i]); next.left=head.left; head.left.right=next; head.left=next; next.right=head; head=next; } } } if(cond) System.out.println(""NO""); else System.out.println(""YES""); } } } // 1 0 1 1 0 0 1",0,Non-Plagiarised 68cdd55d,c18048bf,"import java.io.*; import java.util.*; public class Main { static PrintWriter out; static Kioken sc; public static void main(String[] args) throws FileNotFoundException { boolean t = true; boolean f = false; if (f) { out = new PrintWriter(""output.txt""); sc = new Kioken(""input.txt""); } else { out = new PrintWriter((System.out)); sc = new Kioken(); } int tt = 1; tt = sc.nextInt(); while (tt-- > 0) { solve(); } out.flush(); out.close(); } static boolean flag = false; static List[] ans; public static void dfs(int index, boolean[] visited, int parent, int val, List[] ll){ if(visited[index]){ return; } List l1 = ll[index]; // out.println("" == "" + l1 + "" "" + index); if(l1.size() > 2){ flag = true; return; } visited[index] = true; for(int k: l1){ if(visited[k] == false){ // out.println(visited[k] + "" "" + index + "" "" + k + "" "" + val); ans[index].add(new int[]{k, val}); ans[k].add(new int[]{index, val}); dfs(k, visited, index, (val == 2) ? 5 : 2, ll); } } } public static void solve() { int n = sc.nextInt(); List[] ll = new List[n + 1]; // out.println("" mm "" + n); for (int i = 0; i <= n; i++) { ll[i] = new ArrayList<>(); } int[][] store = new int[n][2]; for (int i = 0; i < n - 1; i++) { int u = sc.nextInt(); int v = sc.nextInt(); store[i][0] = u; store[i][1] = v; // out.println("" === "" + u + "" "" + v); int mm = Math.min(u, v); int mx = Math.max(u, v); // out.println("" u "" + v + "" "" + u); ll[mm].add(mx); ll[mx].add(mm); // ll[v].add(u) } int two = 2; int prime = 5; flag = false; ans = new List[n+1]; int[] arr = new int[n + 1]; for(int i = 0; i <= n; i++){ ans[i] = new ArrayList<>(); } boolean[] visited = new boolean[n+1]; List one = ll[1]; if(one.size() > 2){ out.println(-1); return; } // out.println("" -- "" + one); visited[1] = true; for(int i = 0; i < one.size(); i++){ if(i == 0){ ans[1].add(new int[]{one.get(i), 2}); ans[one.get(i)].add(new int[]{1, 2}); dfs(one.get(i), visited, -1, 5, ll); }else{ ans[1].add(new int[]{one.get(i), 5}); ans[one.get(i)].add(new int[]{1, 5}); dfs(one.get(i), visited, -1, 2, ll); } } if (flag) { out.println(-1); return; } for(int i = 0; i < n-1; i++){ // out.println("" -- ""); int u = store[i][0]; int v = store[i][1]; // out.println("" uu "" + u + "" "" + v); if(u == 0 || v == 0){ continue; } int mm = Math.min(u, v); int mx = Math.max(u, v); List vv = ans[mm]; // for(int[] ii:vv){ // out.println(Arrays.toString(ii)); // } if(vv == null){ continue; } for(int[] j: vv){ if(j[0] == mx){ out.print(j[1]+ "" ""); break; } } } out.println(); } public static long gcd(long a, long b) { while (b != 0) { long rem = a % b; a = b; b = rem; } return a; } public static long leftShift(long a) { return (long) Math.pow(2, a); } public static void reverse(int[] arr) { Arrays.sort(arr); int n = arr.length; for (int i = 0; i < arr.length / 2; i++) { int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } return; } public static int lower_bound(ArrayList ar, int k) { int s = 0, e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) <= k) { s = mid + 1; } else { e = mid; } } return Math.abs(s) - 1; } public static int upper_bound(ArrayList ar, int k) { int s = 0; int e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) < k) { s = mid + 1; } else { e = mid; } } if (s == ar.size()) { return -1; } return s; } static class Kioken { // FileInputStream br = new FileInputStream(""input.txt""); BufferedReader br; StringTokenizer st; Kioken(String filename) { try { FileReader fr = new FileReader(filename); br = new BufferedReader(fr); st = new StringTokenizer(""""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } Kioken() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""""); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } public boolean hasNext() { String next = null; try { next = br.readLine(); } catch (Exception e) { } if (next == null || next.length() == 0) { return false; } st = new StringTokenizer(next); return true; } } }","/* 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 {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 int mod = 998244353 ; // static int N = 200005; // static long factorial_num_inv[] = new long[N+1]; // static long natual_num_inv[] = new long[N+1]; // static long fact[] = new long[N+1]; // static void InverseofNumber() //{ // natual_num_inv[0] = 1; // natual_num_inv[1] = 1; // for (int i = 2; i <= N; i++) // natual_num_inv[i] = natual_num_inv[mod % i] * (mod - mod / i) % mod; //} //static void InverseofFactorial() //{ // factorial_num_inv[0] = factorial_num_inv[1] = 1; // for (int i = 2; i <= N; i++) // factorial_num_inv[i] = (natual_num_inv[i] * factorial_num_inv[i - 1]) % mod; //} //static long nCrModP(long N, long R) //{ // long ans = ((fact[(int)N] * factorial_num_inv[(int)R]) % mod * factorial_num_inv[(int)(N - R)]) % mod; // return ans%mod; //} //static boolean prime[]; //static void sieveOfEratosthenes(int n) //{ // prime = new boolean[n+1]; // for (int i = 0; i <= n; i++) // prime[i] = true; // for (int p = 2; p * p <= n; p++) // { // // If prime[p] is not changed, then it is a // // prime // if (prime[p] == true) // { // // Update all multiples of p // for (int i = p * p; i <= n; i += p) // prime[i] = false; // } // } //} static int visited[]; static HashMap hm; public static void main (String[] args) throws java.lang.Exception { // InverseofNumber(); // InverseofFactorial(); // fact[0] = 1; // for (long i = 1; i <= 2*100000; i++) // { // fact[(int)i] = (fact[(int)i - 1] * i) % mod; // } FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scan.nextInt(); while(t-->0){ int n = scan.nextInt(); List> a = new ArrayList>(); for(int i=0;i<=n;i++){ a.add(new ArrayList()); } Pair edge[] = new Pair[n-1]; for(int i=0;i2) flag = 1; if(a.get(i).size()==1) start = i; } if(flag==1) pw.println(-1); else{ visited = new int[n+1]; hm = new HashMap(); dfs(a,start,2); for(int i=0;i> a,int start,int parent){ if(visited[start]==0){ visited[start] = 1; List temp = a.get(start); int len = temp.size(); for(int i=0;i{ // public int compare(Pair p1,Pair p2){ // if(p1.x==p2.x) // return 0; // else if(p1.x=Integer.MAX_VALUE){ ans=-1; } res.append(ans+"" \n""); } } } p++; } System.out.println(res); } private static long solve( long correct1, long correct0, long wrong1, long wrong0,long a) { long op1=Integer.MAX_VALUE; long op2=Integer.MAX_VALUE; if(wrong1==0 && wrong0==0){ return 0; } if(a==1){ { // using correct1 if(correct1>0){ long newcorrect1=1+wrong0; long newcorrect0=wrong1; long newwrong1=correct0; long newwrong0=correct1-1; op1=(1+solve(newcorrect1,newcorrect0,newwrong1,newwrong0,0)); } } } else{ { //using wrong1 { if(wrong1>0){ long newcorrect1=wrong0; long newcorrect0=wrong1-1; long newwrong1=1+correct0; long newwrong0=correct1; op2=(1+solve(newcorrect1,newcorrect0,newwrong1,newwrong0,1)); } } } } long ans=Math.min(op1,op2); return ans; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static long modpower(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; } // SIMPLE POWER FUNCTION=> static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } }","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; 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 t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n, _00 = 0, _01 = 0, _11 = 0, _10 = 0; n = in.nextInt(); char[] s = in.next().toCharArray(); char[] s1 = in.next().toCharArray(); for (int i = 0; i < n; i++) { if(s[i]==s1[i]){ if(s[i]=='0'){ _00++; } else{ _11++; } } else{ if(s[i]=='0'){ _01++; } else{ _10++; } } } int ans = Integer.MAX_VALUE; if(_10 ==_01){ ans = 2*_01; } if(_11 == _00 + 1){ ans = Math.min(ans, 2*_00 + 1); } if(ans == Integer.MAX_VALUE){ out.println(-1); } else{ out.println(ans); } } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList arrayList2 ; public arrayListClass(ArrayList arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i q = new LinkedList<>(); int s = 0; for(int i = 0; i < g.length; i++) { if(g[i].l.size() == 1) { s = i; break; } } q.add(s); int curr = 2; while(!q.isEmpty()) { int u = q.poll(); if(visited[u]) continue; visited[u] = true; for(Edge edge : g[u].l) { if(!visited[edge.v]) { ans[edge.id] = curr; q.add(edge.v); if(curr == 2) curr = 3; else curr = 2; } } } } public static void solve() { int n = sc.nextInt(); Node[] a = new Node[n]; for(int i = 0; i < n; i++) a[i] = new Node(); for(int i = 0; i < n - 1; i++) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; a[u].l.add(new Edge(v, i)); a[v].l.add(new Edge(u, i)); } for(Node node : a) { if(node.l.size() > 2) { out.println(-1); return; } } int[] ans = new int[n - 1]; bfs(a, ans); for(int i = 0; i < n - 1; i++) out.print(ans[i] + "" ""); out.println(); } public static void main(String[] args) { int t = sc.nextInt(); while(t-- > 0) solve(); out.flush(); } } class Edge { int v, id; Edge(int a, int b) { v = a; id = b; } } class Node { ArrayList l; Node() { l = new ArrayList<>(); } } class MyScanner { BufferedReader br; StringTokenizer tok; MyScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch(Exception e) { System.out.println(e); } tok = new StringTokenizer(""""); } public String next() { try { while(!tok.hasMoreTokens()) tok = new StringTokenizer(br.readLine()); } catch(Exception e) { System.out.println(e); } return tok.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static { try { System.setIn(new FileInputStream(""input.txt"")); System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); } catch (Exception e) {} } void solve() { int n = in.nextInt(); ArrayList[] graph = new ArrayList[n + 1]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList(); } for (int i = 0; i < n - 1; i++) { int u = in.nextInt(); int v = in.nextInt(); v--; u--; graph[u].add(new Edge(v, i)); graph[v].add(new Edge(u, i)); } int[] res = new int[n - 1]; for (int i = 0; i < n; i++) { if (graph[i].size() > 2) { out.append(""-1\n""); return; } } int start = -1; for (int i = 0; i < n; i++) { if (graph[i].size() == 1) { start = i; break; } } int currNode = start; int prevNode = -1; int weight = 2; while (true) { ArrayList edges = graph[currNode]; Edge next = edges.get(0); if (next.node == prevNode) { if (edges.size() == 1) { break; } next = edges.get(1); } res[next.index] = weight; weight = 5 - weight; prevNode = currNode; currNode = next.node; } for (int i = 0; i < n - 1; i++) { out.append(res[i] + "" ""); } out.append(""\n""); } public static void main (String[] args) { // Its Not Over Untill I Win - Syed Mizbahuddin Main sol = new Main(); int t = 1; t = in.nextInt(); while (t-- != 0) { sol.solve(); } System.out.print(out); } void println(T[] s) { System.out.println(Arrays.toString(s)); } void println(T s) { System.out.println(s); } void print(int s) { System.out.print(s); } void println(int s) { System.out.println(s); } void println(int[] a) { println(Arrays.toString(a)); } int[] array(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } int[] array1(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) { a[i] = in.nextInt(); } return a; } static FastReader in; static StringBuffer out; final int MAX; final int MIN; int mod ; Main() { in = new FastReader(); out = new StringBuffer(); MAX = Integer.MAX_VALUE; MIN = Integer.MIN_VALUE; mod = (int)1e9 + 7; } } 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; } } class Edge { int node, index; Edge(int node, int index) { this.node = node; this.index = index; } }",0,Non-Plagiarised 856a8eda,c354b74f,"/*input 2 5 2 3 1 2 3 1 2 4 3 3 1 1 2 3 */ import java.io.*; import java.util.*; public class three{ public static class Pair implements Comparable{ int min; int idx; @Override public int compareTo(Pair o) { return min - o.min; } } public static void main(String[] args) throws Exception { MyScanner scn = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String int result = 3*n; out.println(result); // print via PrintWriter */ //The Code Starts here int t = scn.nextInt(); while(t-- > 0){ int n = scn.nextInt(); int m = scn.nextInt(); int x = scn.nextInt(); int arr[] = scn.nextIntArray(n); PriorityQueue pq = new PriorityQueue<>(); System.out.println(""YES""); for(int i=0;i { // long u; // long v; // public Pair(long u, long v) { // this.u = u; // this.v = v; // } // public int hashCode() { // int hu = (int) (u ^ (u >>> 32)); // int hv = (int) (v ^ (v >>> 32)); // return 31 * hu + hv; // } // public boolean equals(Object o) { // Pair other = (Pair) o; // return u == other.u && v == other.v; // } // public int compareTo(Pair other) { // return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v); // } // public String toString() { // return ""[u="" + u + "", v="" + v + ""]""; // } // } //-------------------------------------------------------- } ","//Some of the methods are copied from GeeksforGeeks Website import java.util.*; import java.lang.*; import java.io.*; public class Main { static Reader sc=new Reader(); // static FastReader sc=new FastReader(System.in); static class PairComparator implements Comparator{ // Overriding compare()method of Comparator // for descending order of cgpa public int compare(Pair s1, Pair s2) { if (s1.x < s2.x) return -1; else if (s1.x > s2.x) return 1; return 0; } } public static void main (String[] args) throws java.lang.Exception { // try{ /* int n=sc.nextInt(); ArrayList al=new ArrayList<>(); ArrayList al=new ArrayList<>(); Set set=new HashSet<>(); Collections.sort(al,Collections.reverseOrder()); long n=sc.nextLong(); for(int i=0;i0) { int n=sc.nextInt(); int m=sc.nextInt(); int x=sc.nextInt(); PriorityQueue pq=new PriorityQueue<>(m, new PairComparator()); for(int i=1;i<=m;i++) { Pair p=new Pair(0,i); pq.add(p); } out.println(""YES""); int a[]=new int[n]; for(int i=0;i map=new HashMap<>(); for(int i=0;i> hmap=map.entrySet(); for(Map.Entry data : hmap) { } Iterator it = set.iterator(); while(it.hasNext()) { int x=it.next(); } */ static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>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>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class Graph { int v; ArrayList list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } static void DFS(Graph g, boolean[] visited, int u) { visited[u]=true; int v=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i= 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 !",0,Non-Plagiarised 115c99cb,548ffb07,"import java.io.*; import java.util.*; public class D_Java { public static final int MOD = 998244353; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } int[] f; int[] rf; public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }","import java.io.*; import java.util.*; public class D_Java { public static final int MOD = 998244353; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } int[] f; int[] rf; public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } } ",1,EM ca0c55ad,e14d1ba0,"import java.util.*; public class ss { public static void main(String[]args) { Scanner in=new Scanner (System.in); int t=in.nextInt(); for(int i1=0;i1ar[i]) { m=ar[i]; } s1+=ar[i]; ans[i]=s1-m+m*(n-i/2); } ans[1]=ar[1]*n; m=ar[1]; s1=ar[1]; for(int i=3;iar[i]) { m=ar[i]; } s1+=ar[i]; ans[i]=s1-m+m*(n-i/2); } long mini=ans[0]+ans[1]; for(int i=1;iar[i]) { m=ar[i]; } s1+=ar[i]; ans[i]=s1-m+m*(n-i/2); } ans[1]=ar[1]*n; m=ar[1]; s1=ar[1]; for(int i=3;iar[i]) { m=ar[i]; } s1+=ar[i]; ans[i]=s1-m+m*(n-i/2); } long mini=ans[0]+ans[1]; for(int i=1;i0) { int n = sc.nextInt(); int a[] = new int[n]; for(int i=0;i a1 = new ArrayList<>(); ArrayList a2 = new ArrayList<>(); for (int i = 0; i < n; i++) { if(a[i] == 0) a1.add(i); else a2.add(i); } long dp[][] = new long[n+1][n+1]; for (int i = 0; i <= n; i++) { Arrays.fill(dp[i],-1); } out.write(find(0,0,a1,a2,dp)+""\n""); } out.close(); } private static long find(int i, int j, List a1, ArrayList a2, long[][] dp) { if(j == a2.size()) return 0; int req = a2.size()-j; int ava = a1.size()-i; if(ava not prime // false->prime sv[0] = sv[1] = true; sv[2] = false; for(int i = 0; i< sv.length; i++) { if( !sv[i] && (long)i*(long)i < sv.length ) { for ( int j = i*i; j 0) { if ( (b & 1) > 0){ res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return res; } static long factorial(long n) { long res = 1, i; for (i = 2; i <= n; i++){ res = ((res%mod) * (i%mod))%mod; } return res; } static class Pair { int idx; int v; Pair(int idx, int v){ this.idx = idx; this.v = v; } } public static void main(String[] args) throws Exception { // runFile(); runIo(); int t; t = 1; // t = sc.nextInt(); ans = new StringBuilder(); while( t-- > 0 ) { solve(); } pn(ans+""""); } static int N ; static int M ; static ArrayList f; static ArrayList e; static long dp[][]; static long find(int i, int j ) { if( i == N ) return 0; if( j == M ) return Integer.MAX_VALUE; if (dp[i][j] != -1 ) return dp[i][j]; return dp[i][j] = Math.min( find(i, j+1), Math.abs(f.get(i)-e.get(j)) + find(i+1, j+1) ); } public static void solve() { int n = ni(); f = new ArrayList(); e = new ArrayList(); for(int i = 0; i { 0, 1, 5 } // 0s -> { 2, 3, 6, 7 } ",0,Non-Plagiarised c9da41af,f59d9b6e,"import java.util.*; import java.lang.*; import java.io.*; public class Main { static { try { System.setIn(new FileInputStream(""input.txt"")); System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); } catch (Exception e) {} } void solve() { int n = in.nextInt(); ArrayList[] graph = new ArrayList[n + 1]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList(); } for (int i = 0; i < n - 1; i++) { int u = in.nextInt(); int v = in.nextInt(); v--; u--; graph[u].add(new Edge(v, i)); graph[v].add(new Edge(u, i)); } int[] res = new int[n - 1]; for (int i = 0; i < n; i++) { if (graph[i].size() > 2) { out.append(""-1\n""); return; } } int start = -1; for (int i = 0; i < n; i++) { if (graph[i].size() == 1) { start = i; break; } } int currNode = start; int prevNode = -1; int weight = 2; while (true) { ArrayList edges = graph[currNode]; Edge next = edges.get(0); if (next.node == prevNode) { if (edges.size() == 1) { break; } next = edges.get(1); } res[next.index] = weight; weight = 5 - weight; prevNode = currNode; currNode = next.node; } for (int i = 0; i < n - 1; i++) { out.append(res[i] + "" ""); } out.append(""\n""); } public static void main (String[] args) { // Its Not Over Untill I Win - Syed Mizbahuddin Main sol = new Main(); int t = 1; t = in.nextInt(); while (t-- != 0) { sol.solve(); } System.out.print(out); } void println(T[] s) { System.out.println(Arrays.toString(s)); } void println(T s) { System.out.println(s); } void print(int s) { System.out.print(s); } void println(int s) { System.out.println(s); } void println(int[] a) { println(Arrays.toString(a)); } int[] array(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } int[] array1(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) { a[i] = in.nextInt(); } return a; } static FastReader in; static StringBuffer out; final int MAX; final int MIN; int mod ; Main() { in = new FastReader(); out = new StringBuffer(); MAX = Integer.MAX_VALUE; MIN = Integer.MIN_VALUE; mod = (int)1e9 + 7; } } 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; } } class Edge { int node, index; Edge(int node, int index) { this.node = node; this.index = index; } }","/* 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 class Edge{ int node; int index; Edge(int node, int index){ this.node = node; this.index = index; } } static Scanner scn = new Scanner(System.in); public static void main (String[] args) throws java.lang.Exception{ int t = scn.nextInt(); while(t-->0){ solve(); } } public static void solve(){ int n = scn.nextInt(); ArrayList[]graph = new ArrayList[n]; for(int i = 0; i < n; i++){ graph[i] = new ArrayList<>(); } for(int i = 0; i < n - 1; i++){ int u = scn.nextInt() - 1; int v = scn.nextInt() - 1; graph[u].add(new Edge(v, i)); graph[v].add(new Edge(u, i)); } int start = 0; for(int i = 0; i < n; i++){ if(graph[i].size() > 2){ System.out.println(""-1""); return; }else if(graph[i].size() == 1){ start = i; } } int[]weight = new int[n - 1]; int prevNode = -1, curNode = start, curWeight = 2; while(true){ ArrayListedges = graph[curNode]; Edge next = edges.get(0); if(next.node == prevNode){ if(edges.size() == 1){ break; }else{ next = edges.get(1); } } weight[next.index] = curWeight; prevNode = curNode; curNode = next.node; curWeight = 5 - curWeight; } for(int i = 0; i < n - 1; i++){ System.out.print(weight[i]); System.out.print("" ""); } System.out.println(); } } ",1,(L3) Similar function code with variable rename within a larger code. Additional unused code. Changing the order of declarations. 086f0f90,4a570de6,"import java.io.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int t=sc.nextInt(); while (t-->=1) { int n = sc.nextInt(),m=sc.nextInt(), x = sc.nextInt(); int a[] = sc.readArray(n); PriorityQueue pq=new PriorityQueue<>(); for (int i=0;i 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 String sortString(String s) { char temp[] = s.toCharArray(); Arrays.sort(temp); return new String(temp); } static class Pair implements Comparable { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } // to sort first part // public int compareTo(Pair other) { // if (this.a == other.a) return other.b > this.b ? -1 : 1; // else if (this.a > other.a) return 1; // else return -1; // } // public int compareTo(Pair other) { // if (this.b == other.b) return 0; // if (this.b < other.b) return 1; // else return -1; // } //sort on the basis of first part only public int compareTo(Pair other) { if (this.a == other.a) return 0; else if (this.a > other.a) return 1; else return -1; } } static int[] frequency(String s){ int fre[]= new int[26]; for (int i=0;i0){ long lastBit=n&1; if (lastBit==1){ ans=(int)mul(ans,a); } a=(int)mul(a,a); n>>=1; } return ans; } static int[] find(int n, int start, int diff) { int a[] = new int[n]; a[0] = start; for (int i = 1; i < n; i++) a[i] = a[i - 1] + diff; return a; } static void swap(int a, int b) { int c = a; a = b; b = c; } static void printArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } static boolean sorted(int a[]) { int n = a.length; boolean flag = true; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) flag = false; } if (flag) return true; else return false; } public static int findlog(long n) { if (n == 0) return 0; if (n == 1) return 0; if (n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if (den == 0) return 0; return (int) (num / den); } public static long gcd(long a, long b) { if (b % a == 0) return a; return gcd(b % a, a); } public static int gcdInt(int a, int b) { if (b % a == 0) return a; return gcdInt(b % a, a); } static void sortReverse(int[] a) { ArrayList l = new ArrayList<>(); for (int i : a) l.add(i); // Collections.sort.(l); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.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) { 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[] readArrayLong(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }","import java.io.*; import java.lang.*; import java.util.*; public class c { static class FastScanner { InputStreamReader is; BufferedReader br; StringTokenizer st; public FastScanner() { is = new InputStreamReader(System.in); br = new BufferedReader(is); } String next() throws Exception { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int ni() throws Exception { return Integer.parseInt(next()); } long nextLong() throws Exception { return Long.parseLong(next()); } int[] readArray(int num) throws Exception { int arr[]=new int[num]; for(int i=0;i= 0) { double i= Math.sqrt(x); if(i%1!=0) { return false; } return ((i * i) == x); } return false; } public static int[] ia(int n) { int ar[]=new int[n]; return ar; } public static long[] la(int n) { long ar[]=new long[n]; return ar; } static class pair implements Comparable{ int ht; int id; pair(int ht, int id) { this.ht=ht; this.id=id; } public int compareTo(pair p) { return this.ht-p.ht; } } public static void main(String args[]) throws java.lang.Exception { FastScanner sc=new FastScanner(); int t=sc.ni(); while(t-->0) { int n=sc.ni(); int m=sc.ni(); int x=sc.ni(); int ar[]=ia(n); for(int i=0;i pq=new PriorityQueue<>(); for(int i=0;i o=new ArrayList(), e=new ArrayList(); int n = sc.nextInt(),dp[][]=new int[n+1][n+1]; for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } for(int i=1;i<=o.size();i++){ dp[i][i]=dp[i-1][i-1]+Math.abs(o.get(i-1)-e.get(i-1)); for(int j=i+1;j<=e.size();j++) dp[i][j]=Math.min(dp[i][j-1],dp[i-1][j-1]+Math.abs(o.get(i-1)-e.get(j-1))); } System.out.println(dp[o.size()][e.size()]); } } ","import java.util.*; public class D { public static void main(String[] args) { Scanner sc=new Scanner(System.in); ArrayList o=new ArrayList(), e=new ArrayList(); int n = sc.nextInt(),dp[][]=new int[n+1][n+1]; for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } for(int i=1;i<=o.size();i++){ dp[i][i]=dp[i-1][i-1]+Math.abs(o.get(i-1)-e.get(i-1)); for(int j=i+1;j<=e.size();j++) dp[i][j]=Math.min(dp[i][j-1],dp[i-1][j-1]+Math.abs(o.get(i-1)-e.get(j-1))); } System.out.println(dp[o.size()][e.size()]); } }",1,"(L2) EM Nearly, one variable change" 73f57af1,9a20c823,"/*input 3 2 1 6 3 8 1 2 3 1 3 4 6 7 9 1 2 2 3 6 3 14 12 20 12 19 2 12 10 17 3 17 3 2 6 5 1 5 2 6 4 6 */ import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out; static int MOD = 1000000007; static FastReader scan; /*-------- I/O usaing short named function ---------*/ public static String ns(){return scan.next();} public static int ni(){return scan.nextInt();} public static long nl(){return scan.nextLong();} public static double nd(){return scan.nextDouble();} public static String nln(){return scan.nextLine();} public static void p(Object o){out.print(o);} public static void ps(Object o){out.print(o + "" "");} public static void pn(Object o){out.println(o);} /*-------- for output of an array ---------------------*/ static void iPA(int arr []){ StringBuilder output = new StringBuilder(); for(int i=0; i0){ int n = ni(); l = new long[n]; r = new long[n]; for(int i=0; i adj[] = new ArrayList[n]; for(int i=0; i(); for(int i=0; i adj[], int vertex, int prev, boolean visited[]){ visited[vertex] = true; if(dp[vertex][prev] != null) return dp[vertex][prev]; long ans = 0; for(int x : adj[vertex]){ if(!visited[x]){ if(prev == 0){ ans += Math.max(Math.abs(l[vertex] - l[x]) + solve(adj, x, 0, visited), Math.abs(l[vertex] - r[x]) + solve(adj, x, 1, visited)); //pn(vertex + "" "" + x + "" "" + ans); }else{ ans += Math.max(Math.abs(r[vertex] - l[x]) + solve(adj, x, 0, visited), Math.abs(r[vertex] - r[x]) + solve(adj, x, 1, visited)); //pn(vertex + "" "" + x + "" "" + ans); } } } visited[vertex] = false; //pn(ans); return dp[vertex][prev] = ans; } } ","import java.util.*; import java.io.*; public class Parsas_Humongous_Tree { 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 shuffle(int[] a) { Random r = new Random(); for (int i = 0; i <= a.length - 2; i++) { int j = i + r.nextInt(a.length - i); swap(a, i, j); } } public static void swap(int[] a, int i, int j) { int 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) { int n = t.nextInt(); long[][] cost = new long[n][2]; List[] graph = new ArrayList[n]; dp = new long[n][2]; for (int i = 0; i < n; ++i) { cost[i][0] = t.nextLong(); cost[i][1] = t.nextLong(); graph[i] = new ArrayList<>(); } for (int i = 0; i < n - 1; ++i) { int x = t.nextInt() - 1; int y = t.nextInt() - 1; graph[x].add(y); graph[y].add(x); } o.println(Math.max(dfs(graph, cost, 0, 0, -1), dfs(graph, cost, 0, 1, -1))); } o.flush(); o.close(); } private static long[][] dp; private static long dfs(List[] graph, long[][] cost, int u, int j, int par) { if (dp[u][j] != 0) return dp[u][j]; for (int v : graph[u]) if (v != par) { long c1 = Math.abs(cost[u][j] - cost[v][0]) + dfs(graph, cost, v, 0, u); long c2 = Math.abs(cost[u][j] - cost[v][1]) + dfs(graph, cost, v, 1, u); dp[u][j] += Math.max(c1, c2); } return dp[u][j]; } }",0,Non-Plagiarised 680ba922,90dc2b20,"import java.util.*; import java.io.*; public class Solution { 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(); } } static int parent(int a , int p[]) { if(a == p[a]) return a; return p[a] = parent(p[a],p); } static void union(int a , int b , int p[] , int size[]) { a = parent(a,p); b = parent(b,p); if(a == b) return; if(size[a] < size[b]) { int temp = a; a = b; b = temp; } p[b] = a; size[a] += size[b]; } static long getSum(int index , long BITree[]) { long sum = 0; // Iniialize result // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse ancestors of BITree[index] while(index>0) { // Add current element of BITree // to sum sum += BITree[index]; // Move index to parent node in // getSum View index -= index & (-index); } return sum; } // Updates a node in Binary Index Tree (BITree) // at given index in BITree. The given value // 'val' is added to BITree[i] and all of // its ancestors in tree. public static void updateBIT(int n, int index, long val , long BITree[]) { // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse all ancestors and add 'val' while(index <= n) { // Add 'val' to current node of BIT Tree BITree[index] += val; // Update index to that of parent // in update View index += index & (-index); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int dp[][]; static int f(int pos , int take , int arr[]) { if(pos == -1) { if(take == 0) return 0; return -10000000; } if(dp[pos][take] != -1) return dp[pos][take]; if(pos+1-take == arr[pos]) dp[pos][take] = Math.max(dp[pos][take],1 + f(pos-1,take,arr)); dp[pos][take] = Math.max(dp[pos][take],f(pos-1,take,arr)); if(take > 0) dp[pos][take] = Math.max(dp[pos][take],f(pos-1,take-1,arr)); return dp[pos][take]; } public static void main(String []args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); sc.nextLine(); String a = sc.nextLine(); String b = sc.nextLine(); int same = 0 , zo = 0 , oz = 0 , oo = 0 , zz = 0; for(int i = 0 ; i < n ; i++) { if(a.charAt(i) == '0' && b.charAt(i) == '1') oz++; else if(a.charAt(i) == '1' && b.charAt(i) == '0') zo++; else if(a.charAt(i) == '1' && b.charAt(i) == '1') oo++; else zz++; } if(oz == zo || (zz == oo-1)) { int mx = Integer.MAX_VALUE; if(oz == zo) mx = Math.min(mx,2*oz); if(oo-1 == zz) mx = Math.min(mx,zz+oo); System.out.println(mx); } else { System.out.println(-1); } } } }","import java.util.*; import java.io.*; public class C1615{ static FastScanner fs = null; public static void main(String[] args) { fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-->0) { int n = fs.nextInt(); String a = fs.next(); String b = fs.next(); char ch1[] = a.toCharArray(); char ch2[] = b.toCharArray(); int c00 = 0; int c01 = 0; int c10 = 0; int c11 = 0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i0){ int n = s.nextInt(); int arr[] = new int[n]; for(int i=0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int i=0;istart){ bool = false; break; } start++; } if(bool){ System.out.println(""YES""); } else{ System.out.println(""NO""); } } t--; } s.close(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class D { static class Pair{ int val; char c; Pair(int a,char b){ this.val=a; this.c=b; } } public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); PrintWriter pw=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int[] a=sc.readArray(n); char[] s=sc.next().toCharArray(); boolean ok=true; ArrayList blues=new ArrayList<>(); ArrayList reds=new ArrayList<>(); for(int i=0;i(start++)){ ok=false; break; } } if(ok){ pw.println(""YES""); } else { pw.println(""NO""); } } pw.flush(); } 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 0) // { // String s = sc.next(); // solve(s); // // } // // } static class Pair implements Comparable { int h; int ind; Pair(int h, int ind) { this.h = h; this.ind = ind; } @Override public int compareTo(Pair o) { return this.h - o.h; } } public static void main(String[] args) { FastReader fs=new FastReader(); int T=fs.nextInt(); for (int tt=0; tt heap = new PriorityQueue<>(); for(int i=0;i x) //// { //// System.out.println(""NO"" + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); //// flag = true; //// break; //// } // if(inc) // tower++; // else // tower--; // } // for(int i=1;i<=m;i++) // { // min = Math.min(min, towers[i]); // max = Math.max(max, towers[i]); // } // if(Math.abs(max - min) > x) // { // System.out.println(""NO"" + max+"" ""+min);// + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); // //flag = true; // continue; // } // if(flag) // continue; System.out.println(""YES""); for(int i:ans) System.out.print(i+"" ""); System.out.println(); } } } ","/* 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 cses { static int mod=1000000007; static FastReader sc=new FastReader(); public static void main (String[] args) throws java.lang.Exception { long startTime=System.currentTimeMillis(); int t=sc.nextInt(); for(int y=0;y pq=new PriorityQueue<>(); int index[]=new int[n]; PriorityQueue pq =new PriorityQueue(new comp()); for(int i=0;i{ public int compare(Node a,Node b) { return a.sum-b.sum; } } static class Node{ int sum; int build; Node(int sum ,int build) { this.sum=sum; this.build=build; } } 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 getExecutionTime(long startTime) { final long endTime = System.currentTimeMillis(); System.out.println(); System.out.println(""Time take is ""+(endTime-startTime)+"" ms""); } } // System.out.println(""Case #""+(y+1)+"": ""+ans); ",0,Non-Plagiarised 6255ee79,ac8ef97c," import java.io.*; import java.util.*; public class Test2 { static class node{ int l,r; ArrayList child; node(int l,int r){ child = new ArrayList(); this.l = l; this.r = r; } } static FastReader f = new FastReader(); public static void main(String[] args) throws IOException { int t =f.nextInt(); while(t-->0) { int n = f.nextInt(); ArrayList arr = new ArrayList(); for(int i = 0;i arr,int i,int p,int pre,long dp[][]) { long min = 0,max = 0; if(dp[i][0]!=-1) { min = dp[i][0]; }else { for(int e:arr.get(i).child) { if(e!=p) { min+=fun(arr, e, i, arr.get(i).l,dp); } } dp[i][0] =min; } if(dp[i][1]!=-1) { max = dp[i][1]; }else { for(int e:arr.get(i).child) { if(e!=p) { max+=fun(arr, e, i, arr.get(i).r,dp); } }dp[i][1] = max; } min+=(Math.abs(arr.get(i).l-pre)); max +=Math.abs(arr.get(i).r-pre); //System.out.println(min+"" max = ""+max+"" i = ""+i+"" per =""+p+"" pre = ""+pre); return Math.max(min, max); } static ArrayList primeFectors(int n){ ArrayList ret = new ArrayList(); while (n%2==0) { ret.add(2); n /= 2; } for (int i = 3; i <= Math.ceil(Math.sqrt(n)); i+= 2) { // While i divides n, print i and divide n while (n%i==0) { ret.add(i); n /= i; } } if (n > 2) ret.add(n); return ret; } 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; } } } ","import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); while(t-->0) { int n=Integer.parseInt(bu.readLine()); g=new ArrayList[n]; int i; for(i=0;i(); String st[]=bu.readLine().split("" ""); a[i][0]=Integer.parseInt(st[0]); a[i][1]=Integer.parseInt(st[1]); s[i][0]=s[i][1]=0; } for(i=0;i g[]; static int N=100000,a[][]=new int[N][2]; static long s[][]=new long[N][2]; static void dfs(int n,int p) { for(int x:g[n]) if(x!=p) { dfs(x,n); s[n][0]+=Math.max(s[x][0]+Math.abs(a[x][0]-a[n][0]),s[x][1]+Math.abs(a[x][1]-a[n][0])); s[n][1]+=Math.max(s[x][0]+Math.abs(a[x][0]-a[n][1]),s[x][1]+Math.abs(a[x][1]-a[n][1])); } } } ",0,Non-Plagiarised 3afcc566,90dc2b20,"//package codeforces.globalround18; import java.io.*; import java.util.*; import static java.lang.Math.*; //Think through the entire logic before jump into coding! //If you are out of ideas, take a guess! It is better than doing nothing! //Read both C and D, it is possible that D is easier than C for you! //Be aware of integer overflow! //If you find an answer and want to return immediately, don't forget to flush before return! public class C { static InputReader in; static PrintWriter out; public static void main(String[] args) { //initReaderPrinter(true); initReaderPrinter(false); solve(in.nextInt()); //solve(1); } static void solve(int testCnt) { for (int testNumber = 0; testNumber < testCnt; testNumber++) { int n = in.nextInt(); char[] a = in.next().toCharArray(), b = in.next().toCharArray(); int match0 = 0, match1 = 0, mismatch10 = 0, mismatch01 = 0; for(int i = 0; i < n; i++) { if(a[i] == b[i]) { if(a[i] == '0') match0++; else match1++; } else { if(a[i] == '0') mismatch01++; else mismatch10++; } } if(mismatch01 + mismatch10 == 0) out.println(0); else { if(match1 - match0 == 1 && mismatch01 == mismatch10) { out.println(min(match0 + match1, mismatch01 + mismatch10)); } else if(match1 - match0 == 1) { out.println(match0 + match1); } else if(mismatch01 == mismatch10) { out.println(mismatch01 + mismatch10); } else out.println(-1); } } 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[] readGraphOneIndexed(int n, int m) { List[] 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[] readGraphZeroIndexed(int n, int m) { List[] 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 a graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildGraph(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; } } }","import java.util.*; import java.io.*; public class C1615{ static FastScanner fs = null; public static void main(String[] args) { fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-->0) { int n = fs.nextInt(); String a = fs.next(); String b = fs.next(); char ch1[] = a.toCharArray(); char ch2[] = b.toCharArray(); int c00 = 0; int c01 = 0; int c10 = 0; int c11 = 0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i[] adj = new LinkedList[V]; for(int v=0;v 2){ System.out.println(""-1""); return; } } int[] weight = new int[V-1]; // int curNode = start; int prevNode = -1; visited[start] = true; for(int v=0;v 0) A.go(); // out.println(); out.flush(); } // >>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<< // static class pair { int x, y; pair(int x, int y) { this.x = x; this.y = y; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = prime * result + y; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; pair other = (pair) obj; if (x != other.x) return false; if (y != other.y) return false; return true; } } static void go() throws Exception { int n=sc.nextInt(); ArrayList> aa=new ArrayList<>(); for(int i=0;i()); } LinkedHashMap map=new LinkedHashMap<>(); for(int i=0;iv) { int temp=v; v=u;u=temp; } map.put(new pair(u,v),0); } for(ArrayList i : aa) { if(i.size()>2) { out.println(-1); return; } } boolean vis[]=new boolean[n]; dfs(aa,0,vis,2,map); for(pair i : map.keySet()) { out.print(map.get(i)+"" ""); } out.println(); } static void dfs(ArrayList> aa,int src,boolean vis[],int see,LinkedHashMap map) { vis[src]=true; for(int i: aa.get(src)) { if(vis[i]==false) { int x=src,y=i; if(x>y) { int temp=x; x=y; y=temp; } pair temp=new pair(x,y); if(see==2) { map.put(temp,5); see=5; }else { map.put(temp,2); see=2; } dfs(aa,i,vis,see,map); } } } static long lcm(long a, long b) { return a * b / gcd(a, b); } // >>>>>>>>>>> Code Ends <<<<<<<<< // // --For Rounding--// static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(Double.toString(value)); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); } // ----Greatest Common Divisor-----// static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } // --- permutations and Combinations ---// static long fact[]; static long invfact[]; static long ncr(int n, int k) { if (k < 0 || k > n) { return 0; } long x = fact[n]; long y = fact[k]; long yy = fact[n - k]; long ans = (x / y); ans = (ans / yy); return ans; } // ---sieve---// static int prime[] = new int[1000006]; // static void sieve() { // Arrays.fill(prime, 1); // prime[0] = 0; // prime[1] = 0; // for (int i = 2; i * i <= 1000005; i++) { // if (prime[i] == 1) // for (int j = i * i; j <= 1000005; j +)= i) { // prime[j] = 0; // } // } // } // ---- Manual sort ------// static void sort(long[] a) { ArrayList aa = new ArrayList<>(); for (long i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } static void sort(int[] a) { ArrayList aa = new ArrayList<>(); for (int i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } // --- Fast exponentiation ---// static long pow(long x, long y) { long res = 1l; while (y != 0) { if (y % 2 == 1) { res = (x * res); } y /= 2; x = (x * x); } return res; } // >>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<< // 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()); } int[] intArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); return a; } long[] longArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextLong(); return a; } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }",0,Non-Plagiarised 00af3420,f4d6d28d,"import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); String[] s = new String[n]; for(int i=0; i pq = new PriorityQueue<>(Collections.reverseOrder()); //Big comes in top; for(int i=0; i 0){ cur += pq.poll(); numberOfWords++; }else{ break; } } MAX = Math.max(MAX, numberOfWords); } pw.println(MAX); } pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ","import java.util.*; import java.io.*; import java.lang.*; import static java.lang.Math.*; public class cp{ static BufferedReader br; static StringTokenizer st; public static void main(String[] args)throws IOException{ br = new BufferedReader(new InputStreamReader(System.in)); List answer = new ArrayList(); for(int t=Integer.parseInt(br.readLine()); t>0; t--){ st = readLine(); int n = tokenInt(); String[] words = new String[n]; int i=0; while(n-- >0){ words[i] = br.readLine(); i++; } answer.add(new Solver().solve(words)); } for (int ans : answer ) System.out.println(ans); } static StringTokenizer readLine() throws IOException { return new StringTokenizer(br.readLine()); } static int tokenInt() { return Integer.parseInt(st.nextToken()); } static long tokenLong(){ return Long.parseLong(st.nextToken()); } static double tokenDouble(){ return Double.parseDouble(st.nextToken()); } static char[] tokenChar(){ return st.nextToken().toCharArray(); } static int[] readIntArray(int n) { int[] a=new int[n]; for (int i=0; i=0; i--){ val += ar[i]; if(val>0) counter++; else break; } ans[m] = counter; m++; } return Arrays.stream(ans).max().getAsInt(); } } /* bac aaada e */ ",0,Non-Plagiarised 4138b081,f729338f,"import java.io.*; import java.util.*; public class Contest1627C { static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { // reads in the next string while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { // reads in the next int return Integer.parseInt(next()); } public long nextLong() { // reads in the next long return Long.parseLong(next()); } public double nextDouble() { // reads in the next double return Double.parseDouble(next()); } } static InputReader r = new InputReader(System.in); static PrintWriter pw = new PrintWriter(System.out); static long mod = 1000000007; static ArrayList[] adj; static ArrayList[] num; static int[] ans; public static void main(String[] args) { int t = r.nextInt(); while (t > 0) { t--; int n = r.nextInt(); adj = new ArrayList[n]; num = new ArrayList[n]; for (int i = 0; i < n; i ++) { adj[i] = new ArrayList(); num[i] = new ArrayList(); } int[] deg = new int[n]; boolean flag = false; for (int i = 0; i < n - 1; i ++) { int a = r.nextInt()-1; int b = r.nextInt()-1; adj[a].add(b); adj[b].add(a); num[a].add(i); num[b].add(i); deg[a] ++; deg[b] ++; if (deg[a] > 2 || deg[b] > 2) { flag = true; } } if (flag) { pw.println(-1); continue; } ans = new int[n]; for (int i = 0; i < n; i ++) { if (deg[i] == 1) { dfs(i,3,-1); } } for (int i = 0; i < n - 1; i ++) { pw.println(ans[i]); } } pw.close(); } static void dfs(int node, int x, int p) { for (int j = 0; j < adj[node].size(); j ++) { int i = adj[node].get(j); if (i == p) { continue; } ans[num[node].get(j)] = x; dfs(i,5-x,node); } } }","import java.io.*; import java.util.*; public class Solution{ public static class Edge { int index; int u, v; Edge(int u, int v, int index) { this.index=index; this.u = u; this.v = v; } } public static void main (String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(br.readLine()); while(t-->0) { int n=Integer.parseInt(br.readLine()); ArrayList graph[] = new ArrayList[n]; for(int i=0; i(); for(int i=0; i2) { poss = false; } else if(graph[i].size() == 1) start_i = i; } if(!poss) { sb.append(""-1\n""); continue; } int wts[] = new int[n-1]; ArrayList edges = new ArrayList<>(); Edge first = graph[start_i].get(0); wts[first.index] = 2; edges = graph[first.v]; while(edges.size()>1) { Edge firste = edges.get(0); Edge sece = edges.get(1); if(wts[firste.index] != 0 ) //second not visited { wts[sece.index] = 5 - wts[firste.index]; edges = graph[sece.v]; } else //first not visited { wts[firste.index] = 5 - wts[sece.index]; edges = graph[firste.v]; } } for(int i=0; i cycle = new ArrayList<>(); cycle.add(query(i)); while (cycle.size() == 1 || !cycle.get(0).equals(cycle.get(cycle.size() - 1))) { cycle.add(query(i)); } cycle.remove(cycle.size() - 1); for(int j = 0; j < cycle.size() - 1; j++){ p[cycle.get(j)] = cycle.get(j + 1); } p[cycle.get(cycle.size() - 1)] = cycle.get(0); //System.out.println(Arrays.toString(p)); } StringBuilder b = new StringBuilder(); b.append(""! ""); for (int i = 0; i < n; i++) { b.append((p[i] + 1) + (i < n - 1 ? "" "" : ""\n"")); } System.out.print(b); System.out.flush(); } in.close(); out.close(); } public static int query(int i) throws Exception { System.out.println(""? "" + (i + 1)); System.out.flush(); int k = Integer.parseInt(in.readLine()); return k - 1; } } ","import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class C { private static StringTokenizer st; private static BufferedReader br; private static PrintWriter out; static boolean[]used; static int[]p; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = nextInt(); while (t --> 0) { int n = nextInt(); used = new boolean[n+1]; p = new int[n+1]; for (int i = 1; i <= n; i++) { if (!used[i]) { go(i); } } System.out.print(""! ""); for (int i = 1; i <= n; i++) { System.out.print(p[i]+"" ""); } System.out.println(); } out.close(); } private static void go(int i) throws IOException { List inCycle = new ArrayList<>(); int first = -1; while (true) { System.out.println(""? "" + i); int x = nextInt(); used[x] = true; if (x == first) { break; } if (first == -1) { first = x; } inCycle.add(x); } List numbers = new ArrayList<>(); for (int j = 0; j < inCycle.size(); j++) { if (inCycle.get(j) == i) { for (int k = j; k < inCycle.size(); k++) { numbers.add(inCycle.get(k)); } for (int k = 0; k < j; k++) { numbers.add(inCycle.get(k)); } break; } } if (numbers.size() == 1) { p[numbers.get(0)] = numbers.get(0); } else { for (int j = 0; j < numbers.size()-1; j++) { p[numbers.get(j)] = numbers.get(j+1); } p[numbers.get(numbers.size()-1)] = numbers.get(0); } } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String next() throws IOException { while (st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } }",0,Non-Plagiarised ad2a1ae2,bc46480a," import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.StringTokenizer; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }} public static void main(String[] args) { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int r[]=new int[n]; int l[]=new int[n]; for(int i=0;i=0;i--) { if(r[i]>=min) min=Math.min(min,l[i]); else { ans+=(max-min+1)*(max-min+2)/2; max=r[i]; min=l[i]; } } ans+=(max-min+1)*(max-min+2)/2; System.out.println(ans); } } } ","import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; /** * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools */ public class Main { static InputReader sc=new InputReader(System.in); public static void main(String[] args) { // Write your solution here int t=sc.nextInt(); while(t-->0){ solve(); } } private static void solve() { int n=sc.nextInt(); Node left[]=new Node[n]; int index=0; Node ini[]=new Node[n]; int tmp[]=new int[n]; for(int i=0;ileft[index].k){ left[index].k=ini[i].k; }else if(ini[i].s>left[index].k){ index++; left[index]=ini[i]; } } long ans=0; for(int i=0;i<=index;i++){ //System.out.println(left[i].k+"" ""+left[i].s); ans+=(long)(left[i].k-left[i].s+2)*(left[i].k-left[i].s+1)/2; } System.out.println(ans); } } class Node implements Comparable{ int k,s; Node(int k,int s){ this.s=s; this.k=k; } @Override public int compareTo(Node node) { return this.s-node.s; } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } ",0,Non-Plagiarised 08cf0478,9291ca83,"import java.util.*; import java.io.*; public class Main { static class Pair { int fi; int se; public Pair(int fi, int se) { this.fi = fi; this.se = se; } } public static void main(final String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int[][] arr = new int[5][n]; for(int i = 0; i < n; i++) { char[] s = sc.next().toCharArray(); int[] cnt = new int[5]; for(int j = 0; j < s.length; j++) { cnt[s[j]-'a']++; } for(int j = 0; j < 5; j++) arr[j][i] = cnt[j]-(s.length-cnt[j]); } int ans = 0; for(int i = 0; i < 5; i++) { Arrays.sort(arr[i]); int maxSum = 0; int words = 0; for(int j = arr[i].length-1; j >=0; j--) { maxSum += arr[i][j]; if(maxSum > 0) words++; } ans = Math.max(ans, words); } System.out.println(ans); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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;} } } ","import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Practice { static HashMap map = new HashMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); int[][] occurances = new int[5][n]; for(int i=0;i=0;j--){ tmpSum+=occurances[i][j]; if(tmpSum>0) tmpAns++; else break; } ans = Math.max(ans, tmpAns); } System.out.println(ans); } } } ",1,"(L2) similar main code with variable renaming, different imports, additional lines. FastScanner Class. Additional unused class." ee270b2a,fc80cbe0,"import java.util.*; public class D{ private static Scanner scanner = new Scanner(System.in); public static void main(String[] args){ int q = scanner.nextInt(); while(q-- > 0){ int n = scanner.nextInt(), k = scanner.nextInt(); int[] a = new int[k]; for(int i=0;i=0;i--){ R[i] = Math.min(min+1,R[i]); min = R[i]; } for(int i=0;i set = new HashSet<>(); long airCond = Long.parseLong(length[1]); long[] boxes = new long[(int)n]; Arrays.fill(boxes,Integer.MAX_VALUE); for(int i = 0 ; i < index.length; i++){ boxes[Integer.parseInt(index[i]) - 1] = Long.parseLong(temperature[i]); set.add(Integer.parseInt(index[i]) - 1); // System.out.println(index[i]); } int prev = -1; for(int i = 0 ; i < boxes.length; i++) { //System.out.println(i +"" ""+set.contains(i)); if(set.contains(i)){ if(prev != - 1) boxes[i] = Math.min((Math.abs(i - prev) ) + boxes[prev],boxes[i]); // System.out.println(i + "" ""+prev); prev = i; } if(prev == -1) continue; if(set.contains(i)){ prev = i; } else{ boxes[i] = (Math.abs(i - prev) ) + boxes[prev]; } } prev = boxes.length; for(int i = boxes.length - 1; i >= 0; i--) { if(set.contains(i)){ // System.out.println(i); if(prev != boxes.length) boxes[i] = Math.min((Math.abs(i - prev) ) + boxes[prev],boxes[i]); prev = i; } if(prev == boxes.length) continue; else{ boxes[i] = Math.min((Math.abs(i - prev) ) + boxes[prev],boxes[i]); } } return boxes; } } class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ",0,Non-Plagiarised 0b5cff5a,4fb09c5f,"import java.io.*; import java.text.DecimalFormat; import java.util.*; public class E { static long mod=(long)1e9+7; static long mod1=998244353; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int t= in.nextInt(); while(t-->0) { int n = in.nextInt(); int k = in.nextInt(); int[] a= in.readArray(k); int[] temp = in.readArray(k); int[] pre = new int[n]; Arrays.fill(pre,Integer.MAX_VALUE); int[] suf = new int[n]; Arrays.fill(suf,Integer.MAX_VALUE); for(int i = 0;i=0;i--){ min = Math.min(min,suf[i]); suf[i] = min; min++; } for(int i=0;i 0){ if(b%2 == 1) x=(x*y)%c; y = (y*y)%c; b = b>>1; } return x%c; } public static void debug(Object... o){ System.err.println(Arrays.deepToString(o)); } static int upper_bound(int[] arr,int n,int x){ int mid; int low=0; int high=n; while(low=arr[mid]) low=mid+1; else high=mid; } return low; } static int lower_bound(int[] arr,int n,int x){ int mid; int low=0; int high=n; while(low 0) { int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[k]; int[] t = new int[k]; HashMap hm = new HashMap<>(); for (int i = 0; i < k; i++) { arr[i] = sc.nextInt() - 1; } for (int i = 0; i < k; i++) { t[i] = sc.nextInt(); hm.put(arr[i], t[i]); } int[] left = new int[n]; int[] right = new int[n]; left[0] = hm.getOrDefault(0, -1); right[n - 1] = hm.getOrDefault(n - 1, -1); for (int i = 1; i < n; i++) { if (hm.containsKey(i)) { if (left[i - 1] < 0) { left[i] = hm.get(i); } else { left[i] = Math.min(hm.get(i), left[i - 1] + 1); } } else { left[i] = left[i - 1] < 0 ? -1 : left[i - 1] + 1; } } for (int i = n - 2; i >= 0; i--) { if (hm.containsKey(i)) { if (right[i + 1] < 0) { right[i] = hm.get(i); } else { right[i] = Math.min(hm.get(i), right[i + 1] + 1); } } else { right[i] = right[i + 1] < 0 ? -1 : right[i + 1] + 1; } } for (int i = 0; i < n; i++) { if (left[i] < 0) { pw.print(right[i] + "" ""); } else if (right[i] < 0) { pw.print(left[i] + "" ""); } else { pw.print(Math.min(left[i], right[i]) + "" ""); } } pw.println(); } pw.flush(); pw.close(); } // inclusive private static void rotate(int[] arr, int l, int r) { int temp = arr[r]; for (int i = r - 1; i >= l; i--) { arr[i + 1] = arr[i]; } arr[l] = temp; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream System) throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() { for (long i = 0; i < 3e9; i++) ; } } static class Pair { int a; int b; boolean asc; Pair(int a, int b, boolean asc) { this.a = a; this.b = b; this.asc = asc; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return a == pair.a && b == pair.b && asc == pair.asc; } @Override public int hashCode() { return Objects.hash(a, b, asc); } } } ",0,Non-Plagiarised 73f1c5f5,da0b7cb2,"import java.util.*; import java.io.*; public class Ana { static int n, a, b, da, db; static ArrayList[] graph; public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { n = sc.nextInt(); a = sc.nextInt() - 1; b = sc.nextInt() - 1; da = sc.nextInt(); db = sc.nextInt(); graph = new ArrayList[n]; for (int i = 0; i < n; i++) graph[i] = new ArrayList(); for (int i = 0; i < n - 1; i++) { int u = sc.nextInt() - 1, v = sc.nextInt() - 1; graph[u].add(v); graph[v].add(u); } int[] dist = new int[n]; Arrays.fill(dist, -1); bfs(a, dist); boolean bobwins = true; // if false alice wins if (dist[b] <= da || 2 * da >= db) bobwins = false; int far = a; for (int i = 0; i < n; i++) if (dist[i] > dist[far]) far = i; Arrays.fill(dist, -1); bfs(far, dist); for (int i = 0; i < n; i++) if (dist[i] > dist[far]) far = i; if(2*da>=dist[far])//max path bobwins = false; // out.println(dist[far]); out.println(bobwins?""Bob"":""Alice""); } out.close(); } static void bfs(int s, int[] dist) { Queue q = new LinkedList(); q.add(s); dist[s] = 0; while (!q.isEmpty()) { int u = q.remove(); for (int v : graph[u]) { if (dist[v] == -1) { dist[v] = 1 + dist[u]; q.add(v); } } } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(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 int[] nextIntArray(int n) throws IOException { int[] ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = nextInt(); return ans; } 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(); } } }","import java.io.*; import java.util.*; import static java.lang.Math.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Codeforces { public static void main(String[] args) throws IOException { // InputStream inputStream = new FileInputStream(""input.txt""); // OutputStream outputStream = new FileOutputStream(""output.txt""); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in.nextInt(), in, out); out.close(); } static class TaskA { long mod = (long)(1000000007); long fact[]; int depth[]; int parentTable[][]; int degree[]; ArrayList leaves; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int diam = 0; public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException { while(testNumber-->0){ int n = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); int na = in.nextInt(); int nb = in.nextInt(); ArrayList> g = new ArrayList<>(); for(int i=0;i<=n;i++) g.add(new ArrayList<>()); for(int i=1;i=nb){ out.println(""Alice""); continue; } // parentTable = new int[n+1][31]; depth = new int[n+1]; diam = 0; dfs(g , a , 0); int distance = depth[b]; // out.println(distance); if(distance <= na){ out.println(""Alice""); continue; } if(2*na >= min(nb , diam)) out.println(""Alice""); else out.println(""Bob""); // max = Integer.MIN_VALUE; // int diameter = diameter(g , 1 , 0); // int height = 0; // for(int i=1;i<=n;i++) // height = max(height , depth[i]); // // out.println(""diameter"" + diameter); // // out.println(""height"" + height); // // out.println(""max"" + max); // diameter = max(diameter-1 , height-1); // // diameter = max(diameter , max-1); // nb = min(nb , diameter); // na = min(na , diameter); // if(na*2 >= nb) // out.println(""Alice""); // else // out.println(""Bob""); } } int dfs(ArrayList> a , int x, int p) { int len = 0; for(int y : a.get(x)) { if(y != p) { depth[y] = depth[x] + 1; int cur = 1 + dfs(a , y, x); diam = max(diam, cur + len); len = max(len, cur); } } return len; } public int diameter(ArrayList> a , int index , int parent){ if(index == parent) return 0; // if(a.get(index).size() == 1 && a.get(index).get(0) == parent) // return 1; ArrayList x = new ArrayList<>(); x.add(0); x.add(0); for(int i=0;i= 4){ int n = x.size(); max = max(max , 1+x.get(n-1) + x.get(n-2)); } return 1 + x.get(x.size()-1); } // public void dfs(ArrayList> a , int index , int parent){ // parentTable[index][0] = parent; // for(int i=1;i<31;i++) // parentTable[index][i] = parentTable[parentTable[parent][i-1]][i-1]; // depth[index] = 1+depth[parent]; // int l = a.get(index).size(); // for(int i=0;i> a , int u , int v){ return depth[u]+depth[v] - 2*depth[lca(a , u , v)]; } public int lca(ArrayList> a , int u , int v){ if(depth[v]>i)&1) == 1) v = parentTable[v][i]; } if(v == u) return v; for(int i=parentTable[v].length-1;i>=0;i--){ if(parentTable[u][i] != parentTable[v][i]){ v = parentTable[v][i]; u = parentTable[u][i]; } } return parentTable[u][0]; } class Pair{ int start; int end; int index; public Pair(int a , int b , int c){ start = a; end = b; end = c; } } class Node{ char value; Node left; Node right; public Node(char value){ this.value = value; left = null; right = null; } } public int[][] multiply(int a[][] , int b[][]){ int c[][] = new int[a.length][b[0].length]; for(int i=0;i0){ if((b&1) == 1) res = multiply(res , a , 10); a = multiply(a , a , 10); b>>=1; } return res; } // for the min max problems public void build(int lookup[][] , int arr[], int n) { for (int i = 0; i < n; i++) lookup[i][0] = arr[i]; for (int j = 1; (1 << j) <= n; j++) { for (int i = 0; (i + (1 << j) - 1) < n; i++) { if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1]) lookup[i][j] = lookup[i][j - 1]; else lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1]; } } } public int query(int lookup[][] , int L, int R) { int j = (int)(Math.log(R - L + 1)/Math.log(2)); if (lookup[L][j] >= lookup[R - (1 << j) + 1][j]) return lookup[L][j]; else return lookup[R - (1 << j) + 1][j]; } // for printing purposes public void print1d(int a[] , PrintWriter out){ for(int i=0;i 0) { long x = b&1; if (x == 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } public long pow(long a, long b) { long res = 1; while (b > 0) { long x = b&1; if (x == 1) res = res * a; a = a * a; b >>= 1; } return res; } public void sortedArrayToBST(TreeSet a , int start, int end) { if (start > end) { return; } int mid = (start + end) / 2; a.add(mid); sortedArrayToBST(a, start, mid - 1); sortedArrayToBST(a, mid + 1, end); } class Combine{ int value; int delete; Combine(int val , int delete){ this.value = val; this.delete = delete; } } class Sort2 implements Comparator{ public int compare(Combine a , Combine b){ if(a.value > b.value) return 1; else if(a.value == b.value && a.delete>b.delete) return 1; else if(a.value == b.value && a.delete == b.delete) return 0; return -1; } } public int lowerLastBound(ArrayList a , int x){ int l = 0; int r = a.size()-1; if(a.get(l)>=x) return -1; if(a.get(r)=x) r = mid-1; else if(a.get(mid)=x) return mid; else if(a.get(mid) a , Integer x){ int l = 0; int r = a.size()-1; if(a.get(l)>x) return l; if(a.get(r)<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a.get(mid) == x && a.get(mid+1)>x) return mid+1; else if(a.get(mid)<=x) l = mid+1; else if(a.get(mid)>x && a.get(mid-1)<=x) return mid; else if(a.get(mid)>x && a.get(mid-1)>x) r = mid-1; } return mid; } public int lowerLastBound(int a[] , int x){ int l = 0; int r = a.length-1; if(a[l]>=x) return -1; if(a[r]=x) r = mid-1; else if(a[mid]=x) return mid; else if(a[mid]x) return l; if(a[r]<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a[mid] == x && a[mid+1]>x) return mid+1; else if(a[mid]<=x) l = mid+1; else if(a[mid]>x && a[mid-1]<=x) return mid; else if(a[mid]>x && a[mid-1]>x) r = mid-1; } return mid; } public long log(float number , int base){ return (long) Math.ceil((Math.log(number) / Math.log(base)) + 1e-9); } public long gcd(long a , long b){ if(agcd 1->xValue 2->yValue return new long[] { d, a, b }; } public void sievePhi(int a[]){ a[0] = 0; a[1] = 1; for(int i=2;i a = new ArrayList<>(); ArrayList b = new ArrayList<>(); for(int i=0;i0) { int n=input.nextInt(); int a[]=new int[n]; ArrayList list=new ArrayList<>(); ArrayList space=new ArrayList<>(); for(int i=0;i o=new ArrayList(), e=new ArrayList(); int n = sc.nextInt(),dp[][]=new int[n+1][n+1]; for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } for(int i=1;i<=o.size();i++){ dp[i][i]=dp[i-1][i-1]+Math.abs(o.get(i-1)-e.get(i-1)); for(int j=i+1;j<=e.size();j++) dp[i][j]=Math.min(dp[i][j-1],dp[i-1][j-1]+Math.abs(o.get(i-1)-e.get(j-1))); } System.out.println(dp[o.size()][e.size()]); } } ","import java.util.*; public class MyClass { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int a[]=new int[n]; ArrayList lt1=new ArrayList<>(); ArrayList lt0=new ArrayList<>(); for(int i=0;i= '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 int parent(int a , int p[]) { if(a == p[a]) return a; return p[a] = parent(p[a],p); } static void union(int a , int b , int p[] , int size[]) { a = parent(a,p); b = parent(b,p); if(a == b) return; if(size[a] < size[b]) { int temp = a; a = b; b = temp; } p[b] = a; size[a] += size[b]; } static long getSum(int index , long BITree[]) { long sum = 0; // Iniialize result // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse ancestors of BITree[index] while(index>0) { // Add current element of BITree // to sum sum += BITree[index]; // Move index to parent node in // getSum View index -= index & (-index); } return sum; } // Updates a node in Binary Index Tree (BITree) // at given index in BITree. The given value // 'val' is added to BITree[i] and all of // its ancestors in tree. public static void updateBIT(int n, int index, long val , long BITree[]) { // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse all ancestors and add 'val' while(index <= n) { // Add 'val' to current node of BIT Tree BITree[index] += val; // Update index to that of parent // in update View index += index & (-index); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int dp[][]; static int f(int pos , int take , int arr[]) { if(pos == -1) { if(take == 0) return 0; return -10000000; } if(dp[pos][take] != -1) return dp[pos][take]; if(pos+1-take == arr[pos]) dp[pos][take] = Math.max(dp[pos][take],1 + f(pos-1,take,arr)); dp[pos][take] = Math.max(dp[pos][take],f(pos-1,take,arr)); if(take > 0) dp[pos][take] = Math.max(dp[pos][take],f(pos-1,take-1,arr)); return dp[pos][take]; } public static void main(String []args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); sc.nextLine(); String a = sc.nextLine(); String b = sc.nextLine(); int same = 0 , zo = 0 , oz = 0 , oo = 0 , zz = 0; for(int i = 0 ; i < n ; i++) { if(a.charAt(i) == '0' && b.charAt(i) == '1') oz++; else if(a.charAt(i) == '1' && b.charAt(i) == '0') zo++; else if(a.charAt(i) == '1' && b.charAt(i) == '1') oo++; else zz++; } if(oz == zo || (zz == oo-1)) { int mx = Integer.MAX_VALUE; if(oz == zo) mx = Math.min(mx,2*oz); if(oo-1 == zz) mx = Math.min(mx,zz+oo); System.out.println(mx); } else { System.out.println(-1); } } } }","import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int sm, n; while(t > 0) { t--; n = sc.nextInt(); String s1,s2; s1 = sc.next(); s2 = sc.next(); int a[] = new int[4]; a[0] = 0; a[1] = 0; a[2] = 0; a[3] = 0; for(int i = 0 ; i < n ; i++) { if(s1.charAt(i) == '0'&& s2.charAt(i) == '1') a[0]++; else if(s1.charAt(i) == '1'&& s2.charAt(i) == '0') a[1]++; else if(s1.charAt(i) == '1'&& s2.charAt(i) == '1') a[2]++; else a[3]++; } // System.out.println(a[0] + "" "" + a[1] + "" "" + a[2] + "" "" + a[3]); int n1 = Integer.MAX_VALUE, n2 = Integer.MAX_VALUE, n3 = Integer.MAX_VALUE; if (a[0] == a[1]) { n1 = 2*a[0]; } if((a[2] - 1) == a[3]) { // System.out.println(a[3] + 1); n2 = 2*a[3] + 1; } if((a[3] + 1) == a[2]) { // System.out.println(a[2] + 1); n3 = 2*a[2] + 1; } int ans = Math.min(n1, Math.min(n2,n3)); if(ans == Integer.MAX_VALUE) { System.out.println(""-1""); } else { System.out.println(ans); } } } } ",0,Non-Plagiarised 29cf2e70,72d9eb5b,"import java.util.*; import java.io.*; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); while(T-- > 0) { int n = in.nextInt(); int[] a = new int[n]; for(int j=0;j blue = new ArrayList<>(); List red = new ArrayList<>(); for(int j=0;jcur) { p = false; break; } else cur++; } if(p) System.out.println(""yes""); else System.out.println(""no""); } } } ","import java.util.*; import java.io.*; public class D { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); while(T-- > 0) { int n = in.nextInt(); int[] a = new int[n]; for(int j=0;j blue = new ArrayList<>(); List red = new ArrayList<>(); for(int j=0;jcur) { p = false; break; } else cur++; } if(p) System.out.println(""yes""); else System.out.println(""no""); } } } ",1,EM 4dc0247e,875ed4c8,"import java.io.*; import java.util.*; public class ComdeFormces { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); // int m=sc.nextInt(); ArrayList> ar=new ArrayList<>(); ArrayList arr=new ArrayList<>(); int c[]=new int[n]; for(int i=0;i<=n;i++) { ar.add(new ArrayList<>()); } for(int i=0;i2) { ans=false; break; } } if(ans) { for(int i=1;i<=n;i++) { if(ar.get(i).size()==1) { boolean vis[]=new boolean[n+1]; dfs(ar,2,i,vis,c); break; } } for(int i=0;i>ar ,int val,int src,boolean vis[],int c[]) { if(vis[src])return; vis[src]=true; for(int i=0;i divisors(int n){ ArrayList ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static int primeDivisor(int n){ ArrayList ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { pr=true; n/=2; } if(pr)ar.add(2); for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; pr=true; } if(pr)ar.add(i); } if(n>2) ar.add(n); return ar.size(); } static int mdlg(int num, int base) { int val=((int)(Math.ceil(Math.log(num)/Math.log(base)))); int val2=(int)Math.pow(base,val); // System.out.println(num+"" ""+Math.pow(base,val)); if(num/val2==0)return val; return val+1; // return val; } static String rev(String s) { char temp[]=s.toCharArray(); for(int i=0;imid)min=mid+1; else if(an=2;i--) { if(a[i]+val[i]>el) { if(val[i]>=el) { long df=a[i]; a[i]-=df; val[i-1]+=(df/3); val[i-2]+=2*(df/3); a[i]+=df%3; } else { long df=a[i]+val[i]-el; val[i-1]+=(df/3); val[i-2]+=2*(df/3); a[i]-=df; a[i]+=df%3; } } } for(int i=0;i> arr, int val,int el) { int s=0; int e=arr.size()-1; int ptr=0; if(val==1)ptr=1; while(s<=e) { int m=s+(e-s)/2; if(arr.get(m).get(ptr)==el)return m; else if(arr.get(m).get(ptr) arr,int el) { int start=0; int end=arr.size()-1; while(start<=end) { int mid=start+(end-start)/2; if(arr.get(mid).a==el)return mid; else if(arr.get(mid).aarr.size()-1)return -2; return -1; } static String eval(String s, long bs, long be,long k) { String ans=""""; for(int i=s.length()-1;i>=0;i--) { if(s.charAt(i)=='a') { ans=""a""+ans; } else if(be>0){ if(be>k) { for(int j=0;j>=1; if(tval==0)cnt[i][j]=cnt[i-1][j]+1; else { cnt[i][j]=cnt[i-1][j]; } j++; } } return cnt; } static long find(int s,long a[]) { if(s>=a.length)return -1; long num=a[s]; for(int i=s;i a, int k) { if(a.size()<1 )return 0; int i=a.size()-1; long ans=0; while(i>=0) { int temp=k; int prev=0; while(temp--!=0 && i>=0) { ans+=Math.abs(a.get(i)-prev); if(temp==0 || i==0)ans+=a.get(i); prev=a.get(i); i--; } } return ans; } static int bs(long a[] ,long num) { int start=0; int end=a.length-1; while(start<=end) { int mid=start+(end-start)/2; if(a[mid]==num) { return mid; } else if(a[mid]n-r)r=n-r; int ans=1; for(int i=0;i=end)return a[end]; int mid=start+(end-start)/2; int min1=mergesort(a,start,mid); int min2=mergesort(a,mid+1,end); merge(a,start,mid,end); return Math.min(min1, min2); } static void merge(int []a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; int b[]=new int[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } public int compareTo(pair b) { return b.b-this.b; } public int compareToo(pair b) { if(this.a!=b.a)return this.a-b.a; else { return b.b-this.b; } } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0){ solve(sc); } } public static void solve(FastReader sc){ int n = sc.nextInt(); ArrayList> graph = new ArrayList>(); for(int i = 0;i()); } for(int i = 0;i2){ out.println(-1);out.flush();return; }else if(graph.get(i).size()==1){ start=i; } } int val=2; int [] wgt = new int[n-1]; int curr = graph.get(start).get(0).node; wgt[graph.get(start).get(0).idx] = val; val=5; while(true){ ArrayList list = graph.get(curr); if(list.size()==1){ break; }else{ for(Edge el : list){ if(wgt[el.idx]==0){ wgt[el.idx] = val; val = 7-val; curr = el.node; } } } } for(int el : wgt){ out.print(el + "" ""); } out.println(); out.flush(); } static class Edge { int node; int idx; Edge(int src, int nbr) { this.node = src; this.idx = nbr; } } /* int [] arr = new int[n]; for(int i = 0;i0) { int n=input.nextInt(); int a[]=new int[n]; for(int i=0;i=2;i--) { if(b[i]+arr[i] 0) { //out.print(""Case #""+(a++)+"": ""); solver.call(in,out); t--; } out.close(); } static class TaskA { int n; long[] arr; public void call(InputReader in, PrintWriter out) { n = in.nextInt(); arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextLong(); } long l, r, mid; l = 0; r = (long)1e10; while (l + 1 < r){ mid = ( l + r)/2; if(ans(mid)){ l = mid; } else{ r = mid; } } out.println(l); } public boolean ans(long mid) { long[] array = new long[n]; long a, b; for (int i = n - 1; i >= 2; i--) { a = mid - array[i]; if(a > 0){ b = arr[i] - a; if(b >= 0){ b/=3; array[i - 1] += b; array[i - 2] += 2*b; } else{ return false; } } else{ b = arr[i]; b/=3; array[i - 1] += b; array[i - 2] += 2*b; } } for (int i = 0; i < 2; i++) { if(arr[i] + array[i] < mid){ return false; } } return true; } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return Integer.compare(this.a, o.a); } } static class answer1 implements Comparable{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { return (o.a - this.a); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l = new ArrayList<>(); for (Long i:a) l.add(i); l.sort(Collections.reverseOrder()); for (int i=0; i0) { int n=ob.nextInt(); PriorityQueue a=new PriorityQueue<>(); PriorityQueue b=new PriorityQueue<>(); long ans=Long.MAX_VALUE; long sum=0; for(int i=0;i { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair a) { return a.y-y; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String s=""""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } "," import java.io.*; import java.util.*; public class test3 { public static void main(String[] args) throws IOException { FastReader f = new FastReader(); int t = f.nextInt(); while(t-->0) { int n = f.nextInt(); int C[] = new int[n]; long ans=Long.MAX_VALUE,pre = 0; PriorityQueue epq = new PriorityQueue(); PriorityQueue opq = new PriorityQueue(); for(int i = 0;i0) { ans = Math.min(ans,pre+ ((long)n-(long)epq.size())*(long)epq.peek() + ((long)n-(long)opq.size())*(long)opq.peek()); } } System.out.println(ans); } } static boolean isPrime(int n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static void print(int x,int y,int d,int n) { int i = 0; System.out.print(x+"" ""+y+"" ""); for(int j = x+d;j0;j-=d) { if(i==n)return; System.out.print(j+"" ""); i++; } for(int j = y+d;j<1000000000;j+=d) { if(i==n)return; System.out.print(j+"" ""); i++; } } static int prime(int n){ int ret = 0; while(n%2==0){ ret++; n/=2; } for(int i=3;i<=Math.sqrt(n);i+=2){ while(n%i==0){ ret++; n/=i; } } if(n>2)ret++; return ret; } static long nCr(int n, int r) { if(n 0; j--) C[j] = (C[j] + C[j-1]); } return C[r]; } static int power(int a,int n, int p) { int res = 1; a = a % p; while (n > 0) { if ((n & 1) == 1) res = (res * a) % p; n = n >> 1; a = (a * a) % p; } return res; } static boolean isPrime(int n, int k) { if (n <= 1 || n == 4) return false; if (n <= 3) return true; while (k > 0) { int a = 2 + (int)(Math.random() % (n - 4)); if (power(a, n - 1, n) != 1) return false; k--; } return true; } static long GCD(long a,long b) { if(a%b==0)return b; else return GCD(b,a%b); } static ArrayList readArray(FastReader f,int size){ ArrayList ret = new ArrayList(); for(int i=0;i 0) { int n = Integer.parseInt(f.readLine()); int[][] occ = new int[n][6]; for(int i = 0; i < n; i++) { char[] temp = f.readLine().toCharArray(); for(char j: temp) { occ[i][j-'a']++; } occ[i][5] = occ[i][0]+occ[i][1]+occ[i][2]+occ[i][3]+occ[i][4]; } int max = 0; for(int i = 0; i < 5; i++) { int[] temp = new int[n]; for(int j = 0; j < n; j++) { temp[j] = occ[j][i]-(occ[j][5]-occ[j][i]); } Arrays.sort(temp); int j; int cur = 0; for(j = n-1; j >= 0; j--) { if(cur+temp[j] <= 0) { break; } cur += temp[j]; } max = Math.max(max, n-j-1); } out.println(max); } f.close(); out.close(); } }","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; import java.util.TreeMap; public class C_CF { public static void main(String[] args) { FastScanner57 fs = new FastScanner57(); PrintWriter pw = new PrintWriter(System.out); int t = fs.ni(); //int t = 1; for (int tc = 0; tc < t; tc++) { int n = fs.ni(); String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = fs.next(); } int res = c(0,s); for (int i = 1; i < 5; i++) { res = Math.max(res,c(i,s)); } pw.println(res); } pw.close(); } public static int c(int l, String[] s) { List list = new ArrayList(); for (int i = 0; i < s.length; i++) { String t = s[i]; int ct = 0; for (int j = 0; j < t.length(); j++) { if (t.charAt(j)-'a'==l) { ct++; } else { ct--; } } list.add(ct); } Collections.sort(list); Collections.reverse(list); int sum = 0; for (int i = 0; i < s.length; i++) { sum += list.get(i); if (sum<=0) return i; } return list.size(); } public static int gcd(int n1, int n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } static class BIT18 { int[] bit; public BIT18(int size) { bit = new int[size]; } public void update(int ind, int delta) { while (ind < bit.length) { bit[ind] += delta; ind = ind + (ind & (-1 * ind)); } } public int sum(int ind) { int s = 0; while (ind > 0) { s += bit[ind]; ind = ind - (ind & (-1 * ind)); } return s; } public int query(int l, int r) { return sum(r) - sum(l); } } // 0 -> left was chosen // 1 -> right was chosen public static void sort(long[] a) { List list = new ArrayList(); for (int i = 0; i < a.length; i++) { list.add(a[i]); } Collections.sort(list); for (int i = 0; i < a.length; i++) { a[i] = list.get(i); } } public static long gcd(long n1, long n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } } class UnionFind16 { int[] id; public UnionFind16(int size) { id = new int[size]; for (int i = 0; i < size; i++) { id[i] = i; } } public int find(int p) { int root = p; while (root != id[root]) { root = id[root]; } while (p != root) { int next = id[p]; id[p] = root; p = next; } return root; } public void union(int p, int q) { int a = find(p), b = find(q); if (a == b) { return; } id[b] = a; } } class FastScanner57 { BufferedReader br; StringTokenizer st; public FastScanner57() { br = new BufferedReader(new InputStreamReader(System.in), 32768); st = null; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) { ret[i] = ni(); } return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) { ret[i] = nl(); } return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ",0,Non-Plagiarised b2590225,f7fc2e94,"//package com.company; import java.util.*; public class P3 { public static class tower implements Comparable{ ArrayList index; int size; tower(){ size = 0; index = new ArrayList<>(); } @Override public int compareTo(tower a) { if(this.size > a.size) { return 1; } else if (this.size < a.size) { return -1; } else { return 0; } } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t>0){ t--; int n = scan.nextInt(); int m = scan.nextInt(); int x = scan.nextInt(); ArrayList arr = new ArrayList<>(); HashMap map = new HashMap<>(); for(int i = 0;i towers = new PriorityQueue<>(); for(int i = 0;i 0){ tower curr = towers.poll(); for(Integer p : curr.index){ ans[p] = count; } count++; } for(int i = 0;i { int h,index; height(int hi,int i) { h=hi; index=i; } public int compareTo(height a) { return this.h-a.h; } public String toString() { return ""(""+this.h+"",""+this.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; } } public static void main(String[] args) { FastReader sc=new FastReader(); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),i; ArrayList arr=new ArrayList<>(); int ans[]=new int[n]; PriorityQueue tower=new PriorityQueue(); for(i=0;i x=new ArrayList<>(); ArrayList y=new ArrayList<>(); for(int i=0;i=0;i--){ if(y.get(i)>p){System.out.println(""NO""); return;} p-=1; } for(int i=0;i0) solve(); } } ","import java.io.*; import java.util.*; public class new1{ public static void main(String[] args) throws IOException{ FastReader s = new FastReader(); //long l1 = System.currentTimeMillis(); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int t = s.nextInt(); for(int z = 0; z < t; z++) { int n = s.nextInt(); int[] arr = new int[n]; ArrayList blue = new ArrayList(); ArrayList red = new ArrayList(); for(int i = 0; i < n; i++) { arr[i] = s.nextInt(); } String str = s.next(); for(int i = 0; i < n; i++) { if(str.charAt(i) == 'B') blue.add(arr[i]); else red.add(arr[i]); } red.sort(null); blue.sort(null); int j = red.size() - 1; int k = blue.size() - 1; while(j >= 0 && red.get(j) > n) j--; boolean ans = true; // System.out.println(blue.toString()); // System.out.println(red.toString()); for(int m = n; m >= 1; m--) { if(j >= 0) j--; else if(k >= 0 && blue.get(k) >= m) k--; else ans = false; //System.out.println(m + "" "" + j + "" "" + k); while(j >= 0 && red.get(j) > m - 1) j--; } if(ans) System.out.println(""YES""); else System.out.println(""NO""); } //output.write((System.currentTimeMillis() - l1) + ""\n""); //output.flush(); } } 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(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}",0,Non-Plagiarised 298ee961,392218ef,"import java.util.*; import java.io.*; public class Main { static void print(String s) { System.out.print(s); } static void printLine(String s) { System.out.println(s); } static double parseDouble(String s) { return Double.parseDouble(s.trim()); } static int parseInt(String s) { return Integer.parseInt(s.trim()); } static String[] split(String s) { return s.split(""\\s+""); } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; StringTokenizer st; int test = parseInt(br.readLine()); for (int t = 0; t < test; t++) { int n = parseInt(br.readLine()); ArrayList blue = new ArrayList(); ArrayList red = new ArrayList(); String[] toks = split(br.readLine()); String color = br.readLine(); for (int i = 0; i < n; i++) { if (color.charAt(i) == 'B') { blue.add(parseInt(toks[i])); } else { red.add(parseInt(toks[i])); } } int[] blueArr = new int[blue.size()]; int[] redArr = new int[red.size()]; for (int i = 0; i < blue.size(); i++) { blueArr[i] = blue.get(i); } for (int i = 0; i < red.size(); i++) { redArr[i] = red.get(i); } Arrays.sort(blueArr); Arrays.sort(redArr); int blueP = 0; // pointer int redP = 0; // pointer // blue -> decrease, red -> increase int start = 1; boolean unable = false; while (start <= n) { if (blueP < blueArr.length) { if (blueArr[blueP] < start) { unable = true; printLine(""NO""); break; } else { blueP++; start++; } } else { if (redArr[redP] > start) { unable = true; printLine(""NO""); break; } else { redP++; start++; } } } if (!unable) { printLine(""YES""); } } } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static void sort(int a[]){ ArrayList arr=new ArrayList<>(); for(int i=0;i=0){ int n=Integer.parseInt(br.readLine()); int a[]=new int[n]; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0;i inc=new ArrayList<>(); ArrayList dec=new ArrayList<>(); for(int i=0;ip)flag=true; p--; } p=1; for(int i=0;i 0) { int n = Integer.parseInt(br.readLine()); String s1 = br.readLine(); String s2 = br.readLine(); long res = solve(s1, s2); for(int i=0;i l = new ArrayList<>(a.length); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } //-----------PrintWriter for faster output--------------------------------- public static FastIO io = new FastIO(); //-----------MyScanner class for faster input---------- static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public String nextLine() { int c; do { c = nextByte(); } while (c < '\n'); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > '\n'); return res.toString(); } public int nextInt() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } //-------------------------------------------------------- }",0,Non-Plagiarised 22b41936,2.92E+060," import java.io.*; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.util.Collections; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.*; public class Main1 { static ArrayList list1 = new ArrayList<>() ; static ArrayList list2 = new ArrayList<>() ; static int n , m ; static long dp[][] ; static long solver(int i , int j ){ // i = empty chairs if (j == m)return 0 ; int tt1 = n-i ; int tt2 = m-j ; if (n-i < m-j)return Long.MAX_VALUE/2 ; if ( dp[i][j] != -1 )return dp[i][j] ; long a = solver(i+1 , j) ; long b = abs( list1.get(i) - list2.get(j)) + solver(i+1 , j+1) ; return dp[i][j] = min(a , b) ; } public static void main(String[] args) throws IOException { // try { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int N = in.nextInt() ; int a[] = in.readArray(N) ; for (int i = 0; i list = new ArrayList<>(); static boolean A[] = new boolean[2 * 90000001]; static void seive(int n) { int maxn = n; //int maxn = 1000000 ; A[0] = A[1] = true; for (int i = 2; i * i <= maxn; i++) { if (!A[i]) { for (int j = i * i; j <= maxn; j += i) A[j] = true; } } for (int i = 2; i <= maxn; i++) if (!A[i]) list.add(i); } static int findLCA(int a, int b, int par[][], int depth[]) { if (depth[a] > depth[b]) { a = a ^ b; b = a ^ b; a = a ^ b; } int diff = depth[b] - depth[a]; for (int i = 19; i >= 0; i--) { if ((diff & (1 << i)) > 0) { b = par[b][i]; } } if (a == b) return a; for (int i = 19; i >= 0; i--) { if (par[b][i] != par[a][i]) { b = par[b][i]; a = par[a][i]; } } return par[a][0]; } static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } static void formArrayForBinaryLifting(int n, int par[][]) { for (int j = 1; j < 20; j++) { for (int i = 0; i < n; i++) { if (par[i][j - 1] == -1) continue; par[i][j] = par[par[i][j - 1]][j - 1]; } } } static void sort(int ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static void sort1(long ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static long ncr(long n, long r, long mod) { if (r == 0) return 1; long val = ncr(n - 1, r - 1, mod); val = (n * val) % mod; val = (val * modInverse(r, mod)) % mod; return val; } static long fast_pow(long base, long n, long M) { if (n == 0) return 1; if (n == 1) return base % M; long halfn = fast_pow(base, n / 2, M); if (n % 2 == 0) return (halfn * halfn) % M; else return (((halfn * halfn) % M) * base) % M; } static long modInverse(long n, long M) { return fast_pow(n, M - 2, M); } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 32 << 10; private final Writer os; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(long c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println() { return append(System.lineSeparator()); } public FastOutput flush() { try { // boolean success = false; // if (stringBuilderValueField != null) { // try { // char[] value = (char[]) stringBuilderValueField.get(cache); // os.write(value, 0, cache.length()); // success = true; // } catch (Exception e) { // } // } // if (!success) { os.append(cache); // } os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } 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()); } } } ","import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ /** * Main , Solution , Remove Public */ public class A { private static long[][] dp; private static ArrayList lis1,lis0; public static void process() throws IOException { int n = sc.nextInt(); int arr[] = sc.readArray(n); lis1 = new ArrayList(); lis0 = new ArrayList(); for(int i = 0; i 0) { // google(TTT++); process(); } out.flush(); out.close(); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } 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; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader(""input.txt"")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } } ",0,Non-Plagiarised abd16ff0,db1ef8b3,"import java.util.*; public class Solve{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long ans=Long.MAX_VALUE; long pre=0; PriorityQueue epq=new PriorityQueue<>(); PriorityQueue opq=new PriorityQueue<>(); for(int i=0;i0) ans=Math.min(ans,pre+opq.peek()*(n-opq.size())+epq.peek()*(n-epq.size())); } System.out.println(ans); } } }","import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ public class C { private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; public static void process() throws IOException { int n = sc.nextInt(); PriorityQueue odd = new PriorityQueue(); PriorityQueue even = new PriorityQueue(); int arr[] = sc.readArray(n); long min = INF; long sumOdd = 0; long sumEven = 0; for (int i = 0; i < n; i++) { int x = arr[i]; if (i % 2 == 0) { even.add(x); sumEven += x; } else { odd.add(x); sumOdd += x; } if (i > 0) { long ans = 0; ans += 1l * even.peek() * (n - (even.size())); ans += 1l * odd.peek() * (n - (odd.size())); ans += sumOdd + sumEven; min = Math.min(ans, min); } } System.out.println(min); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= static FastScanner sc; static PrintWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new PrintWriter(System.out); } else { sc = new FastScanner(100); out = new PrintWriter(""output.txt""); } int t = 1; t = sc.nextInt(); while (t-- > 0) { process(); } out.flush(); out.close(); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } 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; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader(""input.txt"")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } } ",0,Non-Plagiarised 0951d079,927384f2,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; import java.util.StringTokenizer; public class D { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader file = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(file.readLine()); int[] heights = new int[n]; StringTokenizer st = new StringTokenizer(file.readLine()); for(int i = 0; i < n; i++) { heights[i] = Integer.parseInt(st.nextToken()); } int[] dp = new int[n]; dp[0] = 0; Stack high = new Stack<>(); Stack low = new Stack<>(); high.push(0); low.push(0); for(int i = 1; i < n; i++) { dp[i] = dp[i-1]+1; while(!high.isEmpty() && heights[high.peek()] < heights[i]) { dp[i] = Math.min(dp[i], dp[high.peek()]+1); high.pop(); } if(!high.isEmpty()) { dp[i] = Math.min(dp[i], dp[high.peek()]+1); if(heights[high.peek()] == heights[i]) high.pop(); } while(!low.isEmpty() && heights[low.peek()] > heights[i]) { dp[i] = Math.min(dp[i], dp[low.peek()]+1); low.pop(); } if(!low.isEmpty()) { dp[i] = Math.min(dp[i], dp[low.peek()]+1); if(heights[low.peek()] == heights[i]) low.pop(); } high.push(i); low.push(i); } System.out.println(dp[n-1]); } } ","import java.util.*; import java.io.*; public class Main{ static class Point{ int x,y,z; Point(int nx, int ny){ x = nx; y = ny; } @Override public boolean equals(Object o) { Point p = (Point)o; return p.x == x && p.y == y; } } public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = pint(in); Stack min = new Stack(); Stack max = new Stack(); int[] a = new int[n]; int[] dp = new int[n]; StringTokenizer st = new StringTokenizer(in.readLine()); a[0] = pint(st); min.add(0); max.add(0); for(int i = 1; i < n; i++) { a[i] = pint(st); int h = dp[i - 1] + 1; while(!max.isEmpty() && a[i] > a[max.peek()]) { int k = a[max.peek()]; h = Math.min(h, dp[max.pop()] + 1); while(!max.isEmpty() && a[max.peek()] == k) {max.pop();} } if(!max.isEmpty()) { h = Math.min(h, dp[max.peek()] + 1); } while(!min.isEmpty() && a[i] < a[min.peek()]) { int k = a[min.peek()]; h = Math.min(h, dp[min.pop()] + 1); while(!min.isEmpty() && a[min.peek()] == k) {min.pop();} } if(!min.isEmpty()) { h = Math.min(h, dp[min.peek()] + 1); } dp[i] = h; min.add(i); max.add(i); } System.out.println(dp[n - 1]); } static int[] resize(int[] a) { int[] r = new int[a.length * 2]; for(int i = 0; i < a.length; i++) { r[i] = a[i]; } return r; } static int pint(BufferedReader in) throws IOException {return Integer.parseInt(in.readLine());} static int pint(StringTokenizer st) {return Integer.parseInt(st.nextToken());} }",0,Non-Plagiarised 0fd5b95a,6490bbe8,"//package codeforces; import java.io.PrintWriter; import java.util.*; public class codeforces { static int dp[][]=new int[5001][5001]; public static void main(String[] args) { Scanner s=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); int t=1; for(int tt=0;tt z=new ArrayList<>(); ArrayList o=new ArrayList<>(); for(int i=0;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i { if (x[c] != y[c]) return(int)( x[c] - y[c]); return (int)-(x[1]+x[2] - y[1]-y[2]); }); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static int sol(int i,int j,ArrayList z,ArrayList o) { if(j==o.size()) { return 0; } int h=z.size()-i; int l=o.size()-j; if(i==z.size()) { return 10000000; } if(dp[i][j]!=-1) { //System.out.println(i+"" ""+j); return dp[i][j]; } int ans1=sol(i+1,j,z,o); int ans2=sol(i+1,j+1,z,o)+Math.abs(z.get(i)-o.get(j)); dp[i][j]=Math.min(ans1, ans2); return dp[i][j]; } } ","import java.util.*; // import java.lang.*; import java.io.*; // THIS TEMPLATE MADE BY AKSH BANSAL. public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static boolean[] isPrime; private static void primes(){ int num = (int)1e6; // PRIMES FROM 1 TO NUM isPrime = new boolean[num]; for (int i = 2; i< isPrime.length; i++) { isPrime[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(isPrime[i] == true) { for(int j = (i*i); j[] adj; // static void getAdj(int n,int q, FastReader sc){ // adj = new ArrayList[n+1]; // for(int i=1;i<=n;i++){ // adj[i] = new ArrayList<>(); // } // for(int i=0;i 0) { // output.append(solver()).append(""\n""); // } // out.println(output); // _______________________________ int n = sc.nextInt(); int arr[] = new int[n]; for(int i=0;i a = new ArrayList<>(); ArrayList b = new ArrayList<>(); for(int i=0;i0){ int n=sc.nextInt(); int k=sc.nextInt(); int idx[]=new int[k]; for(int i=0;i=0;i--){ right[i]=Math.min(right[i+1]+1,arr[i]); } for(int i=0;i 0;T--) start(); // System.out.print(sb); } void start() { int n = s.nextInt(); int m = s.nextInt(); long arr[] = longArr(m); long arr2[] = longArr(m); long ans [] = new long[n]; Arrays.fill(ans,Integer.MAX_VALUE); for(int i = 0; i=0; i--) { right[i] = Math.min(right[i+1]+1, ans[i]); } StringBuffer x = new StringBuffer(); for(int i =0; i0) { m/=2; y++; } return y; } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } long power(long x, long y, long p) { long res = 1; // Initialize result // Update x if it is more // than or equal to p x = x % p; while (y > 0) { // If y is odd, multiply // x with the 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; } int lower_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; //if(arr[i] > key)return -1; if(arr[j] < key)return -1; while(i 0) { int n = sc.nextInt(); char[] a = sc.next().toCharArray(); char[] b = sc.next().toCharArray(); int x = 0, y = 0, lit = 0,lit2 = 0; for (int i = 0; i < n; i++) { if (a[i] == '1') lit++; if (b[i] == '1') lit2++; if (a[i] == b[i]) x++; else y++; } if(lit == lit2 || n - lit + 1 == lit2) { if (lit == lit2 && n - lit + 1 == lit2) { pw.println(Math.min(x,y)); }else if(lit == lit2) { pw.println(y); }else { pw.println(x); } }else { pw.println(-1); } } pw.close(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; 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 t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n, _00 = 0, _01 = 0, _11 = 0, _10 = 0; n = in.nextInt(); char[] s = in.next().toCharArray(); char[] s1 = in.next().toCharArray(); for (int i = 0; i < n; i++) { if(s[i]==s1[i]){ if(s[i]=='0'){ _00++; } else{ _11++; } } else{ if(s[i]=='0'){ _01++; } else{ _10++; } } } int ans = Integer.MAX_VALUE; if(_10 ==_01){ ans = 2*_01; } if(_11 == _00 + 1){ ans = Math.min(ans, 2*_00 + 1); } if(ans == Integer.MAX_VALUE){ out.println(-1); } else{ out.println(ans); } } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList arrayList2 ; public arrayListClass(ArrayList arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i{ int sum, index; pair(int i){ sum = 0; index = i; } @Override public int compareTo(pair a){ return sum - a.sum; } } public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int t = Integer.parseInt(br.readLine()); while(t-- > 0){ StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int ar[] = new int[n]; st = new StringTokenizer(br.readLine()); int sum = 0, low = x; for(int i = 0; i < n; i++){ ar[i] = Integer.parseInt(st.nextToken()); } PriorityQueue q = new PriorityQueue(); for(int i = 0; i < m; i++) q.add(new pair(i + 1)); sb.append(""YES\n""); for(int i = 0; i < n; i++){ pair p = q.poll(); p.sum += ar[i]; q.add(p); sb.append(p.index + "" ""); } sb.append(""\n""); } System.out.print(sb); } } ","import java.io.*; import java.util.*; public class Codeforces { public static class Tower implements Comparable{ int val; int index; public Tower(int ind, int v) { val = v; index = ind; } @Override public int compareTo(Tower o) { return Integer.compare(val, o.val); } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(br.readLine()); while(cases-- > 0) { String[] str = br.readLine().split("" ""); int n = Integer.parseInt(str[0]); int m = Integer.parseInt(str[1]); int x = Integer.parseInt(str[2]); int[] h = new int[n]; str = br.readLine().split("" ""); for(int i=0; i q = new PriorityQueue<>(m); int[] ans = new int[n]; for(int i=0; i :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static int mod=10000007; static StringBuilder sb=new StringBuilder(); /* start */ public static void main(String [] args) { int t = i(); while(t-->0) { int n = i(); int a[] = input(n); char c[] = inputC(); ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); for(int i=0;in-i) { is = false; break; } } out.println(is==true?""YES"":""NO""); } out.close(); } /* end */ 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 int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static char[] inputC() { String s = sc.nextLine(); return s.toCharArray(); } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } //pair class private static class Pair implements Comparable { int first, second; public Pair(int f, int s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }","import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader obj = new FastReader(); PrintWriter out = new PrintWriter(System.out); int l = obj.nextInt(); while (l-- != 0) { int n = obj.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) num[i] = obj.nextInt(); Vector red = new Vector<>(); Vector blue = new Vector<>(); String s = obj.next(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'R') red.add(num[i]); else blue.add(num[i]); } Collections.sort(blue); Collections.sort(red); int c = 1, f = 0; for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < c) { f = 1; break; } c++; } for (int i = 0; i < red.size(); i++) { if (red.get(i) > c) { f = 1; break; } c++; } if (f == 0) out.println(""YES""); else out.println(""NO""); } out.flush(); } } ",1,"(L6) similar main code with variable renaming, additional lines ,additional one import. More comments. Sort and check in reverse order. Enhanced if statement." ac144188,e899614e,"import java.util.*; import java.io.*; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.Math.max; public class EdB { static long[] mods = {1000000007, 998244353, 1000000009}; static long mod = mods[0]; public static MyScanner sc; public static PrintWriter out; public static void main(String[] largewang) throws Exception{ // TODO Auto-generated method stub sc = new MyScanner(); out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); Set sums = new HashSet<>(); boolean found = false; int[] arr = readArrayInt(n); for(int j = 0;j copy = new ArrayList<>(); for (int i : array) copy.add(i); Collections.sort(copy); for(int i = 0;i0) { int n = sc.nextInt(); Set sums = new HashSet<>(); boolean found = false; int[] arr = readArrayInt(n); for(int j = 0;j copy = new ArrayList<>(); for (int i : array) copy.add(i); Collections.sort(copy); for(int i = 0;i[] adj; static ArrayList[] num; static int[] ans; public static void main(String[] args) { int t = r.nextInt(); while (t > 0) { t--; int n = r.nextInt(); adj = new ArrayList[n]; num = new ArrayList[n]; for (int i = 0; i < n; i ++) { adj[i] = new ArrayList(); num[i] = new ArrayList(); } int[] deg = new int[n]; boolean flag = false; for (int i = 0; i < n - 1; i ++) { int a = r.nextInt()-1; int b = r.nextInt()-1; adj[a].add(b); adj[b].add(a); num[a].add(i); num[b].add(i); deg[a] ++; deg[b] ++; if (deg[a] > 2 || deg[b] > 2) { flag = true; } } if (flag) { pw.println(-1); continue; } ans = new int[n]; for (int i = 0; i < n; i ++) { if (deg[i] == 1) { dfs(i,3,-1); } } for (int i = 0; i < n - 1; i ++) { pw.println(ans[i]); } } pw.close(); } static void dfs(int node, int x, int p) { for (int j = 0; j < adj[node].size(); j ++) { int i = adj[node].get(j); if (i == p) { continue; } ans[num[node].get(j)] = x; dfs(i,5-x,node); } } }","/* 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 class Edge{ int node; int index; Edge(int node, int index){ this.node = node; this.index = index; } } static Scanner scn = new Scanner(System.in); public static void main (String[] args) throws java.lang.Exception{ int t = scn.nextInt(); while(t-->0){ solve(); } } public static void solve(){ int n = scn.nextInt(); ArrayList[]graph = new ArrayList[n]; for(int i = 0; i < n; i++){ graph[i] = new ArrayList<>(); } for(int i = 0; i < n - 1; i++){ int u = scn.nextInt() - 1; int v = scn.nextInt() - 1; graph[u].add(new Edge(v, i)); graph[v].add(new Edge(u, i)); } int start = 0; for(int i = 0; i < n; i++){ if(graph[i].size() > 2){ System.out.println(""-1""); return; }else if(graph[i].size() == 1){ start = i; } } int[]weight = new int[n - 1]; int prevNode = -1, curNode = start, curWeight = 2; while(true){ ArrayListedges = graph[curNode]; Edge next = edges.get(0); if(next.node == prevNode){ if(edges.size() == 1){ break; }else{ next = edges.get(1); } } weight[next.index] = curWeight; prevNode = curNode; curNode = next.node; curWeight = 5 - curWeight; } for(int i = 0; i < n - 1; i++){ System.out.print(weight[i]); System.out.print("" ""); } System.out.println(); } } ",0,Non-Plagiarised d5dc6626,f59d9b6e,"import java.util.*; import java.io.*; public class Main { // 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.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 public static void main(String[] args) { FastReader reader = new FastReader(); StringBuilder sb = new StringBuilder(""""); int t = reader.nextInt(); int ans = 0; while (t-- > 0) { int n = reader.nextInt(); int nodes[] = new int[n]; int edges[][] = new int[n-1][2]; ArrayList graph[] = new ArrayList[n]; for(int i=0; i(); } for(int i=0; i2){ possible = false; } } Arrays.fill(nodes, 0); int first = 2; int second = 5; if(possible){ int fill_ans[] = new int[n-1]; find(0, -1, graph, fill_ans, n, first, second, true); for(int i=0; i graph[], int fill_ans[], int n, int first, int second, boolean first_fill){ for(Pair p: graph[node]){ if(p.a==par){ continue; } if(first_fill){ fill_ans[p.b] = first; }else{ fill_ans[p.b] = second; } find(p.a, node, graph, fill_ans, n, first, second, !first_fill); first_fill = !first_fill; } } static class Pair{ int a, b; Pair(int x, int y){ a = x; b = y; } } }","/* 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 class Edge{ int node; int index; Edge(int node, int index){ this.node = node; this.index = index; } } static Scanner scn = new Scanner(System.in); public static void main (String[] args) throws java.lang.Exception{ int t = scn.nextInt(); while(t-->0){ solve(); } } public static void solve(){ int n = scn.nextInt(); ArrayList[]graph = new ArrayList[n]; for(int i = 0; i < n; i++){ graph[i] = new ArrayList<>(); } for(int i = 0; i < n - 1; i++){ int u = scn.nextInt() - 1; int v = scn.nextInt() - 1; graph[u].add(new Edge(v, i)); graph[v].add(new Edge(u, i)); } int start = 0; for(int i = 0; i < n; i++){ if(graph[i].size() > 2){ System.out.println(""-1""); return; }else if(graph[i].size() == 1){ start = i; } } int[]weight = new int[n - 1]; int prevNode = -1, curNode = start, curWeight = 2; while(true){ ArrayListedges = graph[curNode]; Edge next = edges.get(0); if(next.node == prevNode){ if(edges.size() == 1){ break; }else{ next = edges.get(1); } } weight[next.index] = curWeight; prevNode = curNode; curNode = next.node; curWeight = 5 - curWeight; } for(int i = 0; i < n - 1; i++){ System.out.print(weight[i]); System.out.print("" ""); } System.out.println(); } } ",0,Non-Plagiarised 47d54299,63bfa731,"// package com.company.Codechef; // import com.sun.security.jgss.GSSUtil; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class a { static int depth[]; static ArrayList tree[]; static int diameter=0; public static void main(String[] args) { FastReader input=new FastReader(); int t=input.nextInt(); while (t-->0){ diameter=0; int n=input.nextInt(); int a=input.nextInt(); int b=input.nextInt(); int da=input.nextInt(); int db=input.nextInt(); depth=new int[n+1]; tree=new ArrayList[n+1]; for (int i = 0; i <=n ; i++) { tree[i]=new ArrayList<>(); } for (int i = 0; i = Math.min(diameter, db) ||depth[b]<=da){ System.out.println(""Alice""); }else { System.out.println(""Bob""); } } } private static int dfs(int root, int p) { int len=0; for(int child:tree[root]){ if (child!=p){ depth[child]=depth[root]+1; int curr=1+dfs(child,root); diameter=Math.max(diameter,curr+len); len=Math.max(len,curr); } } return len; } 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; } } }"," import java.util.*; import java.io.*; public class D { static ArrayList adj[] = new ArrayList[(int)1e5+7]; static int diameter = 0; static int[] depth = new int[(int)1e5 + 7]; public static void main(String[] args) { FastReader in = new FastReader(); int t = in.nextInt(); while(t-- > 0){ int n = in.nextInt(); int a = in.nextInt(), b = in.nextInt(), da = in.nextInt(), db = in.nextInt(); for(int i = 1; i <= n; i++){ adj[i] = new ArrayList<>(); } for(int i = 1; i <=n; i++){ adj[i].clear(); } for(int i = 0; i < n- 1; i++){ int u = in.nextInt(); int v = in.nextInt(); adj[u].add(v); adj[v].add(u); } diameter = 0; depth[a] = 0; dfs(a, -1); System.out.println(2 * da >= Math.min(diameter, db) || depth[b] <= da ? ""Alice"" : ""Bob""); } } static int dfs(int node, int parent){ int len = 0; for(int x : adj[node]){ if(x != parent){ depth[x] = depth[node] + 1; int cur = 1 + dfs(x, node); diameter = Math.max(diameter, cur + len); len = Math.max(len, cur); // System.out.print(""x "" + x + "" node "" + node + "" par "" + parent); // System.out.println("" cur "" + cur + "" len "" + len + "" diam "" + diameter); } } return len; } static long getDigitSum(long n) { long sum = 0; while (n > 0) { sum = sum + n % 10; n = n/10; } return sum; } 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[] readArray(int n){ int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = nextInt(); } return a; } } } ",1,"(L3) Code Reuse with variable renaming, additional code and comments. Unused new function. Changing the order of declaration." 43b85d63,a37923d1,"import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Map.Entry; import java.util.Random; import java.util.TreeSet; public final class CF_724_D2_D2 { static boolean verb=true; static void log(Object X){if (verb) System.err.println(X);} static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+"" "");System.err.println("""");}} static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+"" "");System.err.println("""");}} static void logWln(int[] X){if (verb) {for (int U:X) System.err.print(U+"" "");}} static void log(int[] X,int L){if (verb) {for (int i=0;i0) { if (e%2==1) x=(b*x)%m; b=(b*b)%m; e=e/2; } return x; } static long mod=1000000007; // Global vars static BufferedWriter out; static InputReader reader; static int pgcd(int a,int b){ if (a ts=new TreeSet(); ts.add(b[0]); ts.add(NX); ts.add(PX); int core=b[0]; boolean ok=true; for (int i=1;ix) { ok=false; //log(""fail 1""); break; } //log(""core:""+core+"" x:""+x+"" y:""+y); core=x; ts.add(x); } else { int y=ts.higher(core); if (y= numChars) { curChar = 0; numChars = stream.read(buf); if (numChars <= 0) { return -1; } } return buf[curChar++]; } public final String readString() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final String readString(int L) throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(L); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final int readInt() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log(""d:""+d); if (d == '-') { neg = true; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log(""res:""+res); if (neg) return -res; return res; } public final long readLong() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log(""d:""+d); if (d == '-') { neg = true; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log(""res:""+res); if (neg) return -res; return res; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }","import java.util.Scanner; import java.util.TreeSet; public class D { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int test = scn.nextInt(); for (int t = 0; t < test; t++) { int n = scn.nextInt(); int[] b = new int[n]; TreeSet ts = new TreeSet<>(); int lastAdded = -1; boolean ans = true; for (int i = 0; i < n; i++) { b[i] = scn.nextInt(); } for (int val : b) { if (t == 4) { int x = 2; } if (val > lastAdded) { Integer between = ts.higher(lastAdded); if (between != null && between < val) { ans = false; break; } } if (val < lastAdded) { Integer between = ts.lower(lastAdded); if (between != null && between > val) { ans = false; break; } } ts.add(val); lastAdded = val; } if (ans) System.out.println(""YES""); else System.out.println(""NO""); } } boolean between(int mid, int a, int b) { return a >= mid && mid >= b || a <= mid && mid <= b; } } ",0,Non-Plagiarised 10584086,f229aa7f,"import java.util.*; import java.io.*; public class _1615_C { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(in.readLine()); while(t-- > 0) { int n = Integer.parseInt(in.readLine()); String a = in.readLine(); String b = in.readLine(); int x = 0; int y = 0; int match = 0; for(int i = 0; i < n; i++) { if(a.charAt(i) == '1') { x++; } if(b.charAt(i) == '1') { y++; } if(a.charAt(i) == b.charAt(i)) { match++; } } if(x != y && n - x + 1 != y) { out.println(-1); }else { int moves = Integer.MAX_VALUE; if(x == y) { int mismatch = n - match; moves = Math.min(moves, mismatch); } if(n - x + 1 == y) { moves = Math.min(moves, match); } out.println(moves); } } in.close(); out.close(); } } ","import java.util.*; import java.io.*; import java.math.*; public class cf { static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); char[] a = sc.next().toCharArray(); char[] b = sc.next().toCharArray(); int x = 0, y = 0, lit = 0,lit2 = 0; for (int i = 0; i < n; i++) { if (a[i] == '1') lit++; if (b[i] == '1') lit2++; if (a[i] == b[i]) x++; else y++; } if(lit == lit2 || n - lit + 1 == lit2) { if (lit == lit2 && n - lit + 1 == lit2) { pw.println(Math.min(x,y)); }else if(lit == lit2) { pw.println(y); }else { pw.println(x); } }else { pw.println(-1); } } pw.close(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }",0,Non-Plagiarised 1dab88fb,bac616ee,"import java.util.*; public class Main { static class Edge{ public int node; public int index; public Edge(int n, int i){ node=n; index=i; } } static Scanner sc=new Scanner(System.in); public static void main(String[] args) { int test=sc.nextInt(); while(test-->0){ solve(); } } static void solve(){ int n=sc.nextInt(); ArrayList> graph= new ArrayList>(); for(int i=0;i()); } for (int i = 0; i < n - 1; i++) { int u = sc.nextInt(); int v = sc.nextInt(); u--; v--; graph.get(u).add(new Edge(v, i)); graph.get(v).add(new Edge(u, i)); } int start = 0; for (int i = 0; i < n; i++) { if (graph.get(i).size() > 2) { System.out.println(""-1""); return; } else if (graph.get(i).size() == 1) { start = i; } } int[] weight = new int[n - 1]; int prevNode = -1; int curNode = start; int curWeight = 2; while (true) { ArrayList edges = graph.get(curNode); Edge next = edges.get(0); if (next.node == prevNode) { if (edges.size() == 1) { break; } else { next = edges.get(1); } } weight[next.index] = curWeight; prevNode = curNode; curNode = next.node; curWeight = 5 - curWeight; } for (int i = 0; i < n - 1; i++) { System.out.print(weight[i]); System.out.print("" ""); } System.out.println(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class NotAssigning { 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 nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(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> t, int cur, boolean mode, int[] w) { vis[cur] = true; for (Pair p : t.get(cur)) { if (!vis[p.a]) { if (mode) { w[p.b] = 3; } else { w[p.b] = 2; } dfs(t, p.a, !mode, w); } } } public static void solve(int n, int[] u, int[] v) { ArrayList> t = new ArrayList>(n); for (int i=0; i()); } for (int i=0; i 2) { System.out.println(""-1""); return; } if (t.get(i).size() == 1) { start = i; } } vis = new boolean[n]; int[] w = new int[n-1]; dfs(t, start, false, w); StringBuilder ans = new StringBuilder(); for (int i=0; i 0) { int n = in.nextInt(); int[] u = new int[n-1]; int[] v = new int[n-1]; for (int i=0; i[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList aa:temp) System.out.println(aa); } static long cal(long val, long pow, long mod) { if(pow == 0) return 1; long res = cal(val, pow/2, mod); long ret = (res*res)%mod; if(pow%2 == 0) return ret; return (val*ret)%mod; } static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); } } static int mod = (int) 1e9; static LinkedList[] temp, idx; static long inf = (long) Long.MAX_VALUE; // static long inf = Long.MAX_VALUE; // static int max; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); String a = sc.next(), b = sc.next(); int _00 = 0, _01 = 0, _10 = 0, _11 = 0; for(int i = 0; i < n; i++) { if(a.charAt(i) == '0' && b.charAt(i) == '0') _00++; if(a.charAt(i) == '0' && b.charAt(i) == '1') _01++; if(a.charAt(i) == '1' && b.charAt(i) == '0') _10++; if(a.charAt(i) == '1' && b.charAt(i) == '1') _11++; } int ans = Integer.MAX_VALUE; if(_10 == _01) ans = _01 + _10; if(_10 > 0) { int n00 = _10 - 1; int n01 = _11; int n10 = _00 + 1; int n11 = _01; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } if(_11 > 0) { int n00 = _10; int n01 = _11 - 1; int n10 = _00; int n11 = _01 + 1; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } ret.append(ans == Integer.MAX_VALUE ? -1 : ans); ret.append(""\n""); } System.out.println(ret); } } ","import javax.swing.plaf.IconUIResource; import java.lang.reflect.Array; import java.text.CollationElementIterator; import java.util.*; import java.io.*; //Timus judge id- 323935JJ public class Main { //---------------------------------------------------------------------------------------------- public static class Pair implements Comparable { int x=0,y=0; int z=0; public Pair(int a, int b) { this.x=a; this.y=b; } public int compareTo(Pair o) { return this.x - o.x; } } public static int mod = (int) (1e9 + 7); static int ans = Integer.MAX_VALUE; public static void main(String hi[]) throws Exception { FastReader sc = new FastReader(); int t =sc.nextInt(); while(t-->0) { int n =sc.nextInt(); String a = sc.nextLine(),b=sc.nextLine(); int count1=0,count2=0,count3=0,count4=0; for(int i=0;i0) { int n=sc.nextInt(); long arr[]=new long[n]; for(int i=0;i hs = new HashSet<>(); int minLen = Integer.MAX_VALUE; for(int i=0 ; i=0 ; j--) rev += str[i].charAt(j); if(hs.contains(rev)) { mark = true; break; } if(str[i].length() == 3) { String ans = rev.substring(1, rev.length()); if(hs.contains(ans)){ mark = true; break; } } if(str[i].length() < 3) { for(int k=0 ; k<26 ; k++) { String str1 = (char)(k + 'a') + rev; if(hs.contains(str1)) { mark= true; break; } } } hs.remove(str[i]); } if(!mark) gs.append(""NO"" + ""\n""); else gs.append(""YES"" + ""\n""); } } System.out.println(gs); } }","import java.util.*; public class Main { public static void main(String[] args){ Scanner scn = new Scanner(System.in); int t = scn.nextInt(); StringBuilder sb = new StringBuilder(""""); for(int A=0 ; A hm = new HashMap<>(); int min = 4; for(int i=0 ; i=0 ; j--) s += arr[i].charAt(j); if(hm.containsKey(s)) { flag = true; break; } if(arr[i].length() < 3) { for(int k=0 ; k<26 ; k++) { String str = (char)(k + 'a') + s; if(hm.containsKey(str)) { flag= true; break; } } } if(arr[i].length() == 3) { String str = s.substring(1, s.length()); if(hm.containsKey(str)){ flag = true; break; } } hm.remove(arr[i]); } if(flag) sb.append(""YES"" + ""\n""); else sb.append(""NO"" + ""\n""); } } System.out.println(sb); } }",1,(L6) Similar Code with variable name change. Different conditions. Different Logic. Hashmap Vs Hashset. c9159d9c,d3a96420,"import java.util.*; public class SolutionB { public static long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ","import java.util.*; public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i R=new Vector<>(); Vector B=new Vector<>(); for(int i=0;in+1){System.out.println(""NO"");yes=false;break;} } } if(yes)System.out.println(""YES""); } sc.close(); } } ",0,Non-Plagiarised 93ee4612,da5cf40b,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, FastScanner in, PrintWriter out) { int numTests = in.nextInt(); for (int test = 0; test < numTests; test++) { int n = in.nextInt(); char[] a = in.next().toCharArray(); char[] b = in.next().toCharArray(); int ka = 0; int kb = 0; int k11 = 0; int k01 = 0; for (int i = 0; i < n; i++) { if (a[i] == '1') { ++ka; } if (b[i] == '1') { ++kb; } if (a[i] == '1' && b[i] == '1') { ++k11; } if (a[i] == '0' && b[i] == '1') { ++k01; } } if (ka == 0) { out.println(kb == 0 ? 0 : -1); continue; } int ans = Integer.MAX_VALUE; if (ka == kb) { ans = Math.min(ans, 2 * (ka - k11)); } if (ka == n - kb + 1) { int cur = 0; if (k11 == 0) { cur = 1 + 2 * (kb - k01); } else { cur = 1 + 2 * (kb - k01 - 1); } ans = Math.min(ans, cur); } if (ans == Integer.MAX_VALUE) { ans = -1; } out.println(ans); } } } static class FastScanner { private BufferedReader in; private StringTokenizer st; public FastScanner(InputStream stream) { try { in = new BufferedReader(new InputStreamReader(stream, ""UTF-8"")); } catch (Exception e) { throw new AssertionError(); } } public String next() { while (st == null || !st.hasMoreTokens()) { try { String rl = in.readLine(); if (rl == null) { return null; } st = new StringTokenizer(rl); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ","/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=(long)1e9+7; /* start */ public static void main(String [] args) { // int testcases = 1; int testcases = i(); while(testcases-->0) { solve(); } out.flush(); out.close(); } static void solve() { int n = i(); char c[] = inputC(); char d[] = inputC(); int x01=0,x10=0,x00=0,x11=0; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long[] sort(long a[]) { ArrayList arr = new ArrayList<>(); for(long i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } static int[] sort(int a[]) { ArrayList arr = new ArrayList<>(); for(Integer i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } //pair class private static class Pair implements Comparable { long first, second; public Pair(long f, long s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }",0,Non-Plagiarised a5d5a95f,c4ca2ff3,"import java.util.*; import java.io.*; public class Main { // 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.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 public static void main(String[] args) { FastReader reader = new FastReader(); int Q = reader.nextInt(); outer: for (int q = 0; q < Q; q++) { int N = reader.nextInt(); int[][] scores = new int[5][N]; for (int i = 0; i < N; i++) { int[] occurs = new int[5]; String word = reader.next(); for (int j = 0; j < word.length(); j++) { occurs[word.charAt(j) - 'a']++; } for (int j = 0; j < 5; j++) { scores[j][i] = occurs[j] - (word.length() - occurs[j]) ; } } int bestCount = 0; for (int i = 0; i < 5; i++) { int[] curr = scores[i]; Arrays.sort(curr); int currentCount = 1; int currentScore = curr[curr.length - 1]; for (int j = curr.length - 2; j >= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ","/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); PrintWriter out=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int freq[][]=new int[n][5]; int rem[][]=new int[n][5]; for(int i=0;i=0;k--) { if(sum+arr[k]>0) { sum=sum+arr[k]; total++; } else { break; } } ans=Math.max(ans,total); } out.println(ans); } out.flush(); out.close(); } } ",0,Non-Plagiarised 0f3a2acf,16e6d8bb,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Practice { static int[][] vals; static ArrayList> adjList; static long[][] ans; public static void main(String[] args) throws IOException { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(bu.readLine()); while (t-- > 0) { Integer n = Integer.parseInt(bu.readLine()); vals = new int[2][n]; adjList = new ArrayList<>(); for(int i=0;i()); } for(int i=0;i> adjList, Integer prev, long[][] ans, int[][] vals) { ans[0][current] = 0L; ans[1][current] = 0L; for(Integer node: adjList.get(current)){ if(node.equals(prev)) continue; DFS(node, adjList, current, ans, vals); ans[0][current] += Math.max(ans[0][node] + Math.abs(vals[0][current] - vals[0][node]), ans[1][node] + Math.abs(vals[0][current] - vals[1][node])); ans[1][current] += Math.max(ans[0][node] + Math.abs(vals[1][current] - vals[0][node]) , ans[1][node] + Math.abs(vals[1][current] - vals[1][node])); } } } ","import java.util.*; import java.io.*; import java.lang.*; public class CodeChef { static long dp[][]; public static void main (String[] args) throws java.lang.Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0) { int n=Integer.parseInt(br.readLine()); int arr[][]=new int[n+1][2]; for(int i=1;i<=n;i++) { String str[]=br.readLine().split("" ""); int l=Integer.parseInt(str[0]);int r=Integer.parseInt(str[1]); arr[i][0]=l;arr[i][1]=r; } dp=new long[n+1][2]; Setadj[]=new HashSet[n+1]; for(int i=0;i<=n;i++)adj[i]=new HashSet(); for(int i=0;i[] adj,int arr[][]) { dp[root][0]=dp[root][1]=0; Iteratoriter=adj[root].iterator(); while(iter.hasNext()) { int i=iter.next(); adj[i].remove(root); fun(i,adj,arr); dp[root][0]+=Math.max(Math.abs(arr[root][0]-arr[i][0])+dp[i][0], Math.abs(arr[root][0]-arr[i][1])+dp[i][1]); dp[root][1]+=Math.max(Math.abs(arr[root][1]-arr[i][0])+dp[i][0], Math.abs(arr[root][1]-arr[i][1])+dp[i][1]); } } } ",1,"(L5) Similar function code with variable renaming and function renaming, different imports. Change for with while." 7011024d,eea69e7f,"import java.util.*; public class D { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); ArrayList occupied = new ArrayList<>(); ArrayList vacant = new ArrayList<>(); for (int i = 0; i < n; i++) { int x = scanner.nextInt(); if (x == 1) occupied.add(i); else vacant.add(i); } Solution Solution = new Solution(occupied, vacant); // System.out.println(Solution.tabulation()); System.out.println(Solution.memoization()); } } class Solution { ArrayList occupied, vacant; int x, y; public Solution(ArrayList occupied, ArrayList vacant) { this.occupied = occupied; this.vacant = vacant; x = occupied.size(); y = vacant.size(); } int tabulation() { return tabulation(x, y); } int tabulation(int x, int y) { int[][] dp = new int[x+1][y+1]; for (int i = 0; i <= x; i++) { Arrays.fill(dp[i], Integer.MAX_VALUE/2); } for (int i = 0; i <= x; i++) { dp[i][0] = 0; } for (int i = 0; i <= y; i++) { dp[0][i] = 0; } for (int i = 1; i <= x; i++) { for (int j = 1; j <= y; j++) { if(i == j) { dp[i][j] = dp[i-1][j-1] + Math.abs(occupied.get(i-1) - vacant.get(j-1)); } else { dp[i][j] = Math.min(dp[i][j-1], dp[i-1][j-1] + Math.abs(occupied.get(i-1) - vacant.get(j-1))); } } } return dp[x][y]; } int memoization() { int[][] dp = new int[x][y]; for (int i = 0; i < x; i++) { Arrays.fill(dp[i], -1); } return memoization(dp, x-1, y-1); } int memoization(int[][] dp, int n, int m) { if(n < 0) { return 0; } if(m < n) { return Integer.MAX_VALUE; } if(dp[n][m] != -1) { return dp[n][m]; } int first = memoization(dp, n, m-1); int second = memoization(dp, n-1, m-1) + Math.abs(occupied.get(n) - vacant.get(m)); dp[n][m] = Math.min(first, second); return dp[n][m]; } }","import java.util.*; public class Solution { public static int minMoves(int[] input) { List people = new ArrayList(); List chairs = new ArrayList(); for (int i = 0; i < input.length; i++) { if (input[i] == 1) { people.add(i); } else { chairs.add(i); } } int[] memo = new int[chairs.size() + 1]; for (int p = 1; ((!people.isEmpty()) && (p <= people.size())); p++) { int prev = memo[p]; memo[p] = memo[p - 1] + Math.abs(people.get(p - 1) - chairs.get(p - 1)); for (int c = p + 1; c <= chairs.size(); c++) { int tmp = memo[c]; memo[c] = Math.min(memo[c - 1], prev + Math.abs(people.get(p - 1) - chairs.get(c - 1))); prev = tmp; } } return memo[memo.length - 1]; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] input = new int[n]; for (int i = 0; i < n; i++) { input[i] = sc.nextInt(); } System.out.println(Solution.minMoves(input)); } }",0,Non-Plagiarised 00f79486,ce0b2178,"/* In_The_Name_Of_Allah_The_Merciful */ import java.util.*; import java.io.*; public class Main { class Pair implements Comparable{ int f,s; Pair(int x,int y){ f=x; s=y; } @Override public int compareTo(Pair a) { if(a.f!=this.f)return Integer.compare(f,a.f); else return Integer.compare(s,a.s); } } PrintWriter out; FastReader sc; long[] m1= {(long)(1e9+7),998244353}; long mod=m1[1]; long maxlong=Long.MAX_VALUE; long minlong=Long.MIN_VALUE; StringBuilder sb; /****************************************************************************************** *****************************************************************************************/ public void sol() { int n=ni(); int[] ar=new int[n]; for(int i=0;i red=new PriorityQueue<>(Collections.reverseOrder()),blue=new PriorityQueue<>(); for(int i=0;i0) { if(red.poll()>a) { no();return; }a--; }a=1; while(blue.size()>0) { if(blue.poll()0) g.sol(); g.out.flush(); } /**************************************************************************************** *****************************************************************************************/ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public int ni(){ return sc.nextInt(); }public long nl(){ return sc.nextLong(); }public double nd(){ return sc.nextDouble(); }public char[] rl(){ return sc.nextLine().toCharArray(); }public String rl1(){ return sc.nextLine(); } public void pl(Object s){ out.println(s); } public void pr(Object s){ out.print(s); }public String next(){ return sc.next(); }public long abs(long x){ return Math.abs(x); } public int abs(int x){ return Math.abs(x); } public double abs(double x){ return Math.abs(x); }public long min(long x,long y){ return (long)Math.min(x,y); } public int min(int x,int y){ return (int)Math.min(x,y); } public double min(double x,double y){ return Math.min(x,y); }public long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); }public long lcm(long a, long b) { return (a / gcd(a, b)) * b; } void sort1(int[] a) { ArrayList 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); } } void sort(int[] a) { ArrayList 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); } }void sort(char[] a) { ArrayList l = new ArrayList<>(); for (char i : a) { l.add(i); } Collections.sort(l); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } }void sort1(char[] a) { ArrayList l = new ArrayList<>(); for (char i : a) { l.add(i); } Collections.sort(l,Collections.reverseOrder()); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } } void sort(long[] a) { ArrayList 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); } }void sort1(long[] a) { ArrayList l = new ArrayList<>(); for (long i : a) { l.add(i); } Collections.sort(l,Collections.reverseOrder()); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } } void sort(double[] a) { ArrayList l = new ArrayList<>(); for (double i : a) { l.add(i); } Collections.sort(l); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } }long pow(long a,long b){ if(b==0){ return 1; }long p=pow(a,b/2); if(b%2==0) return mMultiplication(p,p)%mod; else return (mMultiplication(mMultiplication(p,p),a))%mod; } int swap(int a,int b){ return a; }long swap(long a,long b){ return a; }double swap(double a,double b){ return a; } boolean isPowerOfTwo (int x) { return x!=0 && ((x&(x-1)) == 0); }boolean isPowerOfTwo (long x) { return x!=0 && ((x&(x-1)) == 0); }public long max(long x,long y){ return (long)Math.max(x,y); } public int max(int x,int y){ return (int)Math.max(x,y); } public double max(double x,double y){ return Math.max(x,y); }long sqrt(long x){ return (long)Math.sqrt(x); }int sqrt(int x){ return (int)Math.sqrt(x); }void input(int[] ar,int n){ for(int i=0;i= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } int strSmall(ArrayList arr, int target) { int start = 0, end = arr.size()-1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr.get(mid) > target) { start = mid + 1; ans=start; } else { end = mid - 1; } } return ans; }long mMultiplication(long a,long b) { long res = 0; a %= mod; while (b > 0) { if ((b & 1) > 0) { res = (res + a) % mod; } a = (2 * a) % mod; b >>= 1; } return res; }long nCr(int n, int r ,long p) { if (n 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; }long modInverse(long n, long p) { return power(n, p - 2, p); } int[][] floydWarshall(int graph[][],int INF,int V) { int dist[][] = new int[V][V]; int i, j, k; for (i = 0; i < V; i++) for (j = 0; j < V; j++) dist[i][j] = graph[i][j]; for (k = 0; k < V; k++) { for (i = 0; i < V; i++) { for (j = 0; j < V; j++) { if (dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k] + dist[k][j]; } } }return dist; } class minque { Deque q; minque(){ q=new ArrayDeque(); }public void add(long p){ while(!q.isEmpty()&&q.peekLast()>p)q.pollLast(); q.addLast(p); }public void remove(long p) { if(!q.isEmpty()&&q.getFirst()==p)q.removeFirst(); }public long min() { return q.getFirst(); } } int find(subset[] subsets, int i) { if (subsets[i].parent != i) subsets[i].parent = find(subsets, subsets[i].parent); return subsets[i].parent; }void Union(subset[] subsets, int x, int y) { int xroot = find(subsets, x); int yroot = find(subsets, y); if (subsets[xroot].rank < subsets[yroot].rank) { subsets[xroot].parent = yroot; } else if (subsets[yroot].rank < subsets[xroot].rank) { subsets[yroot].parent = xroot; } else { subsets[xroot].parent = yroot; subsets[yroot].rank++; } }class subset { int parent; int rank; } }","import java.io.*; import java.util.*; public class D { static class Pair implements Comparable{ int a; char b; public Pair(int a, char b) { this.a = a; this.b = b; } @Override public int compareTo(Pair p) { if(this.b == p.b) return this.a - p.a; return this.b - p.b; } } public static void main(String[] args)throws IOException { FastScanner scan = new FastScanner(); PrintWriter output = new PrintWriter(System.out); int t = scan.nextInt(); for(int tt = 0;tt pairs = new ArrayList(); for(int i = 0;i i && pairs.get(i-1).b == 'B') { continue; } else { possible = false; break; } } output.println(possible == true ? ""YES"" : ""NO""); } output.flush(); } public static int[] sort(int arr[]) { List list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); for(int i = 0;i0) { st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(f.readLine()); long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(st.nextToken()); } solve(n, arr); } } static void solve(long n, long[] arr) { long minEven = Integer.MAX_VALUE; long minOdd = arr[0]; long evenSum = 0; long oddSum = arr[0]; long finans = Long.MAX_VALUE; long oddAns, evenAns; long oddcount=1; long evencount=0; for (int k = 1; k < n; k++) { if (k%2==1) { evenSum+=arr[k]; evencount++; minEven = Math.min(minEven, arr[k]); } else { oddSum+=arr[k]; oddcount++; minOdd = Math.min(minOdd, arr[k]); } oddAns = oddSum+(n-oddcount)*minOdd; evenAns = evenSum+(n-evencount)*minEven; finans = Math.min(finans, oddAns+evenAns); } System.out.println(finans); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class MinimumGridPath { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int cases = Integer.parseInt(line); for(int i = 0; i{ int x; int y; public point(int x,int y){ this.x = x; this.y = y; } public String toString(){ return(x + "" "" + y); } public boolean equals(Object x){ point y = ((point)(x)); if (this.x == y.x && this.y == y.y){ return true; } return false; } public int hashCode(){ return Objects.hash(x,y); } public int compareTo(point other){ if(this.x < other.x){ return -1; }else if(this.x == other.x && this.y == other.y){ return 0; } return 1; } } }","import java.io.*; import java.util.*; public class C { public static void main (String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int t = Integer.parseInt(st.nextToken()); while (t-->0) { st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(f.readLine()); long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(st.nextToken()); } solve(n, arr); } } static void solve(long n, long[] arr) { long minEven = Integer.MAX_VALUE; long minOdd = arr[0]; long evenSum = 0; long oddSum = arr[0]; long finans = Long.MAX_VALUE; long oddAns, evenAns; long oddcount=1; long evencount=0; for (int k = 1; k < n; k++) { if (k%2==1) { evenSum+=arr[k]; evencount++; minEven = Math.min(minEven, arr[k]); } else { oddSum+=arr[k]; oddcount++; minOdd = Math.min(minOdd, arr[k]); } oddAns = oddSum+(n-oddcount)*minOdd; evenAns = evenSum+(n-evencount)*minEven; finans = Math.min(finans, oddAns+evenAns); } System.out.println(finans); } } ",0,Non-Plagiarised 1dab88fb,7b5f64b7,"import java.util.*; public class Main { static class Edge{ public int node; public int index; public Edge(int n, int i){ node=n; index=i; } } static Scanner sc=new Scanner(System.in); public static void main(String[] args) { int test=sc.nextInt(); while(test-->0){ solve(); } } static void solve(){ int n=sc.nextInt(); ArrayList> graph= new ArrayList>(); for(int i=0;i()); } for (int i = 0; i < n - 1; i++) { int u = sc.nextInt(); int v = sc.nextInt(); u--; v--; graph.get(u).add(new Edge(v, i)); graph.get(v).add(new Edge(u, i)); } int start = 0; for (int i = 0; i < n; i++) { if (graph.get(i).size() > 2) { System.out.println(""-1""); return; } else if (graph.get(i).size() == 1) { start = i; } } int[] weight = new int[n - 1]; int prevNode = -1; int curNode = start; int curWeight = 2; while (true) { ArrayList edges = graph.get(curNode); Edge next = edges.get(0); if (next.node == prevNode) { if (edges.size() == 1) { break; } else { next = edges.get(1); } } weight[next.index] = curWeight; prevNode = curNode; curNode = next.node; curWeight = 5 - curWeight; } for (int i = 0; i < n - 1; i++) { System.out.print(weight[i]); System.out.print("" ""); } System.out.println(); } } ","import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static FastReader obj = new FastReader(); public static PrintWriter out = new PrintWriter(System.out); public static void sort(long[] a) { ArrayList arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } public static void revsort(long[] a) { ArrayList arr = new ArrayList<>(); for (int i = 0; i < a.length; i++) arr.add(a[i]); Collections.sort(arr, Collections.reverseOrder()); for (int i = 0; i < arr.size(); i++) a[i] = arr.get(i); } //Cover the small test cases like for n=1 . public static class pair { int a; int b; pair(int x, int y) { a = x; b = y; } } public static long l() { return obj.nextLong(); } public static int i() { return obj.nextInt(); } public static String s() { return obj.next(); } public static long[] l(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = l(); return arr; } public static int[] i(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = i(); return arr; } public static long ceil(long a, long b) { return (a + b - 1) / b; } public static void p(long val) { out.println(val); } public static void p(String s) { out.println(s); } public static void pl(long[] arr) { for (int i = 0; i < arr.length; i++) { out.print(arr[i] + "" ""); } out.println(); } public static void p(int[] arr) { for (int i = 0; i < arr.length; i++) { out.print(arr[i] + "" ""); } out.println(); } public static void sortpair(ArrayList arr) { //ascending just change return 1 to return -1 and vice versa to get descending. //compare based on value of pair.a arr.sort(new Comparator() { public int compare(pair o1, pair o2) { long val = o1.a - o2.a; if (val == 0) return 0; else if (val > 0) return 1; else return -1; } }); } // Take of the small test cases such as when n=1,2 etc. // remember in case of fenwick tree ft is 1 based but our array should be 0 based. // in fenwick tree when we update some index it doesn't change the value to val but it // adds the val value in it so remember to add val-a[i] instead of just adding val. //in case of finding the inverse mod do it (biexpo(a,mod-2)%mod + mod )%mod public static ArrayList> adj; public static int[] ans; public static void main(String[] args) { int len = i(); while (len-- != 0) { int n = i(); adj=new ArrayList<>(n+1); ans=new int[n]; int ok=0; for(int i=0;i<=n;i++)adj.add(new ArrayList<>()); for(int i=0;i2)ok=1; if(adj.get(b).size()>2)ok=1; } if(ok==1)out.println(-1); else { int[] vis=new int[n+1]; if(adj.get(1).size()==2) { vis[adj.get(1).get(1).a]=1; dfs(1,vis,11); vis[adj.get(1).get(1).a]=0; vis[1]=0; dfs(1,vis,2); } else { dfs(1,vis,11); } for(int i=0;i 0) { int n=i(); int[] arr=arrI(n); String s=string(); ArrayList lR=new ArrayList<>(); ArrayList lB=new ArrayList<>(); for(int i=0;i=k) { k+=1; } else { st=false; break; } } boolean st2=true; k=n; for(int i=0;ik) { st2=false; break; } else { k-=1; } } if(st && st2) out.print(""YES""); else out.print(""NO""); out.print(""\n""); out.flush(); } out.close(); } static class pair { long x, y; pair(long ar, long ar2) { x = ar; y = ar2; } } static void sort(long[] a) // check for long { ArrayList 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 sort(int[] a) { ArrayList 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); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static class DescendingComparator implements Comparator { public int compare(Integer a, Integer b) { return b - a; } } static class AscendingComparator implements Comparator { public int compare(Integer a, Integer b) { return a - b; } } static boolean isPalindrome(char X[]) { int l = 0, r = X.length - 1; while (l <= r) { if (X[l] != X[r]) return false; l++; r--; } return true; } static long fact(long N) { long num = 1L; while (N >= 1) { num = ((num % mod) * (N % mod)) % mod; N--; } return num; } static long pow(long a, long b) { long mod = 1000000007; long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) pow = (pow * x) % mod; x = (x * x) % mod; b /= 2; } return pow; } static long toggleBits(long x)// one's complement || Toggle bits { int n = (int) (Math.floor(Math.log(x) / Math.log(2))) + 1; return ((1 << n) - 1) ^ x; } static int countBits(long a) { return (int) (Math.log(a) / Math.log(2) + 1); } 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 = i + 6) if (N % i == 0 || N % (i + 2) == 0) return false; return true; } static long GCD(long a, long b) { if (b == 0) { return a; } else return GCD(b, a % b); } // Debugging Functions Starts static void print(char A[]) { for (char c : A) System.out.print(c + "" ""); System.out.println(); } static void print(boolean A[]) { for (boolean c : A) System.out.print(c + "" ""); System.out.println(); } static void print(int A[]) { for (int a : A) System.out.print(a + "" ""); System.out.println(); } static void print(long A[]) { for (long i : A) System.out.print(i + "" ""); System.out.println(); } static void print(ArrayList A) { for (int a : A) System.out.print(a + "" ""); System.out.println(); } // Debugging Functions END // ---------------------- // IO FUNCTIONS STARTS static HashMap getHashMap(int A[]) { HashMap mp = new HashMap<>(); for (int a : A) { int f = mp.getOrDefault(a, 0) + 1; mp.put(a, f); } return mp; } public static Map mapSortByValue(Map hm) { // Create a list from elements of HashMap List> list = new LinkedList>(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator>() { public int compare(Map.Entry o1, Map.Entry o2) { return o1.getValue() - o2.getValue(); } }); // put data from sorted list to hashmap Map temp = new LinkedHashMap(); for (Map.Entry aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static String string() { return in.nextLine(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] arrI(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] arrL(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) A[i] = in.nextLong(); return A; } } class MyFastReaderPC3C { BufferedReader br; StringTokenizer st; public MyFastReaderPC3C() { 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; } } ","import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.io.*; public class Div2 { private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static String solution(int [] arr, int n, String st) { ArrayList red = new ArrayList<>(); ArrayList blue = new ArrayList<>(); for(int i = 0; i=0; j--) { if(red.get(j)>cr) return ""NO""; cr--; } return ""YES""; } private static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { MyScanner s = new MyScanner(); int t = s.nextInt(); for(int j = 0; j0) { int n=sc.nextInt(); int arr[]=new int[n]; int i,max=Integer.MIN_VALUE,min=Integer.MAX_VALUE; for(i=0;imax) max=arr[i]; if(arr[i]=2;--i) { if(temp[i] 0) { int n = sc.nextInt(); int[] h = new int[n]; int i, b = MAX, e = MIN; for (i = 0; i < n; i++) { h[i] = sc.nextInt(); if (b > h[i]) b = h[i]; if (e < h[i]) e = h[i]; } int[] s = new int[n]; int c, d, ans = b; // System.out.println(b + "" "" + e); while (b <= e) { c = (b + e) / 2; // System.out.println(c); // sc.next(); for (i = 0; i < n; i++) { s[i] = 0; } for (i = n - 1; i >= 2; i--) { if (h[i] + s[i] < c) { e = c - 1; break; } else { d = Math.min(h[i], h[i] + s[i] - c) / 3; s[i - 1] += d; s[i - 2] += 2 * d; } } // System.out.println(i); if (i == 1) { if (h[i] + s[i] < c || h[i - 1] + s[i - 1] < c) { e = c - 1; } else { ans = c; b = c + 1; } } } System.out.println(ans); } } }",0,Non-Plagiarised c34bb733,ea899386,"//package pack; import java.io.*; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.*; import java.io.*; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.*; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Vector; import static java.lang.Math.sqrt; import static java.lang.Math.floor; public class topcoder { static class pair{ int first; int second; public pair(int first, int second) { this.first = first; this.second = second; } } static class Compare{ static void compare(ArrayListarr, int n) { Collections.sort(arr,new Comparator() { public int compare(pair p1, pair p2) { return p1.first-p2.first; } }); } } static class pairr implements Comparable{ Integer value; Integer index; public pairr(Integer value, Integer index) { this.value = value; this.index = index; } @Override public int compareTo(pairr o) { return value-o.value; } } static class Key { 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 long binary_search(int s, int e, long num, long []ar) { if(s > e) { return -1; } int mid = (s+e)/2; if(s == e && ar[s] >= num) { return ar[s]; }else if(s == e && ar[s] < num) { return -1; }else if(ar[mid] < num) { return binary_search(mid+1,e,num,ar); }else if(ar[mid] >= num) { return binary_search(s,mid,num,ar); } return -1; } public static int index_search(int s, int e, long num, long []ar) { if(s > e) { return -1; } int mid = (s+e)/2; if(s == e && ar[s] >= num) { return s; }else if(s == e && ar[s] < num) { return -1; }else if(ar[mid] < num) { return index_search(mid+1,e,num,ar); }else if(ar[mid] >= num) { return index_search(s,mid,num,ar); } return -1; } 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 boolean digit_exists(long n) { while(n > 0) { if(n%10 == 9) return true; n = n/10; } return false; } public static int log(int n) { int c = 0; while(n > 0) { c++; n /=2; } return c; } 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; } static void simpleSieve(int limit, Vector prime) { // Create a boolean array ""mark[0..n-1]"" and initialize // all entries of it as true. A value in mark[p] will // finally be false if 'p' is Not a prime, else true. boolean mark[] = new boolean[limit+1]; for (int i = 0; i < mark.length; i++) mark[i] = true; for (int p=2; p*pl) { // Compute all primes smaller than or equal // to square root of n using simple sieve int limit = (int) (floor(sqrt(n))+1); Vector prime = new Vector<>(); simpleSieve(limit, prime); // Divide the range [0..n-1] in different segments // We have chosen segment size as sqrt(n). int low = limit; int high = 2*limit; // While all segments of range [0..n-1] are not processed, // process one segment at a time while (low < n) { if (high >= n) high = n; // To mark primes in current range. A value in mark[i] // will finally be false if 'i-low' is Not a prime, // else true. boolean mark[] = new boolean[limit+1]; for (int i = 0; i < mark.length; i++) mark[i] = true; // Use the found primes by simpleSieve() to find // primes in current range for (int i = 0; i < prime.size(); i++) { // Find the minimum number in [low..high] that is // a multiple of prime.get(i) (divisible by prime.get(i)) // For example, if low is 31 and prime.get(i) is 3, // we start with 33. int loLim = (int) (floor(low/prime.get(i)) * prime.get(i)); if (loLim < low) loLim += prime.get(i); /* Mark multiples of prime.get(i) in [low..high]: We are marking j - low for j, i.e. each number in range [low, high] is mapped to [0, high-low] so if range is [50, 100] marking 50 corresponds to marking 0, marking 51 corresponds to 1 and so on. In this way we need to allocate space only for range */ for (int j=loLim; j 0) { power++; k /=2 ; } long check = (long)Math.pow(2, power-1); if(k1 == check) { return power; } // System.out.println(power); long f = (long)Math.pow(2, power-1); long rem = k1-f; return find_indexNum(rem); } public static void sortPair(ArrayListl, int n) { n = l.size(); Compare obj = new Compare(); obj.compare(l, n); } public static int add(long n, long num, long a, int i) { //System.out.println(num); if(num > n)return -1; if(num == n) { return i; } if(a < 2050)return -1; long temp = num+a; if(temp <= n) { return add(n,temp,a,i+1); }else if(temp > n){ a /= 10; return add(n,num,a,i); } return -1; } public static void shuffle(int []array, int num,int t_index, boolean []vis, int m ) { for(int i = 0; i < m; i++) { if(vis[i] == false) { int temp = array[i]; if(i < t_index) { vis[i] = true; } array[i] = num; array[t_index] = temp; // System.out.println(array[t_index]+"" ""+array[i]); break; } } } public static void rotate(int []arr,int j, int times, int m) { if(j == 0) { int temp1 = arr[0]; arr[0] = arr[times]; arr[times] = temp1; }else { int temp = arr[j]; int z = arr[0]; arr[0] = arr[times]; arr[j] = z; arr[times] = temp; } } public static void recur(int i,int A, int B,int []dp,int []metal, int n, boolean took,int ind) { if(i-A <= 0 && i-B <= 0)return; int count = 0; for(int j = 1; j <= n; j++) { if(dp[j] >= metal[j]) { count++; } } if(count == n)return; if(i-A >= 0 && i-B >= 0 && dp[i] > 0 && dp[i] > metal[i]) { dp[i]--; dp[i-A]++; dp[i-B]++; } if(ind == 6) { // System.out.println(Arrays.toString(dp)); } recur(i-A,A,B,dp,metal,n,took,ind); recur(i-B,A,B,dp,metal,n,took,ind); } 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; } 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 boolean poss( int r, int c, int k, int n, int m,boolean [][]vis) { if(k < 0)return false; if(r > n || c > m || r < 1 || c < 1)return false; if(r == n && c == m && k == 0) { // System.out.println(k); return true; } if(vis[r][c] == true) { return false; } vis[r][c] = true; return poss(r+1,c,k-c,n,m,vis) || poss(r,c+1,k-r,n,m,vis); } public static void dfs(LinkedList[]list, HashMapmap, int parent, int n) { Stackst = new Stack<>(); } public static boolean pos(int n) { int i = 1; boolean pos = false; while(i*i <= n) { if(i*i*2 == n || i*i*4 == n) { pos = true; break; } i++; } if(pos)return true; return false; } public static void main(String args[])throws IOException{ // System.setIn(new FileInputStream(""Case.txt"")); BufferedReader ob = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(ob.readLine()); while( t--> 0) { StringTokenizer st = new StringTokenizer(ob.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int []ar = new int[n]; st = new StringTokenizer(ob.readLine()); PriorityQueuepq = new PriorityQueue<>(); for(int i = 0; i < n; i++) { ar[i] = Integer.parseInt(st.nextToken()); pq.add(ar[i]); } PriorityQueuep = new PriorityQueue<>(); for(int i =0; i < n; i++) { p.add(new pairr(ar[i],i)); } int []ans = new int[n]; for(int i = 0; i < n; i++) { pairr a = p.poll(); ans[a.index] = (i%m)+1; } System.out.println(""YES""); for(int i = 0; i < n; i++ ) { System.out.print(ans[i]+"" ""); } System.out.println(); } } } ","import java.io.*; import java.util.*; public class Codeforces { public static class Tower implements Comparable{ int val; int index; public Tower(int ind, int v) { val = v; index = ind; } @Override public int compareTo(Tower o) { return Integer.compare(val, o.val); } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(br.readLine()); while(cases-- > 0) { String[] str = br.readLine().split("" ""); int n = Integer.parseInt(str[0]); int m = Integer.parseInt(str[1]); int x = Integer.parseInt(str[2]); int[] h = new int[n]; str = br.readLine().split("" ""); for(int i=0; i q = new PriorityQueue<>(m); int[] ans = new int[n]; for(int i=0; i red = new Vector<>(); Vector blue = new Vector<>(); String s = obj.next(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'R') red.add(num[i]); else blue.add(num[i]); } Collections.sort(blue); Collections.sort(red); int c = 1, f = 0; for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < c) { f = 1; break; } c++; } for (int i = 0; i < red.size(); i++) { if (red.get(i) > c) { f = 1; break; } c++; } if (f == 0) out.println(""YES""); else out.println(""NO""); } out.flush(); } } ","import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.io.*; public class Div2 { private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static String solution(int [] arr, int n, String st) { ArrayList red = new ArrayList<>(); ArrayList blue = new ArrayList<>(); for(int i = 0; i=0; j--) { if(red.get(j)>cr) return ""NO""; cr--; } return ""YES""; } private static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { MyScanner s = new MyScanner(); int t = s.nextInt(); for(int j = 0; j=0; i--) forced[i]=Math.min(forced[i], forced[i+1]+1); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i0){ int n = fs.nextInt(), k = fs.nextInt(); int[] positions = fs.readArray(k), temps = fs.readArray(k); int[] forced = new int[n]; Arrays.fill(forced, Integer.MAX_VALUE/2); for(int i=0; i=0; i--) forced[i] = Math.min(forced[i], forced[i+1]+1); for(int i=0; i ""+a); } public static void debug(long a, long b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(char a, char b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(int[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(char[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(HashMap map){ System.out.print(""Map--> ""+map.toString()); } } } ",1,"(L5) similar code in main with variable change, replace for with while, within a slightly larger code, different imports" 4303de0d,c9a316ca,"import java.io.*; import java.util.*; public class ParsasHumongousTree { 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 Output { private final PrintWriter writer; public Output(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public Output(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static class Pair { int a; int b; public Pair(int a, int b) { this.a=a; this.b=b; } } static HashMap> edge=new HashMap(); static Pair a[]; static long dp[][]; static void dfs(int node, int parent) { for(int i:edge.get(node)) { if(i!=parent) { dfs(i,node); dp[node][0]+=Math.max(Math.abs(a[node].a-a[i].a)+dp[i][0],Math.abs(a[node].a-a[i].b)+dp[i][1]); dp[node][1]+=Math.max(Math.abs(a[node].b-a[i].a)+dp[i][0],Math.abs(a[node].b-a[i].b)+dp[i][1]); } } } public static void main(String args[]) { FastReader sc=new FastReader(); Output out=new Output(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); a=new Pair[n+1]; edge.clear(); for(int i=1;i list=edge.get(u); list.add(v); edge.put(u,list); } else { List list=new ArrayList(); list.add(v); edge.put(u,list); } if(edge.containsKey(v)) { List list=edge.get(v); list.add(u); edge.put(v,list); } else { List list=new ArrayList(); list.add(u); edge.put(v,list); } } dp=new long[n+1][2]; dfs(1,0); out.printLine(((long)Math.max(dp[1][0],dp[1][1]))); out.flush(); } } }"," import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import static javax.swing.UIManager.get; import static javax.swing.UIManager.getString; public class Main { static class Pair implements Comparable { int x = 0; int y = 0; public Pair(int x1, int y1) { x = x1; y = y1; } @Override public int compareTo(Pair o) { return this.x - o.x; } } static boolean checkPallindrome(int n) { ArrayList list = new ArrayList<>(); while (n > 0) { list.add(n % 10); n /= 10; } int low = 0, high = list.size() - 1; while (low <= high) { if (list.get(low) != list.get(high)) return false; low++; high--; } return true; } static boolean check(String s) { int low = 0, high = s.length() - 1; while (low <= high) { if (s.charAt(low) != s.charAt(high)) return false; low++; high--; } return true; } class Node implements Comparable { int x = 0, y = 0, z = 0; @Override public int compareTo(Node o) { return this.y - o.y; } } static int min = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); //(1)very very important**(never take the first problem for granted, always check the test cases) take 5 minutes more and check the edge cases // 5 minutes will not decreases rating as much as a wrong submission does it is easy u just think with an open mind and u will surely get the answer //(2)let ur brain consume the problem don't just jump to the solution. after reading the problem take a pause 1 minute //(3)go through the example test cases and also at least two of ur own test cases.Think of testcases which are difficult(edge cases).dry run ur concept //(4) sometimes if else condition is not required but due to if else you miss some points and get wrong answer int t = sc.nextInt(); while (t-- > 0) { int n =sc.nextInt(); ArrayList> list = new ArrayList<>(); for(int i=0;i()); ArrayList list1 = new ArrayList<>(); for(int i=0;i> list,ArrayList list1) { for(int v:list.get(u)) { if(v==p) continue; dfs(v,u,dp,list,list1); dp[1][u]+= Math.max(Math.abs(list1.get(u).y-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).y-list1.get(v).y)+dp[1][v]); dp[0][u]+=Math.max(Math.abs(list1.get(u).x-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).x-list1.get(v).y)+dp[1][v]); } } //static int lcs( int[] X, int[] 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[i-1] == Y[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]; //} // syntax of conditional operator y=(x==1)?1:0; //Things to check when u r getting wrong answer // 1- check the flow of the code //2- If ur stuck read the problem once again //3- before submitting always check the output format of ur code //4- don't check standings until problem B is done //5- if u r thinking ur concept is correct but still u r getting wrong answer try to implement it in another way //6- By default, java interpret all numeral literals as 32-bit integer values. // If you want to explicitely specify that this is something bigger then 32-bit integer you should use suffix L for long values. example long a = 600851475143L //All the functions long pow(long a,long b,long m) { a%=m; long res=1L; while(b>0) { long temp=b&1; if(temp==1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) { // Initially, all elements are in // their own set. parent[i] = i; } } // Returns representative of x's set int find(int x) { // Finds the representative of the set // that x is an element of if (parent[x] != x) { // if x is not the parent of itself // Then x is not the representative of // his set, parent[x] = find(parent[x]); // so we recursively call Find on its parent // and move i's node directly under the // representative of this set } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { // Find representatives of two sets int xRoot = find(x), yRoot = find(y); // Elements are in the same set, no need // to unite anything. if (xRoot == yRoot) return; // If x's rank is less than y's rank if (rank[xRoot] < rank[yRoot]) // Then move x under y so that depth // of tree remains less parent[xRoot] = yRoot; // Else if y's rank is less than x's rank else if (rank[yRoot] < rank[xRoot]) // Then move y under x so that depth of // tree remains less parent[yRoot] = xRoot; else // if ranks are the same { // Then move y under x (doesn't matter // which one goes where) parent[yRoot] = xRoot; // And increment the result tree's // rank by 1 rank[xRoot] = rank[xRoot] + 1; } } } static void debug(String s) { System.out.println(s); } //collections.sort use merge sort instead of quick sort but arrays.sort use quicksort whose worst time complexity is O(n^2) static int[] sort(int[] a) { ArrayList list = new ArrayList<>(); for(int i=0;i0) { int n = sc.nextInt(); sc.nextLine(); String [] str = new String[n]; int res = 0; for(int i=0;i=0;p--) { sum+=arr[p]; if(sum>0) { count++; } else { break; } } res=Math.max(count , res); } System.out.println(res); t--; } } }","import java.io.*; import java.util.*; public class C { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); try{ int t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); int lst[][] = new int[n][5]; for(int i=0; i=0; x--){ sum+=val[x]; if(sum>0){ ans++; }else{ break; } } fans = Math.max(fans, ans); } bw.write(fans+""\n""); } bw.flush(); }catch(Exception e){ return; } } } ",1,"(L3) Similar code with variable renaming, additional code. Changing the order of declaration." 74b5ad88,dc575a6c,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; public class A { static int[][] A; static long[][] B; static ArrayList> ar; public static void main(String[] args) { CP sc =new CP(); int tt = sc.nextInt(); while (tt-- > 0) { int n = sc.nextInt(); ar = new ArrayList<>(); for(int i=0;i()); A = new int[n+1][2]; B = new long[n+1][2]; for(int i=1;i[]adj; static int[][]arr; static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); arr=new int[n][2]; adj=new ArrayList[n]; for(int i=0;i(); } for(int i=0;i=0;) { reqTime=times[i]-damage[i]+1; long time=times[i]; i--; while(i>=0 && times[i]>=reqTime) { long thisReqTime=times[i]-damage[i]+1; reqTime=Math.min(reqTime, thisReqTime); i--; } long x=time-reqTime+1; // pn(x); ans+=(x*(x+1)/2); } pn(ans); } static long MOD=(long)(1e9+7); static boolean check(String x, String ans) { if(x.length()!=ans.length()) return x.length()>ans.length(); if(x.compareTo(ans) <= -1) return false; else return true; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void pn(Object o) { System.out.println(o); } static void p(Object o) { System.out.print(o); } static void flush() { System.out.flush(); } static void debugInt(int[] arr) { for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i>1); } static String getBinaryFromDecimal(int x) { StringBuilder sb=new StringBuilder(); for(int i=0;i<31;++i) { if((x&1)==0) sb.append('0'); else sb.append('1'); x=x>>1; } return sb.reverse().toString(); } static boolean[] sieve() { int size=(int)(1e5+5); boolean[] isPrime=new boolean[size]; Arrays.fill(isPrime, true); for(int i=2;i { public int compare(String s1, String s2) { if(s1.length()!=s2.length()) return s2.length()-s1.length(); if(s1.compareTo(s2) <= -1) return 1; else return -1; } }","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[]; static boolean v[]; // static int mod=998244353;; static int mod=1000000007; static int max; static int bit[]; //static long fact[]; // static long A[]; static HashMap map; //static StringBuffer sb=new StringBuffer(""""); //static HashMap map; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); long A[]=inputL(n); long B[]=inputL(n); long C[]=new long[n]; for(int i=0;i=0;i--) { if(C[i]>min) { continue; } if(A[i] { int x; int y; int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int find(int A[],int a) { if(A[a]==a) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return find(A, A[a]); //} //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void print(int A[]) { for(int i : A) { out.print(i+"" ""); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static HashMap hash(long A[]){ HashMap map=new HashMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(long A[]){ TreeMap map=new TreeMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, 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; } } } ",0,Non-Plagiarised 3a12e509,52cd85f2,"import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } static class Pair implements Cloneable, Comparable { 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)+500*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; } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; int taxC,taxD; Node(int ver) { vertex=ver; taxD=0; taxC=0; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(nn) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } 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') { 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 void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class PC3C { static PrintWriter out = new PrintWriter(System.out); static MyFastReaderPC3C in = new MyFastReaderPC3C(); static long mod = (long) (1e9 + 7); public static void main(String[] args) throws Exception { int test = i(); while (test-- > 0) { int n=i(); int[] arr=arrI(n); String s=string(); ArrayList lR=new ArrayList<>(); ArrayList lB=new ArrayList<>(); for(int i=0;i=k) { k+=1; } else { st=false; break; } } boolean st2=true; k=n; for(int i=0;ik) { st2=false; break; } else { k-=1; } } if(st && st2) out.print(""YES""); else out.print(""NO""); out.print(""\n""); out.flush(); } out.close(); } static class pair { long x, y; pair(long ar, long ar2) { x = ar; y = ar2; } } static void sort(long[] a) // check for long { ArrayList 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 sort(int[] a) { ArrayList 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); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static class DescendingComparator implements Comparator { public int compare(Integer a, Integer b) { return b - a; } } static class AscendingComparator implements Comparator { public int compare(Integer a, Integer b) { return a - b; } } static boolean isPalindrome(char X[]) { int l = 0, r = X.length - 1; while (l <= r) { if (X[l] != X[r]) return false; l++; r--; } return true; } static long fact(long N) { long num = 1L; while (N >= 1) { num = ((num % mod) * (N % mod)) % mod; N--; } return num; } static long pow(long a, long b) { long mod = 1000000007; long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) pow = (pow * x) % mod; x = (x * x) % mod; b /= 2; } return pow; } static long toggleBits(long x)// one's complement || Toggle bits { int n = (int) (Math.floor(Math.log(x) / Math.log(2))) + 1; return ((1 << n) - 1) ^ x; } static int countBits(long a) { return (int) (Math.log(a) / Math.log(2) + 1); } 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 = i + 6) if (N % i == 0 || N % (i + 2) == 0) return false; return true; } static long GCD(long a, long b) { if (b == 0) { return a; } else return GCD(b, a % b); } // Debugging Functions Starts static void print(char A[]) { for (char c : A) System.out.print(c + "" ""); System.out.println(); } static void print(boolean A[]) { for (boolean c : A) System.out.print(c + "" ""); System.out.println(); } static void print(int A[]) { for (int a : A) System.out.print(a + "" ""); System.out.println(); } static void print(long A[]) { for (long i : A) System.out.print(i + "" ""); System.out.println(); } static void print(ArrayList A) { for (int a : A) System.out.print(a + "" ""); System.out.println(); } // Debugging Functions END // ---------------------- // IO FUNCTIONS STARTS static HashMap getHashMap(int A[]) { HashMap mp = new HashMap<>(); for (int a : A) { int f = mp.getOrDefault(a, 0) + 1; mp.put(a, f); } return mp; } public static Map mapSortByValue(Map hm) { // Create a list from elements of HashMap List> list = new LinkedList>(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator>() { public int compare(Map.Entry o1, Map.Entry o2) { return o1.getValue() - o2.getValue(); } }); // put data from sorted list to hashmap Map temp = new LinkedHashMap(); for (Map.Entry aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static String string() { return in.nextLine(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] arrI(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] arrL(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) A[i] = in.nextLong(); return A; } } class MyFastReaderPC3C { BufferedReader br; StringTokenizer st; public MyFastReaderPC3C() { 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; } } ",0,Non-Plagiarised 23194f89,bcc5473d,"import java.io.*; import java.util.*; public class new1{ static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader s = new FastReader(); int t = s.nextInt(); for(int z = 0; z < t; z++) { int n = s.nextInt(); int[] ti = new int[n]; for(int i = 0; i < n; i++) ti[i] = s.nextInt(); int[] he = new int[n]; for(int i = 0; i < n; i++) he[i] = s.nextInt(); long ans = 0; int st = ti[n - 1] - he[n - 1] + 1; int en = ti[n - 1]; //System.out.println(st + "" "" + en); for(int i = n - 2; i >= 0; i--) { int st1 = ti[i] - he[i] + 1; int en1 = ti[i]; if(en1 >= st) { st = Math.min(st, st1); } else { long a1 = ((en - st + 1L) * (en - st + 2L)) / 2; ans = ans + a1; st = st1; en = en1; //System.out.println(a1); } } ans = ans + ((en - st + 1L) * (en - st + 2L)) / 2; System.out.println(ans); } //output.flush(); } } 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(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}"," import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; public class k { //public static int mod=1000000007; public static void printDivisors(int n) { // Note that this loop runs till square root int x=(int) Math.sqrt(n); int p=0; for (int i=1; i<=x; i++) { if (n%i == 0) { // If divisors are equal, print only one if (n/i == i) p++; else // Otherwise print both p=p+2; } } System.out.println(p); } public static ArrayList Factors(long n) { ArrayList arr=new ArrayList(); int k=0; while (n%2==0) { k++; n /=2; arr.add((long)2); } int p=(int) Math.sqrt(n); for (int i = 3; i <=p; i+= 2) { if(n==1)break; while (n%i == 0) { k++; arr.add((long)i); n /= i; } } if (n > 2) { arr.add(n); } return arr; } 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 long gcd(long x, long p) { if (x == 0) return p; return gcd(p%x, x); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static HashMap sortByValue(HashMap hm) { // Create a list from elements of HashMap List > list = new LinkedList >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator >() { public int compare(Map.Entry o1, Map.Entry o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap temp = new LinkedHashMap(); for (Map.Entry aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static int sieve = 1000000 ; static boolean[] prime = new boolean[sieve + 1] ; public static void sieveOfEratosthenes() { // FALSE == prime and 1 // TRUE == COMPOSITE // time complexity = 0(NlogLogN)== o(N) // gives prime nos bw 1 to N // size - 1e7(at max) for(int i = 4; i<= sieve ; i++) { prime[i] = true ; i++ ; } for(int p = 3; p*p <= sieve; p++) { if(prime[p] == false) { for(int i = p*p; i <= sieve; i += p) prime[i] = true; } p++ ; } } public static void arrInpInt(int [] arr, int n) throws IOException { Reader reader = new Reader(); for(int i=0;i high) { return low; } int mid = low + (high - low) / 2; if (arr[mid] >= X) { return lower_bound(arr, low, mid - 1, X); } return lower_bound(arr, mid + 1, high, X); } //if present - return the index of next greater value //not present- return the index of next greater value //if greater than all the values return N(taking high=N-1) //if smaller than all the values return 0(taking low =0)\ static int upper_bound(int arr[], int low, int high, int X) { if (low > high) return low; int mid = low + (high - low) / 2; if (arr[mid] <= X) { return upper_bound(arr, mid + 1, high, X); } return upper_bound(arr, low, mid - 1, X); } public static class Pair {// comparator with class int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sortbyColumn(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else if (entry1[col] < entry2[col]) return -1; else return 0; } }); } public static void sortbyColumn1(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else if (entry1[col] < entry2[col]) return -1; else if(entry1[col] == entry2[col]) { if(entry1[col-1]>entry2[col-1]) return -1; else if(entry1[col-1]{ public int compare(p s1, p s2) { if (s1.h > s2.h) return -1; else if (s1.h < s2.h) return 1; else if(s1.h==s2.h) { if(s1.no>s2.no)return -1; else return 1; } return 0; } } static long hcf(long a,long b) { while (b > 0) { long temp = b; b = a % b; a = temp; } return a; } static int lower_bound_arr(ArrayList arr, int low, int high, int X) { if (low > high) { return low; } int mid = low + (high - low) / 2; if (arr.get(mid) >= X) { return lower_bound_arr(arr, low, mid - 1, X); } return lower_bound_arr(arr, mid + 1, high, X); } public static void main(String args[]) throws NumberFormatException, IOException ,java.lang.Exception { Reader reader = new Reader(); //sieveOfEratosthenes(); //Scanner reader=new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); // BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // int cases=Integer.parseInt(br.readLine()); // int cases=1; int cases=reader.nextInt(); while (cases-->0){ // long N=reader.nextLong(); //long M=reader.nextLong(); int N=reader.nextInt(); // int P=reader.nextInt(); //// // String[] first=br.readLine().split("" ""); // long N=Long.parseLong(first[0]); // long K=Long.parseLong(first[1]); // long X=Long.parseLong(first[2]); // String s2=br.readLine(); // String s3=br.readLine(); // char[] s11=s2.toCharArray(); // char[] s12=new char[s11.length]; //int max=Integer.MIN_VALUE; // int min=Integer.MAX_VALUE; //int mod=1000000007; // HashMap> map=new HashMap>(); HashMap map=new HashMap(); // HashMap map=new HashMap(); // HashMap map1=new HashMap(); //HashMap path=new HashMap(); //TreeMap map=new TreeMap(Collections.reverseOrder()); // HashSet set =new HashSet(); // HashSet right =new HashSet(); // TreeSet a =new TreeSet(); //TreeSet b =new TreeSet(); // TreeSet map=new TreeSet(); // long[] arr=new long[N]; // int[] odd=new int[100001]; int[] sec=new int[N]; int[] pow=new int[N]; // int[][] arr=new int[N][P]; ArrayList list=new ArrayList(); // ArrayList list3=new ArrayList(); // ArrayList list1=new ArrayList(); // ArrayList bees=new ArrayList(); // boolean[]arr1=new boolean[N]; // // for(int i=0;i=0) { // System.out.println(last +"" ""+ind); if(sec[i]>=ind) { if(sec[i]-ind+1 arr0=new ArrayList<>(); ArrayList arr1=new ArrayList<>(); for(int i=0;i z = new ArrayList<>(); List o = new ArrayList<>(); int cnt = 0; for (int i = 0; i < n; i++) { if (arr[i] == 0) { cnt++; z.add(i); }else{ o.add(i); } } int[][] dp = new int[cnt + 1][(n - cnt) + 1]; int one = n - cnt; Arrays.fill(dp[0], 100000000); dp[0][0] = 0; // System.out.println(one); int min = 100000000; for (int i = 1; i <= cnt; i++) {// the position of zero, Arrays.fill(dp[i], 100000000); dp[i][0] = 0; for (int j = 1; j <= Math.min(one, i); j++) {// the position of one if (cnt - i < one - j){ dp[i][j] = 100000000; }else{ dp[i][j] = Math.min(dp[i - 1][j - 1] + Math.abs(o.get(j - 1) - z.get(i - 1)), dp[i - 1][j]); } if (j == one){ min = Math.min(min, dp[i][j]); } } } min = Math.min(min, dp[0][n - cnt]); out.println(min); } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop 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; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static int[] sieveEratosthenes(int n) { if (n <= 32) { int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; for (int i = 0; i < primes.length; i++) { if (n < primes[i]) { return Arrays.copyOf(primes, i); } } return primes; } int u = n + 32; double lu = Math.log(u); int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)]; ret[0] = 2; int pos = 1; int[] isnp = new int[(n + 1) / 32 / 2 + 1]; int sup = (n + 1) / 32 / 2 + 1; int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; for (int tp : tprimes) { ret[pos++] = tp; int[] ptn = new int[tp]; for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31); for (int j = 0; j < sup; j += tp) { for (int i = 0; i < tp && i + j < sup; i++) { isnp[j + i] |= ptn[i]; } } } // 3,5,7 // 2x+3=n int[] magic = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14}; int h = n / 2; for (int i = 0; i < sup; i++) { for (int j = ~isnp[i]; j != 0; j &= j - 1) { int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27]; int p = 2 * pp + 3; if (p > n) break; ret[pos++] = p; if ((long) p * p > n) continue; for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q; } } return Arrays.copyOf(ret, pos); } // reverse division for 2 public static long[] rdiv2(int n, int mod){ long[] arr = new long[n + 5]; arr[0] = 1; long rev2 = (mod + 1) / 2; for (int i = 1; i < n; i++) { arr[i] = arr[i - 1] * rev2 % mod; } return arr; } static List primeFactors(int n) { // Print the number of 2s that divide n List ls = new ArrayList<>(); if (n % 2 == 0) ls.add(2); while (n%2==0) { n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n if (n % i == 0) ls.add(i); while (n%i == 0) { n /= i; } } if (n > 1) ls.add(n); return ls; } static int find(int i, int[] par){ if (par[i] < 0) return i; return par[i] = find(par[i], par); } static boolean union(int i, int j, int[] par){ int pi = find(i, par); int pj = find(j, par); if (pi == pj) return false; if (par[pi] < par[pj]){ par[pi] += par[pj]; par[pj] = pi; }else{ par[pj] += par[pi]; par[pi] = pj; } return true; } } ",0,Non-Plagiarised 42fe7dd0,9291ca83,"import java.util.*; public class Solution { static Scanner sc=new Scanner(System.in); public static void main(String args[]) { int t=sc.nextInt(); outer:while(t-->0){ int n=sc.nextInt(); int[][] ct=new int[n][5]; int[] len=new int[n]; for (int i=0;i=0;j--){ sum+=diff[j]; if (sum>0) { inc++; }else { break; } } mx=Math.max(mx,inc); } System.out.println(mx); } } } ","import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Practice { static HashMap map = new HashMap<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); int[][] occurances = new int[5][n]; for(int i=0;i=0;j--){ tmpSum+=occurances[i][j]; if(tmpSum>0) tmpAns++; else break; } ans = Math.max(ans, tmpAns); } System.out.println(ans); } } } ",1,"(L3) Similar main, variable name change, different spacing, different imports. Changing the order of declaration." 4a1573d6,db8d728d," import java.util.*; import java.math.*; import java.io.*; public class A{ static FastReader scan=new FastReader(); public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); static LinkedListedges[]; static boolean stdin = true; static String filein = ""input""; static String fileout = ""output""; static int dx[] = { -1, 0, 1, 0 }; static int dy[] = { 0, 1, 0, -1 }; int dx_8[]={1,1,1,0,0,-1,-1,-1}; int dy_8[]={-1,0,1,-1,1,-1,0,1}; static char sts[]={'U','R','D','L'}; static boolean prime[]; static long LCM(long a,long b){ return (Math.abs(a*b))/gcd(a,b); } public static int upperBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = low+(high-low) / 2; if ( array[mid]>value) { high = mid ; } else { low = mid+1; } } return low; } static long gcd(long a, long b) { if(a!=0&&b!=0) while((a%=b)!=0&&(b%=a)!=0); return a^b; } static int countSetBits(int n) { int count = 0; while (n > 0) { if((n&1)!=1) count++; //count += n & 1; n >>= 1; } return count; } static void sieve(long n) { prime = new boolean[(int)n+1]; for(int i=0;iinters=new ArrayList(); static StringBuilder sb; static void swap(int i,int j,StringBuilder st) { char tmp=st.charAt(i); st.setCharAt(i,st.charAt(j)); st.setCharAt(j,tmp); } private static int next(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to right side if target is // greater. if(arr[mid]==target) return mid; if (arr[mid] { public int compare(String o1,String o2){ return o1.length()-o2.length(); } } public static class comp2 implements Comparator{ public int compare(String o1,String o2){ return o1.compareTo(o2); } } static StringBuilder a,b; static boolean isPowerOfTwo(int 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 ArrayListv; static ArrayListpows; static void block(long x) { v = new ArrayList(); pows=new ArrayList(); while (x > 0) { v.add((int)x % 3); x = x / 3; } // Displaying the output when // the bit is '1' in binary // equivalent of number. for (int i = 0; i < v.size(); i++) { if (v.get(i)==1||v.get(i)==0) { pows.add(i); } } } static long mod=(long)(1e9)+7; static int countWaysUtil(int x, int n, int num) { // Base cases int val = (int) (x - Math.pow(num, n)); if (val == 0) return 1; if (val < 0) return 0; // Consider two possibilities, num is // included and num is not included. return countWaysUtil(val, n, num + 1) + countWaysUtil(x, n, num + 1); } static int countWays(int x, int n) { return countWaysUtil(x, n, 1); } static int dp[][]; static int n; static int arr[]; static int rec(int i,int prev) { if(i==n) return 0; if(dp[i][prev]!=-1){ //out.println(""FUCK""); return dp[i][prev]; } if(i==0) return dp[i][prev]=Math.max(rec(i+1,1),rec(i+1,0)); else return dp[i][prev]=Math.max(rec(i+1,0)+Math.abs(arr[i]-(prev==0?arr[i-1]:1)),rec(i+1,1)+Math.abs(1-(prev==0?arr[i-1]:1))); } static boolean can(int i,int j) { int x=i,y=j; int x2=Math.abs(y-x),y2=y+x; if(x>=x2&&y<=y2) return true; return false; } public static void main(String[] args) throws Exception { //SUCK IT UP AND DO IT ALRIGHT //scan=new FastReader(""div7.in""); //out = new PrintWriter(""div7.out""); //System.out.println(countSetBits(2015)); //int elem[]={1,2,3,4,5}; //System.out.println(""avjsmlfpb"".compareTo(""avjsmbpfl"")); int tt=1; /*for(int i=0;i<=100;i++) if(prime[i]) arr.add(i); System.out.println(arr.size());*/ // check(new StringBuilder(""05:11"")); // System.out.println(26010000000000L%150); tt=scan.nextInt(); outer:while(tt-->0) { int n=scan.nextInt(),m=scan.nextInt(); char board[][]=new char[n][m]; for(int i=0;ires[]=new ArrayList[3*n*m]; for(int i=0;i<3*n*m;i++) res[i]=new ArrayList(); int k=0; for(int i=0;iarr=new ArrayList(); ArrayListarr2=new ArrayList(); if(i+1 0) { if (e % 2 == 1) r = r * b ; b = b * b; e >>= 1; } return r; } private static void sort(long[] arr) { List list = new ArrayList<>(); for (long object : arr) list.add(object); Collections.sort(list); //Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } private static void sort2(long[] arr) { List list = new ArrayList<>(); for (long object : arr) list.add(object); Collections.sort(list); Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } public static class FastReader { BufferedReader br; StringTokenizer root; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } FastReader(String filename)throws Exception { br=new BufferedReader(new FileReader(filename)); } boolean hasNext(){ String line; while(root.hasMoreTokens()) return true; return false; } String next() { while (root == null || !root.hasMoreTokens()) { try { root = new StringTokenizer(br.readLine()); } catch (Exception addd) { addd.printStackTrace(); } } return root.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (Exception addd) { addd.printStackTrace(); } return str; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextInt(); } return array; } } static class Pair implements Comparable{ public int x, y; public Pair(int x1, int y1) { x=x1; y=y1; } @Override public int hashCode() { return (int)(x + 31 * y); } public String toString() { return x + "" "" + y; } @Override public boolean equals(Object o){ if (o == this) return true; if (o.getClass() != getClass()) return false; Pair t = (Pair)o; return t.x == x && t.y == y; } public int compareTo(Pair o) { return (o.y-y); } static class pair{ int i; int j; pair(int i,int j){ this.i=i; this.j=j; }}} static class tuple{ int x,y,z; tuple(int a,int b,int c){ x=a; y=b; z=c; } } static class Edge{ int d,w; Edge(int d,int w) { this.d=d; this.w=w; } } } ","import java.util.*; import java.io.*; import java.math.*; import java.lang.*; public class BinaryTable { // static int mod = 998244353; static int mod = 1000000007; private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws Exception { FastReader scn = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scn.nextInt(); outer : while(t-->0){ int n = scn.nextInt(); int m = scn.nextInt(); int[][] arr = new int[n][m]; for(int i=0; i list = new ArrayList<>(); if(n % 2 == 0 && m % 2 == 0){ for(int i=0; i list = new ArrayList<>(); for (int i=0; i list = new ArrayList<>(); for(int i=0; i list = new ArrayList<>(); // for(int i=0; i list = new ArrayList<>(); for (int i=0; i list = new ArrayList<>(); for (int i=0; i list){ Collections.sort(list, Collections.reverseOrder()); } private static int lowerBound(int[] arr, int x){ int n = arr.length, si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(arr[mid] == x){ if(mid-1 >= 0 && arr[mid-1] == arr[mid]){ ei = mid-1; }else{ return mid; } }else if(arr[mid] > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } private static int upperBound(int[] arr, int x){ int n = arr.length, si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(arr[mid] == x){ if(mid+1 < n && arr[mid+1] == arr[mid]){ si = mid+1; }else{ return mid + 1; } }else if(arr[mid] > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } private static int upperBound(ArrayList list, int x){ int n = list.size(), si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(list.get(mid) == x){ if(mid+1 < n && list.get(mid+1) == list.get(mid)){ si = mid+1; }else{ return mid + 1; } }else if(list.get(mid) > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } // (x^y)%p in O(logy) private static long power(long x, long y){ long res = 1; x = x % mod; while(y > 0){ if ((y & 1) == 1){ res = (res * x) % mod; } y = y >> 1; x = (x * x) % mod; } return res; } public static boolean nextPermutation(int[] arr) { if(arr == null || 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; } if(last >= 0){ int nextGreater = arr.length-1; for(int i=arr.length-1; i>last; i--){ if(arr[i] > arr[last]){ nextGreater = i; break; } } swap(arr, last, nextGreater); } reverse(arr, last+1, arr.length-1); return true; } private static void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } private static void reverse(int[] arr, int i, int j){ while(i < j){ swap(arr, i++, j--); } } private static String reverseStr(String s){ StringBuilder sb = new StringBuilder(s); return sb.reverse().toString(); } // TC- O(logmax(a,b)) private static int gcd(int a, int b) { if(a == 0){ return b; } return gcd(b%a, a); } private static long gcd(long a, long b) { if(a == 0L){ return b; } return gcd(b%a, a); } private static long lcm(long a, long b) { return a / gcd(a, b) * b; } // TC- O(logmax(a,b)) private static int lcm(int a, int b) { return a / gcd(a, b) * b; } private static long inv(long x){ return power(x, mod - 2); } private static long summation(long n){ return (n * (n + 1L)) >> 1; } }",0,Non-Plagiarised 722e318f,c9159d9c,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; public class TaskB { static long mod = 1000000007; static FastScanner scanner; static final StringBuilder result = new StringBuilder(); public static void main(String[] args) { // 2 : 1000000000 scanner = new FastScanner(); int T = scanner.nextInt(); for (int t = 0; t < T; t++) { solve(t + 1); result.append(""\n""); } System.out.println(result); } static void solve(int t) { int n = scanner.nextInt(); int[] a = scanner.nextIntArray(n); String s = scanner.nextToken(); List blue = new ArrayList<>(); List red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (s.charAt(i) == 'B') { blue.add(a[i]); } else { red.add(a[i]); } } Collections.sort(blue); Collections.sort(red); for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < i + 1) { result.append(""NO""); return; } } for (int i = 0; i < red.size(); i++) { if (red.get(i) > i + 1 + blue.size()) { result.append(""NO""); return; } } result.append(""YES""); } static class WithIdx implements Comparable { int val, idx; public WithIdx(int val, int idx) { this.val = val; this.idx = idx; } @Override public int compareTo(WithIdx o) { if (val == o.val) { return Integer.compare(idx, o.idx); } return Integer.compare(val, o.val); } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } String[] nextStringArray(int n) { String[] res = new String[n]; for (int i = 0; i < n; i++) res[i] = nextToken(); return res; } } static class PrefixSums { long[] sums; public PrefixSums(long[] sums) { this.sums = sums; } public long sum(int fromInclusive, int toExclusive) { if (fromInclusive > toExclusive) throw new IllegalArgumentException(""Wrong value""); return sums[toExclusive] - sums[fromInclusive]; } public static PrefixSums of(int[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } public static PrefixSums of(long[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } } static class ADUtils { static void sort(int[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } static void reverse(int[] arr) { int last = arr.length / 2; for (int i = 0; i < last; i++) { int tmp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = tmp; } } static void sort(long[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } } static class MathUtils { static long[] FIRST_PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051}; static long[] primes(int to) { long[] all = new long[to + 1]; long[] primes = new long[to + 1]; all[1] = 1; int primesLength = 0; for (int i = 2; i <= to; i++) { if (all[i] == 0) { primes[primesLength++] = i; all[i] = i; } for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) { all[(int) (i * primes[j])] = primes[j]; } } return Arrays.copyOf(primes, primesLength); } static long modpow(long b, long e, long m) { long result = 1; while (e > 0) { if ((e & 1) == 1) { /* multiply in this bit's contribution while using modulus to keep * result small */ result = (result * b) % m; } b = (b * b) % m; e >>= 1; } return result; } static long submod(long x, long y, long m) { return (x - y + m) % m; } static long modInverse(long a, long m) { long g = gcdF(a, m); if (g != 1) { throw new IllegalArgumentException(""Inverse doesn't exist""); } else { // If a and m are relatively prime, then modulo // inverse is a^(m-2) mode m return modpow(a, m - 2, m); } } static public long gcdF(long a, long b) { while (b != 0) { long na = b; long nb = a % b; a = na; b = nb; } return a; } } } /* 5 3 2 3 8 8 2 8 5 10 1 */","import java.util.*; public class SolutionB { public static long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ",0,Non-Plagiarised 0ca738ce,931faca2,"import java.io.*; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class G { public static void main(String[] args) { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); Task solver = new Task(); int t = 1; for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out); out.close(); } static class Task { static int max = (int) (4e5), MOD = 998244353; static long[] fact = new long[max+1], invFact = new long[max+1], naturalInverse = new long[max+1]; public void solve(int testNumber, FastReader scan, PrintWriter out) { int n = scan.nextInt(), k = scan.nextInt(); Item[] lanterns = new Item[2 * n]; for(int i = 0; i < n; i++) { int l = scan.nextInt(), r = scan.nextInt(); lanterns[i * 2] = new Item(l, 0); lanterns[i * 2 + 1] = new Item(r, 1); } Arrays.sort(lanterns); precomp(); int have = 0; long ans = 0; for(Item x : lanterns) { if(x.start == 1) have--; else { ans = (ans + binomial(have, k - 1)) % MOD; have++; } } out.println(ans); } static class Item implements Comparable { int val; int start; public Item(int a, int b) { val = a; start = b; } @Override public int compareTo(Item item) { int ret = Integer.compare(val, item.val); if(ret == 0) ret = Integer.compare(start, item.start); return ret; } } static void precomp() { fact[0] = invFact[0] = invFact[1] = naturalInverse[0] = naturalInverse[1] = 1; for(int i = 1; i <= max; i++) { fact[i] = (fact[i-1]*i)%MOD; if(i == 1) continue; naturalInverse[i] = naturalInverse[MOD % i] * (MOD - MOD/i) % MOD; invFact[i] = (invFact[i-1]*naturalInverse[i])%MOD; } } static long binomial(int a, int b) { if(a < b) return 0; return ((fact[a]*invFact[b])%MOD*invFact[a-b])%MOD; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } 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; } } }","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[][][][]; static int mod=1000000007; static int mod1=998244353; static int max; static long bit[]; static long seg[]; static long fact[]; static long A[]; static long[] fac = new long[300001]; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { //CHECK FOR N=1 //CHECK FOR N=1 //StringBuffer sb=new StringBuffer(""""); int ttt=1; // ttt =i(); fac[0] = 1; for (int i = 1; i <= 300000; i++) fac[i] = fac[i - 1] * i % mod1; outer :while (ttt-- > 0) { int n=i(); int k=i(); Pair P[]=new Pair[2*n]; int c=0; for(int i=0;i { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return +1; else if(this.xo.y) return +1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END //static void add(int v) { // if(!map.containsKey(v)) { // map.put(v, 1); // } // else { // map.put(v, map.get(v)+1); // } //} //static void remove(int v) { // if(map.containsKey(v)) { // map.put(v, map.get(v)-1); // if(map.get(v)==0) // map.remove(v); // } //} public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, 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; } } } ",0,Non-Plagiarised ba468e1f,d9199dfd,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = fastReader.nextInt(); } ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); char c[] = fastReader.next().toCharArray(); for (int i = 0; i < n; i++) { if (c[i] == 'B') { b.add(a[i]); } else { r.add(a[i]); } } Collections.sort(b); Collections.sort(r); int sizeb = b.size(); boolean isValid = true; for (int i = 1 , j = 0; i <=sizeb; i++ , j++){ if (b.get(j) < i){ isValid =false; } } for (int i = sizeb+1 , j = 0; i <=n && j < r.size(); i++ , j++){ if (r.get(j) > i){ isValid =false; } } if (isValid){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Simple{ public static void main(String args[]){ //System.out.println(""Hello Java""); Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t>0){ int n = s.nextInt(); int arr[] = new int[n]; for(int i=0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int i=0;istart){ bool = false; break; } start++; } if(bool){ System.out.println(""YES""); } else{ System.out.println(""NO""); } } t--; } s.close(); } } ",0,Non-Plagiarised c4ca2ff3,d83f74f7,"/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); PrintWriter out=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int freq[][]=new int[n][5]; int rem[][]=new int[n][5]; for(int i=0;i=0;k--) { if(sum+arr[k]>0) { sum=sum+arr[k]; total++; } else { break; } } ans=Math.max(ans,total); } out.println(ans); } out.flush(); out.close(); } } ","import java.util.*; import java.io.*; import java.math.*; public class A { static FastReader sc=new FastReader(); static long dp[][]; static int mod=1000000007; static int max; static int bit[]; static long ans; static HashMap map; public static void main(String[] args) { //CHECK FOR N=1 //CHECK FOR N=1 PrintWriter out=new PrintWriter(System.out); StringBuffer sb=new StringBuffer(""""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); String A[]=inputS(n); Pair P[]=new Pair[n]; int B[][]=new int[n][5]; for(int i=0;i { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { int a=o.y-o.x; int b=this.y-this.x; if(a>b) return 1; else if(a o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } // public int hashCode() // { // final int temp = 14; // int ans = 1; // ans =x*31+y*13; // return ans; // } // // // Equal objects must produce the same // // hash code as long as they are equal // @Override // public boolean equals(Object o) // { // if (this == o) { // return true; // } // if (o == null) { // return false; // } // if (this.getClass() != o.getClass()) { // return false; // } // Pair other = (Pair)o; // if (this.x != other.x || this.y!=other.y) { // return false; // } // return true; // } } //FRENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, 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; } } } ",0,Non-Plagiarised