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); } } ","import java.io.*; import java.util.*; public class Main { static long mod = 1000000007; 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(); } } ",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 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(); } } ","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,"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; } int bit[]=new int[(int)1e6]; /////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// } ","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 MyWriter extends PrintWriter { private MyWriter(OutputStream outputStream) { super(outputStream); } void println(int[] a) { for (int v : a) { println(v); } } 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; } 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 { public static void main(String[] args) { MyScanner sc = new MyScanner(); int t = sc.nextInt(); while (t-- != 0) { int n = sc.nextInt(); long a[] = new long[n]; for(int i=0;i0){ 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; } } static class Block implements Comparable{ int i, w; public Block(int a, int b) { i=a; w=b; } } 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(); } } } ","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; } } ",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); } } } ",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; i0) { 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;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); } } } ","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); } } } ",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 */ // 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()); } 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;i 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 class Pair implements Comparable{ char x; int y; Pair(char x, int y){ this.x = x; this.y = y; } } // 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()); // } // // } } ","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; } } } ",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;i0){ 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,"import java.io.*; import java.util.*; public class Solution { 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(); } } ","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); } } ","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(); } } ",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--; } } } ","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 { //************************* FR CLASS ENDS ********************************** static long mod = (long) (1e9 + 7); // ----------------------------------DSU-------------------------------- static int parent[]; static int rank[]; /* ***************************************************************************************************************************************************/ 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,"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; } } /*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; /* for (1/a)%mod = ( a^(mod-2) )%mod ----> use expo to calc -->(a^(mod-2)) */ 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 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); } } ","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() { }); 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; /* for (1/a)%mod = ( a^(mod-2) )%mod ----> use expo to calc -->(a^(mod-2)) */ 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 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 final long mod=(long)1e9+7; /*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; } }*/ 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 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 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; // } // } // } } ","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; } } } ",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(); } } ","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 int MOD=1000003; public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); FastWriter out = new FastWriter(); int t=in.nextInt(); //int t=1; while (t-->0){ 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])); } ",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(); } } ","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,"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 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]); } } } ",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,"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); } // 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 protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } } // Function to precompute inverse of factorials // Function to calculate factorial of 1 to 200001 // Function to return nCr % p in O(1) time } ",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; } } ",0,Non-Plagiarised 3e93b259,a60fba84,"import java.util.*; import java.io.*; public class Main { 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])); } } } ","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; } // SIMPLE POWER FUNCTION=> } ","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); } } } } ",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; 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=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i= 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(); } } ","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(); } } ",1,EM 3c74c140,732c98a0,"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; } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; 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; } void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i= 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 long MOD=1000000000; 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""); } } ","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; } } ","import java.util.*; import java.io.*; public class AiseHi { static Scanner sc = new Scanner(System.in); public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); z : while(t-->0) { 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 boolean check(long n,long val) { // if(n == 0) return true; // // while(val<=n) { //// if(check(n-val,)) // } // } // static int ceil(int a,int b) { // return a/b + (a%b==0?0:1); // } // static int fac[] = new int[2000009]; // static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } } ",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 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; } } ",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(available[] 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());} } ","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) { 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) // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step // function to find first index >= x // function to find last index <= y // function to count elements within given range int[] fact= new int[MAXN]; int[] inv= new int[MAXN]; 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; // } // } } // fast input reader class; } ",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[] 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 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+""ms""); } private static boolean oj = System.getProperty(""ONLINE_JUDGE"") != null; ///////////////////////////////////////////////////////////////////////////////////////////////////////// //custom multiset (replace with HashMap if needed) // compress Big value to Time Limit // Fast Writer // Fast Inputs } ","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; } 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; } 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); } } } ","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(); } } ",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; } } ","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 int i() { return sc.nextInt(); } static String s() { return sc.next(); } 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) { //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 final Random random=new Random(); } ","import java.util.*; import java.io.*; public class Main{ public static class Node { int val; Node left; Node right; Node(int val) { this.val=val; } } public static void main(String[] args) throws java.io.IOException { 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;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""); } } } ",0,Non-Plagiarised 68cdd55d,c18048bf,"import java.io.*; import java.util.*; public class Main { static PrintWriter out; static FastReader sc; public static void main(String[] args) throws FileNotFoundException { boolean t = true; boolean f = false; if (f) { out = new PrintWriter(""output.txt""); sc = new FastReader(""input.txt""); } else { out = new PrintWriter((System.out)); sc = new FastReader(); } 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(); } } ","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 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=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; } // SIMPLE POWER FUNCTION=> } ","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 final Random random=new Random(); } ",0,Non-Plagiarised 9c55bc1b,c9da41af,"import java.util.*; import java.io.*; public class Main { static MyScanner sc; static PrintWriter out; static { sc = new MyScanner(); out = new PrintWriter(System.out); } public static void bfs(Node[] g, int[] ans) { Arrays.fill(ans, -1); boolean[] visited = new boolean[g.length]; Queue 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<>(); } } ","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 print(int s) { System.out.print(s); } 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 Edge { int node, index; Edge(int node, int index) { this.node = node; this.index = index; } } ",0,Non-Plagiarised 856a8eda,c354b74f,"import java.io.*; import java.util.*; public class three{ public static class Pair implements Comparable{ int min; int idx; } 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 + ""]""; // } // } //-------------------------------------------------------- } ","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 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 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; } 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; } 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; } 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; } 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 0 ) { solve(); } System.out.println(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[] 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 print(int s) { System.out.print(s); } 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 Edge { int node, index; Edge(int node, int index) { this.node = node; this.index = index; } } ","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 { 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 } static int mod =(int)(1e9+7); static long mod(long x) { return ((x % mod + mod) % mod); } static long add(long x, long y) { return mod(mod(x) + mod(y)); } //Fast Power(logN) static void printArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } } ","import java.io.*; import java.lang.*; import java.util.*; public class c { public static int[] ia(int n) { int ar[]=new int[n]; return ar; } static class pair implements Comparable{ int ht; int id; pair(int ht, int id) { this.ht=ht; this.id=id; } } 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,"import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out; static FastReader scan; /*-------- I/O usaing short named function ---------*/ public static int ni(){return scan.nextInt();} public static long nl(){return scan.nextLong();} public static void pn(Object o){out.println(o);} /*-------- for output of an array ---------------------*/ /*-------------- for input in an array ---------------------*/ /*------------ for taking input faster ----------------*/ // Method to check if x is power of 2 //Method to return lcm of two numbers //Method to count digit of a number //Method for sorting //Method for checking if a number is prime or not static long[] l, r; public static void main (String[] args) throws java.lang.Exception { OutputStream outputStream =System.out; out =new PrintWriter(outputStream); scan =new FastReader(); //for fast output sometimes StringBuilder sb = new StringBuilder(); int t = ni(); while(t-->0){ 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 { 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 { // 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. static int dp[][]; 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;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 { 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(); } } ",1,"(L5) similar main code with variable renaming, different imports, additional lines. Extra comments. FastReader Class. Nested vs single if statement." d1cd194e,dbffab11,"import java.util.*; import java.lang.*; import java.io.*; public class Template { // static void solve(String s) // { //// Scanner sc = new Scanner(System.in); //// String s = sc.next(); // // int x[] = new int[2]; // x[0] = x[1] = -1; // // int ans = 0; // int n = s.length(); // 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; } } 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(); } } } ","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{ } static class Node{ int sum; int build; Node(int sum ,int build) { this.sum=sum; this.build=build; } } } ",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); } } ","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,"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); } } } ","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[] 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; } } 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); } } } // >>>>>>>>>>> Code Ends <<<<<<<<< // // --For Rounding--// // ----Greatest Common Divisor-----// // --- permutations and Combinations ---// static long fact[]; static long invfact[]; // ---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 ------// // --- Fast exponentiation ---// // >>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<< // } ",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(); } } ","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()); } } class Solver{ public int solve(String[] words) throws IOException{ char[] alphabets = {'a', 'b', 'c', 'd', 'e'}; int[][] arr = new int[5][words.length]; int i=0; for(String s : words) { char[] wordArr = s.toCharArray(); int j=0; for (char alpha : alphabets) { int counter = 0; for(char letter : wordArr){ if(alpha == letter) counter++; } arr[j][i] = 2*counter - s.length(); j++; } i++; } int[] ans = new int[5]; int m=0; for (int[] ar : arr) { Arrays.sort(ar); int val=0; int counter=0; for(i=ar.length-1; i>=0; i--){ val += ar[i]; if(val>0) counter++; else break; } ans[m] = counter; m++; } return Arrays.stream(ans).max().getAsInt(); } } ",0,Non-Plagiarised 4138b081,f729338f,"import java.io.*; import java.util.*; public class Contest1627C { 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 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 { 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; } } ",0,Non-Plagiarised 08cf0478,9291ca83,"import java.util.*; import java.io.*; public class Main { 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); } } } ","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; } } ",0,Non-Plagiarised 0b5cff5a,4fb09c5f,"import java.io.*; import java.text.DecimalFormat; import java.util.*; public class E { 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) { 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 } ",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); } } } } } ","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 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 = 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) { 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;i0){ 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 final Random random=new Random(); } ",0,Non-Plagiarised 7686c854,8a729537,"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;i0) { 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); } } } ",1,"(L3) similar main function with variable renaming, additional code, different imports. Additional unused functions." ae4d5b49,f665e87b,"import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException{ //BufferedReader f = new BufferedReader(new FileReader(""uva.in"")); BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = Integer.parseInt(f.readLine()); while(t-- > 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(); } // 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); } } } ",0,Non-Plagiarised b2590225,f7fc2e94,"import java.util.*; public class P3 { public static class tower implements Comparable{ ArrayList index; int size; tower(){ size = 0; index = new ArrayList<>(); } } 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 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(); } } ",0,Non-Plagiarised 298ee961,392218ef,"import java.util.*; import java.io.*; public class Main { static void printLine(String s) { System.out.println(s); } 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 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]; } ","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(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// } ",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; 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(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// } ",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{ 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 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,"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 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 { private static boolean[] isPrime; // static ArrayList[] 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; 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(); } } ","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 final Random random=new Random(); } ",0,Non-Plagiarised 8a5fe3d9,ea899386,"import java.io.*; import java.util.*; import java.text.*; import java.math.*; public class Main { static class pair implements Comparable{ int sum, index; pair(int i){ sum = 0; index = i; } } 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; } } 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; i0) { 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 int i() { return sc.nextInt(); } static String s() { return sc.next(); } 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 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;j0) { int n = sc.nextInt(); Set sums = new HashSet<>(); boolean found = false; int[] arr = readArrayInt(n); for(int j = 0;j[] 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.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 // 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; } } } ","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,"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; } } ","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; } } ",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 output(Object o){outputWln(""""+o+""\n""); } static void outputWln(Object o){try {out.write(""""+ o);} catch (Exception e) {}} static long mod=1000000007; // Global vars static BufferedWriter out; static InputReader reader; static int PX=Integer.MAX_VALUE; static int NX=Integer.MIN_VALUE; static void process() throws Exception { out = new BufferedWriter(new OutputStreamWriter(System.out)); reader = new InputReader(System.in); int T=reader.readInt(); int CX=26; for (int t=0;t 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 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""); } } } ",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(); } } ",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 Pair { int a, b; public Pair(int a, int b) { this.a = a; this.b = b; } } static boolean vis[]; public static void dfs(ArrayList> 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, 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 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 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); } } } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); /* 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 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ","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 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,"import java.util.*; import java.io.*; public class Main { PrintWriter out; FastReader sc; 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(); } /**************************************************************************************** *****************************************************************************************/ public int ni(){ return sc.nextInt(); }public char[] rl(){ return sc.nextLine().toCharArray(); } public void pl(Object s){ out.println(s); } public String next(){ return sc.next(); } void yes(){ pl(""YES""); }void no(){ pl(""NO""); } } ","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; } } 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; 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); } } ",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 { public static FastReader obj = new FastReader(); public static PrintWriter out = new PrintWriter(System.out); //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 int i() { return obj.nextInt(); } 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 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() { }); } // 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 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); } // 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 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>() { }); // 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; } } ","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 { 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,"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 pairr implements Comparable{ Integer value; Integer index; public pairr(Integer value, Integer index) { this.value = value; this.index = index; } } // Prints all prime numbers smaller than '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 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; } } 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 { 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; 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> 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; } } 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 //collections.sort use merge sort instead of quick sort but arrays.sort use quicksort whose worst time complexity is O(n^2) //function to print an array for debugging //normal gcd function, always put the greater number as a and the smaller number as b //to find gcd and lcm for numbers of long data type //Input Reader to read faster input } ",0,Non-Plagiarised 3088ca9c,7a9c69d8,"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--; } } } ","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; 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 void pn(Object o) { System.out.println(o); } static long[] takeLong(int n, FastScanner fs) { long[] arr=new long[n]; for(int i=0;i 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] 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""); } // Function to precompute inverse of factorials // Function to calculate factorial of 1 to 200001 // Function to return nCr % p in O(1) time } ","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 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); } // 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 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>() { }); // 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; } } ",0,Non-Plagiarised 23194f89,bcc5473d,"import java.io.*; import java.util.*; public class new1{ 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(); } } ","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; // method to return LCM of two numbers 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 >() { }); // 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] ; //if present - return the first occurrence of the no //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) //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)\ public static void sortbyColumn(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator() { }); } public static void sortbyColumn1(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator() { }); } 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); } // method to return LCM of two numbers // reverse division for 2 } ",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 int perm=0,FOR=0; static boolean flag=false; static int len=100000000; static ArrayListinters=new ArrayList(); static StringBuilder sb; 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] v; static ArrayListpows; static long mod=(long)(1e9)+7; static int dp[][]; static int n; static int arr[]; 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{ public int x, y; public Pair(int x1, int y1) { x=x1; y=y1; } } } ","import java.util.*; import java.io.*; import java.math.*; import java.lang.*; public class BinaryTable { // static int mod = 998244353; static int mod = 1000000007; 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 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""); } } ","import java.util.*; public class SolutionB { 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; } } 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; } } } ","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; } // public int hashCode() // { // final int temp = 14; // int ans = 1; // ans =x*31+y*13; // return ans; // } // @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; // } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > 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 //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 long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; 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; } static int i() { return sc.nextInt(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i 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""); } } } } ","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,"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 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; } /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > 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 //END static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i