filename_1,filename_2,code_1,code_2,labels,notes 51151974,c23278ec,"import java.io.*; import java.util.*; public class Solution{ public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int testCase = sc.nextInt(); while (testCase-->0){ int n = sc.nextInt(); String[] strArr = new String[n]; for(int i=0; i al = new ArrayList<>(); for(int i=0; i all = new ArrayList<>(); for(int j=0; j 0) { int n = in.nextInt(); String[] s = new String[n]; int[][] freq = new int[n][6]; for (int i = 0; i < n; i++) { s[i] = in.nextLine(); for (char c : s[i].toCharArray()) { freq[i][c - 'a']++; freq[i][5]++; } } int totmax = 0; for (int i = 0; i < 5; i++) { List diffs = new ArrayList<>(n); for (int j = 0; j < n; j++) { diffs.add(2 * freq[j][i] - freq[j][5]); } Collections.sort(diffs); Collections.reverse(diffs); int curr = 0, cnt = 0; while (cnt < diffs.size() && curr + diffs.get(cnt) > 0) { curr += diffs.get(cnt++); } totmax = Math.max(totmax, cnt); } out.println(totmax); } } } } ",0,Non-plagiarised 13441e8f,141effef,"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; 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 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,Plagiarised cdb801a1,e14d1ba0,"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.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;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]> 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;i 0){ int n=in.nextInt(); long[] k=new long[n]; long[] h=new long[n]; for(int i=0;ir){ //out.println(m); res[i]=res[i-1]+(m*(m+1))/2; power[i]=h[i]; } else{ res[i]=Long.MAX_VALUE; for(int j=i-1;j>=0;j--){ if(power[j]+k[i]-k[j] >= h[i]){ long x=power[j]+k[i]-k[j]; if(x>=h[i]){ if(k[i]-h[i]+1>k[j]){ power[i]=h[i]; res[i]=res[j]+(m*(m+1))/2; } else{ power[i]=x; long c=(x*(x+1))/2; long d=(power[j]*(power[j]+1))/2; res[i]=res[j]+c-d; } break; } } } } l=Math.min(l,lc); r=k[i]; } out.println(res[n-1]); } out.flush(); } } ","import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long k[]=new long[n]; for(int i=0;i al=new ArrayList<>(); long csp=h[n-1],idx=k[n-1]-h[n-1]; for(int i=n-2;i>=0;i--) { if(idx0){ 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; i0){ int n = sc.nextInt(); char[] a = sc.next().toCharArray(); char[] b = sc.next().toCharArray(); int a1=0, b1=0; for(int i=0;i0) { n = sc.nextInt(); H = new int[n]; int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { H[i] = sc.nextInt(); max = Math.max(H[i], max); min = Math.min(H[i], min); } int mid = 0; while (min < max) { mid = min + (max-min+1)/2; if(check(mid)) { min = mid; } else max = mid-1; } System.out.println(min); } } public static boolean check(int x){ int S[] = Arrays.copyOf(H, H.length); for (int i = n-1; i >= 2; i--) { if(S[i]=2){ // S[i]-=move*3; S[i-1]+=(move); S[i-2]+=2*(move); } } return S[0]>= x && S[1] >= x; } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class fastTemp { static int n; static int arr[]; public static void main(String[] args) { FastReader fs = new FastReader(); int t = fs.nextInt(); while(t-- >0){ n = fs.nextInt(); arr = new int[n]; int max = Integer.MIN_VALUE; for(int i=0;i=2;i--){ if(ar[i]=x && ar[1]>=x; } } ",1,Plagiarised 0df4050e,d9199dfd,"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.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(); } } ",1,Plagiarised df594a00,fcbe7917,"import java.io.*; import java.util.*; public class Codeforces { 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) { br.readLine(); String[] str = br.readLine().split("" ""); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int[] a = new int[k]; int[] t = new int[k]; str = br.readLine().split("" ""); for(int i=0; i=0; i--) { right[i] = Math.min(right[i], minright); minright = right[i] == Integer.MAX_VALUE ? Integer.MAX_VALUE : right[i]+1; } for(int i=0; i0){ String gap=br.readLine(); st=new StringTokenizer(br.readLine()); int n= Integer.parseInt(st.nextToken()); int k= Integer.parseInt(st.nextToken()); int pos[]=new int[k]; st=new StringTokenizer(br.readLine()); for(int i=0;i=0;i--){ if(min==Integer.MAX_VALUE){ min=ans[i]; } else{ min=Math.min(min+1,ans[i]); } r[i]=min; } for(int i=0;i> adj= new ArrayList<>(N); static { for(int i=0; i()); } } static int[][] a = new int[2][N]; static long[][] dp = new long[2][N]; static void dfs(int v, int p){ dp[0][v] = 0; dp[1][v]=0; for(int u: adj.get(v)) { if(u!=p) { dfs(u, v); dp[0][v] += Math.max(Math.abs(a[0][v] - a[1][u]) + dp[1][u], Math.abs(a[0][v] - a[0][u]) + dp[0][u]); dp[1][v] += Math.max(Math.abs(a[1][v] - a[1][u]) + dp[1][u], Math.abs(a[1][v] - a[0][u]) + dp[0][u]); } } } public static void main(String[] args) throws IOException{ // write your code here FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); for(int i=1; i<=n; i++) { a[0][i] = sc.nextInt(); a[1][i] = sc.nextInt(); adj.set(i, new ArrayList<>()); } for(int i=1; i> adj= new ArrayList<>(N); static { for(int i=0; i()); } } static int[][] a = new int[2][N]; static long[][] dp = new long[2][N]; static void dfs(int v, int p){ dp[0][v] = 0; dp[1][v]=0; for(int u: adj.get(v)) { if(u!=p) { dfs(u, v); dp[0][v] += Math.max(Math.abs(a[0][v] - a[1][u]) + dp[1][u], Math.abs(a[0][v] - a[0][u]) + dp[0][u]); dp[1][v] += Math.max(Math.abs(a[1][v] - a[1][u]) + dp[1][u], Math.abs(a[1][v] - a[0][u]) + dp[0][u]); } } } public static void main(String[] args) throws IOException{ // write your code here FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); for(int i=1; i<=n; i++) { a[0][i] = sc.nextInt(); a[1][i] = sc.nextInt(); adj.set(i, new ArrayList<>()); } 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.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;i=qs && se<=qe) return tree[index]; if(qeei) return; if(si == ei ) { tree[index] = arr[id]; return; } if(si > ei) return; int mid = (ei + si)/2; update( id, si, mid , 2*index); update( id , mid+1, ei , 2*index+1); tree[index] = Math.min(tree[2*index] ,tree[2*index+1]); } } */ /* ***************************************************************************************************************************************************/ // static MyScanner sc = new MyScanner(); // only in case of less memory static Reader sc = new Reader(); static StringBuilder sb = new StringBuilder(); public static void main(String args[]) throws IOException { int tc = 1; tc = sc.nextInt(); for(int i = 1 ; i<=tc ; i++) { // sb.append(""Case #"" + i + "": "" ); // During KickStart && HackerCup TEST_CASE(); } System.out.println(sb); } static void TEST_CASE() { int n = sc.nextInt(); ArrayList> adj = new ArrayList<>(); for(int i =0 ; i()); int[] U = new int[n-1] , V = new int[n-1]; for(int i = 0 ; i2) { sb.append(""-1\n""); return; } if(adj.get(i).size() == 1) { ind = i; } } Map map = new HashMap<>(); dfs(adj, ind, -1, true, map); for(int i =0 ; i> adj ,int u , int p ,boolean eve ,Map map ) { if(eve) { map.put(u+"" ""+p, 2); }else { map.put(u+"" ""+p, 3); } for(int v:adj.get(u)) { if(v == p) continue; eve = !eve; dfs(adj, v, u, eve, map); } } } ","import java.io.*; import java.util.*; public class new1{ public static void dfs(ArrayList > aList1, int p, int u, int[] ans, int v) { int[] aa = aList1.get(u).get(0); if(aa[0] != p) { ans[aa[1]] = v; if(v == 2) dfs(aList1, u, aa[0], ans, 3); else dfs(aList1, u, aa[0], ans, 2); } else if(aList1.get(u).size() > 1){ aa = aList1.get(u).get(1); ans[aa[1]] = v; if(v == 2) dfs(aList1, u, aa[0], ans, 3); else dfs(aList1, u, aa[0], ans, 2); } } 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(); ArrayList > aList1 = new ArrayList >(n + 1); for (int j = 1; j <= n + 1; j++) { ArrayList list = new ArrayList<>(); aList1.add(list); } for(int j = 0; j < n - 1; j ++) { int u = s.nextInt(); int v = s.nextInt(); int[] aa = {v, j}; int[] bb = {u, j}; aList1.get(u).add(aa); aList1.get(v).add(bb); } int pos = 1; int ind = -1; for(int i = 1; i <= n; i++) { if(aList1.get(i).size() > 2) { pos = 0; break; } if(aList1.get(i).size() == 1) { ind = i; } } if(pos == 0) { output.write(-1 + ""\n""); } else { int[] ans = new int[n - 1]; dfs(aList1, -1, ind, ans, 2); for(int i = 0; i < n - 1; i++) { output.write(ans[i] + "" ""); } output.write(""\n""); } } output.flush(); } } ",0,Non-plagiarised 8703709f,d2901569,"import java.io.*; import java.util.*; public class Main { // static boolean[] prime = new boolean[10000000]; final static long mod = 1000000007; public static void main(String[] args) { // sieve(); InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 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.util.Scanner; public class Solution { static int mod=1000000007;; // public static void main(String[] args) { // TODO Auto-generated method stub // System.out.println(); Scanner sc=new Scanner(System.in); int tt=sc.nextInt(); // // while(tt-->0){ int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;imap=new HashMap<>(); public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); //int testCases=1; while(testCases-- > 0){ solve(in); } out.close(); } catch (Exception e) { return; } } public static void solve( FastReader in){ int n=in.nextInt(); String s=in.next(); String t=in.next(); //int k=in.nextInt(); //long y=in.nextInt(); //long n=in.nextLong(); //int k=in.nextInt(); //long k=in.nextLong(); StringBuilder res=new StringBuilder(); char[] s1=s.toCharArray(); char[] t1=t.toCharArray(); int ans=n+2; int[] cnt={0,0}; for(int i=0;in){ res.append(""-1""); } else{ res.append(""""+ans); } //int ans=x.size()+y.size(); //res.append(""""+""Yes""); //res.append(""""+""""); System.out.println(res.toString()); } static < E > void print(E res) { System.out.println(res); } } ","import java.io.BufferedReader; import java.io.IOException; import java.lang.*; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; //Count the number of coprime's upto N // Returns nCr % p using Fermat's little theorem. //Modular Operations for Addition and Multiplication. /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-- > 0) { int n = sc.nextInt(); char[] a = sc.next().toCharArray(), b = sc.next().toCharArray(); int c00 = 0, c01 = 0, c10 = 0, c11 = 0; for(int i = 0;i seats,people; static int n1,n2; static long solve(int i,int j){ if(i==n1) return 0; long ans = Integer.MAX_VALUE; if(n1-i>n2-j) return ans; if(dp[i][j]!=-1) return dp[i][j]; ans = Math.min(solve(i,j+1),solve(i+1,j+1)+Math.abs(people.get(i)-seats.get(j))); // out.printf(""%d %d : %ld"",i,j,ans); return dp[i][j]=ans; } public static void main(String args[])throws IOException{ int n=sc.nextInt(); seats = new ArrayList<>(n/2); people = new ArrayList<>(n/2); for(int i=1;i<=n;i++){ if(sc.nextInt()==0){ seats.add(i); }else{ people.add(i); } } n1=people.size(); n2=seats.size(); // if(n2==n){ // out.println(0); // } dp = new long[n1][n2]; for(int i=0;i= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-- > 0) { int n = sc.nextInt(); char[] a = sc.next().toCharArray(), b = sc.next().toCharArray(); int c00 = 0, c01 = 0, c10 = 0, c11 = 0; for(int i = 0;i 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 35f0c004,efa38999,"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=input.nextInt(); while(T-->0) { int n=input.nextInt(); String a=input.next(); String b=input.next(); int same1=0,same0=0,opp1=0,opp0=0; for(int i=0;i 0) { int n = reader.nextInt(); String a = reader.nextLine(); String b = reader.nextLine(); ans = -1; int even_demand = 0; int odd_demand = 0; int same_ones = 0, same_zeros = 0; int diff_ones = 0, diff_zeros = 0; for(int i=0; i 0) { int n = fr.nextInt(), m = fr.nextInt(), x = fr.nextInt(); ArrayList pp = new ArrayList<>(); int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = fr.nextInt(); Pair pr = new Pair(A[i], i); pp.add(pr); } Collections.sort(pp); Collections.reverse(pp); int ps[] = new int[n]; int pk[] = new int[n]; Arrays.fill(ps, 0); Arrays.fill(pk, 0); int index = 0; for (int i = 0; i < n; i++) { if (pk[index] < x) { pk[index] += pp.get(i).a; } ps[pp.get(i).b] = index + 1; index++; index = index == m ? 0 : index; } pt.println(""YES""); for (int i = 0; i < n; i++) { pt.print(ps[i] + "" ""); } pt.println(); t--; } pt.close(); } catch ( Exception e) { return; } } static void merge(long arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; long L[] = new long[n1]; long R[] = new long[n2]; for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } static void sort(long arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; sort(arr, l, m); sort(arr, m + 1, r); merge(arr, l, m, r); } } static class Pair implements Comparable { int a, b; Pair(int a, int b) { this.a = a; this.b = b; } } } ","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(); } } } ",0,Non-plagiarised a7063d01,ac4d0fc5,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; 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); solve(in, out); out.close(); } static int parent[]; static int rank[]; static long m = 0; static int parent1[]; static int rank1[]; static long max1 = 0; static int count = 0; static int count1 = 0; static boolean possible; public static void solve(InputReader sc, PrintWriter pw){ int i, j = 0; // int t = 1; long mod = 1000000007; // int factors[] = new int[1000001]; // ArrayList ar = new ArrayList<>(); // sieveOfEratosthenes(1000000, factors, ar); // HashSet set = new HashSet<>(); // for(int x:ar){ // set.add(x); // } int t = sc.nextInt(); u: while (t-- > 0) { int n = sc.nextInt(); int e[][] = new int[n-1][2]; int x[] = new int[n]; int m = 0; for(i=0;i2) pw.println(-1); else{ if(n==2){ pw.println(2); } else if(n==3){ pw.println(2+"" ""+3); } else{ int d = 0; int ans[] = new int[n-1]; ArrayList ar[] = new ArrayList[n]; ArrayList ar1[] = new ArrayList[n]; for(i=0;i(); ar1[i] = new ArrayList<>(); } for(i=0;i ar[], ArrayList ar1[], int ans[], int par, int v){ if(ar[d].get(0)!=par){ ans[ar1[d].get(0)] = v; visit(ar[d].get(0), ar, ar1, ans, d, 5-v); return; } if(ar[d].size()==1) return; ans[ar1[d].get(1)] = v; visit(ar[d].get(1), ar, ar1, ans, d, 5-v); } } ","import java.io.*; import java.util.*; public class Main { static boolean[] ret; static boolean[] updated; static ArrayList[] adjacencyList; static Edge[] edgeList; static class Edge { int start, end, number; public Edge (int _start, int _end, int _number) { start = _start; end = _end; number = _number; } } public static void dfs(int node) { updated[node] = true; for (int next : adjacencyList[edgeList[node].start]) { if (!updated[next]) { ret[next] = !ret[node]; dfs(next); } } for (int next : adjacencyList[edgeList[node].end]) { if (!updated[next]) { ret[next] = !ret[node]; dfs(next); } } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int numCases = Integer.parseInt(br.readLine()); for (int i = 0; i < numCases; i++) { int numVertices = Integer.parseInt(br.readLine()); int[] numEdges = new int[numVertices]; edgeList = new Edge[numVertices - 1]; adjacencyList = new ArrayList[numVertices]; for (int j = 0; j < numVertices; j++) { adjacencyList[j] = new ArrayList<>(); } for (int j = 0; j < numVertices - 1; j++) { StringTokenizer st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken()) - 1; int b = Integer.parseInt(st.nextToken()) - 1; edgeList[j] = new Edge(a, b, j); numEdges[a]++; numEdges[b]++; adjacencyList[a].add(j); adjacencyList[b].add(j); } boolean good = true; for (int j = 0; j < numVertices; j++) { if (numEdges[j] > 2) { good = false; break; } } if (!good) { pw.println(-1); } else { ret = new boolean[numVertices - 1]; updated = new boolean[numVertices - 1]; dfs(0); for (boolean b : ret) { if (b) pw.print(5 + "" ""); else pw.print(2 + "" ""); } pw.println(); } } br.close(); pw.close(); } } ",0,Non-plagiarised 1162c08f,a4d6775d,"import java.util.*; public class CodeForces1525C{ 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()]); } } ","import java.io.*; import java.util.*; public class ArmChairs { public static int solution(int n, int[] arr) { ArrayList one = new ArrayList(); ArrayList zero = new ArrayList(); for (int i = 0; i < n; i++) { if (arr[i] == 1) { one.add(i); } else { zero.add(i); } } int[][] dp = new int[one.size() + 1][zero.size() + 1]; for (int i = 1; i <= one.size(); i++) { dp[i][i] = dp[i - 1][i - 1] + Math.abs(one.get(i - 1) - zero.get(i - 1)); for (int j = i + 1; j <= zero.size(); j++) { dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j - 1] + Math.abs(one.get(i - 1) - zero.get(j - 1))); } } return dp[one.size()][zero.size()]; } public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); String[] s = br.readLine().split("" ""); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(s[i]); } log.write(Integer.toString(solution(n, arr)) + ""\n""); log.flush(); } } ",1,Plagiarised 9fc811f7,cff39394,"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.util.ArrayList; 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); DTreeTag solver = new DTreeTag(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class DTreeTag { int diam = 0; public int dfs(ArrayList g[], int x, int depth[], int p) { int len = 0; for (int y : g[x]) { if (y != p) { depth[y] = depth[x] + 1; int cur = 1 + dfs(g, y, depth, x); diam = Math.max(diam, cur + len); len = Math.max(len, cur); } } return len; } public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int a = in.nextInt() - 1; int b = in.nextInt() - 1; int da = in.nextInt(); int db = in.nextInt(); int dis[] = new int[n]; ArrayList g[] = new ArrayList[n]; for (int i = 0; i < n; i++) g[i] = new ArrayList<>(); for (int i = 0; i < n - 1; i++) { int u = in.nextInt() - 1; int v = in.nextInt() - 1; g[u].add(v); g[v].add(u); } diam = 0; dfs(g, a, dis, -1); int disb = dis[b]; if (2 * da >= Math.min(diam, db) || disb <= da) { out.println(""Alice""); } else { out.println(""Bob""); } } } } ","import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class D { static int diam=0; public static int dfs(int a, int p,int[] depth,ArrayList[] list) { int len=0; for(int y:list[a]) { if(y==p) continue; depth[y]=depth[a]+1; int cur=1+dfs(y,a,depth,list); diam=Math.max(cur+len,diam); len=Math.max(cur, len); } return len; } public static void main(String[] args) { MyScanner s = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); try { int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int a=s.nextInt(); int b=s.nextInt(); int da=s.nextInt(); int db=s.nextInt(); ArrayList[] list=new ArrayList[n+1]; for(int i=0;i<=n;i++) list[i]=new ArrayList(); for(int i=0;i=Math.min(diam, db) || depth[b]<=da) { System.out.println(""Alice""); } else { System.out.println(""Bob""); } } out.close(); }catch(Exception e) { System.out.println(e); return; } } public static PrintWriter out; } ",1,Plagiarised 00af3420,86102d81,"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.*; import java.util.*; public class Aqueous { static MyScanner sc = new MyScanner(); public static void main(String[] args) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); String s[] = new String[n]; for(int i = 0; i=0; k--) { if(cur+ls[k]>=1) { cur+=ls[k]; score++; } } ans = Math.max(ans, score); } System.out.println(ans); } } } ",0,Non-plagiarised 1162c08f,734a94be,"import java.util.*; public class CodeForces1525C{ 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()]); } } ","import java.io.*; import java.math.*; import java.util.*; public class test { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuffer res = new StringBuffer(); int tc = 1; while(tc-->0) { int n = sc.nextInt(); ArrayList one = new ArrayList<>(); ArrayList zero = new ArrayList<>(); for(int i=0;i0) { z=c=0; n=d.nextInt(); int a[]=new int[n]; for(i=0;i= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long INF = 1000000000000000007L; int n = sc.nextInt(); long[] c = new long[n+1]; for(int i = 1;i<=n;i++) c[i] = sc.nextLong(); long ans = INF; long mo = INF, so = 0, co = 0; long me = INF, se = 0, ce = 0; for(int i=1;i<=n;i++) { if(i%2 == 1) { mo = min(mo,c[i]); so += c[i]; co++; } else { me = min(me,c[i]); se += c[i]; ce++; } if(i>=2) { long x = so + (n - co) * mo + se + (n - ce) * me; ans=min(ans,x); } } fout.println(ans); } fout.close(); } } ",0,Non-plagiarised 0922b7e7,d1cd194e,"import java.io.*; import java.util.*; public class PhoenixAndTowers { public static void main(String[] args) throws IOException { // BufferedReader in = new BufferedReader(new FileReader(""PhoenixAndTowers.in"")); // PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""PhoenixAndTowers.out""))); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int T = Integer.parseInt(in.readLine()); for (int i = 0; i < T; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int X = Integer.parseInt(st.nextToken()); PriorityQueue towers = new PriorityQueue(); for (int j = 1; j <= M; j++) towers.add(new Tower(j, 0)); out.println(""YES""); st = new StringTokenizer(in.readLine()); for (int j = 0; j < N; j++) { Tower t = towers.remove(); t.size += Integer.parseInt(st.nextToken()); towers.add(t); out.print(t.idx + "" ""); } out.println(); } out.close(); in.close(); } public static class Tower implements Comparable { int idx, size; public Tower(int idx, int size) { this.idx = idx; this.size = size; } } } ","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(); } } } ",0,Non-plagiarised 4303de0d,c9a316ca,"import java.io.*; import java.util.*; public class ParsasHumongousTree { static class Pair { int a; int b; public Pair(int a, int b) { this.a=a; this.b=b; } } static HashMap> edge=new HashMap(); static Pair a[]; static long dp[][]; static void dfs(int node, int parent) { for(int i:edge.get(node)) { if(i!=parent) { dfs(i,node); dp[node][0]+=Math.max(Math.abs(a[node].a-a[i].a)+dp[i][0],Math.abs(a[node].a-a[i].b)+dp[i][1]); dp[node][1]+=Math.max(Math.abs(a[node].b-a[i].a)+dp[i][0],Math.abs(a[node].b-a[i].b)+dp[i][1]); } } } public static void main(String args[]) { FastReader sc=new FastReader(); Output out=new Output(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); a=new Pair[n+1]; edge.clear(); for(int i=1;i list=edge.get(u); list.add(v); edge.put(u,list); } else { List list=new ArrayList(); list.add(v); edge.put(u,list); } if(edge.containsKey(v)) { List list=edge.get(v); list.add(u); edge.put(v,list); } else { List list=new ArrayList(); list.add(u); edge.put(v,list); } } dp=new long[n+1][2]; dfs(1,0); out.printLine(((long)Math.max(dp[1][0],dp[1][1]))); out.flush(); } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import static javax.swing.UIManager.get; import static javax.swing.UIManager.getString; public class Main { static class Pair implements Comparable { int x = 0; int y = 0; public Pair(int x1, int y1) { x = x1; y = y1; } } 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 6f393cfe,d3a0b8d2,"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; } } } ","import java.io.File; import java.io.IOException; import java.util.*; public class C { public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0){ int n = in.nextInt(); int[][] cnt = new int[n][5]; int[] len = new int[n]; for (int i = 0; i < n; i++){ String s = in.next(); len[i] = s.length(); for (char c : s.toCharArray()) cnt[i][c-'a']++; } int max = 0; for (int i = 0; i < 5; i++){ int[] diff = new int[n]; for (int j = 0; j < n; j++) diff[j] = cnt[j][i] - (len[j] - cnt[j][i]); Arrays.sort(diff); int j = n-2, sum = diff[n-1]; while (j>=0 && sum > 0){ max = Math.max(max, n - 1 - j); sum += diff[j]; j--; } if (sum > 0) max = Math.max(max, n); } System.out.println(max); } } } ",0,Non-plagiarised 8f6421f3,ea2fc2bc,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; public class Main{ public static void main (String[] args){ FastReader s = new FastReader(); int t=1;t=s.ni(); for(int test=1;test<=t;test++){ int n=s.ni(),k=s.ni(); int position[]=s.readArray(k),temp[]=s.readArray(k); int ans[]=new int[n]; Arrays.fill(ans,Integer.MAX_VALUE/2); for(int i=0;i=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i=0;i--) { dp[i]=Math.min(dp[i], dp[i+1]+1); } //Print(dp); /*for(int i=0;i 0) { int n = input.nextInt(); int m = input.nextInt(); int x = input.nextInt(); int arr[] = new int[n]; for(int i = 0; i < n; i++) arr[i] = input.nextInt(); PriorityQueue queue = new PriorityQueue(); out.println(""YES""); int res[] = new int[n]; for(int i = 1; i <= m; i++) { queue.add(new Pair(0, i)); } for(int i = 0; i < n; i++) { Pair p = queue.remove(); out.print(p.second()+"" ""); queue.add(new Pair(p.first()+arr[i], p.second())); } out.println(); out.flush(); } } } class Pair implements Comparable { public int x; public int y; public Pair(int x, int y) { this.x = x; this.y = y; } public int first() { return x; } public int second() { return y; } } ","import java.io.*; import java.util.*; public class Asd { static PrintWriter w = new PrintWriter(System.out); static FastScanner s = new FastScanner(); static boolean sd = false; public static void main(String[] args) { int t = s.nextInt(); //int t=1; while (t-- > 0) { solve(); } w.close(); } public static class Student { public int i1; public int value; // A parameterized student constructor public Student(int i1,int i2) { this.i1 = i1; this.value=i2; } public int getkey() { return i1; } public int getValue() { return value; } } static class StudentComparator implements Comparator{ // Overriding compare()method of Comparator // for descending order of cgpa } /* Function to print all the permutations of the string static String swap(String str, int i, int j) { char ch; char[] array = str.toCharArray(); ch = array[i]; array[i] = array[j]; array[j] = ch; return String.valueOf(array); } static void permute(String str,int low,int high) { if(low == high) list.add(Long.parseLong(str)); int i; for(i = low; i<=high; i++){ str = swap(str,low,i); permute(str, low+1,high); str = swap(str,low,i); } } use permute(str2,0,str2.length()-1); to perform combinations */ public static void solve() { int n=s.nextInt(); int m=s.nextInt(); int x=s.nextInt(); int arr[]=new int[n];int res[]=new int[n]; for(int i=0;i pq=new PriorityQueue(new StudentComparator()); 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;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,Plagiarised 16a2a867,3951966f,"import java.util.*; import java.io.*; public class Armchairs{ public static void main(String[] args) { FastReader fr = new FastReader(); PrintWriter out = new PrintWriter(System.out); Scanner sc= new Scanner (System.in); //Code From Here---- int t =fr.nextInt(); ArrayList chairs= new ArrayList<>(); ArrayList free= new ArrayList<>(); for (int i = 0; i < t; i++) { int state =fr.nextInt(); if(state==1) { chairs.add(i); } else{ free.add(i); } } int [][] dp=new int [t][t]; for (int[] is : dp) { Arrays.fill(is, -1); } int ans=solve(chairs,free,0,0,chairs.size(),dp); out.println(ans); out.flush(); sc.close(); } //This RadixSort() is for long method private static int solve(ArrayList chairs, ArrayList free, int i, int j, int size,int [][] dp) { if (dp[i][j]!=-1) { return dp[i][j]; } if (size==0) { return 0; } if (j==free.size()) { return 10000000; } int a=solve(chairs, free, i, j+1, size,dp); int b=Math.abs(chairs.get(i)-free.get(j))+solve(chairs, free, i+1, j+1, size-1,dp); dp[i][j]=Math.min(a, b); return dp[i][j]; } // For Fast Input ---- } ","import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; public class Armchairs { static ArrayList f; static ArrayList u; static int dp[][]; static int fun(int i, int j){ if(i == f.size()) return 0; if(j == u.size()) return 99999999; if(dp[i][j] != -1) return dp[i][j]; int ans1 = fun(i, j+1); int ans2 = fun(i+1, j+1) + Math.abs(f.get(i)-u.get(j)); return dp[i][j] = Math.min(ans1, ans2); } private static int solve(int n, int a[]) { for (int i = 0; i < n; i++) { if (a[i]==0) u.add(i); else f.add(i); } return fun(0,0); } public static void main(String[] args) throws IOException { Scanner s = new Scanner(); int t = 1; StringBuilder ans = new StringBuilder(); int count = 0; while (t-- > 0) { int n = s.nextInt(); int a[] = new int[n]; dp=new int[n][n]; for (int i = 0; i < n; i++) { a[i]=s.nextInt(); } f=new ArrayList<>(); u=new ArrayList<>(); for( int i=0; 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.util.*; public class Solution{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i l=new Vector<>(), r=new Vector<>(); for(int i=0;i n - i) ok = false; System.out.print((ok ? ""YES"" : ""NO"")+'\n'); } } } ",0,Non-plagiarised b728ba1d,d04e5afb,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.util.Objects; import java.util.Collections; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CPhoenixAndTowers solver = new CPhoenixAndTowers(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CPhoenixAndTowers { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); ArrayList> a = new ArrayList<>(); for (int i = 0; i < n; ++i) { a.add(new Pair<>(in.nextInt(), i)); } Collections.sort(a); int[] ans = new int[n]; int[] sum = new int[m]; int j = 1; for (int i = 0; i < n; ++i) { ans[a.get(i).y] = j; sum[j - 1] += a.get(i).x; j++; if (j == m + 1) j = 1; } for (int i = 1; i < m; ++i) { if (Math.abs(sum[i - 1] - sum[i]) > k) { out.println(""NO""); } } out.println(""YES""); for (int e : ans) { out.print(e + "" ""); } out.println(); } } static class Pair implements Comparable> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } } } ","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.util.Objects; import java.util.Collections; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CPhoenixAndTowers solver = new CPhoenixAndTowers(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CPhoenixAndTowers { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); ArrayList> a = new ArrayList<>(); for (int i = 0; i < n; ++i) { a.add(new Pair<>(in.nextInt(), i)); } Collections.sort(a); int[] ans = new int[n]; int[] sum = new int[m]; int j = 1; for (int i = 0; i < n; ++i) { ans[a.get(i).y] = j; sum[j - 1] += a.get(i).x; j++; if (j == m + 1) j = 1; } for (int i = 1; i < m; ++i) { if (Math.abs(sum[i - 1] - sum[i]) > k) { out.println(""NO""); } } out.println(""YES""); for (int e : ans) { out.print(e + "" ""); } out.println(); } } static class Pair implements Comparable> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } } } ",1,Plagiarised 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 18e2441c,b728ba1d,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.Map; import java.util.HashMap; public class cf1515 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } static class Task { public void solve(InputReader in, PrintWriter out) { int t = in.nextInt(); while (t-- != 0) { int n = in.nextInt(); int m = in.nextInt(); int x = in.nextInt(); TreeMap> map = new TreeMap<>(); for (int i = 0; i < n; i++) { int j = in.nextInt(); if (!map.containsKey(j)) { map.put(j, new ArrayList()); } map.get(j).add(i); } out.println(""YES""); int[] ans = new int[n]; int sta = 0; for (int s : map.keySet()) { for (int i = 0; i < map.get(s).size(); i++) { ans[map.get(s).get(i)] = (sta++) % m + 1; } } for(int i=0;i> a = new ArrayList<>(); for (int i = 0; i < n; ++i) { a.add(new Pair<>(in.nextInt(), i)); } Collections.sort(a); int[] ans = new int[n]; int[] sum = new int[m]; int j = 1; for (int i = 0; i < n; ++i) { ans[a.get(i).y] = j; sum[j - 1] += a.get(i).x; j++; if (j == m + 1) j = 1; } for (int i = 1; i < m; ++i) { if (Math.abs(sum[i - 1] - sum[i]) > k) { out.println(""NO""); } } out.println(""YES""); for (int e : ans) { out.print(e + "" ""); } out.println(); } } static class Pair implements Comparable> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } } } ",0,Non-plagiarised 722e318f,b790ef12,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; public class TaskB { static long mod = 1000000007; static FastScanner scanner; static final StringBuilder result = new StringBuilder(); public static void main(String[] args) { // 2 : 1000000000 scanner = new FastScanner(); int T = scanner.nextInt(); for (int t = 0; t < T; t++) { solve(t + 1); result.append(""\n""); } System.out.println(result); } static void solve(int t) { int n = scanner.nextInt(); int[] a = scanner.nextIntArray(n); String s = scanner.nextToken(); List blue = new ArrayList<>(); List red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (s.charAt(i) == 'B') { blue.add(a[i]); } else { red.add(a[i]); } } Collections.sort(blue); Collections.sort(red); for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < i + 1) { result.append(""NO""); return; } } for (int i = 0; i < red.size(); i++) { if (red.get(i) > i + 1 + blue.size()) { result.append(""NO""); return; } } result.append(""YES""); } } ","import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { FastReader obj = new FastReader(); PrintWriter out = new PrintWriter(System.out); int l = obj.nextInt(); while (l-- != 0) { int n = obj.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) num[i] = obj.nextInt(); Vector red = new Vector<>(); Vector blue = new Vector<>(); String s = obj.next(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'R') red.add(num[i]); else blue.add(num[i]); } Collections.sort(blue); Collections.sort(red); int c = 1, f = 0; for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < c) { f = 1; break; } c++; } for (int i = 0; i < red.size(); i++) { if (red.get(i) > c) { f = 1; break; } c++; } if (f == 0) out.println(""YES""); else out.println(""NO""); } out.flush(); } } ",1,Plagiarised 3e8ff074,d9199dfd,"import java.io.*; import java.util.*; public class blue_red_permutation { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while (T-- > 0) { int N = Integer.parseInt(br.readLine()); String line1[] = br.readLine().split("" ""); char line2[] = br.readLine().toCharArray(); Range ranges[] = new Range[N]; for (int i = 0; i < N; i++) { int cnt = Integer.parseInt(line1[i]); int low = line2[i] == 'B' ? Math.min(1, cnt) : Math.max(1, cnt); int high = line2[i] == 'R' ? Math.max(N, cnt) : Math.min(N, cnt); ranges[i] = new Range(low, high); } Arrays.sort(ranges); boolean doable = true; for (int i = 0; i < N; i++) { if (!ranges[i].contains(i + 1)) { doable = false; break; } } System.out.println(doable ? ""YES"" : ""NO""); } } static class Range implements Comparable { final int low, high; Range(int low,int high) { this.low = low; this.high = high; } public boolean contains(int val) { return val >= this.low && val <= this.high; } } } ","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 d2eb953e,dcf09f37,"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) { int n = sc.nextInt(); pair = new int[n+1][2]; dp = new long[n+1][2]; for(int i=1;i<=n;i++){ pair[i][0]=sc.nextInt(); pair[i][1]=sc.nextInt(); } getAdj(n, n-1, sc); output.append(solver(n)).append(""\n""); } out.println(output); // _______________________________ // int n = sc.nextInt(); // out.println(solver()); // ________________________________ out.flush(); } static int[][] pair; static long[][] dp; public static long solver(int n) { dfs(1, 0); return Math.max(dp[1][0], dp[1][1]); } static void dfs(int node, int parent){ for(Integer child: adj[node]){ if(child!=parent){ dfs(child, node); long left1 = Math.abs(pair[node][0]-pair[child][0]) + dp[child][0]; long right1 = Math.abs(pair[node][0]-pair[child][1]) + dp[child][1]; long left2 = Math.abs(pair[node][1]-pair[child][0]) + dp[child][0]; long right2 = Math.abs(pair[node][1]-pair[child][1]) + dp[child][1]; dp[node][0] += Math.max(left1, right1); dp[node][1] += Math.max(left2, right2); } } } } ","import java.io.*; import java.util.*; public class E { static long dp[][]; static long val[][]; static ArrayList arr[]; 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(); arr=new ArrayList[n+1]; val=new long[n+1][2]; dp=new long[n+1][2]; for(int i=0;i<=n;i++) Arrays.fill(dp[i], -1); for(int i=1;i<=n;i++) { val[i][0]=sc.nextLong();val[i][1]=sc.nextLong(); } for(int i=0;i<=n;i++) arr[i]=new ArrayList<>(); for(int i=0;i=0;i--) { sum+=x[i]; if(sum<=0) break; c++; } max=Math.max(max,c); } System.out.println(max); } } } ","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(); } } ",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> list; public static void main(String[] args){ int tt = fs.nextInt(); for (int t=0;t(); for (int i=0;i()); for (int i=0;i 2){ pw.println(-1); return; } else if (list.get(i).size() == 1){ start = i; } } int[] ans = new int[n-1]; int prev = -1; int cur = start; int curWeight = 2; while (true){ Edge now = list.get(cur).get(0); if (now.node == prev){ if (list.get(cur).size() == 1){ break; } now = list.get(cur).get(1); } ans[now.index] = 5 - curWeight; curWeight = ans[now.index]; prev = cur; cur = now.node; } for (int i : ans){ pw.printf(""%d "", i); } pw.println(); } static class Edge { int node; int index; public Edge(int node, int index){ this.node = node; this.index = index; } } // ----------input 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(); ArrayList> graph = new ArrayList<>(); for (int j = 0; j < n; j++) { graph.add(new ArrayList<>()); } for (int j = 0; j < n - 1; j++) { int u; int v; u = scan.nextInt(); v = scan.nextInt(); u--; v--; graph.get(u).add(new Pair(v, j)); graph.get(v).add(new Pair(u, j)); } boolean soluble = true; int curV = 0; int prevV = -1; int[] ans = new int[n]; int prime = 2; for (int j = 0; j < n; j++) { ArrayList list = graph.get(j); if (list.size() > 2) { soluble = false; } else if (list.size() == 1) { curV = j; } } if (soluble) { for (int j = 0; j < n - 1; j++) { ArrayList list = graph.get(curV); for (int z = 0; z < list.size(); z++) { if (list.get(z).vertex != prevV) { ans[list.get(z).numberOfEdge] = prime; prime = changePrime(prime); prevV = curV; curV = list.get(z).vertex; break; } } } for (int j = 0; j < n - 1; j++) { System.out.print(ans[j] + "" ""); } System.out.println(); } else { System.out.println(-1); } } } public static int changePrime(int prime) { if (prime == 2) { prime = 3; } else { prime = 2; } return prime; } } class Pair { int vertex; int numberOfEdge; public Pair(int vertex, int numberOfEdge) { this.vertex = vertex; this.numberOfEdge = numberOfEdge; } } ",0,Non-plagiarised 80c384e4,967b67b0,"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) solve(); } private static void solve() { int n = in.nextInt(); int k = in.nextInt(); int a[] = new int[k+1]; for(int i=1; i<=k; i++) a[i] = in.nextInt(); long l[] = new long[n+1]; long r[] = new long[n+1]; for(int i=1; i<=n; i++) { l[i] = Integer.MAX_VALUE; r[i] = Integer.MAX_VALUE; } for(int i=1; i<=k; i++) { l[a[i]] = in.nextInt(); r[a[i]] = l[a[i]]; } for(int i=2;i<=n;i++) { l[i] = Math.min(l[i-1]+1, l[i]); } for(int i=n-1;i>=0;i--) { r[i] = Math.min(r[i+1]+1, r[i]); } for(int i=1;i<=n;i++) { System.out.print(Math.min(l[i], r[i])+"" ""); } System.out.println(); } } ","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) solve(); } private static void solve() { int n = in.nextInt(); int k = in.nextInt(); int a[] = new int[k+1]; for(int i=1; i<=k; i++) a[i] = in.nextInt(); long l[] = new long[n+1]; long r[] = new long[n+1]; for(int i=1; i<=n; i++) { l[i] = Integer.MAX_VALUE; r[i] = Integer.MAX_VALUE; } for(int i=1; i<=k; i++) { l[a[i]] = in.nextInt(); r[a[i]] = l[a[i]]; } for(int i=2;i<=n;i++) { l[i] = Math.min(l[i-1]+1, l[i]); } for(int i=n-1;i>=0;i--) { r[i] = Math.min(r[i+1]+1, r[i]); } for(int i=1;i<=n;i++) { System.out.print(Math.min(l[i], r[i])+"" ""); } System.out.println(); } } ",1,Plagiarised 6f02c6d9,c9159d9c,"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(); } } ","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 00af3420,5449d33c,"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.*; import java.util.*; import java.lang.*; public class C { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.Main(in, out); out.close(); } static class Solver { public void Main(InputReader in, PrintWriter out) { int T = in.nextInt(); for (int t = 0; t < T; t++) { int n = in.nextInt(); String[] A = new String[n]; for (int i = 0; i < n; i++) { A[i] = in.next(); } int ans = 0; for (char c = 'a'; c <= 'e'; c++) { int[] ls = new int[n]; for (int i = 0; i < n; i++) { int delta = 0; for (int j = 0; j < A[i].length(); j++) { if (A[i].charAt(j) == c) { delta += 1; } else { delta -= 1; } } ls[i] = delta; } Arrays.sort(ls, 0, n); int cur = 0; int score = 0; for (int i = n - 1; i >= 0; i--) { if (cur + ls[i] >= 1) { cur += ls[i]; score += 1; } } ans = Math.max(ans, score); } out.println(ans); } } } } ",0,Non-plagiarised 2b2d3b84,9fd33d5a,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { FastReader in = new FastReader(); int t=in.nextInt(); while(t-->0) { int n=in.nextInt(); int k=in.nextInt(); int a[]=new int[k]; int ans[]=new int[n]; int tem[]=new int[k]; for(int i=0;i=0;i--) { p=Math.min(p+1,c[i]); r[i]=p; } for(int i=0;i prime = new ArrayList<>(); public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); int T = in.nextInt(); OUTER: while(T-->0) { int n=in.nextInt(), k=in.nextInt(); int a[]=new int[k]; for(int i=0; i=0; i--) { if(ans[i]!=0) { temp=Math.min(temp, ans[i]); } right[i]=temp; temp+=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;i0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i l=new Vector<>(), r=new Vector<>(); for(int i=0;i n - i) ok = false; System.out.print((ok ? ""YES"" : ""NO"")+'\n'); } } } ","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 464a03b8,c9159d9c,"import java.util.*; public class Soltion{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); Integer[] arr = new Integer[n]; for(int i=0;i blue = new ArrayList<>(); List red = new ArrayList<>(); for(int i=0;i=0;i--){ if(red.get(i)>q){ flag = false; break; } q--; } 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 8d6f1bf5,e90a198b,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Menorah { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t > 0) { int n = Integer.parseInt(br.readLine()); String 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 2e404969,bc46480a,"import java.util.*; import java.lang.*; import java.io.*; public class Codechef { static long fans[] = new long[200001]; static long inv[] = new long[200001]; static long mod = 1000000007; public static void main(String[] args) throws java.lang.Exception { FastReader in = new FastReader(System.in); StringBuilder sb = new StringBuilder(); int t = 1; t = in.nextInt(); while (t > 0) { --t; int n = in.nextInt(); long time[] = generateArray(in, n); long hp[] = generateArray(in, n); int s = 0; long ans = 0; while(s=l && time[s]<=r) { ++s; } long temp = r - l; ans += (temp*(temp+1))/2; } sb.append(ans+""\n""); } System.out.print(sb); } static long[] generateArray(FastReader in, int n) throws IOException { long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = in.nextLong(); return arr; } } ","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 42fe7dd0,c4ca2ff3,"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.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(); } } ",1,Plagiarised 2eb89317,5f0a176e,"import java.util.*; import java.io.*; ////*************************************************************************** /* public class E_Gardener_and_Tree implements Runnable{ public static void main(String[] args) throws Exception { new Thread(null, new E_Gardener_and_Tree(), ""E_Gardener_and_Tree"", 1<<28).start(); } public void run(){ WRITE YOUR CODE HERE!!!! JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!! } } */ /////************************************************************************** public class C_Menorah{ public static void main(String[] args) { FastScanner s= new FastScanner(); //PrintWriter out=new PrintWriter(System.out); //end of program //out.println(answer); //out.close(); StringBuilder res = new StringBuilder(); int t=s.nextInt(); int p=0; while(p=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.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class a729 { public static void main(String[] args) throws IOException { // try { BufferedWriter out = new BufferedWriter( new OutputStreamWriter(System.out)); BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); PrintWriter pt = new PrintWriter(System.out); FastReader sc = new FastReader(); int t = sc.nextInt(); for(int o = 0 ; o=l && hi<=r) { // return seg[idx]; // } // if(hir) { // return Integer.MAX_VALUE; // } // int mid = (lo + hi)/2; // int left = query(seg,idx*2 +1, lo, mid, l, r); // int right = query(seg,idx*2 + 2, mid + 1, hi, l, r); // return Math.min(left, right); //} // // for sum // //public static void update(int[]seg,int idx, int lo , int hi , int node , int val) { // if(lo == hi) { // seg[idx] += val; // }else { //int mid = (lo + hi )/2; //if(node<=mid && node>=lo) { // update(seg, idx * 2 +1, lo, mid, node, val); //}else { // update(seg, idx*2 + 2, mid + 1, hi, node, val); //} //seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2]; // //} //} //--------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------- } //------------------------------------------------------------------------------------------------------------------------------------------------------------ //----------------------------------------------------------------------------------------------------------------------------------------------------------- ",0,Non-plagiarised 00db6701,0c1143f7,"import java.util.*; import java.io.*; public class Main { public static void main(String args[]) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=fs.nextInt(); while(t-->0) { int n=fs.nextInt(); int c[]=fs.readArray(n); int i; long mn0=c[0]; long mn1=c[1]; long s0=c[0]; long s1=c[1]; long ans; ans=(mn0+mn1)*n*1L; for(i=2;i 0) { int n = sc.nextInt(); int[] a = new int[n]; for(int i = 0 ; i< n ; i++) { a[i] = sc.nextInt(); } long oddMin = a[1]; long evenMin = a[0]; long res = (n * oddMin) + (n * evenMin); long oddSum = a[1]; long evenSum = a[0]; for(int i = 2 ;i < n ; i++) { if(i % 2 == 1) { oddSum += a[i]; oddMin = Math.min(oddMin, a[i]); } else { evenSum += a[i]; evenMin = Math.min(evenMin, a[i]); } int odd = (i + 1) / 2; int even = (i / 2) + 1; long minCostOdd = oddSum + oddMin*(n - odd); long minCostEven = evenSum + evenMin*(n - even); res = Math.min(res, minCostOdd + minCostEven); } System.out.println(res); } } // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2 // worst case since it uses a version of quicksort. Although this would never // actually show up in the real world, in codeforces, people can hack, so // this is needed. } ",0,Non-plagiarised 29cf2e70,2f4509a0,"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 Main { private static FS sc = new FS(); private static class extra { static int[] intArr(int size) { int[] a = new int[size]; for(int i = 0; i < size; i++) a[i] = sc.nextInt(); return a; } } static int mod = (int) 1e9 + 7; static LinkedList[] temp, temp2; static int inf = (int) 1e9; // static long inf = Long.MAX_VALUE; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); int[] a = extra.intArr(n); String s = sc.next(); ArrayList red = new ArrayList<>(), blue = new ArrayList<>(); for(int i = 0; i < n; i++) { if(s.charAt(i) == 'R') red.add(a[i]); else blue.add(a[i]); } Collections.sort(red); Collections.sort(blue); int start = 1, flag = 0; for(int aa:blue) { if(start > aa) { flag = 1; break; } start++; } for(int aa:red) { if(start < aa) { flag = 1; break; } start++; } if(flag == 1) ret.append(""NO\n""); else ret.append(""YES\n""); } System.out.println(ret); } } ",1,Plagiarised 83b44c9c,e431de28,"import java.util.Scanner; public class MinimumGridPath { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int test = scanner.nextInt(); StringBuilder sb = new StringBuilder(); for (int t = 0; t < test; t++) { int n = scanner.nextInt(); long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = scanner.nextLong(); } long minx = arr[0]; long miny = arr[1]; long min = minx * n + miny * n; long sumx = arr[0]; long sumy = arr[1]; for(int i=2; i0){ int n = s.nextInt(); long[] aa =new long[n]; for(int i=0;i one=new ArrayList<>(); static ArrayList zero=new ArrayList<>(); static long dp[][]= new long[5001][5001]; static long solve(int i,int j){ if (i==one.size())return 0; if (j==zero.size())return Integer.MAX_VALUE; if (dp[i][j]!=-1){ return dp[i][j]; } return dp[i][j]=Math.min(solve(i+1,j+1)+Math.abs(one.get(i)-zero.get(j)),solve(i,j+1)); } public static void main(String[] args) { FastScanner sc = new FastScanner(); // int t=sc.nextInt(); // while (t-->=1){ int n=sc.nextInt(); int a[]=sc.readArray(n); for (long i[]:dp){ Arrays.fill(i,-1); } for (int i=0;i l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static long mod =(long)(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) } ","import java.io.*; import java.util.*; import java.lang.Math; public class Main { static Scanner sc; static StringBuilder ans; /*-------------- for input in an value ---------------------*/ static int ni() { return sc.nextInt(); } /*-------------- for input in an array ---------------------*/ /*-------------- File vs Input ---------------------*/ static void runIo() throws Exception { sc = new Scanner(System.in); } public static void main(String[] args) throws Exception { // runFile(); runIo(); int t; t = 1; // t = sc.nextInt(); ans = new StringBuilder(); while( t-- > 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 list = new ArrayList(arr[start].keySet()); for(int node:list){ if(vis[node]==false) { long[] curr = maxBeauty(arr,lv,rv,node,start,vis); ans[0] += Math.max(curr[0] + Math.abs(lv[start]-lv[node]),curr[1] + Math.abs(lv[start]-rv[node])); ans[1] += Math.max(curr[0] + Math.abs(rv[start]-lv[node]),curr[1] + Math.abs(rv[start]-rv[node])); } } return ans; } public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int tc = Integer.parseInt(br.readLine()); while (tc > 0) { int n = Integer.parseInt(br.readLine()); boolean[] vis = new boolean[n+1]; HashMap[] arr = new HashMap[n+1]; for(int i=0;i<=n;i++){ arr[i] = new HashMap(); } long[] lv = new long[n+1]; long[] rv = new long[n+1]; for(int i=1;i<=n;i++){ String[] s1 = br.readLine().split("" ""); lv[i] = Long.valueOf(s1[0]); rv[i] = Long.valueOf(s1[1]); } for(int i=0;i() { }); } 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; } } // static void calc(int n){ // int i,j; // dp[n-1]=0; // if(n>1) // dp[n-2]=1; // for(i=n-3;i>=0;i--){ // long ind=n-i-1; // dp[i]=((ind*(long)mypow(10,ind-1))%MOD+dp[i+1])%MOD; // } // } static long dist[],dp[][],left[],right[]; static int visited[],isit[]; static ArrayList>> adj[],li; //static int dp[][][]; static int MOD=1000000007; static char ch[]; static int[] sieve,is_sieve; static TreeSet tr; static long mat[][]; // static void bfs(int node,int par,Pair p[],long taken){ // LinkedList li=new LinkedList<>(); // li.add(node); // while(!li.isEmpty()){ // int x=li.pollFirst(); // long lowNode=p[x-1].x; // long highNode=p[x-1].y; // int left=0,right=0; // visited[x]=1; // for(Pair> pp:adj[x]){ // long max=0; // if(selected[pp.x]==0){ // max=Math.max(Math.abs(lowNode-pp.y.y),Math.abs(highNode-pp.y.x)); // if(max==Math.abs(lowNode-pp.y.y)){ // left++; // }else{ // right++; // } // }else{ // max=Math.max(Math.abs(lowNode-selected[pp.x]),Math.abs(highNode-selected[pp.x])); // if(max==Math.abs(lowNode-selected[pp.x])){ // left++; // }else{ // right++; // } // } // if(visited[pp.x]==0) // li.add(pp.x); // } // if(left>=right){ // selected[x]=lowNode; // }else{ // selected[x]=highNode; // } // } // } static void dfs(int node,int par, Pair p[]){ for(Pair> pp:adj[node]){ if(pp.x!=par){ //sum+=Math.abs(selected[node]-selected[pp.x]); dfs(pp.x,node,p); //System.out.println(node+"" ""+pp.x); long x=Math.abs(p[node].x-p[pp.x].x); long y=Math.abs(p[node].x-p[pp.x].y); long z=Math.abs(p[node].y-p[pp.x].x); long w=Math.abs(p[node].y-p[pp.x].y); left[node]+=Math.max(x+left[pp.x],y+right[pp.x]); right[node]+=Math.max(z+left[pp.x],w+right[pp.x]); } } } public static void main(String args[]){ InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); int t,i,j,tno=0,tte; t=in.nextInt(); //t=1; //tte=t; while(t-->0){ //sum=0; int n=in.nextInt(); adj=new ArrayList[n+1]; left=new long[n+1]; right=new long[n+1]; visited=new int[n+1]; for(i=0;i(); } Pair p[]=new Pair[n+1]; for(i=1;i<=n;i++){ p[i]=new Pair<>(in.nextLong(),in.nextLong()); } for(i=0;i(v,p[v])); adj[v].add(new Pair<>(u,p[u])); } //bfs(1,-1,p,Long.MAX_VALUE); dfs(1,-1,p); // for(i=0;i z=new ArrayList<>(),o=new ArrayList<>(); long dp[][]=new long[n+1][n+1]; int i,j,a; for(i=0;i z=new ArrayList<>(),o=new ArrayList<>(); long dp[][]=new long[n+1][n+1]; int i,j,a; for(i=0;i 0) { // int n = Integer.parseInt(br.readLine()); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long k = Long.parseLong(st.nextToken()); st = new StringTokenizer(br.readLine()); long arr[] = new long[n]; long tot_sum = 0; for(int i = 0; i < n; i++) { long e = Long.parseLong(st.nextToken()); arr[i] = e; tot_sum+=e; } if(tot_sum <= k) { output.write(""0\n""); continue; } Arrays.sort(arr); long psum = 0; long res = tot_sum - k; for(int p = 0; p < n - 1; p++) { int ind = n - p - 1; psum+=arr[ind]; long sum = arr[0] + psum - tot_sum + k; double d = sum / (double)(p + 2); long x = (long)Math.floor(d); // output.write(""x = "" + x + "" sum = "" + sum + "" d = "" + d + ""\n""); long numsteps = Math.max(arr[0] - x, 0) + p + 1; if(numsteps < 0) continue; // output.write(""for p = "" + p + "" the number of steps req = "" + numsteps + "" and the x = "" + x + ""\n""); res = Math.min(res, numsteps); } output.write(res + ""\n""); // int k = Integer.parseInt(st.nextToken()); // char arr[] = br.readLine().toCharArray(); // output.write(); // int n = Integer.parseInt(st.nextToken()); // HashMap map = new HashMap(); // if // output.write(""YES\n""); // else // output.write(""NO\n""); // long a = Long.parseLong(st.nextToken()); // long b = Long.parseLong(st.nextToken()); // if(flag == 1) // output.write(""NO\n""); // else // output.write(""YES\n"" + x + "" "" + y + "" "" + z + ""\n""); // output.write(n+ ""\n""); } output.flush(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static long floor(long a, long b) { long res = a / b; while(res * b > a) res--; return res; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long k = Long.parseLong(st.nextToken()); st = new StringTokenizer(br.readLine()); Long[] p = new Long[n]; for(int i = 0 ;i { int f, s; Pair(int f, int s) { this.f = f; this.s = s; } } public static void main(String[] args) throws IOException { PriorityQueue pq = new PriorityQueue(); for (int t = readInt(); t > 0; --t) { int n = readInt(), m = readInt(), x = readInt(); System.out.println(""YES""); for (int i = 1; i <= m; ++i) { pq.add(new Pair(readInt(), i)); System.out.print(i + "" ""); } for (int i = m + 1; i <= n; ++i) { Pair p = pq.poll(); p.f += readInt(); pq.add(p); System.out.print(p.s + "" ""); } System.out.println(); pq.clear(); } } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } } ","import java.io.*; import java.util.*; public class Main { static class Pair implements Comparable { int f, s; Pair(int f, int s) { this.f = f; this.s = s; } } public static void main(String[] args) throws IOException { PriorityQueue pq = new PriorityQueue(); for (int t = readInt(); t > 0; --t) { int n = readInt(), m = readInt(), x = readInt(); System.out.println(""YES""); for (int i = 1; i <= m; ++i) { pq.add(new Pair(readInt(), i)); System.out.print(i + "" ""); } for (int i = m + 1; i <= n; ++i) { Pair p = pq.poll(); p.f += readInt(); pq.add(p); System.out.print(p.s + "" ""); } System.out.println(); pq.clear(); } } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } } ",1,Plagiarised 734a94be,f6ca6fc8,"import java.io.*; import java.math.*; import java.util.*; public class test { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuffer res = new StringBuffer(); int tc = 1; while(tc-->0) { int n = sc.nextInt(); ArrayList one = new ArrayList<>(); ArrayList zero = new ArrayList<>(); for(int i=0;i o=new ArrayList(); ArrayList e=new ArrayList(); for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } int dp[][]=new int[o.size()+1][e.size()+1]; 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,Plagiarised 07038b12,a18cb2c1,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class h { public static int r1=0; static long[][] f=new long[501][501]; public static void main(String[] args) { OutputStream outputStream =System.out; PrintWriter out =new PrintWriter(outputStream); FastReader s=new FastReader(); int t=s.nextInt(); while(t>0) { int n=s.nextInt(); for(int i=1;i<=n;i++) { vis[i]=0; deg[i]=0; ans[i]=0; f1[i]=new ArrayList<>(); } for(int i=1;i<=n-1;i++) { int x=s.nextInt(); int y=s.nextInt(); f1[x].add(new pair1(y,i)); f1[y].add(new pair1(x,i)); deg[x]++; deg[y]++; } // dfs(1); int node=-1; boolean p=false; for(int i=1;i<=n;i++) { if(deg[i]>2) { p=true; } if(deg[i]==1) { node=i; } } if(p) { out.println(-1); }else { dfs(node,2); // System.out.println(); for(int i=1;i<=n-1;i++) { out.print(ans[i]+"" ""); } out.println(); } t--; } out.close(); } static int[] ans=new int[100001]; static int[] deg=new int[100001]; static void dfs(int node,int v) { vis[node]=1; // deg[node]++; for(int i=0;i primes=new ArrayList<>(); static ArrayList[] f1=new ArrayList[100001]; } ","import java.util.*; import java.io.*; public class C1627 { 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(); int[][] edges = new int[n - 1][2]; int[] deg = new int[n]; boolean valid = true; ArrayList[] adjList = new ArrayList[n]; for (int i = 0; i < n; i++) { adjList[i] = new ArrayList<>(); } for (int i = 0; i < n - 1; i++) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; edges[i] = new int[]{u, v}; deg[u]++; deg[v]++; valid &= deg[u] <= 2 && deg[v] <= 2; adjList[u].add(i); adjList[v].add(i); } if (!valid) { pw.println(-1); continue; } int root = -1; for (int i = 0; i < n; i++) { if (adjList[i].size() == 1) root = i; } int[] ans = new int[n - 1]; int curColor = 2; int par = -1; while (true) { int nxt = -1; for (int e : adjList[root]) { int other = edges[e][0] ^ edges[e][1] ^ root; if (other != par) { ans[e] = curColor; curColor = 5 - curColor; nxt = other; break; } } if (nxt == -1) break; par = root; root = nxt; } for (int x : ans) { pw.print(x + "" ""); } pw.println(); } pw.close(); } } ",0,Non-plagiarised c9159d9c,f0ede32a,"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 Soltion{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); Integer[] arr = new Integer[n]; for(int i=0;i blue = new ArrayList<>(); List red = new ArrayList<>(); for(int i=0;i=0;i--){ if(red.get(i)>q){ flag = false; break; } q--; } for(int i=0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (line.charAt(i) == 'B') { blue.add(data[i]); } else { red.add(data[i]); } } Collections.sort(blue); Collections.sort(red); int st = 1; boolean ok = true; for (int i : blue) { if (i < st) { ok = false; break; } st++; } if (ok) { for (int i : red) { if (i > st) { ok = false; break; } st++; } } out.println(ok ? ""Yes"" : ""No""); } out.close(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; public class TaskB { static long mod = 1000000007; static FastScanner scanner; static final StringBuilder result = new StringBuilder(); public static void main(String[] args) { // 2 : 1000000000 scanner = new FastScanner(); int T = scanner.nextInt(); for (int t = 0; t < T; t++) { solve(t + 1); result.append(""\n""); } System.out.println(result); } static void solve(int t) { int n = scanner.nextInt(); int[] a = scanner.nextIntArray(n); String s = scanner.nextToken(); List blue = new ArrayList<>(); List red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (s.charAt(i) == 'B') { blue.add(a[i]); } else { red.add(a[i]); } } Collections.sort(blue); Collections.sort(red); for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < i + 1) { result.append(""NO""); return; } } for (int i = 0; i < red.size(); i++) { if (red.get(i) > i + 1 + blue.size()) { result.append(""NO""); return; } } result.append(""YES""); } } ",0,Non-plagiarised 313b42e6,e45446bc,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Div2 { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] s = reader.readLine().split("" ""); StringBuilder sb = new StringBuilder(); Div2 div2 = new Div2(); int t = Integer.parseInt(s[0]); while (t-- > 0) { s = reader.readLine().split("" ""); int n = Integer.parseInt(s[0]); s = reader.readLine().split("" ""); long[] cs = new long[n]; for (int i = 0; i < n; i++) { cs[i] = Long.parseLong(s[i]); } long min1 = cs[0]; long min2 = cs[1]; long cost = n * min1 + n * min2; long sum = min1 + min2; for (int i = 2; i < n; i++) { sum += cs[i]; int count = i / 2; if (i % 2 == 0) { min1 = Math.min(min1, cs[i]); cost = Math.min(cost, sum + (n - count - 1) * min1 + (n - count) * min2); } else { count++; min2 = Math.min(min2, cs[i]); cost = Math.min(cost, sum + (n - count) * min1 + (n - count) * min2); } } sb.append(cost).append(""\n""); } System.out.println(sb.toString()); } } ","import java.util.*; import java.lang.*; import java.io.*; public class C { // *** ++ // +=-==+ +++=- // +-:---==+ *+=----= // +-:------==+ ++=------== // =-----------=++========================= // +--:::::---:-----============-=======+++==== // +---:..:----::-===============-======+++++++++ // =---:...---:-===================---===++++++++++ // +----:...:-=======================--==+++++++++++ // +-:------====================++===---==++++===+++++ // +=-----======================+++++==---==+==-::=++**+ // +=-----================---=======++=========::.:-+***** // +==::-====================--: --:-====++=+===:..-=+***** // +=---=====================-... :=..:-=+++++++++===++***** // +=---=====+=++++++++++++++++=-:::::-====+++++++++++++*****+ // +=======++++++++++++=+++++++============++++++=======+****** // +=====+++++++++++++++++++++++++==++++==++++++=:... . .+**** // ++====++++++++++++++++++++++++++++++++++++++++-. ..-+**** // +======++++++++++++++++++++++++++++++++===+====:. ..:=++++ // +===--=====+++++++++++++++++++++++++++=========-::....::-=++* // ====--==========+++++++==+++===++++===========--:::....:=++* // ====---===++++=====++++++==+++=======-::--===-:. ....:-+++ // ==--=--====++++++++==+++++++++++======--::::...::::::-=+++ // ===----===++++++++++++++++++++============--=-==----==+++ // =--------====++++++++++++++++=====================+++++++ // =---------=======++++++++====+++=================++++++++ // -----------========+++++++++++++++=================+++++++ // =----------==========++++++++++=====================++++++++ // =====------==============+++++++===================+++==+++++ // =======------==========================================++++++ // created by : Nitesh Gupta public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { String[] scn = (br.readLine()).trim().split("" ""); int n = Integer.parseInt(scn[0]); long[] arr = new long[n]; scn = (br.readLine()).trim().split("" ""); for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(scn[i]); } long min; long hor = arr[0], ver = arr[1]; long min1 = 0, min2 = 0; min = (hor + ver) * n; long x = 0, y = 0; for (int i = 2; i < n; i++) { if (i % 2 == 0) { x += 1; if (arr[i] >= hor) { min1 += arr[i]; } else { min1 += hor; hor = arr[i]; } } else { y += 1; if (arr[i] >= ver) { min2 += arr[i]; } else { min2 += ver; ver = arr[i]; } } long pro = (n - x) * hor + (n - y) * ver; min = Math.min(min, min1 + min2 +pro); } sb.append(min); sb.append(""\n""); } System.out.println(sb); return; } } ",0,Non-plagiarised 3b498a39,69b2fd22,"import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static long dp[][]; static int max; public static void main(String[] args) { PrintWriter out=new PrintWriter(System.out); //StringBuffer sb=new StringBuffer(""""); int ttt=1; //ttt =i(); outer :while (ttt-- > 0) { int n=i(); int A[]=input(n); dp=new long[n+1][n+1]; for(int i=0;i<=n;i++) { Arrays.fill(dp[i],-1); } ArrayList l=new ArrayList(); ArrayList m=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;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,Plagiarised 23cb8587,48801d9e,"import java.io.*; import java.util.*; public class C { static long mod = (long) (1e9 + 7); public static void main(String[] args) throws IOException { Scanner scn = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); int T = scn.ni(), tcs = 0; C: while (tcs++ < T) { int n = scn.ni(); tree = new ArrayList[n + 1]; range = new long[n + 1][2]; for (int i = 0; i <= n; i++) tree[i] = new ArrayList<>(); for (int i = 1; i <= n; i++) { range[i][0] = scn.nl(); range[i][1] = scn.nl(); } for (int i = 0; i < n - 1; i++) { int x = scn.ni(); int y = scn.ni(); tree[x].add(y); tree[y].add(x); } strg = new long[n + 1][2]; for (long a1[] : strg) Arrays.fill(a1, -1L); sb.append(Math.max(DFS(1, -1, 0), DFS(1, -1, 1))); sb.append(""\n""); } out.print(sb); out.close(); } static ArrayList tree[]; static long range[][], strg[][]; static long DFS(int u, int pa, int ok) { if (strg[u][ok] != -1) return strg[u][ok]; long tg = 0; for (int ch : tree[u]) { if (ch == pa) continue; long sg = 0; if (ok == 0) { sg = Math.max(DFS(ch, u, 0) + Math.abs(range[u][0] - range[ch][0]), DFS(ch, u, 1) + Math.abs(range[u][0] - range[ch][1])); } else { sg = Math.max(DFS(ch, u, 0) + Math.abs(range[u][1] - range[ch][0]), DFS(ch, u, 1) + Math.abs(range[u][1] - range[ch][1])); } tg += sg; } return strg[u][ok] = tg; } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class C { private static FastReader fr = new FastReader(); private static PrintWriter out=new PrintWriter(System.out); private static Random random = new Random(); private static long[][] dp; private static long calculate(List[] graph, int current, long[][] r, boolean[] stack, int use){ if(dp[current][use] != -1) return dp[current][use]; stack[current] = true; long max = 0; if(graph[current] != null){ for(int next : graph[current]){ if(!stack[next]){ stack[next] = true; long r1 = Math.abs(r[current][use] - r[next][0]) + calculate(graph, next, r, stack, 0); long r2 = Math.abs(r[current][use] - r[next][1]) + calculate(graph, next, r, stack, 1); max += Math.max(r1, r2); } } } stack[current] = false; dp[current][use] = max; return max; } public static void main(String[] args) throws IOException { StringBuilder sb = new StringBuilder(); // code goes here int t = fr.nextInt(); while (t-- > 0){ int n = fr.nextInt(); long[][] r = new long[n][2]; for(int i = 0; i < n; i++){ r[i] = fr.nextLongArray(2); } List[] graph = new ArrayList[n]; for(int i = 0; i < n - 1; i++){ int u = fr.nextInt(); int v = fr.nextInt(); if(graph[u - 1] == null) graph[u - 1] = new ArrayList<>(); if(graph[v - 1] == null) graph[v - 1] = new ArrayList<>(); graph[u - 1].add(v - 1); graph[v - 1].add(u - 1); } boolean[] stack = new boolean[n]; dp = new long[n][2]; for(int i = 0; i < dp.length; i++){ Arrays.fill(dp[i], -1); } long r1 = calculate(graph, 0, r, stack, 0); long r2 = calculate(graph, 0, r, stack, 1); sb.append(Math.max(r1, r2)).append(""\n""); } System.out.print(sb.toString()); } // Returns n^(-1) mod p // Returns nCr % p using Fermat's // little theorem. } ",0,Non-plagiarised 99bc7da3,b3638571,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Codeforces { static int mod =1000000007; static Set set; 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[]=new int[n]; // set=new HashSet<>(); for(int i=0;i= pot ){ if(j % (pot*3) >= pot){ if(j % (pot*3) >= pot*2){ setSum[j] += sequence[k]; }else{ setSum[j] -= sequence[k]; } } } } } String output = ""NO""; for (int j = 1; j < setSum.length; j++) { if(setSum[j] == 0){ output = ""YES""; break; } } out.println(output); } out.close(); } public static PrintWriter out; } ",0,Non-plagiarised c9159d9c,fae0662f,"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.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) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); for (int tc = 0; tc < t; tc++) { int n = fs.nextInt(); int[] a = fs.readArray(n); String s = fs.nextLine(); // let all blue to be 1 -> blueCount ArrayList blues = new ArrayList(); ArrayList reds = new ArrayList(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'B') { blues.add(a[i]); } else { reds.add(a[i]); } } Collections.sort(blues); Collections.sort(reds); boolean ok = true; for (int i = 1; i <= blues.size(); i++) { if (blues.get(i - 1) < i) { ok = false; break; } } for (int i = blues.size() + 1; i <= n; i++) { if (reds.get(i - blues.size() - 1) > i) { ok = false; break; } } if (ok) { out.println(""YES""); } else { out.println(""NO""); } } out.close(); } } ",0,Non-plagiarised a101df86,f0d91796,"import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); // long mod = 1_000_000_007L; // long mod = 998_244_353L; int t = sc.nextInt(); for ( int zzz=0; zzz 0){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i 0) { int n = readInt(), k = readInt(); int[] a = new int[k], t = new int[k], c = new int[n]; for (int i = 0; i < k; i ++) a[i] = readInt(); for (int i = 0; i < k; i ++) t[i] = readInt(); Arrays.fill(c, Integer.MAX_VALUE); for (int i = 0; i < k; i ++) c[a[i] - 1] = t[i]; int[] l = new int[n], r = new int[n]; int prev = (int) 2e9; for (int i = 0; i < n; i ++) { l[i] = Math.min(prev + 1, c[i]); prev = l[i]; } prev = (int) 2e9; for (int i = n - 1; i >= 0; i --) { r[i] = Math.min(prev + 1, c[i]); prev = r[i]; } for (int i = 0; i < n; i ++) System.out.print(Math.min(l[i], r[i]) + "" ""); System.out.println(); } } static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } static String readLine() throws IOException { return br.readLine().trim(); } } ","import java.io.*; import java.util.*; public class Codeforces { 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) { br.readLine(); String[] str = br.readLine().split("" ""); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int[] a = new int[k]; int[] t = new int[k]; str = br.readLine().split("" ""); for(int i=0; i=0; i--) { right[i] = Math.min(right[i], minright); minright = right[i] == Integer.MAX_VALUE ? Integer.MAX_VALUE : right[i]+1; } for(int i=0; i> g; static int count = 0; /* * ====================================Main================================= */ public static void main(String args[]) throws Exception { // File file = new File(""D:\\VS Code\\Java\\Output.txt""); // FileWriter fw = new FileWriter(""D:\\VS Code\\Java\\Output.txt""); Random rand = new Random(); int t = 1; t = f.nextInt(); int tc = 1; while (t-- != 0) { int n = f.nextInt(); int c[] = new int[n]; long minOdd = 0, minEven = 0; long sumEven = 0, sumOdd = 0; for (int i = 0; i < n ; i++) { c[i] = f.nextInt(); // if (i % 2 == 0) { // minEven = (c[minEven] > c[i]) ? i : minEven; // sumEven += c[i]; // } else { // minOdd = (minOdd > c[i]) ? i : minOdd; // sumOdd += c[i]; // } } minEven = c[0]; minOdd = c[1]; sumEven=c[0]; sumOdd=c[1]; long min=minEven*n + minOdd*n;//for k=2 int even=1,odd=1; for (int k = 3; k <= n; k++) { if(k%2==1){ sumEven+=c[k-1]; minEven=Math.min(minEven, c[k-1]); even++; }else{ sumOdd+=c[k-1]; minOdd=Math.min(minOdd, c[k-1]); odd++; } min=Math.min(min, sumEven-minEven+minEven*(n-even+1) + sumOdd-minOdd+minOdd*(n-odd+1)); } w.write(min+""\n""); } w.flush(); } } ",0,Non-plagiarised 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 b08b1c3c,d92b4600,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class D { static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); Node head = null; boolean notPossible = false; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (head == null) { head = new Node(x); } else { if ((head.next != null && x > head.next.value) || (head.prev != null && x < head.prev.value)) { notPossible = true; } else if ((head.next == null || x <= head.next.value) && x > head.value) { if (head.next != null && x == head.next.value) { head = head.next; continue; } Node temp = head.next; Node next = new Node(x); head.next = next; next.prev = head; next.next = temp; if (temp != null) { temp.prev = next; } head = next; } else if ((head.prev == null || x >= head.prev.value) && x < head.value) { if (head.prev != null && x == head.prev.value) { head = head.prev; continue; } Node temp = head.prev; Node prev = new Node(x); head.prev = prev; prev.next = head; prev.prev = temp; if (temp != null) { temp.next = prev; } head = prev; } } } if (notPossible) { out.println(""NO""); } else { out.println(""YES""); } } out.close(); } static class Node { int value; Node prev; Node next; Node(int value) { this.value = value; this.prev = null; this.next = null; } } } ","import java.util.Scanner; public class D_724 { @SuppressWarnings(""resource"") public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int test = 0; test < t; test++){ int n = input.nextInt(); ListNode on = new ListNode(input.nextInt(), null, null); boolean good = true; for(int i = 1; i < n; i++){ int num = input.nextInt(); if(good){ int at = on.data; if(num > at){ if(on.next == null || num < on.next.data){ on.next = new ListNode(num, on, on.next); on = on.next; if(on.next != null){ on.next.prev = on; } }else if(num == on.next.data){ on = on.next; }else{ good = false; } }else if(num < at){ if(on.prev == null || num > on.prev.data){ on.prev = new ListNode(num, on.prev, on); on = on.prev; if(on.prev != null){ on.prev.next = on; } }else if(num == on.prev.data){ on = on.prev; }else{ good = false; } } } } if(good){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } static class ListNode{ int data; ListNode prev; ListNode next; ListNode(int data, ListNode prev, ListNode next){ this.data = data; this.prev = prev; this.next = next; } } } ",0,Non-plagiarised 2eb89317,fcc7e8fa,"import java.util.*; import java.io.*; ////*************************************************************************** /* public class E_Gardener_and_Tree implements Runnable{ public static void main(String[] args) throws Exception { new Thread(null, new E_Gardener_and_Tree(), ""E_Gardener_and_Tree"", 1<<28).start(); } public void run(){ WRITE YOUR CODE HERE!!!! JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!! } } */ /////************************************************************************** public class C_Menorah{ public static void main(String[] args) { FastScanner s= new FastScanner(); //PrintWriter out=new PrintWriter(System.out); //end of program //out.println(answer); //out.close(); StringBuilder res = new StringBuilder(); int t=s.nextInt(); int p=0; while(p=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 6e7cd58b,cfba313d,"import java.util.*; import java.io.*; public class CodeforcesRound734 { static FastReader sc = new FastReader(); public static void main(String[] args) throws IOException { try { int t = sc.nextInt(); while (t-- > 0) { // A(); // B1(); // B2(); C(); } } catch (Exception e) { // return; e.printStackTrace(); } } static void C() { int n = sc.nextInt(); int a[][] = new int[5][n]; for (int i = 0; i < n; i++) { String s = sc.next(); for (int j = 0; j < s.length(); j++) { if (s.charAt(j) == 'a') a[0][i]++; else a[0][i]--; if (s.charAt(j) == 'b') a[1][i]++; else a[1][i]--; if (s.charAt(j) == 'c') a[2][i]++; else a[2][i]--; if (s.charAt(j) == 'd') a[3][i]++; else a[3][i]--; if (s.charAt(j) == 'e') a[4][i]++; else a[4][i]--; } } for (int x[] : a) { Arrays.sort(x); } int ans = 0; for (int i = 0; i < 5; i++) { int temp = 0, cnt = 0; for (int j = n - 1; j >= 0; j--) { temp += a[i][j]; if (temp <= 0) break; else cnt++; } ans = Math.max(ans, cnt); } System.out.println(ans); } } ","import java.io.*; import java.util.*; public class C {//Any Class Name static class Code { private void solve(InputReader in, OutputWriter out) throws IOException { ArrayOpn o= new ArrayOpn(); int t = in.readInt(); while(t -- > 0) { int n=in.readInt(); int[][] freq= new int[5][n]; for(int i=0; i=0; j--) { temp+=freq[i][j]; if(temp<=0) { break; } count++; } ans=Math.max(ans, count); } out.printLine(ans); } out.close(); } } static class ArrayOpn{ static final Random random = new Random(); private void sort(int A[]) { int n = A.length; for(int i=0; i= 0; j--){ if(sum + vals[j] > 0){ x++; sum += vals[j]; } else { break; } } if(x > ans) { ans = x; } } System.out.println(ans); } String n(){ return in.next(); } int ni() { return in.nextInt(); } } } ","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(); int Q = reader.nextInt(); outer: for (int q = 0; q < Q; q++) { int N = reader.nextInt(); int[][] scores = new int[5][N]; for (int i = 0; i < N; i++) { int[] occurs = new int[5]; String word = reader.next(); for (int j = 0; j < word.length(); j++) { occurs[word.charAt(j) - 'a']++; } for (int j = 0; j < 5; j++) { scores[j][i] = occurs[j] - (word.length() - occurs[j]) ; } } int bestCount = 0; for (int i = 0; i < 5; i++) { int[] curr = scores[i]; Arrays.sort(curr); int currentCount = 1; int currentScore = curr[curr.length - 1]; for (int j = curr.length - 2; j >= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ",0,Non-plagiarised 26ad111c,b0a01ee7,"import java.io.*; import java.util.*; public class C { public static void main(String[] args) { FastReader f = new FastReader(); StringBuffer sb=new StringBuffer(); int test=f.nextInt(); while(test-->0) { int n=f.nextInt(); String str[]=new String[n]; for(int i=0;i c=new ArrayList<>(); for(int i=0;icountTtl) { adv++; totalAdv+=(countC-countTtl); } else if(countC==countTtl) equal++; else c.add(Math.abs(countTtl-countC)); } if(adv>0) count+=adv+equal; Collections.sort(c); for(int i:c) { if(totalAdv>i) { totalAdv-=i; count++; } } return count; } } ","import java.util.*; public class interestingstory { public static void main(String[] args) throws Exception { // your code goes here try{ Scanner sc =new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int answer = 0; String [] string_arr = new String[n]; for (int i = 0; i< n; i++){ string_arr[i] = sc.next(); } for(char c = 'a'; c <= 'e'; c++){ int [] diff = new int[n]; for (int j = 0; j < string_arr.length; j++){ for(int i = 0; i < string_arr[j].length(); i++){ if(string_arr[j].charAt(i) == c){ diff[j] += 1; } else { diff[j] += -1; } } } Arrays.sort(diff); int sum = 0; int ans = n; for(int p = n-1; p >= 0;p--){ sum += diff[p]; if (sum <= 0) { ans = n - p - 1; break; } } answer = Math.max(answer, ans); } System.out.println(answer); } } catch(java.lang.Exception e){} } } ",0,Non-plagiarised a5d5a95f,ab7507bf,"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(); int Q = reader.nextInt(); outer: for (int q = 0; q < Q; q++) { int N = reader.nextInt(); int[][] scores = new int[5][N]; for (int i = 0; i < N; i++) { int[] occurs = new int[5]; String word = reader.next(); for (int j = 0; j < word.length(); j++) { occurs[word.charAt(j) - 'a']++; } for (int j = 0; j < 5; j++) { scores[j][i] = occurs[j] - (word.length() - occurs[j]) ; } } int bestCount = 0; for (int i = 0; i < 5; i++) { int[] curr = scores[i]; Arrays.sort(curr); int currentCount = 1; int currentScore = curr[curr.length - 1]; for (int j = curr.length - 2; j >= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ","import java.util.*; import java.io.*; public class C1551 { 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(); char[][] arr = new char[n][]; for (int i = 0; i < arr.length; i++) { arr[i] = sc.next().toCharArray(); } int[][] cnt = new int[n][5]; for (int i = 0; i < cnt.length; i++) { for (char c : arr[i]) { cnt[i][c - 'a']++; } } int fans = 0; for (int letter = 0; letter < 5; letter++) { ArrayList al = new ArrayList(); for (int i = 0; i < n; i++) { al.add(2 * cnt[i][letter] - arr[i].length); } Collections.sort(al, Collections.reverseOrder()); int sum = 0; int ans = 0; for (int x : al) { sum += x; if (sum > 0) { ans++; } else { break; } } fans = Math.max(ans, fans); } pw.println(fans); } pw.close(); } } ",0,Non-plagiarised 0588b869,69b2fd22,"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> adj = new ArrayList>(n); for(int k = 0; k < n; k++) adj.add(new HashSet()); for(int k = 0; k < n-1; k++){ adj.get(k).add(k+1); } //closest number before that is < Stack stk = new Stack(); stk.add(new Num(array[0],0)); for(int k = 1; k < n; k++){ while(!stk.isEmpty() && stk.peek().x > array[k]){ stk.pop(); } if(!stk.isEmpty()){ adj.get(stk.peek().i).add(k); } stk.add(new Num(array[k],k)); } //closest number after that is < stk = new Stack(); stk.add(new Num(array[n-1],n-1)); for(int k = n-2; k >= 0; k--){ while(!stk.isEmpty() && stk.peek().x > array[k]){ stk.pop(); } if(!stk.isEmpty()){ adj.get(k).add(stk.peek().i); } stk.add(new Num(array[k],k)); } //closest number before that is > stk = new Stack(); stk.add(new Num(array[0],0)); for(int k = 1; k < n; k++){ while(!stk.isEmpty() && stk.peek().x < array[k]){ stk.pop(); } if(!stk.isEmpty()){ adj.get(stk.peek().i).add(k); } stk.add(new Num(array[k],k)); } //closest number after that is > stk = new Stack(); stk.add(new Num(array[n-1],n-1)); for(int k = n-2; k >= 0; k--){ while(!stk.isEmpty() && stk.peek().x < array[k]){ stk.pop(); } if(!stk.isEmpty()){ adj.get(k).add(stk.peek().i); } stk.add(new Num(array[k],k)); } int[] path = new int[n]; Arrays.fill(path,Integer.MAX_VALUE); path[0] = 0; for(int k = 0; k < n; k++){ for(int nei : adj.get(k)){ path[nei] = Math.min(path[nei],path[k]+1); } } int answer = path[n-1]; out.println(answer); out.close(); } public static class Num{ int x; int i; public Num(int a, int b){ x = a; i = b; } } } ","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; import java.util.ArrayList; import java.util.Vector; import java.util.StringTokenizer; import java.io.BufferedReader; 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); DDiscreteCentrifugalJumps solver = new DDiscreteCentrifugalJumps(); solver.solve(1, in, out); out.close(); } static class DDiscreteCentrifugalJumps { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); ArrayList jumps[] = new ArrayList[n]; int h[] = new int[n]; for (int i = 0; i < n; i++) { h[i] = in.nextInt(); jumps[i] = new ArrayList<>(); } Stack s = new Stack<>(); for (int i = 0; i < n; i++) { while (s.size() > 0 && s.peek()[0] > h[i]) { s.pop(); } if (s.size() > 0) { jumps[i].add(s.peek()[1]); } s.add(new int[]{h[i], i}); } s.clear(); for (int i = 0; i < n; i++) { while (s.size() > 0 && s.peek()[0] < h[i]) { s.pop(); } if (s.size() > 0) { jumps[i].add(s.peek()[1]); } s.add(new int[]{h[i], i}); } s.clear(); for (int i = n - 1; i >= 0; i--) { while (s.size() > 0 && s.peek()[0] < h[i]) { s.pop(); } if (s.size() > 0) { jumps[s.peek()[1]].add(i); } s.add(new int[]{h[i], i}); } s.clear(); for (int i = n - 1; i >= 0; i--) { while (s.size() > 0 && s.peek()[0] > h[i]) { s.pop(); } if (s.size() > 0) { jumps[s.peek()[1]].add(i); } s.add(new int[]{h[i], i}); } s.clear(); int dp[] = new int[n]; dp[0] = 0; for (int i = 1; i < n; i++) { dp[i] = Integer.MAX_VALUE; for (int x : jumps[i]) { dp[i] = Math.min(dp[i], dp[x] + 1); } } out.print(dp[n - 1]); } } } ",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,Plagiarised 66e74577,6e207cbf,"import java.io.*; import java.util.*; public class Menorah { public static void main(String[] args) throws Exception { FastIO in = new FastIO(); int t = in.nextInt(); for (int tc=0; tc 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 3c667d4f,a7894e0b,"import java.util.*; public class j { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0) { int len=in.nextInt(); int t=in.nextInt(); int pos[]=new int[t]; int temp[]=new int[t]; for(int i=0;i=0;i--) { range[i]=Math.min(range[i+1]+1,range[i]); } for(int i=0;i0) { int n=sc.nextInt(); int k=sc.nextInt(); int[] ac=new int[k]; long[] ans=new long[n]; Arrays.fill(ans, Integer.MAX_VALUE/2); for(int i=0;i=0;i--) { ans[i]=Math.min(ans[i], ans[i+1]+1); } for(int i=0;izer=new ArrayList(),one=new ArrayList(); for(int i=0;ione,ArrayListzer,int i,int j,int count,long memo[][]) { if(count==0) return 0; if(i==one.size()||j==zer.size()) return Integer.MAX_VALUE; if(memo[i][j]!=-1) return memo[i][j]; long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE; a=arm(one, zer, i+1, j+1,count-1,memo)+Math.abs(one.get(i)-zer.get(j)); b=arm(one, zer, i, j+1,count,memo); memo[i][j]=Math.min(a, b); return Math.min(a, b); } } ","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()]); } } ",0,Non-plagiarised 0f14b12d,7d12d33c,"import java.io.BufferedReader; import java.io.IOException; import java.io.*; import java.util.*; import javax.management.Query; public class Test{ 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(); String [] words = new String[n]; int [] occ = new int[5]; int [] occWord = new int [5]; boolean [] found ; for(int i =0;i pq = new PriorityQueue<>(); for (String word : words){ pq.add(new Pair(word,occOfMaxChar(word, maxChar)-occOfOtherChar(word, maxChar))); } int res = 0; int curr = 0; int maxCharCount = 0; int otherCharCount =0; while(!pq.isEmpty()){ String word = pq.poll().x; maxCharCount +=occOfMaxChar(word, maxChar); otherCharCount += occOfOtherChar(word, maxChar); curr ++; if(maxCharCount >otherCharCount){ res = curr; } } maxRes = Math.max(maxRes, res); } System.out.println(maxRes);} } public static int occOfMaxChar (String s, int maxChar){ int occ = 0; for(int i =0 ;i gold ; static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.*; import java.util.*; import javax.management.Query; public class Test{ 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(); String [] words = new String[n]; for(int i =0;i pq = new PriorityQueue<>(); for (String word : words){ pq.add(new Pair(word,occOfMaxChar(word, maxChar)-occOfOtherChar(word, maxChar))); } int res = 0; int curr = 0; int maxCharCount = 0; int otherCharCount =0; while(!pq.isEmpty()){ String word = pq.poll().x; maxCharCount +=occOfMaxChar(word, maxChar); otherCharCount += occOfOtherChar(word, maxChar); curr ++; if(maxCharCount >otherCharCount){ res = curr; } } maxRes = Math.max(maxRes, res); } System.out.println(maxRes);} } public static int occOfMaxChar (String s, int maxChar){ int occ = 0; for(int i =0 ;i gold ; static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } } } ",1,Plagiarised c287ea9d,d2901569,"import java.util.*; import java.io.*; public class monstersandspells { public static void main(String args[]) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); /* 1 5 1 5 8 9 10 1 2 6 1 2 */ int t = in.nextInt(); for ( ; t > 0; t--) { int n = in.nextInt(); long[] times = new long[n]; long[] health = new long[n]; for (int i = 0; i < n; i++) times[i] = in.nextLong(); for (int i = 0; i < n; i++) health[i] = in.nextLong(); long small = 0; long prev = 0; long lastDamage = 0; for (int i = 0; i < n; i++) { long diff = times[i] - prev; boolean use = true; long delta = 0; //System.out.println(i + "" "" + times[i] + "" "" + diff); if (diff >= health[i]) { delta += health[i]; long curr = health[i]; long lastTime = times[i]; for (int j = i + 1; j < n; j++) { long increase = times[j] - lastTime; //long power = damageOverTime(increase + curr, curr + 1); if (curr + increase >= health[j]) { curr += increase; lastTime = times[j]; } else { delta += (health[j] - (curr + increase)); curr = health[j]; lastTime = times[j]; } } if (delta <= diff) { use = true; } else use = false; } else use = false; if (use) { //System.out.println(damageOverTime(health[i], 1)); small += damageOverTime(delta, 1); lastDamage = delta; } else { small += damageOverTime((times[i] - prev) + lastDamage, lastDamage + 1); lastDamage+=(times[i] - prev); } // System.out.println(use + "" "" + delta + "" "" + lastDamage + "" "" + small); prev = times[i]; } out.println(small); } out.close(); } public static long damageOverTime(long endPower, long startPower) { return triangleSum(endPower) - triangleSum(startPower - 1); } public static long triangleSum(long a) { return a * (a + 1) / 2; } } ","import java.util.*; import java.util.Scanner; public class Solution { static int mod=1000000007;; // public static void main(String[] args) { // TODO Auto-generated method stub // System.out.println(); Scanner sc=new Scanner(System.in); int tt=sc.nextInt(); // // while(tt-->0){ int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i(); // sieveOfEratosthenes((int)1e6+5); while(tc-->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 ans; //function to find prime factors of n //fenwick tree implementaion //Function to find number of set bits // function to find last index <= y // static class GraphMap{ // Map> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static PrintWriter out=new PrintWriter(System.out); } ","import java.io.*; import java.util.*; public class cp { static int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // primeSet=new HashSet<>(); // sieveOfEratosthenes((int)1e6+5); while(tc-->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> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static PrintWriter out=new PrintWriter(System.out); } ",1,Plagiarised 4548305b,c0aa6246,"import java.util.function.Consumer; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.io.*; import java.lang.Math.*; public class KickStart2020{ public static void main(String[] args) throws Exception{ FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); int arr[] = new int[k]; int temp[] = new int[k]; for(int i = 0; i < k; i++) arr[i] = sc.nextInt(); for(int i = 0; i < k; i++) temp[i] = sc.nextInt(); long brr[] = new long[n]; Arrays.fill(brr, Integer.MAX_VALUE); for(int i = 0; i < k; i++) brr[arr[i] - 1] = temp[i]; for(int i = 1; i < n; i++) { brr[i] = Math.min(brr[i], brr[i - 1] + 1); } for(int i = n - 2; i >= 0; i--) { brr[i] = Math.min(brr[i], brr[i + 1] + 1); } for(long e: brr) out.print(e + "" ""); out.println(); } out.close(); } } ","import java.util.*; import java.util.Map.Entry; import java.lang.*; import java.io.*; import java.math.BigInteger; public class CF { private static FS sc = new FS(); private static class extra { static int[] intArr(int size) { int[] a = new int[size]; for(int i = 0; i < size; i++) a[i] = sc.nextInt(); return a; } } static int mod = (int) 1e9 + 9; // static int mod = (int) 998244353; static int max = (int) 1e6, sq = 316; static LinkedList[] temp; // static int[] par, rank; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); int m = sc.nextInt(); int[] a = extra.intArr(m); int[] b = extra.intArr(m); long[] c = new long[n]; Arrays.fill(c, (int)1e18); for(int i = 0; i < m; i++) c[a[i]-1] = b[i]; long[] l = new long[n]; long[] r = new long[n]; Arrays.fill(l, (int)1e18); Arrays.fill(r, (int)1e18); long min = (long)1e18; for(int i = 0; i < n; i++) { min = Math.min(min+1, c[i]); l[i] = min; } min = (int)1e18; for(int i = n-1; i >= 0; i--) { min = Math.min(min+1, c[i]); r[i] = min; } for(int i = 0; i < n; i++) { ret.append(Math.min(l[i], r[i]) + "" ""); } ret.append(""\n""); } System.out.println(ret); } } ",0,Non-plagiarised b434c275,f8c99dd0,"import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; public final class A { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); // static node1 seg[]; //static pair moves[]= {new pair(-1,0),new pair(1,0), new pair(0,-1), new pair(0,1)}; public static void main(String args[])throws IOException { int T=i(); outer:while(T-->0) { int N=i(); int size[]=new int[N]; PriorityQueue q[]=new PriorityQueue[26]; for(int i=0; i<26; i++)q[i]=new PriorityQueue(); for(int i=0; i q_new=new PriorityQueue<>(); q_new=q[i]; int c=0; long f=0; while(q_new.size()>0) { node1 x=q_new.remove(); // System.out.println(x.f+"" ""+x.size+"" ""+x.a); f+=x.a; if(f>0) { c++; max=Math.max(max, c); } else break; } } out.println(max); } out.close(); } // static void build(int v,int tl,int tr,long A[]) // { // if(tl==tr) // { // seg[v]=new node1(A[tl],A[tr],1,true); // return ; // } // int tm=(tl+tr)/2; // build(2*v,tl,tm,A); // build(2*v+1,tm+1,tr,A); // seg[v]=merge(seg[2*v],seg[2*v+1]); // } // static node1 ask(int v,int tl,int tr,int l,int r) // { // if(l>r)return new node1(0,0,0,false);//verify true or false // if(tl==l && tr==r)return seg[v]; // int tm=(tl+tr)/2; // node1 a=ask(v*2,tl,tm,l,Math.min(tm, r)); // node1 b=ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r); // return merge(a,b); // } // static node1 merge(node1 a,node1 b) // { // long s=0; // long l1=a.L,r1=a.R,c1=a.cnt; // long l2=b.L,r2=b.R,c2=b.cnt; // long g=GCD(l2,r1); s=c1+c2; // if(g==1) // { // s--; // g=(l2*r1)/g; // if(c1==1) // { // l1=g; // } // if(c2==1)r2=g; // return new node1(l1,r2,s,true); // } // return new node1(l1,r2,s,a.leaf^b.leaf); // } static int i() { return in.nextInt(); } } class node1 implements Comparable { int index,f,size; long a; node1(int f,int i,int size) { this.f=f; this.index=i; this.size=size; a=2*f-size; } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader ","import java.util.*; import java.io.*; public class Solution { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void solve() throws IOException { int n = Integer.parseInt(br.readLine()); ArrayList words = new ArrayList<>(); ArrayList lens = new ArrayList<>(); //count [a,b,c,d,e] for (int i = 0; i < n; i++) { String temp = br.readLine(); int[] word = new int[5]; for (int j = 0; j < temp.length(); j++) { word[(int)(temp.charAt(j)) - 97]++; } words.add(word); lens.add(temp.length()); } int ans = 0; for (int i = 0; i < 5; i++) { ArrayList sums = new ArrayList<>(); //target occ - other occ for (int j = 0; j < words.size(); j++) { sums.add(words.get(j)[i] - (lens.get(j) - words.get(j)[i])); } Collections.sort(sums); int loc = 0; int run = 0; for (int j = sums.size() - 1; j >= 0; j--) { if(run + sums.get(j) > 0) { loc++; run += sums.get(j); } else break; } ans = Math.max(ans, loc); } System.out.println(ans); } public static void main(String[] args) throws IOException { int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { solve(); } } } ",0,Non-plagiarised 0df4050e,f5fde094,"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.util.*; import java.io.*; import java.lang.*; import java.util.StringTokenizer; public class Solution { static HritikScanner sc = new HritikScanner(); static PrintWriter pw = new PrintWriter(System.out, true); static StringBuilder sb = new StringBuilder(); public static void main(String[] args) { int t = ni(); while (t-- > 0) { solve(); } } static void solve() { int n = ni(); int[] arr = nextIntArray(n); char[] col = sc.next().toCharArray(); int[] cB = new int[n+1]; int[] cR = new int[n+1]; for(int i = 0; i < n; i++) { // pl((col[i] == 'R' && arr[i] > n)); // pl((col[i] == 'B' && arr[i] < 1)); if((col[i] == 'R' && arr[i] > n)||(col[i] == 'B' && arr[i] < 1)) { System.out.println(""NO""); return; } if(col[i] == 'B') { if(arr[i] > n) continue; cB[arr[i]]++; if(cB[arr[i]] > arr[i]) { System.out.println(""NO""); return; } } else { if(arr[i] < 1) continue; cR[arr[i]]++; if(cR[arr[i]] > (n-(arr[i]-1))) { System.out.println(""NO""); return; } } // pa(cB); // pa(cR); } // pa(cB); // pa(cR); int[] psum = new int[n+1]; for(int i = 1; i<= n; i++) { psum[i] = psum[i-1]+cB[i]; if(psum[i] > i) { System.out.println(""NO""); return; } } // pa(psum); int[] psum1 = new int[n+1]; psum1[n] = cR[n]; for(int i = n-1; i>= 0; i--) { psum1[i] = psum1[i+1]+cR[i]; if(psum1[i] > (n-(i-1))) { System.out.println(""NO""); return; } } // pa(psum1); System.out.println(""YES""); } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// static int[] nextIntArray(int n) { int[] arr = new int[n]; int i = 0; while (i < n) { arr[i++] = ni(); } return arr; } ///////////////////////////////////////////////////////////////////////////////// static int ni() { return sc.nextInt(); } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// //-----------HritikScanner class for faster input----------// ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Function to return gcd of a and b time complexity O(log(a+b)) // method to return LCM of two numbers ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // method returns Nth power of A } ",0,Non-plagiarised 73f57af1,ac8ef97c,"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.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 5b9a0551,9debf95c,"import java.io.*; import java.lang.reflect.Array; import java.util.*; public class Main { public static void main(String[] args) { FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=in.nextInt(); while(t-->0) solve(in,out); out.close(); } static void solve(FastScanner in,PrintWriter out){ int n=in.nextInt(); long a[]=new long[n]; for (int i = 0; i < n; i++) { a[i]=in.nextLong(); } long odd=Integer.MAX_VALUE,even=Integer.MAX_VALUE; even=a[0]; long sum=a[0]; long ans=Long.MAX_VALUE; for (int i = 1; i < n; i++) { if(i%2==0) { ans=Math.min(ans,(n-i/2)*a[i] + odd*(n-i/2) +sum); even=Math.min(even,a[i]); } else { ans=Math.min(ans,(n-i/2)*a[i] + even*(n-i/2-1) +sum); odd=Math.min(odd,a[i]); } sum+=a[i]; } out.println(ans); } } ","import java.io.BufferedOutputStream; 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.Comparator; 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; public class Main { static class Clock { protected long start, stop; public void start() { start = System.currentTimeMillis(); } } public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static long mod = 1000000007; static int parent[]; static int rank[]; public static long arr[]; public static int arr1[]; // static void seive(int n) { // arr = new int[n + 1]; // arr[0] = arr[1] = 1; // for (int i = 4; i <= n; i = i + 2) { // arr[i] = 1; // } // for (int i = 3; i * i <= n; i = i + 2) { // if (arr[i] == 0) { // for (int j = i * i; j <= n; j = j + i) { // arr[j] = 1; // } // // } // } // } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); Clock clock = new Clock(); clock.start(); int t1=sc.nextInt(); for (int t = 0; t { 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) { //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]; long[] array = new long[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); if(i==0){ array[i] = arr[i]; } else array[i] = (long)arr[i] + array[i-1]; } int evenMin = arr[0], oddMin = arr[1]; long ans = ((long) n * (long)arr[0]) + ((long) n * (long)arr[1]); for (int i = 2; i < n; i++) { if(i%2==0){ if(evenMin>arr[i]) { evenMin = arr[i]; } } else{ if(oddMin>arr[i]) { oddMin = arr[i]; } } if(i%2==0){ ans = Math.min(ans, array[i] + (long) ((n - (i / 2)) - 1) * (long)evenMin + (long) ((n - ((i-1) / 2)) - 1) * (long)oddMin ); } else{ ans = Math.min(ans, array[i] + (long) ((n - (i / 2)) - 1) * (long)oddMin + (long) ((n - ((i-1) / 2)) - 1) * (long)evenMin); } } out.println(ans); } } static final Random random=new Random(); } ","import java.io.*; import java.util.*; /* */ public class C { static FastReader sc=null; public static void main(String[] args) { sc=new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int c[]=sc.readArray(n); long dp[]=new long[n]; dp[0]=Long.MAX_VALUE; dp[1]=(long)n*c[1]+ (long)n*c[0]; long preMin[]=new long[n],pre[]=new long[n]; preMin[0]=pre[0]=c[0]; preMin[1]=pre[1]=c[1]; for(int i=2;i 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,Plagiarised 80881cae,f8e7b886,"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.util.*; import java.io.*; import java.time.*; import static java.lang.Math.*; @SuppressWarnings(""unused"") public class C { static boolean DEBUG = false; static Reader fs; static PrintWriter pw; static void solve() { int n = fs.nextInt(), k[] = fs.readArray(n), h[] = fs.readArray(n); int prev_h = h[0], prev_k = k[0]; // int ans = 0; ArrayList intervals = new ArrayList<>(); for (int i = 0; i < n; i++) { int start = k[i] - h[i] + 1; int end = k[i]; intervals.add(new pair(start, end)); } // pw.println(intervals); Collections.sort(intervals); ArrayList merged = new ArrayList<>(); merge(intervals, merged); long ans = 0; for(int i = 0 ; i < merged.size() ; i++) { ans += sum(merged.get(i).len()); } pw.println(ans); } static void merge(ArrayLista1, ArrayLista2) { int n = a1.size(); int index = 0; for(int i =1 ; i < n ; i++) { if(a1.get(index).s >= a1.get(i).f) { a1.get(index).s = max(a1.get(index).s, a1.get(i).s); } else { index++; a1.set(index, a1.get(i)); } } for(int i = 0 ; i <= index ; i++) { a2.add(a1.get(i)); } // pw.println(a1); } // int index = 0; // Stores index of last element // // in output array (modified arr[]) // // // Traverse all input Intervals // for (int i=1; i= arr[i].start) // { // // Merge previous and current Intervals // arr[index].end = Math.max(arr[index].end, arr[i].end); // } // else { // index++; // arr[index] = arr[i]; // } // } static pair merge(pair p1, pair p2) { return new pair(min(p1.f, p2.f), max(p1.s, p2.s)); } static long sum(long n) { return (n * (n + 1) / 2); } static class pair implements Comparable{ int f, s; pair(int f, int s) { this.f = f; this.s = s; } public int len() { return s - f + 1; } } public static void main(String[] args) throws IOException { Instant start = Instant.now(); if (args.length == 2) { System.setIn(new FileInputStream(new File(""D:\\program\\javaCPEclipse\\CodeForces\\src\\input.txt""))); // System.setOut(new PrintStream(new File(""output.txt""))); System.setErr(new PrintStream(new File(""D:\\program\\javaCPEclipse\\CodeForces\\src\\error.txt""))); DEBUG = true; } fs = new Reader(); pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { solve(); } Instant end = Instant.now(); if (DEBUG) { pw.println(Duration.between(start, end)); } pw.close(); } static void sort(int a[]) { ArrayList l = new ArrayList(); for (int x : a) l.add(x); Collections.sort(l); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } } } ",0,Non-plagiarised c1fef98f,fadc1365,"import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Test{ static FastReader scan; static void solve(){ scan.nextLine(); int n=scan.nextInt(); int k=scan.nextInt(); int []arr=new int[n+1]; int []block=new int[k]; int []temp=new int[k]; for(int i=0;i=1;i--){ if(arr[i]==0){ if(prev==Integer.MAX_VALUE-1000){ dp[i]=Math.min(prev,dp[i]); } else{ prev=prev+1; dp[i]=Math.min(prev,dp[i]); } } else{ prev=Math.min(prev+1,arr[i]); dp[i]=Math.min(prev,dp[i]); } } for(int i=1;i<=n;i++){ System.out.print(dp[i]+"" ""); } System.out.println(); } public static void main (String[] args) throws java.lang.Exception{ scan=new FastReader(); int t=scan.nextInt(); while(t-->0){ solve(); } } } ","import java.io.PrintWriter; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class a{ public static void main(String args[]) throws java.lang.Exception{ FastScanner s=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=s.nextInt(); for(int tt=0;tt=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;iar=new ArrayList<>(); for(int i=0;i0){ ans++; } else break; } return ans; } public static void main(String arg[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { int n=Integer.parseInt(br.readLine()); int a[][]=new int[n][5]; int tot[]=new int[n]; for(int i=0;i0) { 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 11c2ab99,28c2d81a,"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 = 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=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;i0){ int n = scan.nextInt(); long[] k = new long[n]; long[] h = new long[n]; for(int i =0;idist){ ans+=summ(dist+lastHP)-summ(lastHP); lastHP+=dist; }else{ long diff = dist-hpComingOut; ans+=summ(hpComingOut); lastHP = hpComingOut; } lastD = k[i]; } System.out.println(ans); } } static long summ(long a){ return (a*(a+1))/2; } } ","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[]; static boolean v[]; // static int mod=998244353;; static int mod=1000000007; static int max; static int bit[]; //static long fact[]; // static long A[]; static HashMap map; //static StringBuffer sb=new StringBuffer(""""); //static HashMap map; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); long A[]=inputL(n); long B[]=inputL(n); long C[]=new long[n]; for(int i=0;i=0;i--) { if(C[i]>min) { continue; } if(A[i]0) { st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken());//monsters int time[]=new int[n];//time int health[]=new int[n];//health st=new StringTokenizer(br.readLine()); for(int i=0;i{ int x, time; public State(int x, int time) { this.x=x;this.time=time; } } } ","import java.io.*; import java.util.*; public class c { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numcases = Integer.parseInt(in.readLine()); for(int casenum = 0; casenum < numcases; casenum++){ int n = Integer.parseInt(in.readLine()); long[] t = new long[n]; long[] h = new long[n]; StringTokenizer tokenizer = new StringTokenizer(in.readLine()); for(int i = 0; i < n; i++){ t[i] = Integer.parseInt(tokenizer.nextToken()); } tokenizer = new StringTokenizer(in.readLine()); for(int i = 0; i < n; i++){ h[i] = Integer.parseInt(tokenizer.nextToken()); } long mana = 0; int index = 0; while(index < n){ long start = t[index] - h[index]; long end = t[index]; for(int i = index+1; i < n; i++){ if(t[i] - h[i] < start){ start = t[i] - h[i]; end = t[i]; index = i; } else if(t[i] - end < h[i]){ end = t[i]; index = i; } } mana += (end - start + 1) * (end - start) / 2; index++; } System.out.println(mana); } in.close(); out.close(); } } ",0,Non-plagiarised b55888de,d3a0b8d2,"import java.lang.reflect.Array; import java.util.*; public class Rough { 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 s[] = new String[n]; int f[][] = new int[n][5]; for (int i = 0; i < n; i++) { s[i] = sc.nextLine(); for (int j = 0; j < s[i].length(); j++) { f[i][s[i].charAt(j)-'a']++; } } int ans = 0; for ( int i = 0; i < 5; i++) { ArrayList al = new ArrayList<>(); for (int j = 0; j < n; j++) { int o = 0; for (int k = 0; k < 5; k++) { if(k != i) o+=f[j][k]; } al.add(f[j][i]-o); } Collections.sort(al,Collections.reverseOrder()); int max = 0; int x = 0; for (int j = 0; j < n; j++) { x+=al.get(j); if(x<=0)break; max++; } ans = Math.max(max,ans); } System.out.println(ans); } sc.close(); } } ","import java.io.File; import java.io.IOException; import java.util.*; public class C { public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0){ int n = in.nextInt(); int[][] cnt = new int[n][5]; int[] len = new int[n]; for (int i = 0; i < n; i++){ String s = in.next(); len[i] = s.length(); for (char c : s.toCharArray()) cnt[i][c-'a']++; } int max = 0; for (int i = 0; i < 5; i++){ int[] diff = new int[n]; for (int j = 0; j < n; j++) diff[j] = cnt[j][i] - (len[j] - cnt[j][i]); Arrays.sort(diff); int j = n-2, sum = diff[n-1]; while (j>=0 && sum > 0){ max = Math.max(max, n - 1 - j); sum += diff[j]; j--; } if (sum > 0) max = Math.max(max, n); } System.out.println(max); } } } ",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 ones = new ArrayList(); ArrayList zeroes = new ArrayList(); for(int i = 0; i < n; i++){ if(ar[i] == 1) ones.add(i); else zeroes.add(i); } int r = ones.size(); int c = zeroes.size(); int time[][] = new int[r][c]; System.out.println(calculateTime(time, r, c, 0, 0, ones, zeroes)); } public static int calculateTime(int time[][], int r, int c, int currR, int currC, ArrayList ones, ArrayList zeroes){ // System.out.println(currR + "" "" + currC); if(currR == r) return 0; if(currC == c) return (int)1e9; if(time[currR][currC] != 0) return time[currR][currC]; return time[currR][currC] = Math.min((calculateTime(time, r, c, currR + 1, currC + 1, ones, zeroes) + Math.abs(ones.get(currR) - zeroes.get(currC))), calculateTime(time, r, c, currR, currC + 1, ones, zeroes)); } } ","import java.io.*; import java.util.*; public class E { public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int cnt = n; boolean[] non = new boolean[n]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) { if(Integer.parseInt(st.nextToken()) == 0) { non[i] = true; cnt--; } } int x = 0; int y = 0; int[] location = new int[cnt]; int[] rlocation = new int[n-cnt]; for(int i = 0; i < n; i++) { if(!non[i]) { location[x] = i; x++; }else{ rlocation[y] = i; y++; } } int[][] dp = new int[(n-cnt)+1][cnt+1]; Arrays.fill(dp[0], 100000000); dp[0][0] = 0; for(int i = 0; i < n-cnt; i++) { //System.out.println(""HIT""); if(i < (n-cnt)) Arrays.fill(dp[i+1], 100000000); for(int j = 0; j < cnt; j++) { if(i < (n-cnt)) { dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j]); dp[i+1][j+1] = Math.min(dp[i+1][j+1], dp[i][j] + Math.abs(rlocation[i] - location[j])); //System.out.println(dp[i+1][j+1] + "" "" + dp[i][j] + "" "" + j + "" "" + rlocation[i] + "" "" + location[j]); } } } int min = Integer.MAX_VALUE; for(int i = 0; i < (n-cnt)+1; i++) { min = Math.min(dp[i][cnt], min); } System.out.println(min); } } ",0,Non-plagiarised 7686c854,edce3e39,"import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.IntToLongFunction; import java.lang.*; import java.io.*; import java.math.*; public final class CF { public static void main(String[]args)throws IOException { FastReader ob=new FastReader(); int t=ob.nextInt(); StringBuffer sb=new StringBuffer(); while(t-->0) { int n=ob.nextInt(); PriorityQueue a=new PriorityQueue<>(); PriorityQueue b=new PriorityQueue<>(); long ans=Long.MAX_VALUE; long sum=0; for(int i=0;i 0) { int n = sc.nextInt(); int[] a = extra.intArr(n); PriorityQueue c = new PriorityQueue<>(); PriorityQueue d = new PriorityQueue<>(); long sum = 0; long min = Long.MAX_VALUE; for(int i = 0; i < n; i++) { sum += a[i]; if(i%2 == 0) c.add(a[i]); else d.add(a[i]); if(i != 0) { min = Math.min(min, sum + (n - c.size())*1L*c.peek() + (n-d.size())*1L*d.peek()); } } ret.append(min + ""\n""); } System.out.println(ret); } } ",1,Plagiarised 268eb6c6,3cf63146,"import java.util.*; import java.io.*; public class Test { // Fast IO class static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[k]; int[] temp = new int[n]; for (int i = 0; i < k; i++) a[i] = sc.nextInt(); for (int i = 0; i < k; i++) temp[a[i] - 1] = sc.nextInt(); int[] left = new int[n]; int[] right = new int[n]; Arrays.fill(left, Integer.MAX_VALUE - 1); Arrays.fill(right, Integer.MAX_VALUE - 1); if (temp[0] > 0) left[0] = temp[0]; for (int i = 1; i < n; i++) { left[i] = Math.min(left[i - 1] + 1, left[i]); if (temp[i] > 0) left[i] = Math.min(left[i], temp[i]); } if (temp[n - 1] > 0) right[n - 1] = temp[n - 1]; for (int i = n - 2; i >= 0; i--) { right[i] = Math.min(right[i + 1] + 1, right[i]); if (temp[i] > 0) right[i] = Math.min(right[i], temp[i]); } for (int i = 0; i < n; i++) out.print(Math.min(left[i], right[i]) + "" ""); out.println(); } out.flush(); out.close(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.time.LocalDateTime; import java.util.*; public class B { static int tree[]; static int up[]; static int n; static int mod =1000000007; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer: while(t-->0) { n=fs.nextInt(); int k=fs.nextInt(); int ac[]=fs.readArray(k); int temp[]=fs.readArray(k); int arr[]=new int[n]; Arrays.fill(arr, Integer.MAX_VALUE/2); for(int i=0;i=0;i--) { ans[i]=Math.min(Math.min(arr[i],left[i]),ans[i+1]+1); } // for(int i=0;i 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 ac7187d8,b7a6c59c,"import java.io.*; import java.util.*; public class C { public static void main (String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int t = Integer.parseInt(st.nextToken()); while (t-->0) { st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(f.readLine()); long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(st.nextToken()); } solve(n, arr); } } static void solve(long n, long[] arr) { long minEven = Integer.MAX_VALUE; long minOdd = arr[0]; long evenSum = 0; long oddSum = arr[0]; long finans = Long.MAX_VALUE; long oddAns, evenAns; long oddcount=1; long evencount=0; for (int k = 1; k < n; k++) { if (k%2==1) { evenSum+=arr[k]; evencount++; minEven = Math.min(minEven, arr[k]); } else { oddSum+=arr[k]; oddcount++; minOdd = Math.min(minOdd, arr[k]); } oddAns = oddSum+(n-oddcount)*minOdd; evenAns = evenSum+(n-evencount)*minEven; finans = Math.min(finans, oddAns+evenAns); } System.out.println(finans); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class MinimumGridPath { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int cases = Integer.parseInt(line); for(int i = 0; i 0){ int n = s.nextInt(); String a = s.next(); String b = s.next(); int a1 = 0, b1 = 0; for (char c: a.toCharArray()){ if (c == '1') a1++; } for (char c: b.toCharArray()){ if (c == '1') b1++; } int ans = Integer.MAX_VALUE; int res = 0; for (int i = 0; i < n; i++) { if (a.charAt(i) != b.charAt(i)) res++; } if (a1 == b1) ans = Math.min(ans, res); if (b1 == n-a1+1) ans = Math.min(ans, n-res); if (ans == Integer.MAX_VALUE){ System.out.println(""-1""); } else { 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 9399204d,b434c275,"import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; public final class A { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); // static node1 seg[]; //static pair moves[]= {new pair(-1,0),new pair(1,0), new pair(0,-1), new pair(0,1)}; public static void main(String args[])throws IOException { int T=i(); outer:while(T-->0) { int N=i(); int size[]=new int[N]; PriorityQueue q[]=new PriorityQueue[6]; for(int i=0; i<5; i++)q[i]=new PriorityQueue(); for(int i=0; i q_new=new PriorityQueue<>(); q_new=q[i]; int c=0; long f=0; while(q_new.size()>0) { node1 x=q_new.remove(); // System.out.println(x.f+"" ""+x.size+"" ""+x.a); f+=x.a; if(f>0) { c++; max=Math.max(max, c); } else break; } } out.println(max); } out.close(); } // static void build(int v,int tl,int tr,long A[]) // { // if(tl==tr) // { // seg[v]=new node1(A[tl],A[tr],1,true); // return ; // } // int tm=(tl+tr)/2; // build(2*v,tl,tm,A); // build(2*v+1,tm+1,tr,A); // seg[v]=merge(seg[2*v],seg[2*v+1]); // } // static node1 ask(int v,int tl,int tr,int l,int r) // { // if(l>r)return new node1(0,0,0,false);//verify true or false // if(tl==l && tr==r)return seg[v]; // int tm=(tl+tr)/2; // node1 a=ask(v*2,tl,tm,l,Math.min(tm, r)); // node1 b=ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r); // return merge(a,b); // } // static node1 merge(node1 a,node1 b) // { // long s=0; // long l1=a.L,r1=a.R,c1=a.cnt; // long l2=b.L,r2=b.R,c2=b.cnt; // long g=GCD(l2,r1); s=c1+c2; // if(g==1) // { // s--; // g=(l2*r1)/g; // if(c1==1) // { // l1=g; // } // if(c2==1)r2=g; // return new node1(l1,r2,s,true); // } // return new node1(l1,r2,s,a.leaf^b.leaf); // } static int i() { return in.nextInt(); } } class node1 implements Comparable { int index,f,size; long a; node1(int f,int i,int size) { this.f=f; this.index=i; this.size=size; a=2*f-size; } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader ","import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; public final class A { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); // static node1 seg[]; //static pair moves[]= {new pair(-1,0),new pair(1,0), new pair(0,-1), new pair(0,1)}; public static void main(String args[])throws IOException { int T=i(); outer:while(T-->0) { int N=i(); int size[]=new int[N]; PriorityQueue q[]=new PriorityQueue[26]; for(int i=0; i<26; i++)q[i]=new PriorityQueue(); for(int i=0; i q_new=new PriorityQueue<>(); q_new=q[i]; int c=0; long f=0; while(q_new.size()>0) { node1 x=q_new.remove(); // System.out.println(x.f+"" ""+x.size+"" ""+x.a); f+=x.a; if(f>0) { c++; max=Math.max(max, c); } else break; } } out.println(max); } out.close(); } // static void build(int v,int tl,int tr,long A[]) // { // if(tl==tr) // { // seg[v]=new node1(A[tl],A[tr],1,true); // return ; // } // int tm=(tl+tr)/2; // build(2*v,tl,tm,A); // build(2*v+1,tm+1,tr,A); // seg[v]=merge(seg[2*v],seg[2*v+1]); // } // static node1 ask(int v,int tl,int tr,int l,int r) // { // if(l>r)return new node1(0,0,0,false);//verify true or false // if(tl==l && tr==r)return seg[v]; // int tm=(tl+tr)/2; // node1 a=ask(v*2,tl,tm,l,Math.min(tm, r)); // node1 b=ask(v*2+1,tm+1,tr,Math.max(tm+1, l),r); // return merge(a,b); // } // static node1 merge(node1 a,node1 b) // { // long s=0; // long l1=a.L,r1=a.R,c1=a.cnt; // long l2=b.L,r2=b.R,c2=b.cnt; // long g=GCD(l2,r1); s=c1+c2; // if(g==1) // { // s--; // g=(l2*r1)/g; // if(c1==1) // { // l1=g; // } // if(c2==1)r2=g; // return new node1(l1,r2,s,true); // } // return new node1(l1,r2,s,a.leaf^b.leaf); // } static int i() { return in.nextInt(); } } class node1 implements Comparable { int index,f,size; long a; node1(int f,int i,int size) { this.f=f; this.index=i; this.size=size; a=2*f-size; } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader ",1,Plagiarised a3e272af,f7fc2e94,"import java.io.*; import java.util.*; public class Asd { static PrintWriter w = new PrintWriter(System.out); static FastScanner s = new FastScanner(); static boolean sd = false; public static void main(String[] args) { int t = s.nextInt(); //int t=1; while (t-- > 0) { solve(); } w.close(); } public static class Student { public int i1; public int value; // A parameterized student constructor public Student(int i1,int i2) { this.i1 = i1; this.value=i2; } public int getkey() { return i1; } public int getValue() { return value; } } static class StudentComparator implements Comparator{ // Overriding compare()method of Comparator // for descending order of cgpa } /* Function to print all the permutations of the string static String swap(String str, int i, int j) { char ch; char[] array = str.toCharArray(); ch = array[i]; array[i] = array[j]; array[j] = ch; return String.valueOf(array); } static void permute(String str,int low,int high) { if(low == high) list.add(Long.parseLong(str)); int i; for(i = low; i<=high; i++){ str = swap(str,low,i); permute(str, low+1,high); str = swap(str,low,i); } } use permute(str2,0,str2.length()-1); to perform combinations */ public static void solve() { int n=s.nextInt(); int m=s.nextInt(); int x=s.nextInt(); int arr[]=new int[n];int res[]=new int[n]; for(int i=0;i pq=new PriorityQueue(new StudentComparator()); 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;i0) { int n = sc.nextInt(); ArrayList one = new ArrayList<>(); ArrayList zero = new ArrayList<>(); for(int i=0;i o=new ArrayList(), e=new ArrayList(); int n = sc.nextInt(); for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } int dp[][]=new int[o.size()+1][e.size()+1]; 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,Plagiarised 2120328e,6de04ee2,"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;i0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i l=new Vector<>(), r=new Vector<>(); for(int i=0;i n - i) ok = false; System.out.print((ok ? ""YES"" : ""NO"")+'\n'); } } } ",1,Plagiarised 2a655afe,692a4496,"import java.io.*; import java.util.*; public class c { public static BufferedReader in; public static void main(String[] args) throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numcases = Integer.parseInt(in.readLine()); for (int casenum = 0; casenum < numcases; casenum++) { int n = Integer.parseInt(in.readLine()); int[] p = new int[n]; Arrays.fill(p, -1); for (int i = 0; i < n; i++) { if (p[i] != -1) continue; ArrayList 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.*; public class c { public static BufferedReader in; public static void main(String[] args) throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numcases = Integer.parseInt(in.readLine()); for (int casenum = 0; casenum < numcases; casenum++) { int n = Integer.parseInt(in.readLine()); int[] p = new int[n]; Arrays.fill(p, -1); for (int i = 0; i < n; i++) { if (p[i] != -1) continue; ArrayList 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; } } ",1,Plagiarised 643e22cc,bd7281dc,"import java.io.*; import java.util.*; public class C { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { readInput(); out.close(); } static class Tower implements Comparable{ 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 04ed33a5,6b83b22e,"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 = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i=0;i0){ int n=sc.nextInt(); char[] s=new char[n+5]; char[] t=new char[n+5]; String ss=sc.next(); String tt=sc.next(); s=ss.toCharArray(); t=tt.toCharArray(); int cntax = 0, cntbx = 0, same = 0; int ans=MOD9; 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 26e699de,f229aa7f,"import java.util.Scanner; public class Menorah { static int MOD9= 1000000000; public static void main(String[] args){ Scanner sc= new Scanner(System.in); int numberTest=sc.nextInt(); while(numberTest-->0){ int n=sc.nextInt(); char[] s=new char[n+5]; char[] t=new char[n+5]; String ss=sc.next(); String tt=sc.next(); s=ss.toCharArray(); t=tt.toCharArray(); int cntax = 0, cntbx = 0, same = 0; int ans=MOD9; 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(); } } ",0,Non-plagiarised 853acff9,929b98f0,"import java.lang.*; import java.util.*; import java.io.*; public class C { final static int mod = (int)(1e9 + 7); static LinkedList[] adj; static int arr[][] ; static long dp[][] ; public static void main(String[] args) { FastReader fs = new FastReader(); int testcase = 1; testcase = fs.nextInt(); //int i = 1; while (testcase-- > 0) { //System.out.print(""Case #"" + Integer.toString(i) + "": ""); solve(fs); //i++; } } public static void solve(FastReader fs) { int n = fs.nextInt(); arr = new int[n + 1][2]; adj = new LinkedList[n + 1]; dp = new long[n + 1][2]; for (int i = 0; i < adj.length; i++) { adj[i] = new LinkedList(); } for (int i = 1; i < arr.length; i++) { arr[i][0] = fs.nextInt(); arr[i][1] = fs.nextInt(); } for (int i = 0; i < n - 1; i++) { int u = fs.nextInt(); int v = fs.nextInt(); adj[u].add(v); adj[v].add(u); } dfs(1, -1); System.out.println(Math.max(dp[1][0], dp[1][1])); } static void dfs(int source , int parent) { for (int val : adj[source]) { if (val == parent) continue; dfs(val, source); dp[source][0] += Math.max(dp[val][0] + Math.abs(arr[source][0] - arr[val][0]), dp[val][1] + Math.abs(arr[source][0] - arr[val][1])); dp[source][1] += Math.max(dp[val][0] + Math.abs(arr[source][1] - arr[val][0]), dp[val][1] + Math.abs(arr[source][1] - arr[val][1])); } } //IO operation } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.*; public class Main { public static long[] ans(List> edges, long[][] range, int root, boolean[] visited, PrintStream out) { if (visited[root]) { return new long[2]; } visited[root] = true; long[] ans = new long[2]; for (int x : edges.get(root)) { if (!visited[x]) { long[] temp = ans(edges, range, x, visited, out); ans[0] += Math.max(Math.abs(range[root][0] - range[x][0]) + temp[0], Math.abs(range[root][0] - range[x][1]) + temp[1]); ans[1] += Math.max(Math.abs(range[root][1] - range[x][0]) + temp[0], Math.abs(range[root][1] - range[x][1]) + temp[1]); } } return ans; } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintStream out = new PrintStream(System.out); int t = Integer.parseInt(reader.readLine()); while (t-->0) { int n = Integer.parseInt(reader.readLine()); long[][] range = new long[n][2]; for (int i = 0; i < n; i++) { String[] input = reader.readLine().split("" ""); range[i][0] = Integer.parseInt(input[0]); range[i][1] = Integer.parseInt(input[1]); } List> edges = new ArrayList<>(); for (int i = 0; i < n; i++) { edges.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { String[] input = reader.readLine().split("" ""); int u = Integer.parseInt(input[0]) - 1, v = Integer.parseInt(input[1]) - 1; edges.get(u).add(v); edges.get(v).add(u); } int root = 0; for (int i = 0; i < n; i++) { if (edges.get(i).size() > 1) { root = i; break; } if (edges.get(i).size() == 1) { root = i; } } long[] ans = ans(edges, range, root, new boolean[n], out); out.println(Math.max(ans[0], ans[1])); } out.close(); } } ",0,Non-plagiarised 2c7a0000,4201fdf7,"import java.io.*; import java.util.*; public class Codeforces { 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) { int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split("" ""); int[] a = new int[n]; int k = 0; ArrayList pos = new ArrayList<>(); for(int i=0; i pos = new ArrayList(); st = new StringTokenizer(br.readLine()); for(int i=0;i 0){ int n=sc.nextInt(); long k=sc.nextLong(); int[] arr=new int[n]; long sum=0; for(int i=0;i=0;i--) s[i]=s[i+1]+arr[i]-arr[0]; for(int i=n-1;i>=1;i--) { long caseAns=(sum-k-s[i]+n-i)/(n-i+1); caseAns=Math.max(caseAns,0); caseAns+=n-i; ans=Math.min(caseAns,ans); } System.out.println(ans); } sc.close(); } } ","import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; import java.text.DecimalFormat; public final class Solution { static int inf = Integer.MAX_VALUE; static long mod = 1000000000 + 7; static void ne(Scanner sc, BufferedWriter op) throws Exception { int n=sc.nextInt(); long k=sc.nextLong(); long[] arr= new long[n]; long sum=0; for(int i=0;i=1;i--){ sum-=arr[i]; sum+=arr[0]; cc++; if(sum<=k){ min=Math.min(min,cc); break; } } long val=Math.abs(arr[0]-(k/n))+(n-1); min=Math.min(val,min); for(int i=1;i0){ ne(sc, op); } // ne(sc,op); op.flush(); } static void sort(int[] arr){ ArrayList list= new ArrayList<>(); for(int i=0;i list= new ArrayList<>(); for(int i=0;i g[]; static long mod=(long)998244353,INF=Long.MAX_VALUE; // static boolean set[]; static int par[],partial[]; static int Days[],P[][]; static int sum=0,size[]; static int seg[],col[]; // static ArrayList A; static char X[][]; static boolean set[][]; static int D[],min[],A[]; static long dp[][]; // static HashSet visited,imposters; // static HashSet set; // static node1 seg[]; //static pair moves[]= {new pair(-1,0),new pair(1,0), new pair(0,-1), new pair(0,1)}; public static void main(String args[])throws IOException { /* * star,rope,TPST * BS,LST,MS,MQ */ int T=i(); outer:while(T-->0) { int N=i(); int f[]=new int[N+5]; int ask=ask(1); HashSet set=new HashSet<>(); int cnt=0; for(int i=1; i<=N; i++) { if(cnt+1==N) { set=new HashSet<>(); for( i=0; i<=N; i++)set.add(i); for( i=1; i<=N; i++)set.remove(f[i]); int a=-1; for(int v:set) { a=v; } for(i=1; i<=N; i++) { if(f[i]==0)f[i]=a; } break; } if(f[i]==0) { int last=0; set=new HashSet<>(); while(true) { int a=ask(i); f[last]=a; if(set.contains(a)) { break; } last=a; set.add(a); } cnt+=set.size(); } } for(int i=1; i<=N; i++) { ans.append(f[i]+"" ""); } System.out.println(""! ""+ans); ans=new StringBuilder(); } out.println(ans); out.close(); } static int ask(int a) { System.out.println(""? ""+a); // out.flush(); return i(); } static long fact[]; static int ask(int v,int tl,int tr,int l,int r) { // System.out.println(v); // if(v>100)return 0; if(l>r)return Integer.MAX_VALUE; if(tl==l && tr==r)return seg[v]; int tm=(tl+tr)/2; int a=ask(v*2,tl,tm,l,Math.min(tm, r)); // System.out.println(""for--> ""+(v)+"" tm--> ""+(tm+1)+"" tr--> ""+tr+"" l--> ""+Math.max(l, tm+1)+"" r--> ""+r); int b=ask(v*2+1,tm+1,tr,Math.max(l, tm+1),r); return Math.min(a, b); } static int ask(int a,int b) { System.out.println(""? ""+a+"" ""+b); return i(); } // static void build(int v,int tl,int tr,long A[]) // { // if(tl==tr) // { // seg[v]=A[tl]; // } // else // { // int tm=(tl+tr)/2; // build(v*2,tl,tm,A); // build(v*2+1,tm+1,tr,A); // seg[v]=Math.min(seg[v*2], seg[v*2+1]); // } // } static int i() { return in.nextInt(); } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader ",0,Non-plagiarised 4f7af821,8f6421f3,"import java.util.*; public class contestA { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int inf = 1000300300; while (t-->0){ 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--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i(); // sieveOfEratosthenes((int)1e6+5); while(tc-->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> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static PrintWriter out=new PrintWriter(System.out); } ","import java.util.*; import java.io.*; import java.time.*; import static java.lang.Math.*; @SuppressWarnings(""unused"") public class C { static boolean DEBUG = false; static Reader fs; static PrintWriter pw; static void solve() { int n = fs.nextInt(), k[] = fs.readArray(n), h[] = fs.readArray(n); int prev_h = h[0], prev_k = k[0]; // int ans = 0; ArrayList intervals = new ArrayList<>(); for (int i = 0; i < n; i++) { int start = k[i] - h[i] + 1; int end = k[i]; intervals.add(new pair(start, end)); } // pw.println(intervals); Collections.sort(intervals); ArrayList merged = new ArrayList<>(); merge(intervals, merged); long ans = 0; for(int i = 0 ; i < merged.size() ; i++) { ans += sum(merged.get(i).len()); } pw.println(ans); } static void merge(ArrayLista1, ArrayLista2) { int n = a1.size(); int index = 0; for(int i =1 ; i < n ; i++) { if(a1.get(index).s >= a1.get(i).f) { a1.get(index).s = max(a1.get(index).s, a1.get(i).s); } else { index++; a1.set(index, a1.get(i)); } } for(int i = 0 ; i <= index ; i++) { a2.add(a1.get(i)); } // pw.println(a1); } // int index = 0; // Stores index of last element // // in output array (modified arr[]) // // // Traverse all input Intervals // for (int i=1; i= arr[i].start) // { // // Merge previous and current Intervals // arr[index].end = Math.max(arr[index].end, arr[i].end); // } // else { // index++; // arr[index] = arr[i]; // } // } static pair merge(pair p1, pair p2) { return new pair(min(p1.f, p2.f), max(p1.s, p2.s)); } static long sum(long n) { return (n * (n + 1) / 2); } static class pair implements Comparable{ int f, s; pair(int f, int s) { this.f = f; this.s = s; } public int len() { return s - f + 1; } } public static void main(String[] args) throws IOException { Instant start = Instant.now(); if (args.length == 2) { System.setIn(new FileInputStream(new File(""D:\\program\\javaCPEclipse\\CodeForces\\src\\input.txt""))); // System.setOut(new PrintStream(new File(""output.txt""))); System.setErr(new PrintStream(new File(""D:\\program\\javaCPEclipse\\CodeForces\\src\\error.txt""))); DEBUG = true; } fs = new Reader(); pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { solve(); } Instant end = Instant.now(); if (DEBUG) { pw.println(Duration.between(start, end)); } pw.close(); } static void sort(int a[]) { ArrayList l = new ArrayList(); for (int x : a) l.add(x); Collections.sort(l); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } } } ",0,Non-plagiarised 810cf242,968c1e7e,"import java.util.*; import java.io.*; public class E1547{ static int inf = 2*(int)Math.pow(10,9); static FastScanner fs = null; public static void main(String[] args) { fs = new FastScanner(); int t = fs.nextInt(); while(t-->0){ int n = fs.nextInt(); int k = fs.nextInt(); int pos[] = new int[k]; for(int i=0;i=0;i--){ time[i] = Math.min(time[i],1+time[i+1]); } for(int i=0;i> map = new HashMap>(); HashMap count1 = new HashMap (); for(int i=0;i obj = new ArrayList(); obj.add(pos[i]-1); map.put(temp[i],obj); count1.put(temp[i],1); } } int num=min; while(true){ if(!map.containsKey(num)){ break; } ArrayList obj2 = map.get(num); for(int i=0;i(num+1)|| ans[index+1]==0)){ ans[index+1]=num+1; if(map.containsKey(num+1)){ map.get(num+1).add(index+1); } else{ ArrayList object = new ArrayList(); object.add(index+1); map.put(num+1,object); } } if(index-1>=0 && (ans[index-1]>(num+1)|| ans[index-1]==0)){ ans[index-1]=num+1; if(map.containsKey(num+1)){ map.get(num+1).add(index-1); } else{ ArrayList object = new ArrayList(); object.add(index-1); map.put(num+1,object); } } } else if(ans[index]==num){ if(index+1(num+1)|| ans[index+1]==0)){ ans[index+1]=num+1; if(map.containsKey(num+1)){ map.get(num+1).add(index+1); } else{ ArrayList object = new ArrayList(); object.add(index+1); map.put(num+1,object); } } if(index-1>=0 && (ans[index-1]>(num+1)|| ans[index-1]==0)){ ans[index-1]=num+1; if(map.containsKey(num+1)){ map.get(num+1).add(index-1); } else{ ArrayList object = new ArrayList(); object.add(index-1); map.put(num+1,object); } } } } } num++; } for(int i=0;i 0) result = Math.min(result, min); } System.out.println(result); } } ","import java.io.*; import java.util.*; public class D { static int[][] dp; static int solve(int i,int j,ArrayList A,ArrayList B) { if(i==A.size()) { return 0; } if(j==B.size()) { return 1000000009; } if(dp[i][j]!=-1) { return dp[i][j]; } int ans=1000000009; int a=A.get(i); int b=B.get(j); ans=Math.min(ans, Math.abs(a-b)+solve(i+1,j+1,A,B)); ans=Math.min(ans, solve(i,j+1,A,B)); return dp[i][j]=ans; } public static void main(String[] args){ FastReader sc=new FastReader(); int t=1; while(t-->0) { int n=sc.nextInt(); int[] a=new int[n]; ArrayList A=new ArrayList<>(); ArrayList B=new ArrayList<>(); for(int i=0;i0) { int n = sc.nextInt(); int ans[] = new int[n]; for(int i = 1; i <= n; i++) { if(ans[i - 1] != 0) continue; HashSet set = new HashSet<>(); ArrayList arr = new ArrayList<>(); while(true) { int x = query(i); if(set.contains(x)) break; set.add(x); arr.add(x - 1); } for(int j = 0; j < arr.size(); j++) { ans[arr.get(j)] = arr.get((j + 1) % arr.size()) + 1; } } System.out.print(""! ""); for(int x: ans) System.out.print(x+"" ""); System.out.println(); } } } ","import java.awt.Container; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { FastScanner input = new FastScanner(); int tc = input.nextInt(); work: while (tc-- > 0) { int n = input.nextInt(); int ans[] = new int[n]; for (int i = 1; i <=n; i++) { if(ans[i-1]!=0) { // System.out.println(""NO""); continue ; } HashSet set = new HashSet<>(); ArrayList a = new ArrayList<>(); while(true) { System.out.println(""? ""+i); int value = input.nextInt(); if(set.contains(value)) { break; } a.add(value-1); set.add(value); } for (int j = 0; j 0) { int n = scanner.nextInt(); int[] time = new int[n]; int[] h = new int[n]; for(int i = 0; i < n; i++) { time[i] = scanner.nextInt(); } for(int j = 0; j < n; j++) { h[j] = scanner.nextInt(); } long prevMTime = time[n-1]; long prevMHealth = h[n-1]; long manaRequired = 0; long currMTime = time[n-1]; long currMHealth = h[n-1]; long spellCastingTime = prevMTime - prevMHealth + 1; for(int i = n-2; i >= 0; i--) { currMHealth = h[i]; currMTime = time[i]; //spellCastingTime = prevMTime - prevMHealth + 1; if(spellCastingTime <= currMTime && currMTime - spellCastingTime + 1 < currMHealth) { spellCastingTime = currMTime - currMHealth + 1; } else if(spellCastingTime > currMTime) { long hm = (prevMTime - spellCastingTime) + 1; manaRequired += (hm * (hm+1)) / 2; prevMTime =currMTime; prevMHealth = currMHealth; spellCastingTime = prevMTime - prevMHealth + 1; } } long hm = (prevMTime - spellCastingTime) + 1; manaRequired += (hm * (hm+1)) / 2; System.out.println(manaRequired); } } } ","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 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 2560850b,76791c9f,"import java.util.*; import java.io.*; public class notassigning { public static void main(String[] args) throws IOException { BufferedReader fin = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(fin.readLine()); StringBuilder fout = new StringBuilder(); while(t-- > 0) { int n = Integer.parseInt(fin.readLine()); boolean isValid = true; int start = -1; ArrayList> c = new ArrayList>(); for(int i = 0; i < n; i++) { c.add(new ArrayList()); } HashMap, Integer> order = new HashMap, Integer>(); for(int i = 0; i < n - 1; i++) { StringTokenizer st = new StringTokenizer(fin.readLine()); int a = Integer.parseInt(st.nextToken()) - 1; int b = Integer.parseInt(st.nextToken()) - 1; order.put(new ArrayList(Arrays.asList(a, b)), i); c.get(a).add(b); c.get(b).add(a); if((c.get(a).size() == 3 || c.get(b).size() == 3) && isValid) { isValid = false; } } if(!isValid) { fout.append(""-1\n""); continue; } //locate the start of the chain for(int i = 0; i < n; i++) { if(c.get(i).size() == 1) { start = i; break; } } int[] ans = new int[n - 1]; int cur = start; int next = c.get(start).get(0); int prime = 2; while(true) { int index = 0; if(order.containsKey(new ArrayList(Arrays.asList(cur, next)))) { index = order.get(new ArrayList(Arrays.asList(cur, next))); } else { index = order.get(new ArrayList(Arrays.asList(next, cur))); } ans[index] = prime; if(c.get(next).size() == 1) { break; } prime = prime == 3? 2 : 3; int prev = cur; cur = next; next = c.get(cur).get(0) == prev? c.get(cur).get(1) : c.get(cur).get(0); } for(int i : ans) { fout.append(i).append("" ""); } fout.append(""\n""); } System.out.print(fout); } } ","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class 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 a = 1; int t; t = in.nextInt(); //t = 1; while (t > 0) { //out.print(""Case #""+(a++)+"": ""); solver.call(in,out); t--; } out.close(); } static class TaskA { Map> ans; Map visited; Map> map; public void call(InputReader in, PrintWriter out) { int n = in.nextInt(); answer[] arr = new answer[n]; visited = new HashMap<>(); ans = new HashMap<>(); int u, v; map = new HashMap<>(); for (int i = 0; i < n - 1; i++) { arr[i] = new answer(in.nextInt(), in.nextInt()); u = arr[i].a; v = arr[i].b; map.putIfAbsent(u, new ArrayList<>()); map.get(u).add(v); map.putIfAbsent(v, new ArrayList<>()); map.get(v).add(u); } int a = 0; for(Integer i : map.keySet()){ if(map.get(i).size() > 2){ out.println(-1); return; } if(map.get(i).size()==1){ a = i; } } dfs(a, -1, 0); int[] ans1 = new int[n - 1]; for(int i = 0; i < n-1; i++){ u = arr[i].a; v = arr[i].b; if(ans.getOrDefault(u, null)!=null && ans.get(u).get(0)==v){ if(ans.get(u).get(1)==0){ ans1[i] = 2; } else{ ans1[i] = 5; } } else{ if(ans.get(v).get(1)==0){ ans1[i] = 2; } else{ ans1[i] = 5; } } } for(Integer i : ans1){ out.print(i+"" ""); } out.println(); } public void dfs(int child, int par, int c){ if(par!=-1){ ans.putIfAbsent(par, new ArrayList<>()); ans.get(par).add(child); ans.get(par).add(c); } visited.put(child, true); for(Integer i : map.get(child)){ if(!visited.getOrDefault(i, false)){ dfs(i, child, c^1); } } } } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } } static final Random random=new Random(); } ",0,Non-plagiarised 81fb6415,b3d4c5ca,"import java.math.BigInteger; import java.util.*; import java.io.*; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; public class CodeForces { public void run() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); next : while (t-- > 0) { StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long k = Long.parseLong(st.nextToken()); Long[] a = new Long[n]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { a[i] = Long.parseLong(st.nextToken()); } Arrays.sort(a); long ans = Long.MAX_VALUE; long[] lsum = new long[n + 1]; for (int i = 0; i < n; i++) { lsum[i + 1] = lsum[i] + a[i]; } for (long y = 0; y < n; y++) { long x = 0; if ((k - lsum[n - (int)y] + a[0]) >= 0) { x = (k - lsum[n - (int)y] + a[0]) / (y + 1); } else { if ((k - lsum[n - (int)y] + a[0]) % (y + 1) == 0) { x = (k - lsum[n - (int)y] + a[0]) / (y + 1); } else { x = (k - lsum[n - (int)y] + a[0]) / (y + 1) - 1; } } x = a[0] - x; ans = Math.min(ans, Math.max(0, x) + y); } System.out.println(ans); } } public static void main(String[] args) throws Exception { new CodeForces().run(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static long floor(long a, long b) { long res = a / b; while(res * b > a) res--; return res; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long k = Long.parseLong(st.nextToken()); st = new StringTokenizer(br.readLine()); Long[] p = new Long[n]; for(int i = 0 ;i0){ int n = sc.nextInt(); String[] strArr = new String[n]; for(int i=0; i al = new ArrayList<>(); for(int i=0; i all = new ArrayList<>(); for(int j=0; j0){ int n = sc.nextInt(); String [] words = new String[n]; for(int i =0;i pq = new PriorityQueue<>(); for (String word : words){ pq.add(new Pair(word,occOfMaxChar(word, maxChar)-occOfOtherChar(word, maxChar))); } int res = 0; int curr = 0; int maxCharCount = 0; int otherCharCount =0; while(!pq.isEmpty()){ String word = pq.poll().x; maxCharCount +=occOfMaxChar(word, maxChar); otherCharCount += occOfOtherChar(word, maxChar); curr ++; if(maxCharCount >otherCharCount){ res = curr; } } maxRes = Math.max(maxRes, res); } System.out.println(maxRes);} } public static int occOfMaxChar (String s, int maxChar){ int occ = 0; for(int i =0 ;i gold ; static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } } } ",0,Non-plagiarised 3850468c,403e3270,"import java.io.*; import java.util.*; public class solution { static long cr[][]=new long[1001][1001]; //static double EPS = 1e-7; static long mod=1000000007; public static void main(String[] args) { FScanner sc = new FScanner(); //Arrays.fill(prime, true); //sieve(); //ncr(); int t=sc.nextInt(); StringBuilder sb = new StringBuilder(); while(t-->0) { int n=sc.nextInt(); long arr[]=new long[n]; long dp[]=new long[n]; long sum=0; for(int i=0;i1;i--) { if(dp[i]<=sum) continue; long val=Math.min(arr[i],dp[i]-sum)/3; dp[i-1]+=val; dp[i-2]+=2*val; } long min=Integer.MAX_VALUE; for(int i=0;i=sum) return true; else return false; } /* public static void sieve() { prime[0]=prime[1]=false; int n=1000000; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } */ } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.*; //import sun.nio.fs.RegistryFileTypeDetector; public class Codeforces { static int mod= 998244353; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { int n=fs.nextInt(); int arr[]=fs.readArray(n); int l=0, r=1000000000; while(l1;i--) { if(brr[i]+arr[i]=min)&&(arr[1]+brr[1]>=min); } // Use this to input code since it is faster than a Scanner } ",0,Non-plagiarised 6bcc5afd,734a94be,"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;i0) { int n = sc.nextInt(); ArrayList one = new ArrayList<>(); ArrayList zero = new ArrayList<>(); for(int i=0;i[] adj; static int[] l, r; static long[][] dp; @SuppressWarnings(""unchecked"") public static void main(String[] args) throws IOException { int T = readInt(); for (int t = 0; t < T; t++) { int n = readInt(); l = new int[n + 1]; r = new int[n + 1]; for (int i = 1; i <= n; i++) { l[i] = readInt(); r[i] = readInt(); } adj = new ArrayList[n + 1]; for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>(); for (int i = 0; i < n - 1; i++) { int u = readInt(), v = readInt(); adj[u].add(v); adj[v].add(u); } dp = new long[n + 1][2]; vis = new boolean[n + 1]; vis[1] = true; dfs(1); System.out.println(Math.max(dp[1][0], dp[1][1])); } } static void dfs(int u) { for (int x : adj[u]) { if (!vis[x]) { vis[x] = true; dfs(x); dp[u][0] += Math.max(dp[x][0] + Math.abs(l[u] - l[x]), dp[x][1] + Math.abs(l[u] - r[x])); dp[u][1] += Math.max(dp[x][0] + Math.abs(r[u] - l[x]), dp[x][1] + Math.abs(r[u] - r[x])); } } } static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } } ","import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class C { private static final boolean TEST_MODE = true; private static Node[] tree; private static long[] lWt, rWt; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = getInt(br); for (int t=0; t q = new LinkedList<>(); q.add(1); // Constraint: Every node that is in the queue has parent already assigned. while (!q.isEmpty()) { int currId = q.poll(); Node currNode = tree[currId]; // Add all neighbours as children. for (int nbrId : currNode.nbrs) { if (nbrId == currNode.parent) { continue; } tree[nbrId].parent = currId; currNode.addChild(nbrId); q.add(nbrId); } // currNode.nbrs.clear(); } } private static void getMaxBeauty() throws Exception { Stack stack = new Stack<>(); stack.add(1); while (!stack.isEmpty()) { int currId = stack.pop(); Node curr = tree[currId]; // Is leaf ? if (curr.children.size() == 0) { lWt[currId] = 0; rWt[currId] = 0; continue; } // Are all children processed ? boolean allChildrenProcessed = (lWt[curr.children.get(0)] >= 0); if (allChildrenProcessed) { lWt[currId] = 0; rWt[currId] = 0; // Compute lwt and rwt maximized against each child. for (int childId : curr.children) { Node childNode = tree[childId]; long ll = Math.abs(curr.left - childNode.left) + lWt[childId]; long lr = Math.abs(curr.left - childNode.right) + rWt[childId]; lWt[currId] += Math.max(ll, lr); long rl = Math.abs(curr.right - childNode.left) + lWt[childId]; long rr = Math.abs(curr.right - childNode.right) + rWt[childId]; rWt[currId] += Math.max(rl, rr); } } else { // Add all unvisited children. stack.add(currId); stack.addAll(curr.children); } } long res = Math.max(lWt[1], rWt[1]); System.out.println(res); } private static Integer getInt(BufferedReader br) throws Exception { return Integer.parseInt(br.readLine()); } private static int[] getIntArray(int N, BufferedReader br) throws Exception { String s = br.readLine(); String[] tokens = s.split("" ""); int[] result = new int[N]; for (int i=0; i nbrs = new ArrayList<>(); List children = new ArrayList<>(); int left, right; public Node(int l, int r) { this.left = l; this.right = r; } public Node(String s) { String[] tokens = s.split("" ""); this.left = Integer.parseInt(tokens[0]); this.right = Integer.parseInt(tokens[1]); } public void addNbr(int nbr) { nbrs.add(nbr); } public void addChild(int child) { children.add(child); } } ",0,Non-plagiarised 54d7c21e,ad4c7a20,"import java.io.*; import java.util.*; public class cp { // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // primeSet=new HashSet<>(); // sieveOfEratosthenes((int)1e6+5); while(tc-->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 ans; //function to find prime factors of n //fenwick tree implementaion //Function to find number of set bits // function to find last index <= y // static class GraphMap{ // Map> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static PrintWriter out=new PrintWriter(System.out); } ","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,Plagiarised bd3051e3,e2e37533,"import java.io.*; import java.util.*; public class Main { static BufferedReader br; static PrintWriter pr; static int cin() throws Exception { return Integer.valueOf(br.readLine()); } static int[] split() throws Exception { String[] cmd=br.readLine().split("" ""); int[] ans=new int[cmd.length]; for(int i=0;ians=new ArrayList<>(); for(int i=0;ians=new ArrayList<>(); for(int i=0;i 0) { TEST_CASE(); } System.out.println(sb); } static void TEST_CASE() { int n = sc.nextInt(); lr = new long[n][2]; for(int i =0 ; i < n ; i ++) { lr[i][0] = sc.nextLong(); lr[i][1] = sc.nextLong(); } adj = new ArrayList>(); for(int i = 0 ; i ()); for(int i = 0 ; i> adj; static void dfs(int u , int p ) { for(int child:adj.get(u)) { if(child == p) continue; dfs(child , u); } long left = lr[u][0] , right = lr[u][1]; long ansl = 0 , ansr = 0; for(int child:adj.get(u)) { if(child == p) continue; long leftc = lr[child][0] , rightc = lr[child][1]; ansl += Math.max( min[child] + Math.abs(left - leftc) , max[child] +Math.abs(left - rightc) ); } for(int child:adj.get(u)) { if(child == p) continue; long leftc = lr[child][0] , rightc = lr[child][1]; ansr += Math.max( min[child] + Math.abs(right - leftc) , max[child] +Math.abs(right - rightc) ); } min[u] = ansl; max[u] = ansr; } } ","import java.io.*; import java.util.*; public class Solution{ public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } // main solver static class Task{ double eps= 0.00000001; static final int MAXN = 10000001; // stores smallest prime factor for every number static int spf[] = new int[MAXN]; Map> 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 long[] dpl, dpr; List[] adj; int[] l,r; public void solve(InputReader in, PrintWriter out) { int t= in.nextInt(); while(t-->0){ int n= in.nextInt(); l= new int[n]; r= new int[n]; adj= new List[n]; for(int i=0;i(); for(int i=0;i{ // @Override // public int compare(Tuple t1, Tuple t2) { // return t2.l - t1.l; // } // } } // static class Data{ // List arr; // BigInteger prod=new BigInteger(-1); // public Data(List arr, BigInteger prod) { // this.arr= arr; // this.prod= prod; // } // } // fast input reader class; } ",0,Non-plagiarised a60fba84,c695a974,"import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out; static FastReader scan; /*-------- I/O using short named function ---------*/ public static int ni(){return scan.nextInt();} public static long nl(){return scan.nextLong();} /*-------- for output of an array ---------------------*/ /*-------------- for input in an array ---------------------*/ static void lIA(long arr[]){ 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 = fsca.nextInt(); int a[] = new int[n]; for(i=0;i total) { ret++; } else { return ret; } } return ret; } static class Comp implements Comparator { char c; public Comp (char c) { this.c = c; } } } ","import java.util.*; import java.io.*; public class CF_1551c{ public static final void main(String[] args){ Kattio io= new Kattio(); int t= io.getInt(); while(t-->0){ int n= io.getInt(); int[][] ps= new int[5][n]; for(int i=0; imax) max= i; } } io.println(max); } io.close(); } // using mergeSort to avoid Java quicksort TLE hacks static class Kattio extends PrintWriter { private BufferedReader r; private String line, token; private StringTokenizer st; public Kattio(){this(System.in);} public Kattio(InputStream i){ super(new BufferedOutputStream(System.out)); r= new BufferedReader(new InputStreamReader(i)); } public Kattio(InputStream i, OutputStream o){ super(new BufferedOutputStream(o)); r= new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens(){ return peekToken()!=null; } public int getInt(){ return Integer.parseInt(nextToken()); } public String getWord(){ return nextToken(); } private String peekToken(){ if(token==null) try { while(st==null || !st.hasMoreTokens()) { line= r.readLine(); if(line==null) return null; st= new StringTokenizer(line); } token= st.nextToken(); }catch(IOException e){} return token; } private String nextToken() { String ans= peekToken(); token= null; return ans; } } } ",0,Non-plagiarised 169e34bf,ba468e1f,"import java.util.*; public class D{ static Scanner sc; public static void solve(){ int n=sc.nextInt(); Integer a[]=new Integer[n]; int flag; for(int 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = fastReader.nextInt(); } ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); char c[] = fastReader.next().toCharArray(); for (int i = 0; i < n; i++) { if (c[i] == 'B') { b.add(a[i]); } else { r.add(a[i]); } } Collections.sort(b); Collections.sort(r); int sizeb = b.size(); boolean isValid = true; for (int i = 1 , j = 0; i <=sizeb; i++ , j++){ if (b.get(j) < i){ isValid =false; } } for (int i = sizeb+1 , j = 0; i <=n && j < r.size(); i++ , j++){ if (r.get(j) > i){ isValid =false; } } if (isValid){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } } ",0,Non-plagiarised 42c7b9df,adbb2f71,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CSbalansirovannieKuchkiKamnei solver = new CSbalansirovannieKuchkiKamnei(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CSbalansirovannieKuchkiKamnei { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } long t1 = 0; long t2 = (int) 1e9 + 10; long[] b = new long[n]; while (t1 < t2) { long mid = (t1 + t2 + 1) / 2; System.arraycopy(a, 0, b, 0, n); boolean fine = true; for (int i = n - 1; i >= 0; i--) { if (b[i] < mid) { fine = false; break; } if (i >= 2) { long how = Math.min(a[i], (b[i] - mid)) / 3; b[i - 1] += how; b[i - 2] += how * 2; } } if (fine) { t1 = mid; } else { t2 = mid - 1; } } out.println(t1); } } } ","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; import java.util.*; public class cp { public static void main(String args[]) throws Exception { FastScanner sc = new FastScanner(); int T = 1; T = sc.nextInt(); PrintWriter pw = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); while (T-- > 0) { solve(sc, pw, sb); } pw.print(sb); pw.close(); } public static void solve(FastScanner sc, PrintWriter pw, StringBuilder sb) throws Exception { int n=sc.nextInt(); int[] h=new int[n]; for(int i=0;i=0;i--){ if(copy[i]> list = new ArrayList(); for (int i = 0; i < n;i ++) { List temp = new ArrayList(); list.add(temp); } for (int i = 0; i < n-1; i++) { int a = fs.ni()-1, b = fs.ni()-1; list.get(a).add(b); list.get(b).add(a); } Long[][] dp = new Long[n][2]; pw.println(recur(0,0,-1,new long[] {0,0},dp,lr,list)); } pw.close(); } // 0 -> left was chosen // 1 -> right was chosen public static long recur(int ind, int p,int prev, long[] v, Long[][] dp, long[][] lr,List> list) { long last = v[0]; long ls = 0L; long rs = 0L; if (p==1) { last = v[1]; } if (ind!=0) ls += (long)Math.abs(last-lr[ind][0]); if (ind!=0) rs += (long)Math.abs(last-lr[ind][1]); if (dp[ind][p]!=null) return dp[ind][p]; long[] cur = lr[ind]; List temp = list.get(ind); for (int val : temp) { if (prev==val) continue; ls += recur(val,0,ind,cur,dp,lr,list); rs += recur(val,1,ind,cur,dp,lr,list); } return dp[ind][p] = Math.max(ls,rs); } } ","import java.io.*; import java.util.*; public class P1529C { public static final int MAX = 100000; private static final List[] adjacency = new List[MAX]; private static final int[][] pair = new int[MAX][2]; public static void main(String[] args) { SpeedScanner in = new SpeedScanner(); for(int i = 0; i < MAX; ++i) adjacency[i] = new ArrayList<>(); int t = in.nextInt(); while(t-- != 0) { int nv = in.nextInt(); for(int i = 0; i < nv; ++i) { pair[i][0] = in.nextInt(); pair[i][1] = in.nextInt(); } for(int i = 1; i < nv; ++i) { int x = in.nextInt() - 1, y = in.nextInt() - 1; adjacency[x].add(y); adjacency[y].add(x); } long[] alts = dfsTraverse(0, -1); System.out.println(alts[0] >= alts[1] ? alts[0] : alts[1]); for(int i = 0; i < nv; ++i) adjacency[i].clear(); } } private static long[] dfsTraverse(int vertex, int parent) { long sumDiffL = 0, sumDiffR = 0; for(int child: adjacency[vertex]) { if(child == parent) continue; long[] temp = dfsTraverse(child, vertex); sumDiffL += Math.max(Math.abs(pair[vertex][0] - pair[child][0]) + temp[0], Math.abs(pair[vertex][0] - pair[child][1]) + temp[1]); sumDiffR += Math.max(Math.abs(pair[vertex][1] - pair[child][0]) + temp[0], Math.abs(pair[vertex][1] - pair[child][1]) + temp[1]); } return new long[]{sumDiffL, sumDiffR}; } } ",0,Non-plagiarised 0ecf356d,b2bae06a,"import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); int[] h = new int[n]; int[] dp = new int[n]; for(int i = 0; i hi = new Stack<>(); Stack lo = new Stack<>(); hi.push(0); lo.push(0); for(int i = 1; ih[i]){ dp[i] = Math.min(dp[i], dp[lo.peek()]+1); lo.pop(); } if(!lo.isEmpty()){ dp[i] = Math.min(dp[i], dp[lo.peek()]+1); if(h[i] == h[lo.peek()]) lo.pop(); } hi.push(i); lo.push(i); } System.out.println(dp[n-1]); } } ","import java.util.*; import java.io.*; public class D{ static int mod = (int)(1e9+7); public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.nextInt(); int[] arr = in.nextIntArray(n); Stack min = new Stack<>(); Stack max = new Stack<>(); int[] dp = new int[n]; // Arrays.fill(dp,(int)1e9); dp[0] = 0; min.push(0); max.push(0); for(int i=1;iarr[max.peek()]) { int x = arr[max.peek()]; h = Math.min(h,1+dp[max.pop()]); while(!max.isEmpty() && arr[max.peek()]==x) { max.pop(); } } if(!max.isEmpty()) { h = Math.min(h,1+dp[max.peek()]); } while(!min.isEmpty() && arr[i] l = new ArrayList<>(); for(int j=0;j 0)f++; else break; } g = Math.max(g, f); } out.println(g); } } } ","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,Plagiarised 6f393cfe,d61f51c5,"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; } } } ","import java.util.*; import java.lang.*; import java.io.*; public class InterestingStrory { public static void main(String[] args) throws java.lang.Exception { // your code goes here try { // Scanner sc=new Scanner(System.in); FastReader sc = new FastReader(); int t =sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int[][] occ=new int[n][5]; for(int i=0;i=0;l--){ if(currSum+sums[l]<=0){ break; } else{ currSum+=sums[l]; } } ans=Math.max(ans,n-l-1); } System.out.println(ans); } } catch (Exception e) { return; } } } ",1,Plagiarised ac2dfc53,c4187a0e,"import java.io.*; import java.util.*; /* */ public class C{ static FastReader fs=null; static Scanner sc=null; public static void main(String[] args) { sc=new Scanner(System.in); int t=sc.nextInt(); for(int tt=0;tt cycle = new ArrayList<>(); int ans = query(i, in); int now = query(i, in); cycle.add(now); while (now != ans) { now = query(i, in); cycle.add(now); } for (int j = 0; j < cycle.size(); j++) { arr[cycle.get(j)] = cycle.get((j + 1) % cycle.size()) + 1; vis[cycle.get(j)] = true; } } out.print(""! ""); out.println(arr); out.flush(); } int query(int ind, InputReader in) { System.out.println(""? "" + (ind + 1)); return in.nextInt() - 1; } } } ",0,Non-plagiarised 1c4d348d,565f77b7,"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 Solution { static class SortbyHeight implements Comparator { } static class Struct{ int h,ind; Struct(int h,int ind){ this.h=h; this.ind=ind; } } public static void main(String[] args) throws java.lang.Exception { // your code goes here FastReader scn = new FastReader(); int t, k, i, j, l, f, max=0; t=scn.nextInt(); while(t-->0){ int n=scn.nextInt(); int m=scn.nextInt(); int x=scn.nextInt(); Struct a[]=new Struct[n]; for (i=0;im){ ms=1; } b[a[i].ind]=ms; ms++; } System.out.println(""YES""); for (i=0;i 0) solve(); out.println(sb); out.close(); } public static void solve() { // Road To Specialist Day 3 int n = scn.nextInt(), m = scn.nextInt(), x = scn.nextInt(); int[] a = new int[n], ans = new int[n]; for(int i = 0; i < n; i++) a[i] = scn.nextInt(); PriorityQueue pq = new PriorityQueue<>(); for(int i = 0; i < m; i++) pq.add(new Pair(0L, i)); for(int i = 0; i < n; i++) { int e = a[i]; Pair p = pq.poll(); p.value += e; pq.add(p); ans[i] = p.id + 1; } boolean check = false; long prev = pq.poll().value; while(!pq.isEmpty()) { long cur = pq.poll().value; if(Math.abs(cur - prev) > x) check = true; prev = cur; } if(check) sb.append(""NO""); else { sb.append(""YES\n""); for(int i : ans) sb.append(i + "" ""); } sb.append(""\n""); } static class Pair implements Comparable { int id; long value; public Pair(long value, int id) { this.id = id; this.value = value; } } } ",0,Non-plagiarised 5449d33c,dff5ff0a,"import java.io.*; import java.util.*; import java.lang.*; public class C { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.Main(in, out); out.close(); } static class Solver { public void Main(InputReader in, PrintWriter out) { int T = in.nextInt(); for (int t = 0; t < T; t++) { int n = in.nextInt(); String[] A = new String[n]; for (int i = 0; i < n; i++) { A[i] = in.next(); } int ans = 0; for (char c = 'a'; c <= 'e'; c++) { int[] ls = new int[n]; for (int i = 0; i < n; i++) { int delta = 0; for (int j = 0; j < A[i].length(); j++) { if (A[i].charAt(j) == c) { delta += 1; } else { delta -= 1; } } ls[i] = delta; } Arrays.sort(ls, 0, n); int cur = 0; int score = 0; for (int i = n - 1; i >= 0; i--) { if (cur + ls[i] >= 1) { cur += ls[i]; score += 1; } } ans = Math.max(ans, score); } out.println(ans); } } } } ","import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; public class Main { private static void run() throws IOException { int n = in.nextInt(); char[][] a = new char[n][]; for (int i = 0; i < n; i++) { a[i] = in.next().toCharArray(); } int ans = Integer.MIN_VALUE; for (char now = 'a'; now <= 'e'; now++) { ans = Math.max(ans, check(a, now)); } out.println(ans); } private static int check(char[][] a, char target) { int[] count = new int[a.length]; for (int i = 0; i < a.length; i++) { for (char c : a[i]) { if (c == target) { count[i]++; } else { count[i]--; } } } Arrays.sort(count); int ans = 0; int sum = 0; for (int i = a.length - 1; i >= 0; i--) { if (count[i] <= 0) break; ans++; sum += count[i]; } if (ans == 0) return 0; for (int i = a.length - 1; i >= 0; i--) { if (count[i] > 0) continue; if (sum > -count[i]) { sum += count[i]; ans++; } } return ans; } public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int i = 0; i < t; i++) { run(); } out.flush(); in.close(); out.close(); } static final long mod = 1000000007; @SuppressWarnings(""FieldCanBeLocal"") private static Reader in; private static PrintWriter out; } ",0,Non-plagiarised 47d54299,da0b7cb2,"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.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 (a1[0]-a2[0])); 2d array sort lamda public static void main(String[] args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pr = new PrintWriter(System.out); int tc = 1; tc= cinI(); while(tc-->0){ int n =cinI(); String[] a= new String[n]; int[][] f =new int[10][n]; for(int i=0;i=0;i--){ sum+=f[j][i]; if(sum>0){ cnt+=1; } else{ break; } } max=Math.max(max,cnt); } System.out.println(max); } } public static String cin() throws Exception { return br.readLine(); } public static Integer cinI() throws Exception { return Integer.parseInt(br.readLine()); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String args[]) { FastReader s=new FastReader(); int t=s.nextInt(); while(t>0) { Solve solve=new Solve(); t--; int n=s.nextInt(); String str[]=new String[n]; for(int i=0;isolve.solve(arr,n))?ans:solve.solve(arr,n); } System.out.println(ans); } } } class Solve{ public int solve(int arr[],int n) { int ans=0; int sum=0; Arrays.sort(arr); for(int i=n-1;i>=0;i--) { if(sum+arr[i]>0) { sum+=arr[i]; ans++; } else break; } return ans; } } ",0,Non-plagiarised 9069684f,bf85ab7b,"import java.io.*; import java.util.*; public class Test { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static boolean[] vis; static ArrayList[] adj; static int[] l, r; static long[][] dp; @SuppressWarnings(""unchecked"") public static void main(String[] args) throws IOException { int T = readInt(); for (int t = 0; t < T; t++) { int n = readInt(); l = new int[n + 1]; r = new int[n + 1]; for (int i = 1; i <= n; i++) { l[i] = readInt(); r[i] = readInt(); } adj = new ArrayList[n + 1]; for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>(); for (int i = 0; i < n - 1; i++) { int u = readInt(), v = readInt(); adj[u].add(v); adj[v].add(u); } dp = new long[n + 1][2]; vis = new boolean[n + 1]; vis[1] = true; dfs(1); System.out.println(Math.max(dp[1][0], dp[1][1])); } } static void dfs(int u) { for (int x : adj[u]) { if (!vis[x]) { vis[x] = true; dfs(x); dp[u][0] += Math.max(dp[x][0] + Math.abs(l[u] - l[x]), dp[x][1] + Math.abs(l[u] - r[x])); dp[u][1] += Math.max(dp[x][0] + Math.abs(r[u] - l[x]), dp[x][1] + Math.abs(r[u] - r[x])); } } } static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } } ","import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; public class ParsasHumongousTree { public static void main(String args[]) throws IOException { Reader scan = new Reader(); StringBuilder sb = new StringBuilder(); int t = scan.nextInt(); while (t-- > 0) { int n = scan.nextInt(); int[] l = new int[n + 1]; int[] r = new int[n + 1]; for (int i = 1; i <= n; i++) { l[i] = scan.nextInt(); r[i] = scan.nextInt(); } Graph g = new Graph(n); for (int i = 0; i < n - 1; i++) { g.addEdge(scan.nextInt(), scan.nextInt()); } sb.append(g.dfs(l, r) + ""\n""); } System.out.println(sb); } } class Graph { ArrayList[] node; int n; int c = 0; boolean[] vis; Graph(int s) { n = s + 1; vis = new boolean[n + 1]; node = new ArrayList[n + 1]; for (int i = 0; i < n + 1; i++) { node[i] = new ArrayList<>(); } } void addEdge(int u, int v) { node[u].add(v); node[v].add(u); if (node[u].size() == 1) { c = u; } if (node[v].size() == 1) { c = v; } } void cleanVisArray() { for (int i = 0; i < n + 1; i++) { vis[i] = false; } } long dfs(int[] l, int[] r) { cleanVisArray(); long[][] dp = new long[n][2]; dfsMain(1, dp, l, r); return Math.max(dp[1][0], dp[1][1]); } void dfsMain(int v, long[][] dp, int[] l, int[] r) { vis[v] = true; for (int i : node[v]) { if (!vis[i]) { dfsMain(i, dp, l, r); dp[v][0] += Math.max(Math.abs(l[v] - l[i]) + dp[i][0], Math.abs(l[v] - r[i]) + dp[i][1]); dp[v][1] += Math.max(Math.abs(r[v] - l[i]) + dp[i][0], Math.abs(r[v] - r[i]) + dp[i][1]); } } } } ",0,Non-plagiarised ba468e1f,fb312dc6,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = fastReader.nextInt(); } ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); char c[] = fastReader.next().toCharArray(); for (int i = 0; i < n; i++) { if (c[i] == 'B') { b.add(a[i]); } else { r.add(a[i]); } } Collections.sort(b); Collections.sort(r); int sizeb = b.size(); boolean isValid = true; for (int i = 1 , j = 0; i <=sizeb; i++ , j++){ if (b.get(j) < i){ isValid =false; } } for (int i = sizeb+1 , j = 0; i <=n && j < r.size(); i++ , j++){ if (r.get(j) > i){ isValid =false; } } if (isValid){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } } ","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(); } } ",0,Non-plagiarised 505f8562,ed37ba7d,"import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.lang.System.out; import static java.lang.Long.MAX_VALUE; public final class Main{ FastReader in; StringBuffer sb; public static void main(String[] args) { new Main().run(); } void run(){ in= new FastReader(); start(); } void start(){ sb= new StringBuffer(); for(int t=in.nextInt();t>0;t--) solve(); out.print(sb); } long MOD= 1000000007; void solve(){ int n= in.nextInt(); int k= in.nextInt(); long[] a=longArr(k); long[] t=longArr(k); long[] ans= new long[n]; for(int i=0;i=0;i--) { right[i]= min(right[i+1]+1,ans[i]); } for(int i=0;i 0) { solve(); } long endTime = System.currentTimeMillis(); System.out.println(""Time: "" + (endTime - startTime) / tt + "" ms""); out.flush(); pr.flush(); } else { sc = new InputReader(inputStream); out = new PrintWriter(outputStream); pr = new PrintWriter(outputStream); int t = 1; t = sc.nextInt(); while (t-- > 0) { solve(); } out.flush(); } } public static void solve() { n = sc.nextInt(); for (int i = 0; i < n; i++) { dp[i] = inf; ans[i] = inf; } m = sc.nextInt(); for (int i = 0; i < m; i++) arr[i] = sc.nextInt() - 1; for (int i = 0; i < m; i++) { arr2[i] = sc.nextInt(); dp[(int)arr[i]] = arr2[i]; } temp = inf; for (int i = 0; i < n; i++) { temp = Math.min(temp, dp[i]); ans[i] = Math.min(ans[i], temp); temp++; } temp = inf; for (int i = (int)n - 1; i > -1; i--) { temp = Math.min(temp, dp[i]); ans[i] = Math.min(ans[i], temp); temp++; } for (int i = 0; i < n; i++) out.print(ans[i] + "" ""); out.println(""""); } /* * Set Iterator Iterator value = set.iterator(); Displaying the values after * iterating through the iterator * System.out.println(""The iterator values are: ""); while (value.hasNext()) { * System.out.println(value.next()); } */ /* * Map Iterator: for (Map.Entry entry : map.entrySet()){ * System.out.println(""Key => "" + entry.getKey() + "", Value => "" + * entry.getValue());} */ // Globals public static long n, m, temp; public static int template_array_size = (int) 1e6 + 16813; public static long[] arr = new long[template_array_size]; public static long[] arr2 = new long[template_array_size]; public static long[] dp = new long[template_array_size]; public static long[] ans = new long[template_array_size]; public static int inf = Integer.MAX_VALUE; public static int minf = Integer.MIN_VALUE; public static int mod = 1000000007; public static int ml = (int) 1e9; public static String s = """"; public static InputReader sc; public static PrintWriter out; public static PrintWriter pr; // Pair // FastReader Class // Req Functions // debug public static boolean sysFlag = System.getProperty(""ONLINE_JUDGE"") == null; } ",0,Non-plagiarised d3a96420,ff34fab2,"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(); } } ","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=s.nextInt(); int c[]=new int[n]; for(int i=0;i 0) { // Start code int n = sc.nextInt(); long[] cost = new long[n]; long[] a = new long[n]; for (int i = 0; i < n; i++) { cost[i] = sc.nextLong(); a[i] = cost[i]; if (i > 1) a[i] = Math.min(a[i], a[i - 2]); } long sum = cost[0]; long res = Long.MAX_VALUE; for (int i = 1; i < n; i++) { sum += cost[i]; long cur = sum - a[i] - a[i - 1]; int p = (i + 1) / 2; int q = (i + 1) - p; int x = n - p + 1; int y = n - q + 1; cur += (a[i - 1] * x + a[i] * y); res = Math.min(res, cur); } println(res); } sc.close(); } static void println(Object o) { System.out.println(o); } } ",0,Non-plagiarised 07043d35,97a7fab5,"import java.util.*; import java.io.*; public class C{ static int MOD=1000000007; static PrintWriter pw; static FastReader sc; // int [] arr=sc.intArr(n); static int Max=2*100005; // static int [][] arr= new int [Max][5]; // static int [] tot= new int [Max]; static ArrayList> arr= new ArrayList<>(); static ArrayList tot= new ArrayList<>(); static int fun(int ch , int n){ ArrayList list= new ArrayList<>(); for(int i=0;i0){ count++; } } return count; } static void solve() throws Exception{ int n=sc.nextInt(); arr= new ArrayList<>(); tot= new ArrayList<>(); for(int i=0;i()); tot.add(0); for(int j=0;j<5;j++){ ArrayList list=arr.get(i); list.add(0); } } // pw.println(tot); // pw.println(arr); // return; for(int i=0;i list=arr.get(i); list.set((s.charAt(j)-'a'),list.get((s.charAt(j)-'a'))+1); // list.set((s.charAt(j)-'a'),1); } } int ans =0; for(int i=0;i<5;i++){ ans = Math.max(ans,fun(i,n)); } pw.println(ans); } public static void main(String[] args) throws Exception{ try { System.setIn(new FileInputStream(""input.txt"")); System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); } catch (Exception e) { System.err.println(""Error""); } sc= new FastReader(); pw = new PrintWriter(System.out); int tc=1; tc=sc.nextInt(); for(int i=1;i<=tc;i++) { // pw.printf(""Case #%d: ""b, i); solve(); } pw.flush(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.Vector; public class Main{ static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); public static void main(String[] args) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); String[] v = new String[n]; for (int i = 0; i < n; i++) { v[i] = in.next(); } ArrayList> v1 = new ArrayList<>(); for (int i = 0; i < n; i++) { ArrayList list = new ArrayList<>(); for (int j = 0; j < 5; j++) { list.add(0); } v1.add(list); } for (int i = 0; i < n; i++) { String s = v[i]; for (int j = 0; j < s.length(); j++) { int val = v1.get(i).get(s.charAt(j) - 'a'); val++; v1.get(i).set(s.charAt(j) - 'a', val); } } int ret = 0; for (int i = 0; i < 5; i++) { ArrayList v3 = new ArrayList<>(); for (int j = 0; j < n; j++) { String s1 = v[j]; int n2 = s1.length(); int cnt = v1.get(j).get(i); int diff = cnt - (n2 - cnt); v3.add(diff); } Collections.sort(v3); Collections.reverse(v3); int till = 0; for (int k = 0; k < n; k++) { till += v3.get(k); if (till > 0) { ret = Math.max(ret, k + 1); } } } out.println(ret); } out.close(); } } ",0,Non-plagiarised 24b20554,43b10dec,"import java.util.*; import java.lang.*; public class Codeforces { static Scanner sr=new Scanner(System.in); public static void main(String[] args) throws java.lang.Exception { StringBuilder ans = new StringBuilder(""""); int T = sr.nextInt(); while (T-- > 0) { int n=sr.nextInt(); int m=sr.nextInt(); int x=sr.nextInt(); TreeMap>h=new TreeMap<>(); for(int i=0;i()); h.get(a).add(i); } ans.append(""YES""); ans.append('\n'); int an[]=new int[n]; int q=0; for(int z:h.keySet()) { for(int i=0;i 0) { solve(); } } static void solve() { int n = ni(); int m = ni(), x = ni(); Map> map = new TreeMap<>(); System.out.println(""YES""); for(int i = 0; i < n; i++) { int num = ni(); if(!map.containsKey(num)) { map.put(num, new ArrayList()); } map.get(num).add(i); } int[] ans = new int[n]; int q = 0; for(int block : map.keySet()) { for(int i = 0; i < map.get(block).size(); i++) { ans[map.get(block).get(i)] = (q++)%m+1; } } for(int ele : ans) { System.out.print(ele + "" ""); } } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// static int ni() { return sc.nextInt(); } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// //-----------HritikScanner class for faster input----------// ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Function to return gcd of a and b time complexity O(log(a+b)) // method to return LCM of two numbers ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // method returns Nth power of A } ",1,Plagiarised 1a6f8b20,77448a05,"import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Main ob=new Main(); ob.fun(); } public void fun()throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0) { int n=Integer.parseInt(br.readLine()); int ar[][]=new int [n][5]; int len[]=new int[n]; for(int i=0;i pq=new PriorityQueue(Collections.reverseOrder()); for(int i=0;i0) { int num=(int)(pq.poll()); if((sum+num)>0) { ct++; sum+=num; } } return ct; } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.StringTokenizer; public class P4 { static int N = 1000001; // Array to store inverse of 1 to N static long[] factorialNumInverse = new long[N + 1]; // Array to precompute inverse of 1! to N! static long[] naturalNumInverse = new long[N + 1]; // Array to store factorial of first N numbers static long[] fact = new long[N + 1]; // Function to precompute inverse of numbers // Function to precompute inverse of factorials // Function to calculate factorial of 1 to N // Function to return nCr % p in O(1) time public static void main(String[] args) { // TODO Auto-generated method stub FastReader sc = new FastReader(); int t; t = sc.nextInt(); StringBuilder st = new StringBuilder(); // int p = 998244353; // InverseofNumber(p); // InverseofFactorial(p); // factorial(p); // System.out.println(3|1); while (t-- != 0) { int n=sc.nextInt(); String s[]=new String[n]; for(int i=0;i freq=new ArrayList<>(); for(int i=0;i<5;i++) { int f1=0; freq=new ArrayList<>(); for(int j=0;j=0;j--) { total=total+freq.get(j); if(total>0) { x++; }else { break; } } max=Math.max(max, x); } st.append(max+""\n""); } System.out.println(st); } static FastReader sc = new FastReader(); static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[] = new Character[s.length()]; for (int i = 0; i < s.length(); i++) { ch[i] = s.charAt(i); } Arrays.sort(ch); StringBuffer st = new StringBuffer(""""); for (int i = 0; i < s.length(); i++) { st.append(ch[i]); } return st.toString(); } } ",0,Non-plagiarised 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 7f42483d,c9a316ca,"import java.io.*; import java.util.*; public class Main { static final boolean INPUT_FROM_FILE = false; static final String INPUT_FILE = ""input/input.txt""; static final String OUTPUT_FILE = ""input/output.txt""; static final long M = (long) 1e9 + 7; static FastReader in; static FastWriter out; static { try { in = new FastReader(); out = new FastWriter(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws IOException { int t = in.nextInt(); while (t-- > 0) solve(); out.close(); } static long[][] dp; static long dfs(List> tree, int parent, int current, int parentState, int[][] vRange) { if(dp[current][parentState] != -1) { return dp[current][parentState]; } long left = Math.abs(vRange[current][0] - vRange[parent][parentState]); long right = Math.abs(vRange[current][1] - vRange[parent][parentState]); for(int child : tree.get(current)) { if(child != parent) { left += dfs(tree, current, child, 0, vRange); right += dfs(tree, current, child, 1, vRange); } } dp[current][parentState] = Math.max(left, right); return dp[current][parentState]; } private static void solve() { int n = in.nextInt(); int[][] vRange = new int[n+1][2]; for(int i=1; i<=n; i++) { int l = in.nextInt(), r = in.nextInt(); vRange[i][0] = l; vRange[i][1] = r; } List> tree = new ArrayList<>(); for(int i=0; i<=n; i++) tree.add(new LinkedList<>()); for(int i=0; i { 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 0d4d22e0,f898cee0,"import java.util.*; public class CodeForces { static ArrayListres; public static void main(String[] args) { Scanner input = new Scanner(System.in); int test = input.nextInt(); while(test-->0){ int n = input.nextInt(); int m = input.nextInt(); char arr[][] = new char[n][m]; res = new ArrayList<>(); for(int i =0;i0) { // out.printLine(""UAShd""); int n = in.nextInt(),m = in.nextInt(); char[][] arr = new char[n][m]; for(int i=0;i0) // res.deleteCharAt(res.length()-1); out.printLine(nops); if(nops>0) out.print(res); } out.flush(); out.close(); } } ",0,Non-plagiarised 6db218a2,90b71536,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator() { }); } 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; } } // static void calc(int n){ // int i,j; // dp[n-1]=0; // if(n>1) // dp[n-2]=1; // for(i=n-3;i>=0;i--){ // long ind=n-i-1; // dp[i]=((ind*(long)mypow(10,ind-1))%MOD+dp[i+1])%MOD; // } // } static long dist[],dp[][],left[],right[]; static int visited[],isit[]; static ArrayList>> adj[],li; //static int dp[][][]; static int MOD=1000000007; static char ch[]; static int[] sieve,is_sieve; static TreeSet tr; static long mat[][]; static void dfs(int node,int par, Pair p[]){ for(Pair> pp:adj[node]){ if(pp.x!=par){ //sum+=Math.abs(selected[node]-selected[pp.x]); dfs(pp.x,node,p); //System.out.println(node+"" ""+pp.x); long x=Math.abs(p[node].x-p[pp.x].x); long y=Math.abs(p[node].x-p[pp.x].y); long z=Math.abs(p[node].y-p[pp.x].x); long w=Math.abs(p[node].y-p[pp.x].y); left[node]+=Math.max(x+left[pp.x],y+right[pp.x]); right[node]+=Math.max(z+left[pp.x],w+right[pp.x]); } } } public static void main(String args[]){ InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); int t,i,j,tno=0,tte; t=in.nextInt(); //t=1; //tte=t; while(t-->0){ //sum=0; int n=in.nextInt(); adj=new ArrayList[n+1]; left=new long[n+1]; right=new long[n+1]; visited=new int[n+1]; for(i=0;i(); } Pair p[]=new Pair[n+1]; for(i=1;i<=n;i++){ p[i]=new Pair<>(in.nextLong(),in.nextLong()); } for(i=0;i(v,p[v])); adj[v].add(new Pair<>(u,p[u])); } dfs(1,-1,p); // for(i=0;i() { }); } 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; } } // static void calc(int n){ // int i,j; // dp[n-1]=0; // if(n>1) // dp[n-2]=1; // for(i=n-3;i>=0;i--){ // long ind=n-i-1; // dp[i]=((ind*(long)mypow(10,ind-1))%MOD+dp[i+1])%MOD; // } // } static long dist[],dp[][],left[],right[]; static int visited[],isit[]; static ArrayList>> adj[],li; //static int dp[][][]; static int MOD=1000000007; static char ch[]; static int[] sieve,is_sieve; static TreeSet tr; static long mat[][]; // static void bfs(int node,int par,Pair p[],long taken){ // LinkedList li=new LinkedList<>(); // li.add(node); // while(!li.isEmpty()){ // int x=li.pollFirst(); // long lowNode=p[x-1].x; // long highNode=p[x-1].y; // int left=0,right=0; // visited[x]=1; // for(Pair> pp:adj[x]){ // long max=0; // if(selected[pp.x]==0){ // max=Math.max(Math.abs(lowNode-pp.y.y),Math.abs(highNode-pp.y.x)); // if(max==Math.abs(lowNode-pp.y.y)){ // left++; // }else{ // right++; // } // }else{ // max=Math.max(Math.abs(lowNode-selected[pp.x]),Math.abs(highNode-selected[pp.x])); // if(max==Math.abs(lowNode-selected[pp.x])){ // left++; // }else{ // right++; // } // } // if(visited[pp.x]==0) // li.add(pp.x); // } // if(left>=right){ // selected[x]=lowNode; // }else{ // selected[x]=highNode; // } // } // } static void dfs(int node,int par, Pair p[]){ for(Pair> pp:adj[node]){ if(pp.x!=par){ //sum+=Math.abs(selected[node]-selected[pp.x]); dfs(pp.x,node,p); //System.out.println(node+"" ""+pp.x); long x=Math.abs(p[node].x-p[pp.x].x); long y=Math.abs(p[node].x-p[pp.x].y); long z=Math.abs(p[node].y-p[pp.x].x); long w=Math.abs(p[node].y-p[pp.x].y); left[node]+=Math.max(x+left[pp.x],y+right[pp.x]); right[node]+=Math.max(z+left[pp.x],w+right[pp.x]); } } } public static void main(String args[]){ InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); int t,i,j,tno=0,tte; t=in.nextInt(); //t=1; //tte=t; while(t-->0){ //sum=0; int n=in.nextInt(); adj=new ArrayList[n+1]; left=new long[n+1]; right=new long[n+1]; visited=new int[n+1]; for(i=0;i(); } Pair p[]=new Pair[n+1]; for(i=1;i<=n;i++){ p[i]=new Pair<>(in.nextLong(),in.nextLong()); } for(i=0;i(v,p[v])); adj[v].add(new Pair<>(u,p[u])); } //bfs(1,-1,p,Long.MAX_VALUE); dfs(1,-1,p); // for(i=0;i l = new ArrayList<>(), r = new ArrayList<>(); long dp[][]; long ok(int i, int j) { if (dp[i][j] != -1) return dp[i][j]; if (i >= l.size()) { return 0; } if (j >= r.size()) return Integer.MAX_VALUE; long op1 = ok(i + 1, j + 1) + Math.abs(l.get(i) - r.get(j)); long op2 = ok(i, j + 1); return dp[i][j] = Math.min(op1, op2); } void solve() { int t = 1; // t = nextInt(); for (int tt = 0; tt < t; tt++) { int n = nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); if (arr[i] == 0) r.add(i + 1); else l.add(i + 1); } dp = new long[n][n]; for (int i = 0; i < n; i++) Arrays.fill(dp[i], -1); out.println(ok(0, 0)); } out.close(); } } ","import java.util.*; import java.io.*; public class _1525_D { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int n = Integer.parseInt(in.readLine()); int[] a = new int[n]; StringTokenizer line = new StringTokenizer(in.readLine()); int c = 0; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(line.nextToken()); if (a[i] == 1) c++; } int[] pos = new int[c]; int count = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { pos[count] = i; count++; } } int[][] dp = new int[c + 1][n]; for (int i = 1; i <= c; i++) { Arrays.fill(dp[i], Integer.MAX_VALUE); } for (int i = 1; i <= c; i++) { for (int j = 0; j < n; j++) { if (j > 0) { if (a[j] == 0) { if (dp[i - 1][j - 1] != Integer.MAX_VALUE) { dp[i][j] = dp[i - 1][j - 1] + Math.abs(j - pos[i - 1]); } } dp[i][j] = Math.min(dp[i][j], dp[i][j - 1]); } else { if (a[j] == 0 && i == 1) { dp[i][j] = Math.abs(j - pos[i - 1]); } } } } out.println(dp[c][n - 1]); in.close(); out.close(); } } ",0,Non-plagiarised a4d6775d,cb87df79,"import java.io.*; import java.util.*; public class ArmChairs { public static int solution(int n, int[] arr) { ArrayList one = new ArrayList(); ArrayList zero = new ArrayList(); for (int i = 0; i < n; i++) { if (arr[i] == 1) { one.add(i); } else { zero.add(i); } } int[][] dp = new int[one.size() + 1][zero.size() + 1]; for (int i = 1; i <= one.size(); i++) { dp[i][i] = dp[i - 1][i - 1] + Math.abs(one.get(i - 1) - zero.get(i - 1)); for (int j = i + 1; j <= zero.size(); j++) { dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j - 1] + Math.abs(one.get(i - 1) - zero.get(j - 1))); } } return dp[one.size()][zero.size()]; } public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); String[] s = br.readLine().split("" ""); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(s[i]); } log.write(Integer.toString(solution(n, arr)) + ""\n""); log.flush(); } } ","import java.util.*; public class Longjumps { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayList o=new ArrayList(), e=new ArrayList(); int n = sc.nextInt(); for(int i=1;i<=n;i++){ int x=sc.nextInt(); if(x==1)o.add(i); else e.add(i); } int dp[][]=new int[o.size()+1][e.size()+1]; 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,Plagiarised 7d9b95c0,9d33ca79,"import java.util.*; import java.math.*; public class Main { public static class Edge{ int u; int v; // int wt; Edge(int u, int v){ this.u = u; this.v = v; // this.wt = wt; } } 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[] graph = new ArrayList[n]; for(int i=0 ; i(); } String[] arr = new String[n-1]; for(int i=0 ; i 2) { flag = true; }else if(graph[i].size() == 1) src = i; } if(flag) { sb.append(-1 + ""\n""); }else { Map hm = new HashMap<>(); int count = 0; int val = 2; // System.out.println(src); while(count < n) { List e = graph[src]; int i=0; while(i < e.size() && hm.containsKey(src + "" "" + e.get(i).v)) i++; if(i < e.size()) { int nbr = e.get(i).v; // System.out.println(src + "" "" + nbr); hm.put(src + "" "" + nbr, val); hm.put(nbr + "" "" + src, val); val = 5 - val; src = nbr; } count++; } for(int i=0 ; i[]adj; static boolean vis []; static int edges[]; // we need to check that every path of length 1 or 2 must be a prime number // Idea--> we will only use 2 , 3 for the weight assignment // no assignment will be valid if there exists a node connected to 3 others 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(); vis= new boolean [n]; adj= new ArrayList[n]; TreeMap idx = new TreeMap<>(); TreeMap w= new TreeMap<>(); boolean notValid = false; for(int i =0;i(); } for(int i =1;i2||adj[v].size()>2)notValid=true; } if(notValid){ pw.println(-1); continue; } dfs(0,2,w); // vis[0]=true; // dfs(adj[0].get(0),2,w); // if(adj[0].size()==2)dfs(adj[0].get(1),3,w); for(int i =1;iweight){ vis[node]=true; int i =0; for(int x : adj[node]){ if(!vis[x]) { int min = Math.min(x , node); int max = Math.max(x , node); if(i%2==0){ weight.put(new Pair(min , max),w); dfs(x, 5-w,weight); } else{ weight.put(new Pair(min , max),5-w); dfs(x, w, weight); } i++; } } } static class Pair implements Comparable{ int x; int y ; Pair(int x , int y ){ this.x=x; this.y=y; } } } ",0,Non-plagiarised 354d060f,e1c4f3db,"import java.util.*; import java.io.*; public class CodeForces { // For fast input output // end of fast i/o code public static void main(String[] args) { FastReader in = new FastReader(); OutputStream op = System.out; PrintWriter out = new PrintWriter(op); int t = in.nextInt(); for (int i = 1; i <= t; i++) { int n=in.nextInt(); int arr[]=new int[n]; for(int j = 0; j < n; j++) arr[j]=in.nextInt(); helper(n,arr,out); out.println(); } out.close(); } public static void helper(int n,int arr[],PrintWriter o) { int max=Integer.MIN_VALUE; for(int i=2;i=0;i--) { if(copy[i]=2){ copy[i-1]+=min; copy[i-2]+=2*min; }} return true; } } ","import java.util.*; public class BalancedStoneHeaps { public static boolean check(int n, int x, int[] h) { int[] c_h = new int[n]; for (int i = 0; i < n; i++) c_h[i] = h[i]; for (int i = n - 1; i >= 2; i--) { if (c_h[i] < x) return false; int d = Math.min(h[i], c_h[i] - x) / 3; c_h[i - 1] += d; c_h[i - 2] += 2 * d; } return c_h[0] >= x && c_h[1] >= x; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] h = new int[n]; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { h[i] = sc.nextInt(); if (h[i] > max) { max = h[i]; } } int l = 0; int r = max; while (l < r) { int mid = l + (r - l + 1) / 2; if (check(n, mid, h)) { l = mid; } else { r = mid - 1; } } System.out.println(l); } } } ",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,Plagiarised 1097b326,f1f600d9,"import java.util.Scanner; public class Main { public static void solution3(){ Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t-- > 0){ int n; n = scanner.nextInt(); int[] costs = new int[n]; for (int i=0; i> g; static int count = 0; /* * ====================================Main================================= */ public static void main(String args[]) throws Exception { // File file = new File(""D:\\VS Code\\Java\\Output.txt""); // FileWriter fw = new FileWriter(""D:\\VS Code\\Java\\Output.txt""); Random rand = new Random(); int t = 1; t = f.nextInt(); int tc = 1; while (t-- != 0) { int n = f.nextInt(); int c[] = new int[n]; long minOdd = 0, minEven = 0; long sumEven = 0, sumOdd = 0; for (int i = 0; i < n ; i++) { c[i] = f.nextInt(); // if (i % 2 == 0) { // minEven = (c[minEven] > c[i]) ? i : minEven; // sumEven += c[i]; // } else { // minOdd = (minOdd > c[i]) ? i : minOdd; // sumOdd += c[i]; // } } minEven = c[0]; minOdd = c[1]; sumEven=c[0]; sumOdd=c[1]; long min=minEven*n + minOdd*n;//for k=2 int even=1,odd=1; for (int k = 3; k <= n; k++) { if(k%2==1){ sumEven+=c[k-1]; minEven=Math.min(minEven, c[k-1]); even++; }else{ sumOdd+=c[k-1]; minOdd=Math.min(minOdd, c[k-1]); odd++; } min=Math.min(min, sumEven-minEven+minEven*(n-even+1) + sumOdd-minOdd+minOdd*(n-odd+1)); } w.write(min+""\n""); } w.flush(); } } ",0,Non-plagiarised 085ddefc,1500a4fa,"import java.io.*; import java.util.*; public class a { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); String a = sc.next(); String b = sc.next(); int change = 0; int nochange = 0; for(int i=0; i0){ int n=sc.nextInt(); String a=sc.next(); String b=sc.next(); int i; int zero=0,one=0; int x=0,y=0,x1=0,y1=0; for(i=0;i a = new ArrayList<>(); ArrayList b = new ArrayList<>(); for(int i=0;i 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]; } } ",0,Non-plagiarised 41e69083,54eb1a6b,"import java.util.*; public class Solution { public static void main(String[] args) { // TODO Auto-generated method stub Scanner io =new Scanner (System.in); int t = io.nextInt(); for (int iii=0; iii 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 0951d079,0ecf356d,"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.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); int[] h = new int[n]; int[] dp = new int[n]; for(int i = 0; i hi = new Stack<>(); Stack lo = new Stack<>(); hi.push(0); lo.push(0); for(int i = 1; ih[i]){ dp[i] = Math.min(dp[i], dp[lo.peek()]+1); lo.pop(); } if(!lo.isEmpty()){ dp[i] = Math.min(dp[i], dp[lo.peek()]+1); if(h[i] == h[lo.peek()]) lo.pop(); } hi.push(i); lo.push(i); } System.out.println(dp[n-1]); } } ",1,Plagiarised 1be078c4,f339ef6f,"import java.util.*; import java.io.*; public class E_1547 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int T = sc.nextInt(); while(T-->0) { int n = sc.nextInt(), k = sc.nextInt(); int[] a = sc.nextIntArray(k); int[] t = sc.nextIntArray(k); int[] array = new int[n]; Arrays.fill(array, Integer.MAX_VALUE); for(int i = 0; i < k; i++) array[a[i] - 1] = t[i]; int[] pre = new int[n]; int[] post = new int[n]; int prev = (int)2e9; for(int i = 0; i < n; i++) prev = pre[i] = Math.min(prev + 1, array[i]); prev = (int)2e9; for(int i = n - 1; i >= 0; i--) prev = post[i] = Math.min(prev + 1, array[i]); for(int i = 0; i < n; i++) array[i] = Math.min(pre[i], post[i]); for(int i = 0; i < n; i++) pw.print(array[i] + (i == n - 1 ? ""\n"" : "" "")); } pw.flush(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.StringTokenizer; public class Main { static FastReader fr; static int arrForIndexSort[]; public static void main(String[] args) { fr = new FastReader(); int T = 1; T = fr.nextInt(); int t1 = T; while (T-- > 0) { solve(); } } public static void solve() { int n=fr.nextInt(); int k=fr.nextInt(); int[] a = new int[k]; int[] map = new int[n]; int[] temp = new int[n]; Arrays.fill(temp, Integer.MAX_VALUE); Arrays.fill(map, Integer.MAX_VALUE); int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for(int i=0;i=0;i--) { int airConditioner = map[i]; if(airConditioner1){ { long value=total-(odd_min+even_min); value+= odd_min * (n-odd_length+1); value+= even_min * (n-even_length+1); ans= Math.min(value, ans); } } } System.out.println(ans); } } } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(in, out); out.close(); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.PrintStream; import java.io.PrintWriter; public class A { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; //Count the number of coprime's upto N // Returns nCr % p using Fermat's little theorem. //Modular Operations for Addition and Multiplication. /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long INF = 1000000000000000007L; int n = sc.nextInt(); long[] c = new long[n+1]; for(int i = 1;i<=n;i++) c[i] = sc.nextLong(); long ans = INF; long mo = INF, so = 0, co = 0; long me = INF, se = 0, ce = 0; for(int i=1;i<=n;i++) { if(i%2 == 1) { mo = min(mo,c[i]); so += c[i]; co++; } else { me = min(me,c[i]); se += c[i]; ce++; } if(i>=2) { long x = so + (n - co) * mo + se + (n - ce) * me; ans=min(ans,x); } } fout.println(ans); } fout.close(); } } ",0,Non-plagiarised 3b498a39,e6b7a899,"import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static long dp[][]; static int max; public static void main(String[] args) { PrintWriter out=new PrintWriter(System.out); //StringBuffer sb=new StringBuffer(""""); int ttt=1; //ttt =i(); outer :while (ttt-- > 0) { int n=i(); int A[]=input(n); dp=new long[n+1][n+1]; for(int i=0;i<=n;i++) { Arrays.fill(dp[i],-1); } ArrayList l=new ArrayList(); ArrayList m=new ArrayList(); for(int i=0;i ans=new ArrayList<>(); public static void main(String[] args){ PrintWriter out = new PrintWriter(System.out); InputReader sc=new InputReader(System.in); int N = sc.nextInt(); int[] A = sc.nextIntArray(N); ArrayList a1 = new ArrayList(); ArrayList a2 = new ArrayList(); for (int i = 0; i < A.length; i++) { if (A[i]==0) { a1.add(i); }else { a2.add(i); } } int[][] dp = new int[a1.size()+1][a2.size()+1]; for (int i = 0; i < dp.length; i++) { Arrays.fill(dp[i], Integer.MAX_VALUE/2); } dp[0][0] = 0; for (int i = 1; i <= a1.size() ; i++) { int pos1 = a1.get(i-1); for (int j = 0; j <= a2.size(); j++) { dp[i][j] = dp[i-1][j]; if (j-1>=0) { int pos2 = a2.get(j-1); dp[i][j] = Math.min(dp[i][j], dp[i-1][j-1] + Math.abs(pos1-pos2)); } } } System.out.println(dp[a1.size()][a2.size()]); } } ",0,Non-plagiarised 1a6f8b20,f6ed6826,"import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws Exception { Main ob=new Main(); ob.fun(); } public void fun()throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0) { int n=Integer.parseInt(br.readLine()); int ar[][]=new int [n][5]; int len[]=new int[n]; for(int i=0;i pq=new PriorityQueue(Collections.reverseOrder()); for(int i=0;i0) { int num=(int)(pq.poll()); if((sum+num)>0) { ct++; sum+=num; } } return ct; } } ","import java.util.*; import java.io.*; public class Solution { static FastScanner scr=new FastScanner(); // static Scanner scr=new Scanner(System.in); static PrintStream out=new PrintStream(System.out); static StringBuilder sb=new StringBuilder(); static HashMap>hm=new HashMap<>(); static void solve() { int n=scr.nextInt(); int count[]=new int[5]; int store[][]=new int[n][5]; int max=MIN; int length[]=new int[n]; for(int i=0;ia=new ArrayList<>(); for(int i=0;i0) { ans++; }else { break; } } max=Math.max(max, ans); } out.println(max); } static int MAX = Integer.MAX_VALUE; static int MIN = Integer.MIN_VALUE; public static void main(String []args) { int t=scr.nextInt(); while(t-->0) { solve(); } // solve(); // out.println(sb); } } ",0,Non-plagiarised 55ab9b5d,ae4d5b49,"import java.io.*; import java.util.*; public class Main { static int solve(char ch, char[][] str, int N) { int[] a = new int[N]; for (int i = 0; i < N; i++) { int c1 = 0, c2 = 0; for (char x : str[i]) { if (x == ch) c1++; else c2++; } a[i] = c1 - c2; } int sum = 0, count = N; for (int x : a) sum += x; Arrays.sort(a); for (int i = 0; i < N; i++) { if (sum > 0) break; count--; sum -= a[i]; } return count; } public static void main(String[] args) throws IOException { // System.out.println(""===== input =====""); // BufferedReader br = new BufferedReader(new FileReader(""input/input1.txt"")); // BufferedReader br2 = new BufferedReader(new FileReader(""input/input1.txt"")); // String s; // while ((s = br2.readLine()) != null) { // System.out.println(s); // } // System.out.println(""===== output =====""); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); StringBuilder out = new StringBuilder(); int T = Integer.parseInt(st.nextToken()); while (T-- > 0) { int n = Integer.parseInt(br.readLine().trim()); char[][] str = new char[n][]; for (int i = 0; i < n; i++) { str[i] = br.readLine().trim().toCharArray(); } int ans = 0; for (char ch = 'a'; ch <= 'e'; ch++) { ans = Math.max(ans, solve(ch, str, n)); } out.append(ans).append(""\n""); } System.out.println(out); } } ","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(); } } ",0,Non-plagiarised 2.921E+060,46e9aed4,"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(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////// } ","import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public final class Solution { public static void main(String[] args) throws Exception { Reader sc = new Reader(); BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out)); int n=sc.nextInt(); ArrayList fill= new ArrayList(); ArrayList unfilled= new ArrayList<>(); for(int i=0;i 0) { int n = sc.nextInt(); String[] s = new String[n]; for(int i = 0 ; i < n ; i++){ s[i] = sc.next(); } Integer[][] count = new Integer[n][5]; Integer[] totalCount = new Integer[5]; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < 5 ; j++){ count[i][j]=0; } } for(int i = 0 ; i < 5 ; i++){ totalCount[i] = 0; } Integer total = 0; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < s[i].length() ; j++){ int val = s[i].charAt(j) - 'a'; count[i][val]++; totalCount[val]++; total++; } } //2*count[]char > len of total int ans = -1; for(int ch = 0 ; ch < 5 ; ch++){ List ls = new ArrayList<>(); for(int i = 0 ; i < n ; i++){ int c = s[i].length() - (2 * count[i][ch]); ls.add(new StringPair(s[i],c)); } Collections.sort(ls); int finalCount = n; int thisTotal = total; int thisTotalCharcount = totalCount[ch]; int idx = n-1; while(finalCount > ans && 2*thisTotalCharcount <= thisTotal && idx >= 0){//condition true){ thisTotal -= ls.get(idx).s.length(); thisTotalCharcount -= (ls.get(idx).s.length() - ls.get(idx).charCount)/2; idx--; finalCount--; } ans = Integer.max(ans,finalCount); } 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); } } } ",0,Non-plagiarised 90f01508,e00b1794,"import java.io.*; import java.util.*; public class one { static Scanner sc=new Scanner(System.in); boolean prime[]; static int prev=-1; static int dp[][]; public static void main(String[] args) { //int testcase=1; int testcase=sc.nextInt(); //System.out.println(""HI""); while(testcase-->0){ // int x=sc.nextInt(); // int y=sc.nextInt(); //String str[]=new String[size]; solve(); System.out.println(); } } public static void solve(){ HashMap map=new HashMap(); int size=sc.nextInt(); int arr[][]=new int[size-1][2]; for(int i=0;i2||map.get(x[1])>2){ System.out.println(-1); return; } } List> adj=new ArrayList<>(); for(int i=0;i<=size;i++) adj.add(new ArrayList()); for(int x[]:arr){ adj.get(x[0]).add(x[1]); adj.get(x[1]).add(x[0]); } //System.out.println(adj); int vist[]=new int[size+1]; HashMap ans=new HashMap(); for(int i=1;i<=size;i++){ if(vist[i]==0){ dfs(i,vist,adj,ans,2); } } //System.out.println(ans); for(int x[]:arr){ //System.out.print(map.get(x[0])); int a=Math.min(x[0],x[1]); int b=Math.max(x[0],x[1]); String s=a+"" ""+b; System.out.print(ans.get(s)+"" ""); } // map=new HashMap(); // for(int x[]:arr){ // if(map.containsKey(x[0])){ // int val=13-map.get(x[0]); // map.put(x[1],val); // System.out.print(val+"" ""); // }else if(map.containsKey(x[1])){ // int val=13-map.get(x[1]); // map.put(x[0],val); // System.out.print(val+"" ""); // }else{ // System.out.print(2+"" ""); // map.put(x[0],2); // map.put(x[1],2); // } // } } public static void dfs(int node,int vist[],List> adj,HashMap ans,int val){ vist[node]=1; for(int i:adj.get(node)){ if(vist[i]==1) continue; int x=Math.min(i, node); int y=Math.max(i, node); ans.put(x+"" ""+y,val); dfs(i,vist,adj,ans,5-val); val=5-val; } } } ","import java.util.*; import java.io.*; public class Main{ static final Random random=new Random(); static long mod=1000000007L; static HashMapmap=new HashMap<>(); public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); //out.println(""hee""); //int testCases=1; while(testCases-- > 0){ solve(in); } out.close(); } catch (Exception e) { return; } } public static void solve( FastReader in){ int n=in.nextInt(); List> graph=new ArrayList<>(); for(int i=0;i()); } //out.println(""hee""); for(int i=0;i2){ System.out.println(""""+-1); return; } else if(graph.get(i).size()==1){ start=i; } } int[] ans=new int[n-1]; int[] vis=new int[n+1]; vis[start]=1; int w=2; Queue q=new LinkedList<>(); q.add(start); while(!q.isEmpty()){ int x=q.poll(); for(Pair p:graph.get(x)){ if(vis[p.node]==0){ vis[p.node]=1; q.add(p.node); int idx=p.eg_indx; ans[idx]=w; if(w==2)w=5; else w=2; } } } for(int i:ans){ System.out.print(i+"" ""); } System.out.println(""""); } static class Pair{ int node; int eg_indx; Pair(int node,int eg_indx){ this.node=node; this.eg_indx=eg_indx; } } } ",0,Non-plagiarised d8a171a3,f229aa7f,"import java.io.*; import java.util.*; public class 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 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 54d7c21e,80881cae,"import java.io.*; import java.util.*; public class cp { // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // primeSet=new HashSet<>(); // sieveOfEratosthenes((int)1e6+5); while(tc-->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 ans; //function to find prime factors of n //fenwick tree implementaion //Function to find number of set bits // function to find last index <= y // static class GraphMap{ // Map> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static PrintWriter out=new PrintWriter(System.out); } ","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; // } } } ",1,Plagiarised 45e38fad,ec8566b8,"import java.util.*; import java.io.*; public class C_Not_Assigning { // For fast input output static class Edge{ public int node; public int next; Edge(int node, int next){ this.node = node; this.next = next; } } public static void dfs(int u, ArrayList> g,int[] vis, int flag, int[] weight){ vis[u] = 1; for(Edge e : g.get(u)){ if(vis[e.node] == 0){ if(flag == 0) { weight[e.next] = 2; dfs(e.node, g, vis, 1, weight); } else { weight[e.next] = 5; dfs(e.node, g, vis, 0, weight); } } } } // end of fast i/o code public static void main(String[] args) { FastReader reader = new FastReader(); int t = reader.nextInt(); while(t-->0){ int n = reader.nextInt(); int[] order = new int[n+1]; int flag = 0; //ArrayList> adj = new ArrayList<>(n+1); //Map> adj = new HashMap<>(); ArrayList> graph= new ArrayList<>(); for(int i=0;i()); } for(int i=0;i[] g, Map map) { int n = g.length; for (int i = 0; i < n; i++) { if (g[i].size() > 2) { System.out.println(-1); return; } } int[] ans = new int[n - 1]; //dfs(new C(-1, 0), g, ans, 3, new HashSet<>()); Queue queue = new LinkedList<>(); Set seen = new HashSet<>(); int val = 3; for (Integer integer : g[0]) { Integer idx = map.get(new W(0, integer)); ans[idx] = val; queue.add(new int[]{val, integer}); seen.add(integer); val = val == 2 ? 3 : 2; } seen.add(0); while (!queue.isEmpty()) { int[] poll = queue.poll(); for (Integer u : g[poll[1]]) { if (!seen.contains(u)) { seen.add(u); int curr = poll[0] == 2 ? 3 : 2; Integer integer = map.get(new W(poll[1], u)); ans[integer] = curr; queue.add(new int[]{curr, u}); } } } for (int an : ans) { System.out.print(an + "" ""); } System.out.println(); } static class W { int u; int v; public W(int u, int v) { this.u = u; this.v = v; } } public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); List[] g = new ArrayList[n]; for (int j = 0; j < n; j++) { g[j] = new ArrayList<>(); } Map map = new HashMap<>(); for (int j = 0; j < n - 1; j++) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; g[u].add(v); g[v].add(u); map.put(new W(u, v), j); map.put(new W(v, u), j); } sport(g, map); } } } ",0,Non-plagiarised a368f345,e5d02e93,"import java.util.*; import java.io.*; public class codeforces { static FastReader fr; static StringBuilder res; public static void main(String[] args) throws java.lang.Exception { fr = new FastReader(); boolean fixed = false; int t = !fixed ? fr.nextInt() : 1; res = new StringBuilder(); while (t-- > 0) { solve(); } fr.write(res.toString()); fr.close(); } static int M = 1000008; static boolean[] primes = new boolean[M]; static int[] dp = new int[M]; public static void solve() { int n = fr.nextInt(); String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = fr.nextLine(); } char[] chars = { 'a', 'b', 'c', 'd', 'e' }; int ans = 0; for (int i = 0; i < 5; i++) { char ch = chars[i]; List a = new ArrayList<>(); for (int j = 0; j < n; j++) { String s = arr[j]; int c = 0; for (int k = 0; k < s.length(); k++) { if (s.charAt(k) == ch) c++; } a.add(2 * c - s.length()); } // System.out.println(a); Collections.sort(a, Collections.reverseOrder()); int sum = 0, len = 0; for (int k = 0; k < a.size(); k++) { if (sum + a.get(k) <= 0) { break; } else { len++; sum += a.get(k); } } ans = Math.max(ans, len); } res.append(ans + ""\n""); } } ","import java.util.*; import java.io.*; public class C_1551 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; int[] d = new int[n]; int[] e = new int[n]; for(int i = 0; i < n; i++) { String s = sc.next(); int[] cnt = new int[5]; for(int j = 0; j < s.length(); j++) cnt[s.charAt(j) - 'a']++; a[i] = 2 * cnt[0] - s.length(); b[i] = 2 * cnt[1] - s.length(); c[i] = 2 * cnt[2] - s.length(); d[i] = 2 * cnt[3] - s.length(); e[i] = 2 * cnt[4] - s.length(); } Arrays.sort(a); Arrays.sort(b); Arrays.sort(c); Arrays.sort(d); Arrays.sort(e); int max = 0; int sum = 0; for(int i = n - 1; i >= 0; i--) { sum += a[i]; if(sum <= 0) break; max = n - i; } sum = 0; for(int i = n - 1; i >= 0; i--) { sum += b[i]; if(sum <= 0) break; max = Math.max(max, n - i); } sum = 0; for(int i = n - 1; i >= 0; i--) { sum += c[i]; if(sum <= 0) break; max = Math.max(max, n - i); } sum = 0; for(int i = n - 1; i >= 0; i--) { sum += d[i]; if(sum <= 0) break; max = Math.max(max, n - i); } sum = 0; for(int i = n - 1; i >= 0; i--) { sum += e[i]; if(sum <= 0) break; max = Math.max(max, n - i); } pw.println(max); } pw.flush(); } } ",0,Non-plagiarised 5766f176,e7a997b5,"import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { // write your code here boolean readFromLocal = true; //readFromLocal = false; String filepath = ""src/input.txt""; //FileInputStrviseam fileInputStream = new FileInputStream(filepath); InputReader inputReader = new InputReader(System.in); Solve s = new Solve(); s.solve(inputReader); } } class Solve { public void solve(InputReader inputReader) { int t,n; t = inputReader.nextInt(); while (t>0) { t--; n = inputReader.nextInt(); Graph g = new Graph(n); g.res = new int[n-1]; for(int i=1;i[] adj; int size; boolean[] vis; public int [] res; Graph(int n){ this.size = n; this.adj = new ArrayList[n+1]; this.vis = new boolean[n+1]; for (int i = 0; i <=n; i++) { adj[i] = new ArrayList<>(); } } public void addEdge(int a, int b, int edge,boolean biDirectional){ adj[a].add(new int[]{b, edge}); if (biDirectional) { adj[b].add(new int[]{a, edge}); } } public void dfs(int node,int parent,int prime){ for (int[] nodePair: adj[node]) { if (nodePair[0]!=parent){ res[nodePair[1]] = prime; dfs(nodePair[0],node,prime^1); } } } boolean hasDegreeMoreThanTwo() { for (int i = 0; i <= size; i++) { if (adj[i].size()>2){ return true; } } return false; } } ","import java.io.*; import java.util.*; public class c { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for(int i=0; i()); } for(int i=0; i list : graph){ if(list.size() == 1){ indegree1count++; } else if(list.size() == 2){ indegree2count++; } } if(indegree1count == 2 && indegree1count+indegree2count==n){ for(int i=0; i list = graph.get(i); if(list.size() == 1){ dfs(graph, edges, false, -1, i) ; } } for(int i=1; i> graph, int[] edges, boolean isprev2, int parent, int current){ for(Edge e : graph.get(current)){ if(e.v == parent){ continue; } edges[e.id] = isprev2 ? 5 : 2; dfs(graph, edges, !isprev2, current, e.v); } } } class Edge { int u; int v; int id; public Edge(int u, int v, int id) { this.u = u; this.v = v; this.id = id; } } ",0,Non-plagiarised 3f6f1267,cdb7a891,"import java.io.*; import java.util.*; public class T4 { public static void main(String[] args) { FastScanner s = new FastScanner(); T4 main = new T4(); int n = 1; while (n-- > 0) { main.MainPrint(s); } } long mod = 998244353L; private void MainPrint(FastScanner s) { int n = s.nextInt(); k = s.nextInt(); TreeMap map = new TreeMap<>(); int l, r; int[] get; for (int i = 0; i < n; i++) { l = s.nextInt(); r = s.nextInt(); if (!map.containsKey(l)) { get = new int[2]; get[0]++; map.put(l, get); } else { get = map.get(l); get[0]++; } if (!map.containsKey(r + 1)) { get = new int[2]; get[1]++; map.put(r + 1, get); } else { get = map.get(r + 1); get[1]++; } } int count = 0; long ans = 0; precomp(); for (int i : map.keySet()) { get = map.get(i); count += get[0] - get[1]; ans += rem[count] - rem[count-get[0]]; ans %= mod; } if (ans<0) ans+=mod; System.out.println(ans%mod); } long mul(long a, long b) { return a*b%mod; } long exp(long base, long e) { if (e==0) return 1; long half=exp(base, e/2); if (e%2==0) return mul(half, half); return mul(half, mul(half, base)); } long modInv(long x) { return exp(x, mod-2); } long[] facts; long[] factInvs; long[] rem; int k; void precomp() { facts=new long[300_001]; factInvs=new long[300_001]; rem = new long[300_001]; factInvs[0]=facts[0]=1; for (int i=1; i=0; i--) factInvs[i]=mul(factInvs[i+1], i+1); for (int i = k;i prime; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); // int t = Integer.parseInt(br.readLine()); // while (t-- > 0) { fac(); String[] s1 = br.readLine().split("" ""); int n = Integer.parseInt(s1[0]); int k = Integer.parseInt(s1[1]); Long[][] arr = new Long[n][2]; Long[] st = new Long[n]; Long[] end = new Long[n]; for (int i = 0; i < n; i++) { String str = (br.readLine()); String[] s2 = str.split("" ""); arr[i][0] = Long.parseLong(s2[0]); st[i] = arr[i][0]; arr[i][1] = Long.parseLong(s2[1]); end[i] = arr[i][1]; } Arrays.sort(st); Arrays.sort(end); long pp = (power(fac[k], mod - 2)); long[] comb = new long[n + 1]; for (int i = 1; i <= n; i++) { if (i < k) { continue; } // System.out.println(i + "" "" + fac[i] + "" "" + power(fac[k], mod - 2) + "" "" + // fac[k]); comb[i] = (fac[i] * pp) % mod; comb[i] = (comb[i] * (power(fac[i - k], mod - 2))) % mod; } // for (int i = 0; i <= n; i++) { // System.out.print(comb[i] + "" ""); // } HashMap map1 = new HashMap(); HashMap map = new HashMap<>(); for (int i = 0; i < n; i++) { if (map.containsKey(arr[i][0])) { map.put(arr[i][0], map.getOrDefault(arr[i][0], 0) + 1); continue; } int a = getLower(arr[i][0] - 1, st); int b = getLower(arr[i][0] - 1, end); map.put(arr[i][0], map.getOrDefault(arr[i][0], 0) + 1); map1.put(arr[i][0], map1.getOrDefault(arr[i][0], 0)); if (a != -1 || b != -1) { if (b == -1) { int curr = a + 1; map1.put(arr[i][0], map1.getOrDefault(arr[i][0], 0) + curr); continue; } // System.out.println(arr[i][0] + "" "" + b + "" "" + a); int curr = a - b; map1.put(arr[i][0], map1.getOrDefault(arr[i][0], 0) + curr); } } long ans = 0; for (long a : map.keySet()) { ans = (ans + comb[map.get(a) + map1.get(a)] + mod - comb[map1.get(a)]) % mod; } // System.out.println(map + "" "" + map1); pw.println(ans); // } pw.close(); } private static long power(long a, long p) { // TODO Auto-generated method stub long res = 1; while (p > 0) { if (p % 2 == 1) { res = (res * a) % mod; } p = p / 2; a = (a * a) % mod; } return res; } private static void fac() { fac[0] = 1; // TODO Auto-generated method stub for (int i = 1; i < fac.length; i++) { if (i == 1) { fac[i] = 1; } else { fac[i] = i * fac[i - 1]; } if (fac[i] > mod) { fac[i] = fac[i] % mod; } } } private static int getLower(Long long1, Long[] st) { // TODO Auto-generated method stub int left = 0, right = st.length - 1; int ans = -1; while (left <= right) { int mid = (left + right) / 2; if (st[mid] <= long1) { ans = mid; left = mid + 1; } else { right = mid - 1; } } return ans; } } ",0,Non-plagiarised bdfe8110,fadc1365,"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 E { public static void main(String[] args) { FastScanner fs=new FastScanner(); int T=fs.nextInt(); PrintWriter out=new PrintWriter(System.out); for (int tt=0; tt=0; i--) forced[i]=Math.min(forced[i], forced[i+1]+1); for (int i=0; i=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i 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 java.util.*; import java.io.*; public class C { static PrintWriter pw; void solve(int n, char[] a, char[] b) { int same = 0, diff = 0; int[] sameCnt = {0, 0}, diffCnt = {0, 0}; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { same++; sameCnt[a[i] - '0']++; } else { diff++; diffCnt[a[i] - '0']++; } } // tr(same, sameCnt, diff, diffCnt); int res = Integer.MAX_VALUE; if (same % 2 != 0 && sameCnt[1] - sameCnt[0] == 1) res = Math.min(res, same); if (diff % 2 == 0 && diffCnt[1] == diffCnt[0]) res = Math.min(res, diff); pr(res == Integer.MAX_VALUE ? -1 : res); } private void run() { // read_write_file(); // comment this before submission FastScanner fs = new FastScanner(); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); char[] a = fs.next().toCharArray(), b = fs.next().toCharArray(); solve(n, a, b); } } private final String INPUT = ""input.txt""; private final String OUTPUT = ""output.txt""; public static void main(String[] args) { pw = new PrintWriter(System.out); new C().run(); pw.close(); } void pr(int num) { pw.println(num); } void pr(long num) { pw.println(num); } void pr(double num) { pw.println(num); } void pr(String s) { pw.println(s); } void pr(char c) { pw.println(c); } } ",0,Non-plagiarised ccc8ef27,d6fb3b9e,"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 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; } } ",1,Plagiarised 90dc2b20,d8a171a3,"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 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(); } } ","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 && 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 4e9c4bf9,f9e08a46,"import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class E1525D { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int[] arr = new int[n]; ArrayList occupied = new ArrayList<>(); for (int i = 0; i < n; i++) { arr[i] = scn.nextInt(); if (arr[i] == 1) occupied.add(i); } int[][] dp = new int[n + 1][occupied.size() + 1]; for (int[] row : dp) Arrays.fill(row, (int) 1e9); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= occupied.size(); j++) { dp[i][j] = dp[i - 1][j]; if (arr[i - 1] == 0) dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - 1] + Math.abs(i - 1 - occupied.get(j - 1))); } } System.out.println(dp[n][occupied.size()]); } } ","import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Armchair { public static void main(String args[]){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int arr[]=new int[n]; ArrayList list1=new ArrayList(); ArrayList list2=new ArrayList(); for(int i=0;i list1,ArrayList list2,long dp[][]){ for(int i=1;i<=list1.size();i++) dp[i][0]=Integer.MAX_VALUE; for(int i=1;i<=list1.size();i++){ for(int j=1;j<=list2.size();j++){ dp[i][j]=Math.min(Math.abs(list1.get(i-1)-list2.get(j-1))+dp[i-1][j-1],dp[i][j-1]); } } } } ",0,Non-plagiarised 31cdf5fe,80cc284c,"import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-- > 0) { int n = scanner.nextInt(); int[] time = new int[n]; int[] h = new int[n]; for(int i = 0; i < n; i++) { time[i] = scanner.nextInt(); } for(int j = 0; j < n; j++) { h[j] = scanner.nextInt(); } long prevMTime = time[n-1]; long prevMHealth = h[n-1]; long manaRequired = 0; long currMTime = time[n-1]; long currMHealth = h[n-1]; long spellCastingTime = prevMTime - prevMHealth + 1; for(int i = n-2; i >= 0; i--) { currMHealth = h[i]; currMTime = time[i]; //spellCastingTime = prevMTime - prevMHealth + 1; if(spellCastingTime <= currMTime && currMTime - spellCastingTime + 1 < currMHealth) { spellCastingTime = currMTime - currMHealth + 1; } else if(spellCastingTime > currMTime) { long hm = (prevMTime - spellCastingTime) + 1; manaRequired += (hm * (hm+1)) / 2; prevMTime =currMTime; prevMHealth = currMHealth; spellCastingTime = prevMTime - prevMHealth + 1; } } long hm = (prevMTime - spellCastingTime) + 1; manaRequired += (hm * (hm+1)) / 2; System.out.println(manaRequired); } } } ","import java.util.*; public class solution{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); long[] k = new long[n]; long[] h = new long[n]; for(int i = 0;i < n;i++){ k[i] = sc.nextLong(); } for(int i = 0;i < n;i++){ h[i] = sc.nextLong(); } long length = h[n-1]; long curr = 0; long ans = 0; for(int i = n-1;i >= 1;i--){ if(k[i] - k[i-1] >= length){ 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 += k[i] - k[i-1]; } } curr += length; ans += (curr * (curr + 1))/2; System.out.println(ans); } } } ",0,Non-plagiarised 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; i0) { int n=input.nextInt(); String a=input.next(); String b=input.next(); int same1=0,same0=0,opp1=0,opp0=0; for(int i=0;i 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--; } } } ",0,Non-plagiarised 4fd752f7,c7239c97,"import java.io.*; import java.util.*; public class C { public static void main(String[] args) { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(), tt = 0; while(t-->0) { int n = in.nextInt(), m = in.nextInt(), x = in.nextInt(); int aa[] = in.readArray(n); Pair a[] = new Pair[n]; for(int i=0;i pq = new PriorityQueue<>(); Arrays.sort(a); int goneTo[] = new int[n]; for(int i=0;i=0;i--){ Pair xx = pq.poll(); xx.y += a[i].y; goneTo[a[i].x] = xx.x; pq.add(new Pair(xx.x,xx.y)); } Iterator it = pq.iterator(); ArrayList arr = new ArrayList<>(); while(it.hasNext()) arr.add(it.next()); Collections.sort(arr); //for(Pair i : arr) out.print(i.y+"" ""); //out.println(); if(arr.get(m-1).y-arr.get(0).y>x) out.println(""NO""); else{ out.println(""YES""); int pos[] = new int[n]; for(Pair i : a) pos[i.x] = goneTo[i.x]; for(int i : pos) out.print(i+"" ""); out.println(); } //tt++; out.println(""Case #""+tt+"": ""+ans); } out.flush(); } static class Pair implements Comparable { int x, y; Pair(int a, int b){ x = a; y = b; } } static final Random random = new Random(); } ","import java.io.*; import java.util.*; public class C { public static void main(String[] args) { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(), tt = 0; while(t-->0) { int n = in.nextInt(), m = in.nextInt(), x = in.nextInt(); int aa[] = in.readArray(n); Pair a[] = new Pair[n]; for(int i=0;i pq = new PriorityQueue<>(); Arrays.sort(a); int goneTo[] = new int[n]; for(int i=0;i=0;i--){ Pair xx = pq.poll(); xx.y += a[i].y; goneTo[a[i].x] = xx.x; pq.add(new Pair(xx.x,xx.y)); } Iterator it = pq.iterator(); ArrayList arr = new ArrayList<>(); while(it.hasNext()) arr.add(it.next()); Collections.sort(arr); //for(Pair i : arr) out.print(i.y+"" ""); //out.println(); if(arr.get(m-1).y-arr.get(0).y>x) out.println(""NO""); else{ out.println(""YES""); int pos[] = new int[n]; for(Pair i : a) pos[i.x] = goneTo[i.x]; for(int i : pos) out.print(i+"" ""); out.println(); } //tt++; out.println(""Case #""+tt+"": ""+ans); } out.flush(); } static class Pair implements Comparable { int x, y; Pair(int a, int b){ x = a; y = b; } } static final Random random = new Random(); } ",1,Plagiarised 26e699de,76ad805a,"import java.util.Scanner; public class Menorah { static int MOD9= 1000000000; public static void main(String[] args){ Scanner sc= new Scanner(System.in); int numberTest=sc.nextInt(); while(numberTest-->0){ int n=sc.nextInt(); char[] s=new char[n+5]; char[] t=new char[n+5]; String ss=sc.next(); String tt=sc.next(); s=ss.toCharArray(); t=tt.toCharArray(); int cntax = 0, cntbx = 0, same = 0; int ans=MOD9; for(int i=0; i 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); } } } ",0,Non-plagiarised 1984bef1,2063ba3e,"import java.util.*; import java.io.*; public class stoneheaps { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i = 0; i < t; i ++) { int n = Integer.parseInt(br.readLine()); String[] tokens = br.readLine().split("" ""); int[] arr = new int[n]; for(int j = 0; j < n; j++) { arr[j] = Integer.parseInt(tokens[j]); } int l = 1; int r = 1000000000; while(l < r) { int mid = l + (r-l+1)/2; if(check(arr, mid)) { l = mid; } else { r = mid-1; } } System.out.println(l); } } static boolean check(int[] arr, int x) { int[] changed = new int[arr.length]; for(int i = 0; i < arr.length; i ++) { changed[i] = arr[i]; } int n = arr.length; for(int i = n-1; i >= 0; i--) { if(changed[i] < x) { return false; } else if(i > 1){ int change = Math.min(changed[i]-x, arr[i])/3; changed[i-1] = changed[i-1]+change; changed[i-2] = changed[i-2] +change*2; } } return true; } } ","import java.io.*; import java.util.*; public class c { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int numCases = Integer.parseInt(in.readLine()); for (int casenum = 0; casenum < numCases; casenum++) { int n = Integer.parseInt(in.readLine()); long[] arr = new long[n]; StringTokenizer tokenizer = new StringTokenizer(in.readLine()); for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(tokenizer.nextToken()); } long low = 0; long high = 1000000000; low--; while (low < high) { long mid = low + (high - low + 1) / 2; boolean works = test(arr, mid); if (works) { low = mid; } else { high = mid - 1; } //System.out.println(mid + "" "" + works); } System.out.println(low); } in.close(); out.close(); } public static boolean test(long[] arr, long k) { long[] h = new long[arr.length]; for (int i = 0; i < arr.length; i++) { h[i] = arr[i]; } for (int i = h.length - 1; i - 2 >= 0; i--) { if (h[i] < k) break; long d = Math.min((h[i]-k) / 3, arr[i]/3); h[i] -= 3 * d; h[i - 1] += d; h[i-+ 2] += 2 * d; } for (int i = 0; i < h.length; i++) { if (h[i] < k) return false; } //System.out.println(Arrays.toString(h)); return true; } } ",0,Non-plagiarised 1410e423,da5cf40b,"import java.io.*; import java.util.*; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = Integer.parseInt(br.readLine()); while(t --> 0) { int n = Integer.parseInt(br.readLine()); char[] lineA = br.readLine().toCharArray(); char[] lineB = br.readLine().toCharArray(); boolean[] a = new boolean[n]; boolean[] b = new boolean[n]; int ac = 0; int aic = 0; int bc = 0; int stay = 0; int flip = 0; for(int i = 0; i < n; i++) { if(lineA[i] == '1') { ac++; a[i] = true; }else aic++; if(lineB[i] == '1') { bc++; b[i] = true; } if(a[i] == b[i]) stay++; else flip++; } if(ac != bc && aic + 1 != bc) { pw.println(-1); }else { if(ac == aic+1) pw.println(Math.min(stay, flip)); else if(ac == bc) pw.println(flip); else pw.println(stay); } } pw.close(); } } ","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) { int n=i(); int A[]=input(n); dp=new long[n+1][n+1]; for(int i=0;i<=n;i++) { Arrays.fill(dp[i],-1); } ArrayList l=new ArrayList(); ArrayList m=new ArrayList(); for(int i=0;ipos; static void D() throws IOException { int t=1; while(t-->0) { n=ni(); a=nai(n); mem=new long[n][n]; ones=0; pos=new ArrayList(); for(int i=0;i=ones)return j==ones?0:(long)1e14; if(mem[i][j]!=-1)return mem[i][j]; long lv=solve(i+1,j); if(a[i]==0) { int pr=Math.abs(i-pos.get(j)); lv=Math.min(lv, pr+solve(i+1,j+1)); } return mem[i][j]=lv; } static int ni() throws IOException { return sc.nextInt(); } static int[] nai(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); return a; } } ",0,Non-plagiarised 5288afb7,df594a00,"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) { bu.readLine(); String s[]=bu.readLine().split("" ""); int n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1]); int a[]=new int[n],i,x,ac[]=new int[n],b[]=new int[k]; Arrays.fill(a,Integer.MAX_VALUE); s=bu.readLine().split("" ""); for(i=0;i pq=new PriorityQueue<>(); for(i=0;i(); for(i=n-1;i>=0;i--) { if(ac[i]!=0) pq.add(ac[i]+i); if(!pq.isEmpty()) a[i]=Math.min(a[i],pq.peek()-i); } for(i=0;i 0) { br.readLine(); String[] str = br.readLine().split("" ""); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int[] a = new int[k]; int[] t = new int[k]; str = br.readLine().split("" ""); for(int i=0; i=0; i--) { right[i] = Math.min(right[i], minright); minright = right[i] == Integer.MAX_VALUE ? Integer.MAX_VALUE : right[i]+1; } for(int i=0; i0) { 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 3b5cec19,8f31b279,"import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Test{ static class Pair implements Comparable{ int wt; int idx; Pair(int x,int y){ this.wt=x; this.idx=y; } } public static void main (String[] args) throws java.lang.Exception{ FastReader scan=new FastReader(); int t=scan.nextInt(); while(t-->0){ int n=scan.nextInt(); int m=scan.nextInt(); int x=scan.nextInt(); int[]arr=new int[n]; for(int i=0;iq=new PriorityQueue<>(); for(int i=1;i<=m;i++){ q.add(new Pair(0,i)); } System.out.println(""YES""); for(int i=0;i{ int first; int second; Pair(int x,int y){ this.first=x; this.second=y; } } public static void main (String[] args) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while(t-->0){ int n=scan.nextInt(); int m=scan.nextInt(); int x=scan.nextInt(); int[]arr=new int[n]; for(int i=0;i set = new TreeSet<>(); Queue set = new PriorityQueue<>(); for(int i=1;i<=m;i++){ set.add(new Pair(0,i)); } System.out.println(""YES""); 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class P4 { static int dp[][]=new int[5000+1][5000+1]; public static void main(String[] args) { // TODO Auto-generated method stub FastReader sc=new FastReader(); int t=1; //t=sc.nextInt(); StringBuilder s=new StringBuilder(); while(t--!=0) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { P4.dp[i][j]=-1; } } ArrayList one=new ArrayList<>(); ArrayList zero=new ArrayList<>(); for(int i=0;i zero, ArrayList one) { //System.out.println(i+"" ""+j); // TODO Auto-generated method stub if(j==m) { return 0; } int av=n-i; int rem=m-j; if(av heights = new PriorityQueue<>(); for(int i = 0; ix) { out.println(""NO""); return; } out.println(""YES""); out.printlnArray(ans); } static class Pair implements Comparable{ int idx; long val; public Pair(int idx, long val) { this.idx = idx; this.val = val; } public String toString() { return this.idx+"" ""+this.val; } } public static void main(String[] args) { in = new Reader(); out = new Writer(); int t = in.nextInt(); while(t-->0) solve(); out.exit(); } static Reader in; static Writer out; static class Util{ private static Random random = new Random(); static long[] fact; public static int random(int min, int max) { return random.nextInt(max-min+1)+min; } public static void reverse(int[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { int tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(int[] s) { reverse(s, 0, s.length-1); } public static void reverse(long[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { long tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(long[] s) { reverse(s, 0, s.length-1); } public static void reverse(float[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { float tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(float[] s) { reverse(s, 0, s.length-1); } public static void reverse(double[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { double tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(double[] s) { reverse(s, 0, s.length-1); } public static void reverse(char[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { char tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(char[] s) { reverse(s, 0, s.length-1); } public static void reverse(T[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { T tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(T[] s) { reverse(s, 0, s.length-1); } public static void shuffle(int[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); int t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(long[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); long t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(float[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); float t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(double[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); double t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(char[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); char t = s[i]; s[i] = s[j]; s[j] = t; } } public static void shuffle(T[] s) { for (int i = 0; i < s.length; ++i) { int j = random.nextInt(i + 1); T t = s[i]; s[i] = s[j]; s[j] = t; } } public static void sortArray(int[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(long[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(float[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(double[] a) { shuffle(a); Arrays.sort(a); } public static void sortArray(char[] a) { shuffle(a); Arrays.sort(a); } public static > void sortArray(T[] a) { Arrays.sort(a); } } } ","import java.util.*; import java.io.*; public class Solution { static Scanner scn = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); public static void main(String[] HastaLaVistaLa) { int t = scn.nextInt(); while(t-- > 0) solve(); out.println(sb); out.close(); } public static void solve() { // Road To Specialist Day 3 int n = scn.nextInt(), m = scn.nextInt(), x = scn.nextInt(); int[] a = new int[n], ans = new int[n]; for(int i = 0; i < n; i++) a[i] = scn.nextInt(); PriorityQueue pq = new PriorityQueue<>(); for(int i = 0; i < m; i++) pq.add(new Pair(0L, i)); for(int i = 0; i < n; i++) { int e = a[i]; Pair p = pq.poll(); p.value += e; pq.add(p); ans[i] = p.id + 1; } boolean check = false; long prev = pq.poll().value; while(!pq.isEmpty()) { long cur = pq.poll().value; if(Math.abs(cur - prev) > x) check = true; prev = cur; } if(check) sb.append(""NO""); else { sb.append(""YES\n""); for(int i : ans) sb.append(i + "" ""); } sb.append(""\n""); } static class Pair implements Comparable { int id; long value; public Pair(long value, int id) { this.id = id; this.value = value; } } } ",0,Non-plagiarised 07a0e4dc,bac616ee,"import java.io.*; import java.util.*; public class C_NotAssigning_1400 { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); boolean[] visited = new boolean[n]; ArrayList[] adj = new ArrayList[n]; for(int i = 0; i < n; i++) { adj[i] = new ArrayList<>(); } for(int i = 0; i < n-1; i++) { int a = sc.nextInt()-1; int b = sc.nextInt()-1; adj[a].add(new Edge(b, i)); adj[b].add(new Edge(a, i)); } int start = -1; boolean flag = false; for(int i = 0; i < n; i++) { //start from leaf node if(adj[i].size() == 1) { start = i; } else if(adj[i].size() > 2) { flag = true; } } int[] weights = new int[n-1]; Queue que = new LinkedList<>(); que.offer(start); visited[start] = true; int curDist = 0; while(!que.isEmpty()) { int cur = que.poll(); for(Edge e : adj[cur]) { if(!visited[e.to]) { visited[e.to] = true; que.offer(e.to); if(curDist%2 == 0) { weights[e.index] = 2; } else { weights[e.index] = 3; } } } curDist++; } if(flag) { System.out.println(-1); } else { StringBuilder sb = new StringBuilder(); for(int i = 0; i < n-1; i++){ sb.append(weights[i] + "" ""); } System.out.println(sb.toString().trim()); } } out.close(); } static class Edge{ public int to; public int index; Edge(int to, int index){ this.to = to; this.index = index; } } public static PrintWriter out; } ","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; i0){ solve(); } } private static void solve() { int n=sc.nextInt(); char[] a=sc.nextLine().toCharArray(); char[] b = sc.nextLine().toCharArray(); int sml=0,nsml=0; boolean flag=false; int sm1=0; int nsm1=0; for(int i=0;i 0) { int n = sc.nextInt(); String s = sc.nextLine(); String t = sc.nextLine(); solver(s,t, n); } // ================================ // // int n = sc.nextInt(); // solver(); // ================================ // out.flush(); } public static void solver(String s, String t, int n) { int diff = 0; int one = 0; int zero = 0; for(int i=0;i=0 && (n-diff-1)%2==0 && zero>0 && (n-diff-zero)==zero-1){ res = Math.min(res, (n-diff-1)+1); } out.println(res==INF?-1:res); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class CF1 { public static void main(String[] args) { FastScanner sc=new FastScanner(); int T=sc.nextInt(); // int T=1; for (int tt=0; tt 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.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""); } } } ",0,Non-plagiarised 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[] 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 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.*; import java.util.*; public class Codeforces { public static void main(String[] args) throws IOException{ try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); String[] s = br.readLine().split("" ""); String c = br.readLine(); ArrayList blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (c.charAt(i) == 'B') blue.add(Integer.parseInt(s[i])); else red.add(Integer.parseInt(s[i])); } Collections.sort(blue); Collections.sort(red); int p1 = 0, p2 = 0, num = 1, flag = 1; while (num <= n) { if (p1 < blue.size()) { if (blue.get(p1) < num) { flag = 0; break; } p1++; } else if (p2 < red.size()) { if (red.get(p2) > num) { flag = 0; break; } p2++; } num++; } if (flag == 1) System.out.println(""YES""); else System.out.println(""NO""); } } } } ",0,Non-plagiarised 4241f473,77448a05,"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 freq=new ArrayList<>(); for(int i=0;i<5;i++) { int f1=0; freq=new ArrayList<>(); for(int j=0;j=0;j--) { total=total+freq.get(j); if(total>0) { x++; }else { break; } } max=Math.max(max, x); } st.append(max+""\n""); } System.out.println(st); } static FastReader sc = new FastReader(); static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[] = new Character[s.length()]; for (int i = 0; i < s.length(); i++) { ch[i] = s.charAt(i); } Arrays.sort(ch); StringBuffer st = new StringBuffer(""""); for (int i = 0; i < s.length(); i++) { st.append(ch[i]); } return st.toString(); } } ",1,Plagiarised 46bde295,8a858867,"import java.io.*; import java.util.Arrays; public class C { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static int nextInt() { try { in.nextToken(); } catch (IOException e) { e.printStackTrace(); } return (int) in.nval; } private static String next(){ try { in.nextToken(); } catch (IOException e) { e.printStackTrace(); } return in.sval; } public static void main(String[] args) { int t = nextInt(); for (int c = 0; c < t; c++) { int n = nextInt(); String[] info = new String[n]; for (int i = 0; i < n; i++) { info[i] = next(); } int ans = 0; for (int i = 0; i < 5; i++) { char cur = (char) (i+'a'); int[] map = new int[n]; for (int j = 0; j < n; j++) { for (int k = 0; k < info[j].length(); k++) { if(info[j].charAt(k)==cur)map[j]++; else map[j]--; } } Arrays.sort(map); int sum = 0; for(int j = n-1; j >= 0; j--) { sum += map[j]; if(sum<=0){ break; } ans = Math.max(ans,n-j); } } System.out.println(ans); } } } ","import java.io.*; import java.util.*; public class Mainnn{ // static final File ip = new File(""input.txt""); // static final File op = new File(""output.txt""); // static { // try { // System.setOut(new PrintStream(op)); // System.setIn(new FileInputStream(ip)); // } catch (Exception e) { // } // // in = new InputReader(System.in); // } public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); //out.println(result); // print via PrintWriter ///////////////////////////////////////////// int test = sc.nextInt(); while(test-- != 0) { int n = sc.nextInt(); String[] info = new String[n]; for (int i = 0; i < n; i++) { info[i] = sc.next(); } int ans = 0; for (int i = 0; i < 5; i++) { char cur = (char) (i+'a'); int[] map = new int[n]; for (int j = 0; j < n; j++) { for (int k = 0; k < info[j].length(); k++) { if(info[j].charAt(k)==cur)map[j]++; else map[j]--; } } Arrays.sort(map); int sum = 0; for(int j = n-1; j >= 0; j--) { sum += map[j]; if(sum<=0){ break; } ans = Math.max(ans,n-j); } } System.out.println(ans); } ///////////////////////////////////////////// // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- //-------------------------------------------------------- } ",1,Plagiarised 80881cae,9555b9d1,"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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; import java.util.Set; /** * 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; Scanner in = new Scanner(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, Scanner in, PrintWriter out) { int T = in.nextInt(); while (T-- > 0) { solveOne(in, out); } } private void solveOne(Scanner in, PrintWriter out) { int N = in.nextInt(); int[] k = L.readIntArray(N, in), h = L.readIntArray(N, in); Set toRemove = new HashSet<>(); int prevCost = h[0], prevX = k[0]; for (int i = 1; i < N; i++) { for (int j = i; j < N; j++) { int currCost = h[j], currX = k[j]; if (currX - currCost + 1 <= prevX) { if (prevCost + (currX - prevX) > h[j]) h[j] = prevCost + (currX - prevX); } } prevX = k[i]; prevCost = h[i]; } int nextCost = h[N - 1], nextX = k[N - 1]; for (int i = N - 2; i >= 0; i--) { int currCost = h[i], currX = k[i]; if ((nextCost - currCost) >= (nextX - currX)) { toRemove.add(i); continue; } nextCost = currCost; nextX = currX; } long cost = 0; for (int i = N - 1; i >= 0; i--) if (!toRemove.contains(i)) cost += (h[i] * ((long) h[i] + 1)) / 2; out.println(cost); } } static class L { public static int[] readIntArray(int size, Scanner in) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = in.nextInt(); } return array; } } } ",0,Non-plagiarised 6f02c6d9,884f5678,"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(); } } ","import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class JaiShreeRam{ static Scanner in=new Scanner(); static long mod = 1000000007; static ArrayList> adj; public static void main(String[] args) throws Exception{ int z=in.readInt(); while(z-->0) { int n=in.readInt(); int a[]=nia(n); char c[]=in.readString().toCharArray(); ArrayList d=new ArrayList<>(); ArrayList in=new ArrayList<>(); for(int i=0;i=0;i--) { if(in.get(i)>n) { ans=""NO""; break; } n--; } System.out.println(ans); } } static int[] nia(int n){ int[] arr= new int[n]; int i=0; while(i g[] , int arr[][] , int p , long dp[][]) { for(Integer i : g[n]) { if(i != p) { dfs(i,g,arr,n,dp); dp[n][0] += Math.max(dp[i][0]+Math.abs(arr[n][0]-arr[i][0]) , dp[i][1]+Math.abs(arr[n][0]-arr[i][1])); dp[n][1] += Math.max(dp[i][0]+Math.abs(arr[n][1]-arr[i][0]) , dp[i][1]+Math.abs(arr[n][1]-arr[i][1])); } } } public static void main(String []args) throws IOException { Reader sc = new Reader(); StringBuffer str = new StringBuffer(""""); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int arr[][] = new int[n][2]; for(int i = 0 ; i < n; i++) { arr[i][0] = sc.nextInt(); arr[i][1] = sc.nextInt(); } LinkedList g[] = new LinkedList[n]; for(int i = 0 ; i < n ; i++) { g[i] = new LinkedList(); } for(int i = 0 ; i < n-1 ; i++) { int x = sc.nextInt()-1; int y = sc.nextInt()-1; g[x].add(y); g[y].add(x); } long dp[][] = new long[n][2]; dfs(0,g,arr,-1 , dp); str.append(Math.max(dp[0][0] , dp[0][1])); str.append(System.lineSeparator()); } System.out.println(str); } } ","import java.util.*; import java.io.*; public class Main { static long[][]dp; static ArrayList[]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;i0) { 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 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(); } } ","import java.lang.*; import java.util.*; import java.io.*; public class Main { static FastScanner in = new FastScanner(); static final int MOD = 998244353; static int n, k; static int[] fact, invFact; static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } static int pow(int a, int p) { int ans = 1; while (p != 0) { if ((p & 1) != 0) ans = mul(ans, a); a = mul(a, a); p >>= 1; } return ans; } static int inv(int a) { return pow(a, MOD - 2); } static void precalc() { fact = new int[n + 42]; invFact = new int[n + 42]; fact[0] = invFact[0] = 1; for (int i = 1; i < fact.length; ++i) { fact[i] = mul(fact[i - 1], i); invFact[i] = mul(invFact[i - 1], inv(i)); } } static int nCk(int a, int b) { if (b < 0 || a < b) return 0; return mul(fact[a], mul(invFact[a - b], invFact[b])); } static void solve() { n = in.nextInt(); k = in.nextInt(); precalc(); int[] events = new int[2 * n]; for (int i = 0; i < n; ++i) { int l = in.nextInt(), r = in.nextInt(); events[i] = 2 * l; events[i + n] = 2 * r + 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 += nCk(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - nCk(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else balance -= added; } System.out.println(ans); } public static void main(String[] args) { int T = 1; while (T-- > 0) solve(); } } ",1,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,Plagiarised e185bce5,f3d7ce08,"import java.util.*; import java.io.*; import java.math.BigInteger; import java.nio.charset.StandardCharsets; public class Main { private static FS sc = new FS(); static int mod = (int) 1e9; static LinkedList[] temp, idx; static long inf = (long) Long.MAX_VALUE; // static long inf = Long.MAX_VALUE; // static int max; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); String a = sc.next(), b = sc.next(); int _00 = 0, _01 = 0, _10 = 0, _11 = 0; for(int i = 0; i < n; i++) { if(a.charAt(i) == '0' && b.charAt(i) == '0') _00++; if(a.charAt(i) == '0' && b.charAt(i) == '1') _01++; if(a.charAt(i) == '1' && b.charAt(i) == '0') _10++; if(a.charAt(i) == '1' && b.charAt(i) == '1') _11++; } int ans = Integer.MAX_VALUE; if(_10 == _01) ans = _01 + _10; if(_10 > 0) { int n00 = _10 - 1; int n01 = _11; int n10 = _00 + 1; int n11 = _01; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } if(_11 > 0) { int n00 = _10; int n01 = _11 - 1; int n10 = _00; int n11 = _01 + 1; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } ret.append(ans == Integer.MAX_VALUE ? -1 : ans); ret.append(""\n""); } System.out.println(ret); } } ","import javax.swing.plaf.IconUIResource; import java.lang.reflect.Array; import java.text.CollationElementIterator; import java.util.*; import java.io.*; //Timus judge id- 323935JJ public class Main { //---------------------------------------------------------------------------------------------- public static 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;i []arr; public static void main(String[] args) throws IOException, InterruptedException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); String [] strings=new String [n]; int [][]arr=new int [5][n]; int [] total=new int [5]; for(int i=0;i0) { pw.println(n); f=true; } } //pw.println(Arrays.toString(total)); if(!f) { int [] MaxS=new int [5]; for(int i=0;i<5;i++) { Arrays.sort(arr[i]); if(arr[i][n-1]<=0) { MaxS[i]=0; } else { int sum=arr[i][n-1],countWords=1; for(int j=n-2;j>-1 && sum+arr[i][j]>0;j--) { sum+=arr[i][j]; countWords++; } MaxS[i]=countWords; } } int ans=0; //pw.println(Arrays.toString(MaxS)); for(int i=0;i<5;i++) ans=Math.max(ans, MaxS[i]); pw.println(ans); } } pw.flush(); } /*public class UnionFind { int[] p, rank, setSize; int numSets; public UnionFind(int N) { p = new int[numSets = N]; rank = new int[N]; setSize = new int[N]; for (int i = 0; i < N; i++) { p[i] = i; setSize[i] = 1; } } public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); } public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); } public void unionSet(int i, int j) { if (isSameSet(i, j)) return; numSets--; int x = findSet(i), y = findSet(j); if(rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; } else { p[x] = y; setSize[y] += setSize[x]; if(rank[x] == rank[y]) rank[y]++; } } public int numDisjointSets() { return numSets; } public int sizeOfSet(int i) { return setSize[findSet(i)]; } } static class pair implements Comparai)ble { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } }*/ } ","import java.io.*; import java.util.*; public class Solution{ public static int in = 0, count=0; static class comparator implements Comparator{ } public static int solve(ArrayList al, int[] total){ ArrayList c = (ArrayList) al.clone(); java.util.Collections.sort(c, new comparator()); int i= al.size()-1; int sum=0; for(int ii:total) sum+=ii; int check = total[in]; sum-=check; for(; i>=0; i--){ if(check>sum) return i+1; else{ int newSum=0; for(int ii:c.get(i)) newSum+=ii; newSum-=c.get(i)[in]; sum-=newSum; check-=c.get(i)[in]; } } return 0; } public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int testCase = sc.nextInt(); while (testCase-->0){ int n = sc.nextInt(); String[] strArr = new String[n]; for(int i=0; i al = new ArrayList<>(); for(int i=0; i=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i0){ int n=sc.nextInt(); int k=sc.nextInt(); long[] ans=new long[n+1]; long[] tem=new long[n+1]; int[] item=new int[k]; Arrays.fill(ans,max); for(int i=0;i=1;i--){ if(tem[i]!=0){ if(i==n)ans[i]=Math.min(ans[i],tem[i]); else{ ans[i]=Math.min(ans[i],ans[i+1]+1); ans[i]=Math.min(tem[i],ans[i]); } } else{ if(i1)ans[i]=Math.min(ans[i],ans[i-1]+1); } } for(int i=1;i<=n;i++){ sb.append(ans[i]+"" ""); } sb.append(""\n""); } System.out.println(sb); } } ",0,Non-plagiarised 1f6b81b1,51151974,"import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class InterestingStory { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); int t = sc.nextInt(); // int t = 1; while (t-- != 0) { solver.solve(sc, out); } out.close(); } static class Solver { public void solve(InputReader sc, PrintWriter out) { int n = sc.nextInt(); char[][] words = new char[n][]; for(int i = 0; i < n; i++) words[i] = sc.next().toCharArray(); int[][] arr = new int[n][]; for(int i = 0; i < n; i++) { arr[i] = new int[words[i].length]; for(int j = 0; j < arr[i].length; j++) arr[i][j] = words[i][j]-'a'; } int max = 0; for(int now = 0; now < 5; now++) { PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); for(int i = 0; i < n; i++) { int nowcnt = 0; int othercnt = 0; for(int j = 0; j < arr[i].length; j++) { if(arr[i][j]==now) nowcnt++; else othercnt++; } pq.add(nowcnt-othercnt); } int canTake = 0; int sum = 0; while(!pq.isEmpty()) { int nowAdd = pq.poll(); if(sum+nowAdd>0) { sum += nowAdd; canTake++; } else { break; } } max = Math.max(max,canTake); } out.println(max); } } } ","import java.io.*; import java.util.*; public class Solution{ public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int testCase = sc.nextInt(); while (testCase-->0){ int n = sc.nextInt(); String[] strArr = new String[n]; for(int i=0; i al = new ArrayList<>(); for(int i=0; i all = new ArrayList<>(); for(int j=0; j0) solve(in,out); out.close(); } static void solve(FastScanner in,PrintWriter out){ int n=in.nextInt(); long a[]=new long[n]; for (int i = 0; i < n; i++) { a[i]=in.nextLong(); } long odd=Integer.MAX_VALUE,even=Integer.MAX_VALUE; even=a[0]; long sum=a[0]; long ans=Long.MAX_VALUE; for (int i = 1; i < n; i++) { if(i%2==0) { ans=Math.min(ans,(n-i/2)*a[i] + odd*(n-i/2) +sum); even=Math.min(even,a[i]); } else { ans=Math.min(ans,(n-i/2)*a[i] + even*(n-i/2-1) +sum); odd=Math.min(odd,a[i]); } sum+=a[i]; } 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 3e28571b,77b5c134,"import java.io.*; import java.util.*; import java.util.Map.Entry; import static java.lang.Math.*; public class Ans implements Runnable { public static void main(String args[]) { Ans s = new Ans(); s.run(); } InputReader sc = null; PrintWriter pw = null; static ArrayList[] G = new ArrayList[(int)(3e5+10)]; static int[] dist = new int[(int)(3e5+10)]; static int[] a = new int[(int)(3e5+10)]; private static int[] nge(int n){ int[] edges = new int[n]; Arrays.fill(edges, -1); Stack st = new Stack<>(); st.push(0); for(int i = 1; i < n; i++){ while(!st.isEmpty() && a[i] >= a[st.peek()]){ edges[st.pop()] = i; } st.push(i); } //debug(""nge"", edges); return edges; } private static int[] nle(int n){ int[] edges = new int[n]; Arrays.fill(edges, -1); Stack st = new Stack<>(); st.push(0); for(int i = 1; i < n; i++){ while(!st.isEmpty() && a[i] <= a[st.peek()]){ edges[st.pop()] = i; } st.push(i); } //debug(""nle"", edges); return edges; } private static int[] pge(int n){ int[] edges = new int[n]; Arrays.fill(edges, -1); Stack st = new Stack<>(); st.push(n-1); for(int i = n-2; i >= 0; i--){ while(!st.isEmpty() && a[i] >= a[st.peek()]){ edges[st.pop()] = i; } st.push(i); } //debug(""pge"", edges); return edges; } private static int[] ple(int n){ int[] edges = new int[n]; Arrays.fill(edges, -1); Stack st = new Stack<>(); st.push(n-1); for(int i = n-2; i >= 0; i--){ while(!st.isEmpty() && a[i] <= a[st.peek()]){ edges[st.pop()] = i; } st.push(i); } //debug(""ple"", edges); return edges; } private static void buildGraph(int[] edges){ for(int i = 0; i < edges.length; i++){ if(edges[i] != -1){ // G[i].add(edges[i]); // G[edges[i]].add(i); G[min(i, edges[i])].add(max(i, edges[i])); } } } private static void bfs(int n){ dist[0] = 0; ArrayDeque q = new ArrayDeque<>(); q.add(0); while(!q.isEmpty()){ int front = q.pollFirst(); if(front == n-1){ break; } for(int adj : G[front]){ if(dist[adj] == (int)(1e9)){ dist[adj] = 1 + dist[front]; q.add(adj); } } } } public void run() { // InputStream is; // is = new FileInputStream(new File(""input.txt"")); sc = new InputReader(System.in); pw = new PrintWriter(System.out); int n = sc.nextInt(); a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); G[i] = new ArrayList(); } buildGraph(nge(n)); buildGraph(nle(n)); buildGraph(ple(n)); buildGraph(pge(n)); Arrays.fill(dist, (int)(1e9)); bfs(n); pw.println(dist[n-1]); // is.close(); pw.close(); } } ","import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Stack; // https://codeforces.com/contest/1407/problem/D public class Discrete_Centrifugal_Jumps { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] h = new int[n]; for (int i = 0; i < n; i++) h[i] = scan.nextInt(); System.out.println(getMinJump(h, n)); } static int getMinJump(int[] h, int n) { int[] rightG = new int[n], leftG = new int[n]; int[] rightS = new int[n], leftS = new int[n]; Arrays.fill(rightG, -1); Arrays.fill(rightS, -1); Arrays.fill(leftG, -1); Arrays.fill(leftS, -1); Stack stack = new Stack<>(); // next greater in the right segment int i = 0; while (i < n) { if (!stack.empty() && h[i] >= h[stack.peek()]) rightG[stack.pop()] = i; else stack.push(i++); } stack = new Stack<>(); // next smaller in the right segment i = 0; while (i < n) { if (!stack.empty() && h[i] <= h[stack.peek()]) rightS[stack.pop()] = i; else stack.push(i++); } stack = new Stack<>(); // next greater in left segment i = n-1; while (i >= 0) { if (!stack.empty() && h[i] >= h[stack.peek()]) leftG[stack.pop()] = i; else stack.push(i--); } stack = new Stack<>(); // next smaller in left segment i = n-1; while (i >= 0) { if (!stack.empty() && h[i] <= h[stack.peek()]) leftS[stack.pop()] = i; else stack.push(i--); } ArrayList[] jump = new ArrayList[n]; for (i = 0; i < n; i++) jump[i] = new ArrayList<>(); for (i = 0; i < n; i++) { // max(h[i+1] ... h[j-1]) < min(h[i], h[j]) if (rightG[i] != -1) jump[i].add(rightG[i]); if (leftG[i] != -1) jump[leftG[i]].add(i); // max(h[i], h[j]) < min(h[i+1] ... h[j]) if (rightS[i] != -1) jump[i].add(rightS[i]); if (leftS[i] != -1) jump[leftS[i]].add(i); } int[] dp = new int[n]; Arrays.fill(dp, Integer.MAX_VALUE); dp[0] = 0; for (int u = 0; u < n; u++) { for (int v: jump[u]) { dp[v] = Math.min(dp[v], dp[u] + 1); } } return dp[n-1]; } } ",0,Non-plagiarised 63a24497,6e5ab1d2,"import java.util.*; import java.lang.*; import java.io.*; public class Main { void solve() { int n = in.nextInt(); char[] a = in.nextLine().toCharArray(); char[] b = in.nextLine().toCharArray(); int ans = MAX; ans = Math.min(ans, operations(a, b)); ans = Math.min(ans, change(a, b, '1')); ans = Math.min(ans, change(a, b, '0')); if (ans == MAX)ans = -1; out.append(ans + ""\n""); } int operations(char[] a, char[] b) { int count01 = 0 , count10 = 0; int n = a.length; for (int i = 0 ; i < n; i++) { if (a[i] != b[i]) { if (a[i] == '0')count01++; else count10++; } } if (count01 != count10)return MAX; return count01 + count10; } int change(char[] a, char[] b , char ch) { int n = a.length; char[] c = new char[n]; for (int i = 0 ; i < n; i++)c[i] = a[i]; int index = -1; for (int i = 0; i < n; i++) { if (c[i] == '1' && b[i] == ch) { index = i; break; } } if (index == -1)return MAX; for (int i = 0 ; i < n; i++) { if (i == index)continue; c[i] = (char)( '0' + ('1' - c[i]) ); } int local = operations(c, b); if (local == MAX)return MAX; return 1 + local; } public static void main (String[] args) { // It happens - Syed Mizbahuddin Main sol = new Main(); int t = 1; t = in.nextInt(); while (t-- != 0) { sol.solve(); } System.out.print(out); } static { try { System.setIn(new FileInputStream(""input.txt"")); System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); err = new PrintStream(new FileOutputStream(""error.txt"")); } catch (Exception e) {} } static FastReader in; static StringBuilder out; static PrintStream err; final int MAX; final int MIN; int mod ; Main() { in = new FastReader(); out = new StringBuilder(); MAX = Integer.MAX_VALUE; MIN = Integer.MIN_VALUE; mod = (int)1e9 + 7; } } ","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CMenorah solver = new CMenorah(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CMenorah { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(); char[] a = in.next().toCharArray(); char[] b = in.next().toCharArray(); int ans = checkPairs(a, b, -1); ans = Math.min(ans, changePair(a, b, '1')); ans = Math.min(ans, changePair(a, b, '0')); if (ans == Integer.MAX_VALUE) ans = -1; out.println(ans); } int changePair(char[] a, char[] b, char t) { int index = -1; int n = a.length; for (int i = 0; i < n; ++i) { if (a[i] == '1' && b[i] == t) { index = i; break; } } return checkPairs(a, b, index); } int checkPairs(char[] a, char[] b, int changeStringIndex) { int n = a.length; int val = 0; char[] tmp = new char[n]; System.arraycopy(a, 0, tmp, 0, n); if (changeStringIndex != -1) { val = 1; for (int i = 0; i < n; ++i) { if (i == changeStringIndex) continue; tmp[i] = a[i] == '0' ? '1' : '0'; } } int _10 = 0, _01 = 0; for (int i = 0; i < n; ++i) { if (tmp[i] != b[i]) { if (tmp[i] == '0') _01++; else _10++; } } return _01 == _10 ? 2 * _01 + val : Integer.MAX_VALUE; } } } ",1,Plagiarised b2001d68,ba468e1f,"import java.util.*; import java.lang.*; import java.io.*; public class D753 { public static void main(String[] args) throws java.lang.Exception { // your code goes here try { // Scanner sc=new Scanner(System.in); FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i b=new ArrayList<>(); ArrayList r=new ArrayList<>(); for(int i=0;i=cur)cur++; else{ ok=false; break; } //cur++; } for(int i:r){ if(i<=cur)cur++; else{ ok=false; break; } } if(ok)System.out.println(""YES""); else System.out.println(""NO""); } } catch (Exception e) { return; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = fastReader.nextInt(); } ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); char c[] = fastReader.next().toCharArray(); for (int i = 0; i < n; i++) { if (c[i] == 'B') { b.add(a[i]); } else { r.add(a[i]); } } Collections.sort(b); Collections.sort(r); int sizeb = b.size(); boolean isValid = true; for (int i = 1 , j = 0; i <=sizeb; i++ , j++){ if (b.get(j) < i){ isValid =false; } } for (int i = sizeb+1 , j = 0; i <=n && j < r.size(); i++ , j++){ if (r.get(j) > i){ isValid =false; } } if (isValid){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } } ",0,Non-plagiarised ac180326,b1e9f1f6,"import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.Collections; import java.util.Comparator; import java.util.Arrays; import java.util.ArrayList; import java.util.LinkedList; import java.util.Stack; import java.util.Queue; import java.util.PriorityQueue; import java.util.List; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.TreeSet; import java.util.Map; import java.util.HashMap; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; import java.util.Vector; public class Dobby { public static void main(String[] args) { try { FastReader fr = new FastReader(); PrintWriter pt = new PrintWriter(System.out); int t = fr.nextInt(); while (t > 0) { int n = fr.nextInt(), m = fr.nextInt(), x = fr.nextInt(); ArrayList pp = new ArrayList<>(); int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = fr.nextInt(); Pair pr = new Pair(A[i], i); pp.add(pr); } Collections.sort(pp); Collections.reverse(pp); int ps[] = new int[n]; int pk[] = new int[n]; Arrays.fill(ps, 0); Arrays.fill(pk, 0); int index = 0; for (int i = 0; i < n; i++) { if (pk[index] < x) { pk[index] += pp.get(i).a; } ps[pp.get(i).b] = index + 1; index++; index = index == m ? 0 : index; } pt.println(""YES""); for (int i = 0; i < n; i++) { pt.print(ps[i] + "" ""); } pt.println(); t--; } pt.close(); } catch ( Exception e) { return; } } static void merge(long arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; long L[] = new long[n1]; long R[] = new long[n2]; for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } static void sort(long arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; sort(arr, l, m); sort(arr, m + 1, r); merge(arr, l, m, r); } } static class Pair implements Comparable { int a, b; Pair(int a, int b) { this.a = a; this.b = b; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class test { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { String[] st = br.readLine().split("" ""); int n = Integer.parseInt(st[0]); int m = Integer.parseInt(st[1]); int x = Integer.parseInt(st[2]); int[] arr = new int[n]; st = br.readLine().split("" ""); Pair[] temp = new Pair[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(st[i]); temp[i] = new Pair(arr[i], i); } int bcount = n / m; int extra = n % m; int[] ans = new int[n]; sort(temp); int id = 0; int minmax = 0; boolean flag = false; for (int i = 0; i < bcount; i++) { minmax -= temp[id].val; for (int j = 0; j < m; j++) { ans[temp[id].idx] = j + 1; if (j == m) { minmax += temp[id].val; } id++; } if (minmax > x) { sb.append(""NO\n""); flag = true; break; } } for (int i = 0; i < extra; i++) { ans[temp[id].idx] = i + 1; id++; } if (flag == false) { sb.append(""YES\n""); for (int i = 0; i < n; i++) { sb.append(ans[i] + "" ""); } sb.append(""\n""); } } System.out.println(sb); } public static class Pair implements Comparable { int val; int idx; public Pair(int val, int idx) { this.val = val; this.idx = idx; } } public static void sort(Pair[] arr) { ArrayList list = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { list.add(new Pair(arr[i].val, arr[i].idx)); } Collections.sort(list); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } } ",0,Non-plagiarised 3f939694,54488276,"import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws Exception{ Input sc=new Input(); StringBuilder sb=new StringBuilder(); int t=sc.readInt(); for(int f=0;f lst=new ArrayList<>(); int a[]=new int[n]; for(int j=0;j(s2+v2)){ s1+=v1; s2+=v2; co++; } //System.out.println(lst.get(j).a+"" ""+lst.get(j).b); } ans=Math.max(co,ans); } // count all 'a' in each string sb.append(ans+""\n""); } System.out.print(sb); } } class pair implements Comparable{ int a; int b; pair(int a,int b){ this.a=a; this.b=b; } } ","import java.io.*; import java.util.*; public class C { static int n; public static void main (String[] args) throws IOException { FastReader io = new FastReader(); int t = io.nextInt(); for (int ii=0; ii total) { ret++; } else { return ret; } } return ret; } static class Comp implements Comparator { char c; public Comp (char c) { this.c = c; } } } ",0,Non-plagiarised 9310ad0c,f36138e7,"import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long k[]=new long[n]; for(int i=0;i al=new ArrayList<>(); long csp=h[n-1],idx=k[n-1]-h[n-1]; for(int i=n-2;i>=0;i--) { if(idx 0){ int n = sc.nextInt(); long time[] = new long[n]; long health[] = new long[n]; for(int i=0; i=0; i--){ if(i == n-1){ ans += (health[i]*(health[i]+1))/2; continue; } if(health[peak] - (time[peak]-time[i]) <= 0){ peak = i; end = i; ans += (health[i]*(health[i]+1))/2; } else if(health[peak] - (time[peak]-time[i]) < health[i]){ long val = health[peak] + (time[end]-time[peak]); ans -= (val*(val+1))/2; //System.out.println(""Val1: "" + val); val = health[i] + (time[end]-time[i]); ans += (val*(val+1))/2; //System.out.println(""Val2: "" + val); peak = i; } } System.out.println(ans); } } } ",0,Non-plagiarised 30e0cc81,b55888de,"import java.io.*; import java.util.*; import java.math.BigInteger; import java.lang.*; public class Main { public static String[] F(BufferedReader bf) throws Exception { return (bf.readLine().split("" "")); } public static void pr(PrintWriter out,Object o) { out.println(o.toString());//out.flush(); } public static void pr(Object o) { System.out.println(o.toString()); } public static int inInt(String s) { return Integer.parseInt(s); } public static int F(String[] arr,char ch){ int[] nums = new int[arr.length]; for(int i=0;i=0;i--){ if((sum+nums[i]) <= 0){ return arr.length-1-i; } sum += nums[i]; } return arr.length; } public static void main (String[] args) throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out);;;// //int[] map=new int[1000001]; int yy=inInt(bf.readLine()); for(int w=0;w0) { int n = sc.nextInt(); sc.nextLine(); String s[] = new String[n]; int f[][] = new int[n][5]; for (int i = 0; i < n; i++) { s[i] = sc.nextLine(); for (int j = 0; j < s[i].length(); j++) { f[i][s[i].charAt(j)-'a']++; } } int ans = 0; for ( int i = 0; i < 5; i++) { ArrayList al = new ArrayList<>(); for (int j = 0; j < n; j++) { int o = 0; for (int k = 0; k < 5; k++) { if(k != i) o+=f[j][k]; } al.add(f[j][i]-o); } Collections.sort(al,Collections.reverseOrder()); int max = 0; int x = 0; for (int j = 0; j < n; j++) { x+=al.get(j); if(x<=0)break; max++; } ans = Math.max(max,ans); } System.out.println(ans); } sc.close(); } } ",0,Non-plagiarised 3c667d4f,be3b1289,"import java.util.*; public class j { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); while(n-->0) { int len=in.nextInt(); int t=in.nextInt(); int pos[]=new int[t]; int temp[]=new int[t]; for(int i=0;i=0;i--) { range[i]=Math.min(range[i+1]+1,range[i]); } for(int i=0;i=0;i--){ dp[i]=Math.min(dp[i+1]+1,dp[i]); } lPA(dp); //pn(""""); } out.flush(); out.close(); } } ",1,Plagiarised 2bbf754b,3a12e509,"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; } } } ","import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } // Function to precompute inverse of factorials // Function to calculate factorial of 1 to 200001 // Function to return nCr % p in O(1) time } ",0,Non-plagiarised 1ea771ea,2f8c3bf3,"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;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 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.util.*; import java.lang.*; import java.io.*; public class InterestingStrory { public static void main(String[] args) throws java.lang.Exception { // your code goes here try { // Scanner sc=new Scanner(System.in); FastReader sc = new FastReader(); int t =sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int[][] occ=new int[n][5]; for(int i=0;i=0;l--){ if(currSum+sums[l]<=0){ break; } else{ currSum+=sums[l]; } } ans=Math.max(ans,n-l-1); } System.out.println(ans); } } catch (Exception e) { return; } } } ",0,Non-plagiarised 9fd33d5a,c220c822,"import java.util.*; import java.io.*; public class Solution { private static ArrayList prime = new ArrayList<>(); public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); int T = in.nextInt(); OUTER: while(T-->0) { int n=in.nextInt(), k=in.nextInt(); int a[]=new int[k]; for(int i=0; i=0; i--) { if(ans[i]!=0) { temp=Math.min(temp, ans[i]); } right[i]=temp; temp+=1; } for(int i=0; i=1;i--) { suff[i]=suff[i+1]; if(l[i]!=0) { suff[i]=Math.min(suff[i],l[i]+i); } } for(int i=1;i<=n;i++) { System.out.print(Math.min(pre[i]+i,suff[i]-i)+"" ""); } System.out.println(); } } } ",0,Non-plagiarised 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 al; static long min; // static long[] dp; static FastReader sc=new FastReader(); public static void main (String[] args) throws java.lang.Exception { PrintWriter w=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ // dp=new long[n+1][n+1][n]; int n=sc.nextInt(); long[] c=new long[n]; for(int i=0;i=1)min=Math.min(min,min1+min2); } System.out.println(min); } w.flush(); w.close(); } // public static long f(int n, long[] c, int x, int y, int i, long cost) { // long l=Long.MAX_VALUE; // if(i>=n || x>n || y>n)return 0; // if(dp[x][y][i]!=-1)return dp[x][y][i]; // if(x==0 && y==0) {min=Math.min(cost, min);return;} // if(x==0) { // if(i%2!=0)min=Math.min(cost+c[i]*y, min); // return; // } // if(y==0) { // if(i%2==0)min=Math.min(cost+c[i]*x, min); // return; // } // if(i%2==0) { // for(int j=1;j<=x;j++) { // l=Math.min(l,f(n,c,x-j,y,i+1,cost+j*c[i])); // } // } // else { // for(int j=1;j<=y;j++) { // l=Math.min(l,f(n,c,x,y-j,i+1,cost+j*c[i])); // } // } // } } ","import java.util.*; import java.io.*; import java.math.*; public final class Main{ public static void main(String[] args) throws IOException{ // Scanner sc=new Scanner(System.in); FastReader sc=new FastReader(); PrintWriter writer=new PrintWriter(System.out); int tc=sc.nextInt(); while(tc-->0) { int n=sc.nextInt(); long[] c=new long[n]; for(int i=0;i=1) ans=Math.min(ans,min1+min2); } System.out.println(ans); } writer.flush(); writer.close(); } } ",1,Plagiarised 8f31b279,a3e272af,"import java.util.*; import java.io.*; public class JavaTract { static class Pair implements Comparable{ int first; int second; Pair(int x,int y){ this.first=x; this.second=y; } } public static void main (String[] args) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); while(t-->0){ int n=scan.nextInt(); int m=scan.nextInt(); int x=scan.nextInt(); int[]arr=new int[n]; for(int i=0;i set = new TreeSet<>(); Queue set = new PriorityQueue<>(); for(int i=1;i<=m;i++){ set.add(new Pair(0,i)); } System.out.println(""YES""); for(int i=0;i 0) { solve(); } w.close(); } public static class Student { public int i1; public int value; // A parameterized student constructor public Student(int i1,int i2) { this.i1 = i1; this.value=i2; } public int getkey() { return i1; } public int getValue() { return value; } } static class StudentComparator implements Comparator{ // Overriding compare()method of Comparator // for descending order of cgpa } /* Function to print all the permutations of the string static String swap(String str, int i, int j) { char ch; char[] array = str.toCharArray(); ch = array[i]; array[i] = array[j]; array[j] = ch; return String.valueOf(array); } static void permute(String str,int low,int high) { if(low == high) list.add(Long.parseLong(str)); int i; for(i = low; i<=high; i++){ str = swap(str,low,i); permute(str, low+1,high); str = swap(str,low,i); } } use permute(str2,0,str2.length()-1); to perform combinations */ public static void solve() { int n=s.nextInt(); int m=s.nextInt(); int x=s.nextInt(); int arr[]=new int[n];int res[]=new int[n]; for(int i=0;i pq=new PriorityQueue(new StudentComparator()); for(int 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 (int j = 0; j < vertices-1; j++) { String st[] = bu.readLine().split("" ""); int u = Integer.parseInt(st[0]) - 1, v = Integer.parseInt(st[1]) - 1; connections[u].add(v); connections[v].add(u); } dfs(0, -1); out.append(Math.max(s[0][0], s[0][1]) + ""\n""); } System.out.print(out); } static int N = 100000; static int[][] a = new int[N][2]; static long[][] s = new long[N][2]; static ArrayList[] connections; public static void dfs(int n, int parent) { for (int child : connections[n]) { if (child != parent) { dfs(child, n); s[n][0] += Math.max(s[child][0] + Math.abs(a[n][0] - a[child][0]), s[child][1] + Math.abs(a[n][0] - a[child][1])); s[n][1] += Math.max(s[child][0] + Math.abs(a[n][1] - a[child][0]), s[child][1] + Math.abs(a[n][1] - a[child][1])); } } } } ","import java.util.*; import java.io.*; public class Solution { static LinkedList graph[]; static long key[][]; static long value[][]; public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); StringBuffer out=new StringBuffer(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); String input[]; OUTER: while(t--!=0) { int n=Integer.parseInt(br.readLine()); value=new long[n][2]; key=new long[n][2]; 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,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 3cbcb1cc,6045e5d1,"import java.util.*; import java.lang.*; import java.io.*; public class E { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); br.readLine(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { String[] scn = (br.readLine()).trim().split("" ""); int n = Integer.parseInt(scn[0]); int m = Integer.parseInt(scn[1]); long[] land = new long[n + 1]; scn = (br.readLine()).trim().split("" ""); String[] scn1 = (br.readLine()).trim().split("" ""); for (int i = 0; i < m; i++) { int idx = (int) Long.parseLong(scn[i]); long temp = Long.parseLong(scn1[i]); land[idx] = temp; } long[] ans = new long[n + 1]; long min = (long) (1e15); for (int i = 1; i <= n; i++) { if (land[i] != 0) { min = Math.min(min, land[i]); } ans[i] = min; min += 1; } min = (long) (1e15); for (int i = n; i >= 1; i--) { if (land[i] != 0) { min = Math.min(min, land[i]); } ans[i] = Math.min(min, ans[i]); min += 1; } for (int i = 1; i <= n; i++) { sb.append(ans[i] + "" ""); } sb.append(""\n""); if (t != 0) { br.readLine(); } } System.out.println(sb); return; } } ","import java.util.*; import java.lang.*; import java.io.*; public class E { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); br.readLine(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { String[] scn = (br.readLine()).trim().split("" ""); int n = Integer.parseInt(scn[0]); int m = Integer.parseInt(scn[1]); long[] land = new long[n + 1]; scn = (br.readLine()).trim().split("" ""); String[] scn1 = (br.readLine()).trim().split("" ""); for (int i = 0; i < m; i++) { int idx = (int) Long.parseLong(scn[i]); long temp = Long.parseLong(scn1[i]); land[idx] = temp; } long[] ans = new long[n + 1]; long min = (long) (1e15); for (int i = 1; i <= n; i++) { if (land[i] != 0) { min = Math.min(min, land[i]); } ans[i] = min; min += 1; } min = (long) (1e15); for (int i = n; i >= 1; i--) { if (land[i] != 0) { min = Math.min(min, land[i]); } ans[i] = Math.min(min, ans[i]); min += 1; } for (int i = 1; i <= n; i++) { sb.append(ans[i] + "" ""); } sb.append(""\n""); if (t != 0) { br.readLine(); } } System.out.println(sb); return; } } ",1,Plagiarised 8c591975,b6724dd9,"import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; public class Main { private static void run() throws IOException { int n, k; n = in.nextInt(); k = in.nextInt(); int[] a = new int[n]; long[] t = new long[k]; for (int i = 0; i < n; i++) { a[i] = -1; } for (int i = 0; i < k; i++) { a[in.nextInt() - 1] = i; } for (int i = 0; i < k; i++) { t[i] = in.nextLong(); } long[] dp = new long[n]; long now; now = 2000000000; for (int i = 0; i < n; i++) { now++; if (a[i] != -1) { now = Math.min(now, t[a[i]]); } dp[i] = now; } now = 2000000000; for (int i = n - 1; i >= 0; i--) { now++; if (a[i] != -1) { now = Math.min(now, t[a[i]]); } dp[i] = Math.min(dp[i], now); } for (int i = 0; i < n; i++) { out.printf(""%d "", dp[i]); } out.println(); } public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int i = 0; i < t; i++) { run(); } out.flush(); in.close(); out.close(); } static final long mod = 1000000007; @SuppressWarnings(""FieldCanBeLocal"") private static Reader in; private static PrintWriter out; } ","import java.io.*; import java.util.*; public class AirConditioners { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub // System.in and System.out are input and output streams, respectively. InputStream inputStream = System.in; InputReader in = new InputReader(inputStream); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); while (t-- != 0) { int n = in.nextInt(); int k = in.nextInt(); HashMap hm = new HashMap<>(); int[] ac = in.readArray(k); for (int idx = 0; idx < ac.length; idx++) { hm.put(ac[idx], in.nextInt()); } Arrays.sort(ac); long[] lmin = new long[n]; long val = (long) Integer.MAX_VALUE; int acdx = 0; for (int idx = 0; idx < lmin.length; idx++) { if (acdx < ac.length && ac[acdx] - 1 == idx) { val = (long) Math.min(val, hm.get(ac[acdx])); acdx++; } lmin[idx] = val; val++; } acdx = ac.length - 1; val = Integer.MAX_VALUE; for (int idx = lmin.length-1; idx >= 0; idx--) { if (acdx >= 0 && ac[acdx] - 1 == idx) { val = (long) Math.min(val, hm.get(ac[acdx])); acdx--; } lmin[idx] = Math.min(lmin[idx], val); val++; } for (long x : lmin) { out.write(x + "" ""); } out.newLine(); } out.close(); } } ",0,Non-plagiarised 74f4382e,bd584714,"import java.io.*; import java.util.*; public class Solution { static int mod = (int) 1e9 + 7; //static Scanner sc = new Scanner(System.in); static StringBuilder out = new StringBuilder(); static int pri[] = new int[(int) 1e5 + 5]; public static void main(String[] args) throws IOException { int t = sc.nextInt(); //sieve(); int tc = 1; while (tc <= t) { // out.append(""Case #"" + tc + "": ""); Solution run = new Solution(); run.run(); tc++; } System.out.println(out); } ArrayList gr[]; long a[][]; public void run() throws IOException { int n = sc.nextInt(); gr=new ArrayList[n+1]; a=new long[n+1][2]; for(int i=0;i<=n;i++)gr[i]=new ArrayList<>(); for(int i=1;i<=n;i++) { a[i][0]=sc.nextInt(); a[i][1]=sc.nextInt(); } for(int i=0;i[] adj; long[][] dp; public void solve(int testNumber, Scanner sc, PrintWriter pw) { int t = 1; t = sc.nextInt(); while (t-- > 0) { n = sc.nextInt(); l = new long[n]; r = new long[n]; for (int i = 0; i < n; i++) { l[i] = sc.nextInt(); r[i] = sc.nextInt(); } adj = new ArrayList[n]; for (int i = 0; i < n; i++) adj[i] = new ArrayList<>(); for (int i = 0; i < n - 1; i++) { int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; adj[x].add(y); adj[y].add(x); } dp = new long[n + 1][2]; for (long[] x : dp) Arrays.fill(x, -1); long ans = solve(-1, 0, 0); for (long[] x : dp) Arrays.fill(x, -1); ans = Math.max(ans, solve(-1, 0, 1)); pw.println(ans); } } long solve(int from, int i, int f) { if (dp[i][f] != -1) return dp[i][f]; long ans = 0; long a = f == 0 ? l[i] : r[i]; for (int x : adj[i]) { if (x != from) ans += Math.max((Math.abs(l[x] - a) + solve(i, x, 0)), (Math.abs(r[x] - a) + solve(i, x, 1))); } return dp[i][f] = ans; } } } ",0,Non-plagiarised 2b9dfed3,351c9206,"import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ /** * Main , Solution , Remove Public */ public class E { public static void process() throws IOException { int n = sc.nextInt(),k = sc.nextInt(); int index[] = sc.readArray(k); long t[] = sc.readArrayLong(k); PriorityQueue q = new PriorityQueue(); for(int i = 0; i=1) { while(!q.isEmpty() && q.peek().y > i) { q.poll(); } if(q.isEmpty())break; Pair e = q.peek(); ans[i]=min(ans[i],e.x-(n-i)); i--; } for( i = 1; i<=n; i++)out.print(ans[i]+"" ""); out.println(); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner(""input.txt""); out = new FastWriter(""output.txt""); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+""ms""); } private static boolean oj = System.getProperty(""ONLINE_JUDGE"") != null; static class Pair implements Comparable { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// //custom multiset (replace with HashMap if needed) // compress Big value to Time Limit // Fast Writer // Fast Inputs } ","import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ /** * Main , Solution , Remove Public */ public class E { public static void process() throws IOException { int n = sc.nextInt(),k = sc.nextInt(); int index[] = sc.readArray(k); long t[] = sc.readArrayLong(k); PriorityQueue q = new PriorityQueue(); for(int i = 0; i=1) { while(!q.isEmpty() && q.peek().y > i) { q.poll(); } if(q.isEmpty())break; Pair e = q.peek(); ans[i]=min(ans[i],e.x-(n-i)); i--; } for( i = 1; i<=n; i++)out.print(ans[i]+"" ""); out.println(); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner(""input.txt""); out = new FastWriter(""output.txt""); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+""ms""); } private static boolean oj = System.getProperty(""ONLINE_JUDGE"") != null; static class Pair implements Comparable { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// //custom multiset (replace with HashMap if needed) // compress Big value to Time Limit // Fast Writer // Fast Inputs } ",1,Plagiarised 49b94994,f0d91796,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main1582D { public static void main(String[] args) { final FastScanner in = new FastScanner(System.in); final PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int[] a = new int[n]; for (int j = 0; j < n; j++) { a[j] = in.nextInt(); } int[] b = solution(a, n); for (int j = 0; j < n; j++) { out.print(b[j]); out.print("" ""); } out.println(); } out.flush(); out.close(); in.close(); } private static int[] solution(int[] a, int n) { int[] b = new int[n]; int start = 0; if (n % 2 == 1) { if (a[0] + a[1] != 0) { b[0] = -a[2]; b[1] = -a[2]; b[2] = a[0] + a[1]; } else if (a[0] + a[2] != 0) { b[0] = -a[1]; b[1] = a[0] + a[2]; b[2] = -a[1]; } else { b[0] = a[1] + a[2]; b[1] = -a[0]; b[2] = -a[0]; } start = 3; } else { b[0] = -a[1]; b[1] = a[0]; int gcd = gcd(b[0], b[1]); b[0] /= gcd; b[1] /= gcd; start = 2; } for (int i = start; i < n; i += 2) { b[i] = -a[i + 1]; b[i + 1] = a[i]; } return b; } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } } ","import java.io.*; import java.util.*; public class cf { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i=0;i0){ int n=sc.nextInt(); int ar[]=new int[n]; int sum=0; for(int i=0;i 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 11373c16,69b2fd22,"import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { FastReader scan = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int n = scan.nextInt(); ArrayList 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;i0) { int n=ob.nextInt(); PriorityQueue a=new PriorityQueue<>(); PriorityQueue b=new PriorityQueue<>(); long ans=Long.MAX_VALUE; long sum=0; for(int i=0;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,Plagiarised 1c8bb204,7ed5a88d,"import javax.print.DocFlavor; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class BST { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-->0){ int n = Integer.parseInt(br.readLine()); long [] arr = new long[n]; StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { long tmp = Long.parseLong(st.nextToken()); arr[i] = tmp; } int h = 1; int v = 1; long minHor = arr[0]; long minVir = arr[1]; long sum0 = arr[0]; long sum1 = arr[1]; long total = (arr[0] + arr[1])*n; for (int i = 2; i < n; i++) { if(i%2==0){ h++; sum0 += arr[i]; minHor = Math.min(arr[i] , minHor); total = Math.min(total , minHor*(n-h+1)+(sum0-minHor)+minVir*(n-v+1)+(sum1-minVir)); }else { v++; sum1 += arr[i]; minVir = Math.min(arr[i] , minVir); total = Math.min(total , minHor*(n-h+1)+(sum0-minHor)+minVir*(n-v+1)+(sum1-minVir)); } } System.out.println(total); } } } ","import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.io.PrintStream; //import java.util.*; public class Solution { public static final boolean LOCAL = System.getProperty(""ONLINE_JUDGE"")==null; public static void main(String[] args) throws Exception { FastScanner s = new FastScanner(); PrintStream debug = null; if(LOCAL){ s = new FastScanner(""src/input.txt""); PrintStream o = new PrintStream(""src/sampleout.txt""); debug = new PrintStream(""src/debug.txt""); System.setOut(o); } int tcr = s.nextInt(); for(int tc=0;tc 0) { int n = sc.nextInt(); sc.nextLine(); int a[][] = new int[26][26]; int b[][][] = new int[26][26][26]; boolean bl = false; String arr[] = new String[n]; for(int i = 0 ; i < n ; i++) { arr[i] = sc.nextLine(); if(arr[i].length() == 1) { bl = true; } else if(arr[i].length() == 2) { //a[arr[i].charAt(0)-'a'][arr[i].charAt(1)-'a'] = 1; if(arr[i].charAt(0)==arr[i].charAt(1)) bl = true; } else { //b[arr[i].charAt(0)-'a'][arr[i].charAt(1)-'a'][arr[i].charAt(2)-'a'] = 1; if(arr[i].charAt(0) == arr[i].charAt(2)) bl = true; } } if(bl) System.out.println(""YES""); else { for(int i = 0; i < n ; i++) { if(arr[i].length() == 2) { int p1 = arr[i].charAt(0)-'a'; int p2 = arr[i].charAt(1)-'a'; if(a[p2][p1] == 1) bl = true; for(int j = 0; j < 26 ; j++) { if(b[p2][p1][j] == 1) bl = true; } a[p1][p2] = 1; } else { int p1 = arr[i].charAt(0)-'a'; int p2 = arr[i].charAt(1)-'a'; int p3 = arr[i].charAt(2)-'a'; if(a[p3][p2] == 1) bl = true; if(b[p3][p2][p1] == 1) bl = true; b[p1][p2][p3] = 1; } } if(bl) System.out.println(""YES""); else System.out.println(""NO""); } } } } ","import java.io.*; import java.util.*; public class Ishu { static Scanner scan = new Scanner(System.in); static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); static void tc() throws Exception { int n = scan.nextInt(); String[] str = new String[n]; int i, j; for(i=0;i map = new HashMap(); Map par = new HashMap(); for(i=0;i=0;--i) { String cur = str[i]; int len = cur.length(); if(len == 2) { int value = map.get(cur); --value; map.remove(cur); if(value > 0) map.put(cur, value); } else { String pre = cur.substring(0, 2); int value = par.get(pre); --value; par.remove(pre); if(value > 0) par.put(pre, value); value = map.get(cur); --value; map.remove(cur); if(value > 0) map.put(cur, value); } if(len == 2) { StringBuffer buffer = new StringBuffer(cur); buffer.reverse(); String rev = String.valueOf(buffer); if(map.containsKey(rev) || par.containsKey(rev)) { ans = ""YES""; break; } } else { String suf = cur.substring(1, 3); StringBuffer buffer = new StringBuffer(suf); buffer.reverse(); String rev = String.valueOf(buffer); if(map.containsKey(rev)) { ans = ""YES""; break; } buffer = new StringBuffer(cur); buffer.reverse(); rev = String.valueOf(buffer); if(map.containsKey(rev)) { ans = ""YES""; break; } } } output.write(ans + ""\n""); output.flush(); } public static void main(String[] args) throws Exception { int t = 1; t = scan.nextInt(); while(t-- > 0) tc(); } } ",0,Non-plagiarised 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,Plagiarised 8532d5ed,b9595381,"import java.util.*; import java.io.*; public class C_Interesting_Story{ public static void main(String[] args) { FastScanner s= new FastScanner(); StringBuilder res = new StringBuilder(); int t=s.nextInt(); int p=0; while(p list = new ArrayList(); for(int i=0;i nice = new ArrayList(); for(int j=0;j0){ counting++; } else{ break; } } max=Math.max(max,counting); } res.append(max+""\n""); p++; } System.out.println(res); } } ","import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main{ static int dest1; static int dest2; public static void main(String args[]){ FastScanner in = new FastScanner(); int test=in.nextInt(); while(test-->0){ int n=in.nextInt(); int count[][]=new int[n][5]; int total[]=new int[n]; String words[]=new String[n]; for(int i=0;i0){ r+=ans[j]; j++; } max=Math.max(j,max); } System.out.println(max); } } } ",0,Non-plagiarised 8a729537,e270e909,"import java.io.*; import java.util.*; public class test3 { public static void main(String[] args) throws IOException { FastReader f = new FastReader(); int t = f.nextInt(); while(t-->0) { int n = f.nextInt(); int C[] = new int[n]; long ans=Long.MAX_VALUE,pre = 0; PriorityQueue epq = new PriorityQueue(); PriorityQueue opq = new PriorityQueue(); for(int i = 0;i0) { ans = Math.min(ans,pre+ ((long)n-(long)epq.size())*(long)epq.peek() + ((long)n-(long)opq.size())*(long)opq.peek()); } } System.out.println(ans); } } } ","import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); long pre = 0,ans = Long.MAX_VALUE; long[] arr = new long[n]; PriorityQueue epq = new PriorityQueue<>(); PriorityQueue opq = new PriorityQueue<>(); for(int i=0;i0) ans = Math.min(ans,pre+(n-epq.size())*epq.peek()+(n-opq.size())*opq.peek()); } System.out.println(ans); } } } ",1,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;i0) { int n=input.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i list=new ArrayList<>(); for(int i=0;i0) { int j=list.size()-1; int a[]=list.get(j); int l=a[0],r=a[1]; int l1=p,r1=k[i]; if(l1>r) { list.add(new int[]{l1,r1}); break; } else if(l1>=l && l1<=r) { list.remove(j); list.add(new int[]{l,r1}); break; } else { list.remove(j); } } if(list.size()==0) list.add(new int[]{p,k[i]}); } } long sum=0; for(int i=0;i0){ int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i 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());} } ","import java.util.ArrayList; import java.util.Scanner; import java.util.Stack; public class D { static Scanner sc = new Scanner(System.in); static int[] height; static int[] dp; public static void main(String[] args) { int n = sc.nextInt(); height = new int[n]; dp = new int[n]; dp[0] = 0; for (int i = 0; i < n; i++) { height[i] = sc.nextInt(); } Stack rise = new Stack(); Stack fail = new Stack(); rise.push(0); fail.push(0); for (int i = 1; i < n; i++) { dp[i] = dp[i-1]+1; if (rise.isEmpty()) { rise.push(i); } else if (height[rise.peek()] < height[i]) { rise.push(i); } else { while (!rise.isEmpty() && height[rise.peek()] > height[i]) { rise.pop(); if (!rise.isEmpty()) { dp[i] = Math.min(dp[i], dp[rise.peek()] + 1); } } while (!rise.isEmpty() && height[rise.peek()] == height[i]) { rise.pop(); } rise.push(i); } if (fail.isEmpty()) { fail.push(i); } else if (height[fail.peek()] > height[i]) { fail.push(i); } else { while (!fail.isEmpty() && height[fail.peek()] < height[i]) { fail.pop(); if (!fail.isEmpty()){ dp[i] = Math.min(dp[i], dp[fail.peek()] + 1); } } while (!fail.isEmpty() && height[fail.peek()] == height[i]) { fail.pop(); } fail.push(i); } } System.out.println(dp[n - 1]); } } ",0,Non-plagiarised 69b2fd22,7bc92b7f,"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 ones=new ArrayList<>(); ArrayList zero=new ArrayList<>(); for(int i=0;i=0) { cost+=min[i-1][curz-1]; } dp[i][curz]=cost; } minn=Integer.MAX_VALUE; for(int j=0;j=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;i--){ ans[i] = Math.min(ans[i],ans[i+1]+1); } for(int i=0;i list = new ArrayList(); for (int r = 0; r < rows - 1; r++) { for (int c = 0; c < columns - 1; c++) { int r1 = r + 1; int c1 = c + 1; int r2 = r + 2; int c2 = c + 2; while (matrix[r][c] == '1' || matrix[r+1][c] == '1' || matrix[r][c+1] == '1' || matrix[r+1][c+1] == '1') { if (matrix[r][c] == '0' && matrix[r+1][c] == '1' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '1') { // 0 1 1 1 list.add(r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r+1][c] = '0'; matrix[r][c+1] = '0'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '0' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '1') { // 1 0 1 1 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '0'; matrix[r][c+1] = '0'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '1' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '1') { // 1 1 0 1 list.add(r1 +"" ""+ c1 +"" ""+ r2 +"" ""+ c1 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '0'; matrix[r+1][c] = '0'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '1' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '0') { // 1 1 1 0 list.add(r1 +"" ""+ c1 +"" ""+ r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2); matrix[r][c] = '0'; matrix[r+1][c] = '0'; matrix[r][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '1' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '0') { // 1 1 0 0 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '0'; matrix[r][c+1] = '1'; matrix[r+1][c+1] = '1'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '0' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '1') { // 0 0 1 1 list.add(r1 +"" ""+ c1 +"" ""+ r2 +"" ""+ c1 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '1'; matrix[r+1][c] = '1'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '0' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '0') { // 1 0 1 0 list.add(r1 +"" ""+ c1 +"" ""+ r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2); matrix[r][c] = '0'; matrix[r+1][c] = '1'; matrix[r][c+1] = '0'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '1' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '1') { // 0 1 0 1 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '1'; matrix[r][c+1] = '1'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '0' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '0') { // 1 0 0 0 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '0'; matrix[r][c+1] = '1'; matrix[r+1][c+1] = '1'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '1' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '0') { // 0 1 0 0 list.add(r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r+1][c] = '0'; matrix[r][c+1] = '1'; matrix[r+1][c+1] = '1'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '0' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '0') { // 0 0 1 0 list.add(r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r+1][c] = '1'; matrix[r][c+1] = '0'; matrix[r+1][c+1] = '1'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '0' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '1') { // 0 0 0 1 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '1'; matrix[r][c+1] = '1'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '1' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '1') { // 1 1 1 1 list.add(r2 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c2); matrix[r+1][c] = '0'; matrix[r][c+1] = '0'; matrix[r+1][c+1] = '0'; } else if (matrix[r][c] == '1' && matrix[r+1][c] == '0' && matrix[r][c+1] == '0' && matrix[r+1][c+1] == '1') { // 1 0 0 1 list.add(r1 +"" ""+ c1 +"" ""+ r1 +"" ""+ c2 +"" ""+ r2 +"" ""+ c1); matrix[r][c] = '0'; matrix[r][c+1] = '1'; matrix[r+1][c] = '1'; } else if (matrix[r][c] == '0' && matrix[r+1][c] == '1' && matrix[r][c+1] == '1' && matrix[r+1][c+1] == '0') { // 0 1 1 0 list.add(r1 +"" ""+ c1 +"" ""+ r2 +"" ""+ c1 +"" ""+ r2 +"" ""+ c2); matrix[r][c] = '1'; matrix[r+1][c] = '0'; matrix[r+1][c+1] = '1'; } else { System.out.println(""error""); } counter++; } } } System.out.println(counter); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } output.close(); } } ","import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class C2 { static ArrayList list; 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(); for (int i = 0; i < t; i++) { list = new ArrayList<>(); int n = in.nextInt(); int m = in.nextInt(); char[][] arr = new char[n][m]; for (int j = 0; j < n; j++) { arr[j] = in.next().toCharArray(); } for (int j = 0; j < n; j += 2) { for (int k = 0; k < m; k += 2) { if (j == n - 1) j = n - 2; if (k == m - 1) k = m - 2; int cnt = 0; while (arr[j][k] == '1' || arr[j + 1][k] == '1' || arr[j][k + 1] == '1' || arr[j + 1][k + 1] == '1') { // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); if (checkThree(arr, j, k)) { // System.out.println(""3:""); // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); continue; } else if (checkTwo(arr, j, k)) { // System.out.println(""2:""); // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); checkThree(arr, j, k); // System.out.println(""3:""); // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); continue; } else if (checkDiagonal(arr, j, k)) { // System.out.println(""/2:""); // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); } else if (checkOne(arr, j, k)) { // System.out.println(""1:""); // System.out.println(arr[j][k] + "" "" + arr[j][k + 1] + ""\n"" + arr[j + 1][k] + "" "" + arr[j + 1][k + 1]); } // cnt++; // if (cnt == 10) return; // System.out.println(); } // System.out.println(""qwe""); // System.out.println(""qwe""); } } out.println(list.size()); for (Integer[] integers : list) { for (int j = 0; j < integers.length; j++) { out.print((integers[j] + 1) + "" ""); } out.println(); } } out.close(); } public static boolean checkThree(char[][] arr, int i, int j) { if (arr[i][j] == '1' && arr[i][j + 1] == '1' && arr[i + 1][j] == '1') { arr[i][j] = '0'; arr[i][j + 1] = '0'; arr[i + 1][j] = '0'; list.add(new Integer[]{i, j, i, (j + 1), (i + 1), j}); return true; } else if (arr[i][j] == '1' && arr[i][j + 1] == '1' && arr[i + 1][j + 1] == '1') { arr[i][j] = '0'; arr[i][j + 1] = '0'; arr[i + 1][j + 1] = '0'; list.add(new Integer[]{i, j, i, (j + 1), (i + 1), j + 1}); return true; } else if (arr[i + 1][j] == '1' && arr[i + 1][j + 1] == '1' && arr[i][j] == '1') { arr[i + 1][j] = '0'; arr[i + 1][j + 1] = '0'; arr[i][j] = '0'; list.add(new Integer[]{i + 1, j, i + 1, j + 1, (i), j}); return true; } else if (arr[i + 1][j] == '1' && arr[i + 1][j + 1] == '1' && arr[i][j + 1] == '1') { arr[i + 1][j] = '0'; arr[i + 1][j + 1] = '0'; arr[i][j + 1] = '0'; list.add(new Integer[]{i + 1, j, i + 1, j + 1, (i), j + 1}); return true; } return false; } public static boolean checkDiagonal(char[][] arr, int i, int j) { if (arr[i][j] == '1' && arr[i + 1][j + 1] == '1') { arr[i][j] = '0'; arr[i][j + 1] = '1'; arr[i + 1][j] = '1'; list.add(new Integer[]{i, j, i, j + 1, (i + 1), j}); return true; } else if (arr[i + 1][j] == '1' && arr[i][j + 1] == '1') { arr[i + 1][j] = '0'; arr[i][j] = '1'; arr[i + 1][j + 1] = '1'; list.add(new Integer[]{i + 1, j, i, j, (i + 1), j + 1}); return true; } return false; } public static boolean checkOne(char[][] arr, int i, int j) { if (arr[i][j] == '1') { arr[i][j] = '0'; arr[i + 1][j] = '1'; arr[i][j + 1] = '1'; list.add(new Integer[]{i, j, i + 1, j, (i), j + 1}); return true; } else if (arr[i + 1][j] == '1') { arr[i + 1][j] = '0'; arr[i][j] = '1'; arr[i + 1][j + 1] = '1'; list.add(new Integer[]{i + 1, j, i, j, (i + 1), j + 1}); return true; } else if (arr[i][j + 1] == '1') { arr[i][j + 1] = '0'; arr[i][j] = '1'; arr[i + 1][j + 1] = '1'; list.add(new Integer[]{i, j + 1, i, j, (i + 1), j + 1}); return true; } else if (arr[i + 1][j + 1] == '1') { arr[i + 1][j + 1] = '0'; arr[i + 1][j] = '1'; arr[i][j + 1] = '1'; list.add(new Integer[]{i + 1, j + 1, i + 1, j, (i), j + 1}); return true; } return false; } public static char changeValue(char c) { return c == '1' ? '0' : '1'; } public static boolean checkTwo(char[][] arr, int i, int j) { if (arr[i][j] == '1' && arr[i][j + 1] == '1') { arr[i][j] = '0'; arr[i + 1][j + 1] = changeValue(arr[i + 1][j + 1]); arr[i + 1][j] = changeValue(arr[i + 1][j]); list.add(new Integer[]{i, j, i + 1, j + 1, (i + 1), j}); return true; } else if (arr[i][j] == '1' && arr[i + 1][j] == '1') { arr[i][j] = '0'; arr[i + 1][j + 1] = changeValue(arr[i + 1][j + 1]); arr[i][j + 1] = changeValue(arr[i][j + 1]); list.add(new Integer[]{i, j, i + 1, j + 1, (i), j + 1}); return true; } else if (arr[i + 1][j] == '1' && arr[i + 1][j + 1] == '1') { arr[i + 1][j] = '0'; arr[i][j + 1] = changeValue(arr[i][j + 1]); arr[i][j] = changeValue(arr[i][j]); list.add(new Integer[]{i + 1, j, i, j + 1, (i), j}); return true; } else if (arr[i][j + 1] == '1' && arr[i + 1][j + 1] == '1') { arr[i][j + 1] = '0'; arr[i][j] = changeValue(arr[i][j]); arr[i + 1][j] = changeValue(arr[i + 1][j]); list.add(new Integer[]{i, j + 1, i, j, (i + 1), j}); return true; } return false; } } ",0,Non-plagiarised 585af783,f7a0ea6d,"import java.util.*; import java.io.*; public class codeforces { public static void main(String []args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); String s[] = new String[n]; for(int i=0;i pq = new PriorityQueue<>(); for(int j=0;j0) { total+=(2*a[j][i]-a[j][5]); count++; } else if(2*a[j][i]-a[j][5]==0) count1++; else pq.add(a[j][5]-2*a[j][i]); } if(count>0) { count+=count1; int value=0; while(!pq.isEmpty()&&value=total) count--; } return count; } } ","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 0){ int n = io.nextInt(); String s[] = new String[n]; for(int i = 0;i < n;i++)s[i] = io.nextLine(); int ans = 0; for(int i = 0;i < 5;i++){ int count[] = new int[n]; for(int j = 0;j < n;j++){ int freq = 0; for(int k = 0;k < s[j].length();k++){ // System.out.println(s[j].charAt(k) - 'a'); if((s[j].charAt(k) - 'a') == i){ freq++; } } // System.out.println(i + "" "" + freq); count[j] = 2*freq - s[j].length(); } Arrays.sort(count); // for(int it : count)System.out.print(it + "" ""); // System.out.println(); int curr = 0; int j = n - 1; for(;j >= 0 && (curr + count[j] > 0);j--){ curr += count[j]; } ans = Math.max(ans, n - j - 1); } System.out.println(ans); } } // returns the first key greater than or equal to val // returns the first key strictly greater than val } ","import java.util.*; import java.io.*; public class Solution { static long dp[][]; // Updates a node in Binary Index Tree (BITree) // at given index in BITree. The given value // 'val' is added to BITree[i] and all of // its ancestors in tree. public static void main(String []args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // sc.nextLine(); while(t-- > 0) { int n = sc.nextInt(); sc.nextLine(); //String s = sc.nextLine(); int arr[][] = new int[26][n]; for(int i = 0 ; i < n ; i++) { String s = sc.nextLine(); for(int j = 0 ; j < 26 ; j++) { int cnt = 0; for(int k = 0 ; k < s.length() ; k++) { if(s.charAt(k)-'a' == j) cnt++; } arr[j][i] = 2*cnt-s.length(); } } int ans = 0; for(int i = 0 ; i < 26 ; i++) { Arrays.sort(arr[i]); int tot = 0; for(int j = n-1 ; j >= 0 ;j--) { tot += arr[i][j]; if(tot <= 0) break; ans = Math.max(ans,n-j); } } System.out.println(ans); } } } ",0,Non-plagiarised cc669e02,d88fa51c,"import java.util.*; public class Codeforces { // CHECK CONSTRAINTS ALWAYS EDGE CASE MISSED static int mod = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long k = sc.nextLong(); long a[] = new long[n+1]; for(int i = 1 ; i<=n;i++) { a[i] = sc.nextLong(); } a[0] = -1; Arrays.sort(a); long sum = 0; for(int i = 1 ; i<=n;i++) { sum+=a[i]; } if(sum<=k) { System.out.println(0); } else if(sum == k+1) { System.out.println(1); } else { long ans = sum-k; long diff = sum - k; sum = 0; for(int i = n ; i>1 ; i--) { long x = 0; sum+=a[i]; if(sum - (n-i+1)*a[1] >= diff) { x = 0; } else { x = (long) Math.max(Math.ceil((double)(diff - sum + ((n-i+1)*a[1]))/(n-i+2)) , 0); } ans = Math.min(ans, x +n-i+1); } System.out.println(ans); } } } } } ","import java.util.*; import java.io.*; import java.math.BigInteger; public class code{ //@SuppressWarnings(""unchecked"") public static void main(String[] arg) throws IOException{ //Reader in=new Reader(); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(System.in); int t=in.nextInt(); while(t-- > 0){ int n=in.nextInt(); long k=in.nextLong(); PriorityQueue pq=new PriorityQueue(); long[] sum=new long[n+1]; for(int i=0;ia) z--; return z; } } ",0,Non-plagiarised 51d88c51,c2b7b017,"import java.awt.Container; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class Main { public static boolean check(int a[],int value) { int b[]= new int[a.length]; for (int i = a.length-1; i >=2; i--) { if(a[i]+b[i] 0) { int n = input.nextInt(); int a[]= new int[n]; int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { a[i] = input.nextInt(); min = Math.min(min, a[i]); max = Math.max(max, a[i]); } int low = min; int high = max; int ans = 0; while(low<=high) { int mid = low+(high-low)/2; if(check(a, mid)) { ans = mid; low = mid+1; } else { high = mid-1; } } result.append(ans+""\n""); } System.out.println(result); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; // public class Example { public static void main(String[] args) { FastReader sc = new FastReader(); int t= sc.nextInt(); while(t>0){ t--; int ans=Integer.MAX_VALUE; int n=sc.nextInt(); int[] ar= new int[n]; int l=Integer.MAX_VALUE; int h=Integer.MIN_VALUE; for(int i=0;i=2;i--){ if((ar[i]+extra[i]-mid)<0){ return false; } int d=Math.min(ar[i],extra[i]+ar[i]-mid); extra[i-1]=extra[i-1]+d/3; extra[i-2]+=2*(d/3); } int a=ar[0]+extra[0]; int b=ar[1]+extra[1]; return (a>=mid && b>=mid); } } ",1,Plagiarised 624b8db5,e9986d44,"import java.io.*; import java.util.*; public class C { private static ArrayDeque[] edge; private static HashMap map; private static String getHash(int u, int v) { if(u>v) { int tmp=u; u=v; v=tmp; } return u+"" ""+v; } private static void DFS(int u, int p, int[] ans, int val) { for(int v:edge[u]) { if(v==p) continue; ans[map.get(getHash(u,v))]=val; DFS(v,u,ans,5-val); val=5-val; } } public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,N; int T=Integer.parseInt(br.readLine().trim()); StringBuilder sb=new StringBuilder(); while (T-->0) { N=Integer.parseInt(br.readLine().trim()); edge=new ArrayDeque[N]; for(i=0;i(); map=new HashMap<>(); int[] ans=new int[N-1]; int[] deg=new int[N]; for(i=0;i2) break; if(i> graph, int from, int to, int weight) { edge temp = new edge(from, to, weight); edge temp1 = new edge(to, from, weight); graph.get(from).add(temp); graph.get(to).add(temp1); } static int ans = 0; static void dfs(ArrayList> graph, int vertex, boolean [] visited, int [] toReturn, int weight) { //System.out.println(graph.get(vertex).size()); if(visited[vertex]) return; visited[vertex] = true; if(graph.get(vertex).size() > 2) return; for(int i = 0; i < graph.get(vertex).size(); i++) { edge temp = graph.get(vertex).get(i); if(!visited[temp.to]) { //System.out.println(temp.to); toReturn[temp.weight] = weight; dfs(graph, temp.to, visited, toReturn, 5 - weight); weight = 5 - weight; } } } /*GRAPH FUNCTIONS END HERE * GRAPH * GRAPH * GRAPH * GRAPH */ /*disjoint Set START HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ static int [] rank; static int [] parent; /*disjoint Set END HERE * disjoint Set * disjoint Set * disjoint Set * disjoint Set */ /*INPUT START HERE * INPUT * INPUT * INPUT * INPUT * INPUT */ static int nexInt() throws NumberFormatException, IOException { return Integer.parseInt(sc.readLine()); } static int [] inputIntArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split("" ""); int [] toReturn = new int[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Integer.parseInt(s[i]); } return toReturn; } /*INPUT * INPUT * INPUT * INPUT * INPUT * INPUT END HERE */ static void solve() throws IOException { int n = nexInt(); ArrayList> tree = new ArrayList<>(); for(int i = 0; i < n; i++) tree.add(new ArrayList()); for(int i = 0; i < n - 1; i++) { int [] s1 = inputIntArr(); addEdge(tree, s1[0] - 1, s1[1] - 1, i); } int vertex = 0; for(int i = 0; i < tree.size(); i++) { if(tree.get(i).size() > 2) { System.out.println(-1); return; }else if(tree.size() == 1) { vertex = i; } } int [] toReturn = new int[n - 1]; //toReturn.add(2); dfs(tree, vertex, new boolean[n], toReturn, 2); //System.out.println(toReturn.size()); for(int i = 0; i < toReturn.length; i++) if(toReturn[i] != 0)System.out.print(toReturn[i] + "" ""); System.out.println(); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int t = Integer.parseInt(sc.readLine()); for(int i = 0; i < t; i++) solve(); } } ",0,Non-plagiarised c1fef98f,f870e76b,"import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Test{ static FastReader scan; static void solve(){ scan.nextLine(); int n=scan.nextInt(); int k=scan.nextInt(); int []arr=new int[n+1]; int []block=new int[k]; int []temp=new int[k]; for(int i=0;i=1;i--){ if(arr[i]==0){ if(prev==Integer.MAX_VALUE-1000){ dp[i]=Math.min(prev,dp[i]); } else{ prev=prev+1; dp[i]=Math.min(prev,dp[i]); } } else{ prev=Math.min(prev+1,arr[i]); dp[i]=Math.min(prev,dp[i]); } } for(int i=1;i<=n;i++){ System.out.print(dp[i]+"" ""); } System.out.println(); } public static void main (String[] args) throws java.lang.Exception{ scan=new FastReader(); int t=scan.nextInt(); while(t-->0){ solve(); } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.Vector; public class Main { static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); public static void main(String[] args) { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int k = in.nextInt(); int[] v1 = new int[k]; int[] v2 = new int[k]; for (int i = 0; i < k; i++) { v1[i] = in.nextInt(); } for (int i = 0; i < k; i++) { v2[i] = in.nextInt(); } //wejhfduiwehiofhw int[] res = new int[n + 2]; Arrays.fill(res, 2000000000); for (int i = 0; i < k; i++) { res[v1[i]] = v2[i]; } for (int i = 1; i <= n; i++) { int val = Math.min(res[i], res[i - 1] + 1); res[i] = val; } //ewhfowiejp //wedhciuwahidochqowi //wjdhoiqwnlidhqw for (int i = n; i >= 1; i--) { int val1 = Math.min(res[i], res[i + 1] + 1); res[i] = val1; // out.println(res[i]); } for (int i = 1; i <= n; i++) { int r = res[i]; out.print(r + "" ""); } out.println(); } out.close(); } } ",0,Non-plagiarised 169e34bf,fae0662f,"import java.util.*; public class D{ static Scanner sc; public static void solve(){ int n=sc.nextInt(); Integer a[]=new Integer[n]; int flag; for(int 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.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) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); for (int tc = 0; tc < t; tc++) { int n = fs.nextInt(); int[] a = fs.readArray(n); String s = fs.nextLine(); // let all blue to be 1 -> blueCount ArrayList blues = new ArrayList(); ArrayList reds = new ArrayList(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'B') { blues.add(a[i]); } else { reds.add(a[i]); } } Collections.sort(blues); Collections.sort(reds); boolean ok = true; for (int i = 1; i <= blues.size(); i++) { if (blues.get(i - 1) < i) { ok = false; break; } } for (int i = blues.size() + 1; i <= n; i++) { if (reds.get(i - blues.size() - 1) > i) { ok = false; break; } } if (ok) { out.println(""YES""); } else { out.println(""NO""); } } out.close(); } } ",1,Plagiarised 5af25bd7,77ec956f,"import java.io.*; import java.util.*; public class MySolution { public static void main(String[] args) throws Exception { BufferedReader bu = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); int numOfTestCases = Integer.parseInt(bu.readLine()); for (int tc = 1; tc <= numOfTestCases; tc++) { int vertices = Integer.parseInt(bu.readLine()); connections = new ArrayList[vertices]; for (int i = 0; i < vertices; i++) { connections[i] = new ArrayList(); 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 (int j = 0; j < vertices-1; j++) { String st[] = bu.readLine().split("" ""); int u = Integer.parseInt(st[0]) - 1, v = Integer.parseInt(st[1]) - 1; connections[u].add(v); connections[v].add(u); } dfs(0, -1); out.append(Math.max(s[0][0], s[0][1]) + ""\n""); } System.out.print(out); } static int N = 100000; static int[][] a = new int[N][2]; static long[][] s = new long[N][2]; static ArrayList[] connections; public static void dfs(int n, int parent) { for (int child : connections[n]) { if (child != parent) { dfs(child, n); s[n][0] += Math.max(s[child][0] + Math.abs(a[n][0] - a[child][0]), s[child][1] + Math.abs(a[n][0] - a[child][1])); s[n][1] += Math.max(s[child][0] + Math.abs(a[n][1] - a[child][0]), s[child][1] + Math.abs(a[n][1] - a[child][1])); } } } } ","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])); } } } ",1,Plagiarised 8ad1ad84,f652c678,"import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; //import javafx.util.*; public final class B { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); static ArrayList g[]; static long L[],R[],dp[][]; public static void main(String args[])throws IOException { int T=i(); outer:while(T-->0) { int N=i(); setGraph(N); for(int i=1; i<=N; i++) { L[i]=l(); R[i]=l(); } for(int i=1; i(); } } //Debugging Functions Starts //Debugging Functions END //---------------------- //IO FUNCTIONS STARTS static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } //IO FUNCTIONS END } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader ","import java.io.*; import java.text.DecimalFormat; import java.util.*; public class C { static long mod = (long) 1e9 + 7; static long mod1 = 998244353; static ArrayList[] adj; static HashMap hmap; 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(); adj = new ArrayList[n + 1]; for (int i = 0; i <= n; i++) adj[i] = new ArrayList<>(); long[][] dp = new long[n + 1][2]; hmap=new HashMap<>(); for (int i = 1; i <= n; i++) { dp[i][0] = in.nextLong(); dp[i][1] = in.nextLong(); } for (int i = 0; i < n - 1; i++) { int u = in.nextInt(); int v = in.nextInt(); adj[u].add(v); adj[v].add(u); } long[] x=DFS(dp,1,-1); out.println(Math.max(x[0],x[1])); } out.close(); } static long[] DFS(long[][] dp,int s,int prev) { long max=0; long min=0; for (int i : adj[s]) { if (i != prev) { long[] dd=DFS(dp,i,s); min+=Math.max(Math.abs(dp[s][0]-dp[i][0])+dd[0],Math.abs(dp[s][0]-dp[i][1])+dd[1]); max+=Math.max(Math.abs(dp[s][1]-dp[i][0])+dd[0],Math.abs(dp[s][1]-dp[i][1])+dd[1]); } } return new long[] {min,max}; } static final Random random = new Random(); } ",0,Non-plagiarised 3a12e509,fae0662f,"import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } // 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.StringTokenizer; public class D { public static void main(String[] args) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); for (int tc = 0; tc < t; tc++) { int n = fs.nextInt(); int[] a = fs.readArray(n); String s = fs.nextLine(); // let all blue to be 1 -> blueCount ArrayList blues = new ArrayList(); ArrayList reds = new ArrayList(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'B') { blues.add(a[i]); } else { reds.add(a[i]); } } Collections.sort(blues); Collections.sort(reds); boolean ok = true; for (int i = 1; i <= blues.size(); i++) { if (blues.get(i - 1) < i) { ok = false; break; } } for (int i = blues.size() + 1; i <= n; i++) { if (reds.get(i - blues.size() - 1) > i) { ok = false; break; } } if (ok) { out.println(""YES""); } else { out.println(""NO""); } } out.close(); } } ",0,Non-plagiarised 29cf2e70,b2001d68,"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.lang.*; import java.io.*; public class D753 { public static void main(String[] args) throws java.lang.Exception { // your code goes here try { // Scanner sc=new Scanner(System.in); FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i b=new ArrayList<>(); ArrayList r=new ArrayList<>(); for(int i=0;i=cur)cur++; else{ ok=false; break; } //cur++; } for(int i:r){ if(i<=cur)cur++; else{ ok=false; break; } } if(ok)System.out.println(""YES""); else System.out.println(""NO""); } } catch (Exception e) { return; } } } ",1,Plagiarised 1adac634,ee0bc145,"import java.io.*; import java.util.*; public class Main { static int i, j, k, n, m, t, y, x, sum = 0; static long mod = 998244353; static FastScanner fs = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static String str; static long ans; public static void main(String[] args) { t = fs.nextInt(); while (t-- > 0) { n = fs.nextInt(); int [] k = fs.readArray(n); int [] h = fs.readArray(n); List arr = new ArrayList<>(); for(i=0;i comp = new ArrayList<>(); int temp = arr.get(0).x; int tempy = arr.get(0).y; for(i=1;i tempy){ comp.add(new Pair(temp, tempy)); temp = arr.get(i).x; tempy = arr.get(i).y; } else tempy = Math.max(tempy, arr.get(i).y); } comp.add(new Pair(temp, tempy)); for(i=0;i { public int x, y; Pair(int x, int y) { this.x = x; this.y = y; } } } ","import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(); PrintWriter out = new PrintWriter(System.out); 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 < n; ++i) k[i] = sc.nextInt(); for (int i = 0; i < n; ++i) h[i] = sc.nextInt(); Stack stk = new Stack<>(); stk.push(new Pair(0, 0)); for (int i = 0; i < n; ++i) { int cur_pos = k[i]; int cur_inc = h[i]; while (!stk.isEmpty() && !(cur_pos - cur_inc + 1 > stk.peek().pos)) { cur_inc = Math.max(cur_inc, stk.peek().inc + cur_pos - stk.peek().pos); stk.pop(); } stk.add(new Pair(cur_pos, cur_inc)); } long answer = 0; while (!stk.isEmpty()) { answer += (1L * stk.peek().inc * (stk.peek().inc + 1) / 2); stk.pop(); } out.println(answer); } out.flush(); } static class Pair { int pos, inc; public Pair (int pos, int inc) { this.pos = pos; this.inc = inc; } } } ",0,Non-plagiarised 05ca89ed,163d0dde,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class er106c { //By shwetank_verma public static void main(String[] args) { FastReader sc=new FastReader(); try{ int t=1; t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long o=n,e=n; long maxo=Integer.MAX_VALUE; long maxe=Integer.MAX_VALUE; long ans=Long.MAX_VALUE; long temp=0; int a[]=new int[n]; for(int i=0;i b=new ArrayList<>(); } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class aa { public static void main(String[] args) { FastReader d=new FastReader(); int t,i,j,c,z,k,l,n; int mod = (int) 1e9 + 7; int Inf=Integer.MAX_VALUE; int negInf=Integer.MIN_VALUE; t=d.nextInt(); //t=1; //String s; //char ch,ch1,ch2,ch3; while(t-->0) { z=c=0; n=d.nextInt(); int a[]=new int[n]; for(i=0;i red = new ArrayList(); ArrayList blue = new ArrayList(); for(int i=0;inumber){ check2=1; break; } number--; } if(check1==0 && check2==0){ res.append(""YES\n""); } else{ res.append(""NO\n""); } p++; } System.out.println(res); } } ","import java.util.*; public class the_child_and_set { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); in.nextLine(); while(t--!=0) { int n=in.nextInt(); int arr[]=new int[n]; for(int i=0;ibi+(i+1)) { flag=false; break; } } } if(flag) System.out.println(""YES""); else System.out.println(""NO""); } } } ",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> { } public static void main(String[] args) throws IOException { // Check for int overflow!!!! // Should you use a long to store the sum or smthn? BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int T = Integer.parseInt(f.readLine()); for (int i = 0; i < T; i++) { StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); st = new StringTokenizer(f.readLine()); List list = new ArrayList<>(); for (int j = 0; j < n; j++) { int a = Integer.parseInt(st.nextToken()); list.add(a); } ArrayList copy = new ArrayList<>(list); Collections.sort(list); TreeSet> set = new TreeSet<>(new ListComparator()); for (int j = 1; j <= m; j++) { List temp = new ArrayList<>(); temp.add(0); temp.add(j); set.add(temp); // System.out.println(temp); } // System.out.println(set); Map> map = new HashMap<>(); for (int j = n - 1; j >= 0; j--) { if (map.containsKey(list.get(j))) { map.get(list.get(j)).addLast(set.first().get(1)); } else { map.put(list.get(j), new LinkedList<>()); map.get(list.get(j)).addLast(set.first().get(1)); } List temp = new ArrayList<>(); temp.add(set.first().get(0) + list.get(j)); temp.add(set.pollFirst().get(1)); set.add(temp); } // System.out.println(set); if (set.last().get(0) - set.first().get(0) > x) { out.println(""NO""); } else { out.println(""YES""); for (int j = 0; j < n; j++) { out.print(map.get(copy.get(j)).pollFirst() + "" ""); } out.println(); } } out.close(); } } ","import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.PriorityQueue; import java.util.StringTokenizer; public class C { static class Token implements Comparable { final int i, h; Token(int i, int h) { this.i = i; this.h = h; } } static void solve() throws Exception { int tests = scanInt(); for (int test = 0; test < tests; test++) { int n = scanInt(), m = scanInt(); scanInt(); PriorityQueue pq = new PriorityQueue<>(); int h[] = new int[m]; int ans[] = new int[n]; for (int i = 0; i < m; i++) { pq.add(new Token(i, 0)); } for (int i = 0; i < n; i++) { Token cur = pq.remove(); pq.add(new Token(cur.i, h[cur.i] += scanInt())); ans[i] = cur.i; } out.println(""YES""); for (int i = 0; i < n; i++) { out.print((ans[i] + 1) + "" ""); } out.println(); } } static int scanInt() throws IOException { return parseInt(scanString()); } static String scanString() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } static BufferedReader in; static PrintWriter out; static StringTokenizer tok; public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); exit(1); } } } ",0,Non-plagiarised 81a9086f,baebdc56,"import java.io.*; import java.util.*; public class D { static long mod=998244353; static long[] facts, factInvs; public static void main(String[] args)throws IOException { FastReader f=new FastReader(); StringBuffer sb = new StringBuffer(); int n=f.nextInt(); int k=f.nextInt(); Time time[]=new Time[n]; for(int i=0;i pq=new PriorityQueue<>(); for(int i=0;i=0; i--) factInvs[i]=mul(factInvs[i+1], i+1); } static long getNcR(int n, int k) { return mul(facts[n], mul(factInvs[k], factInvs[n-k])); } static long mul(long a, long b) { return a*b%mod; } static long modInv(long x) { return exp(x, mod-2); } static long exp(long base, long e) { if (e==0) return 1; long half=exp(base, e/2); if (e%2==0) return mul(half, half); else return mul(half, mul(half, base)); } static class Time implements Comparable