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); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } } } ",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; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }","import java.io.*; import java.util.*; public class D_Java { public static final int MOD = 998244353; public static int mul(int a, int b) { return (int)((long)a * (long)b % MOD); } int[] f; int[] rf; public int C(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } public static int pow(int a, int n) { int res = 1; while (n != 0) { if ((n & 1) == 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } static void shuffleArray(int[] a) { Random rnd = new Random(); for (int i = a.length-1; i > 0; i--) { int index = rnd.nextInt(i + 1); int tmp = a[index]; a[index] = a[i]; a[i] = tmp; } } public static int inv(int a) { return pow(a, MOD-2); } public void doIt() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); f = new int[n+42]; rf = new int[n+42]; f[0] = rf[0] = 1; for (int i = 1; i < f.length; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv(i)); } int[] events = new int[2*n]; for (int i = 0; i < n; ++i) { tok = new StringTokenizer(in.readLine()); int le = Integer.parseInt(tok.nextToken()); int ri = Integer.parseInt(tok.nextToken()); events[i] = le*2; events[i + n] = ri*2 + 1; } shuffleArray(events); Arrays.sort(events); int ans = 0; int balance = 0; for (int r = 0; r < 2*n;) { int l = r; while (r < 2*n && events[l] == events[r]) { ++r; } int added = r - l; if (events[l] % 2 == 0) { // Open event ans += C(balance + added, k); if (ans >= MOD) ans -= MOD; ans += MOD - C(balance, k); if (ans >= MOD) ans -= MOD; balance += added; } else { // Close event balance -= added; } } in.close(); System.out.println(ans); } public static void main(String[] args) throws IOException { (new D_Java()).doIt(); } }",1,Plagiarised cdb801a1,e14d1ba0,"//package codeforces; import java.io.*; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws java.lang.Exception { FastReader fr = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = fr.ni(); while(t-->0) { int n = fr.ni(); long arr [] = new long[n]; for(int i = 0 ; i < n ; i++) arr[i]= fr.nl(); long even = arr[0]; long odd = arr[1]; long minEven = arr[0]; long minOdd = arr[1]; long ans = (minEven*n) + (minOdd*n); for(int i = 2 ; i < n ; i++) { if((i&1) == 0) { even += arr[i]; minEven = Math.min(minEven, arr[i]); long a = (i+2)/2; long b = (i+1)-a; long temp = (even + (minEven*(n - a))); temp += (odd + (minOdd*(n - b))); ans = Math.min(ans, temp); }else { odd += arr[i]; minOdd = Math.min(minOdd, arr[i]); long a = (i+2)/2; long b = (i+1)-a; long temp = (even + (minEven*(n - a))); temp += (odd + (minOdd*(n - b))); ans = Math.min(ans, temp); } } out.println(ans); } out.close(); } }","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 boolean check(String x, String ans) { if(x.length()!=ans.length()) return x.length()>ans.length(); if(x.compareTo(ans) <= -1) return false; else return true; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void pn(Object o) { System.out.println(o); } static void p(Object o) { System.out.print(o); } static void flush() { System.out.flush(); } static void debugInt(int[] arr) { for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i>1); } static String getBinaryFromDecimal(int x) { StringBuilder sb=new StringBuilder(); for(int i=0;i<31;++i) { if((x&1)==0) sb.append('0'); else sb.append('1'); x=x>>1; } return sb.reverse().toString(); } static boolean[] sieve() { int size=(int)(1e5+5); boolean[] isPrime=new boolean[size]; Arrays.fill(isPrime, true); for(int i=2;i { public int compare(String s1, String s2) { if(s1.length()!=s2.length()) return s2.length()-s1.length(); if(s1.compareTo(s2) <= -1) return 1; else return -1; } }","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[]; static boolean v[]; // static int mod=998244353;; static int mod=1000000007; static int max; static int bit[]; //static long fact[]; // static long A[]; static HashMap map; //static StringBuffer sb=new StringBuffer(""""); //static HashMap map; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); long A[]=inputL(n); long B[]=inputL(n); long C[]=new long[n]; for(int i=0;i=0;i--) { if(C[i]>min) { continue; } if(A[i] { int x; int y; int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int find(int A[],int a) { if(A[a]==a) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return find(A, A[a]); //} //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void print(int A[]) { for(int i : A) { out.print(i+"" ""); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static HashMap hash(long A[]){ HashMap map=new HashMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(long A[]){ TreeMap map=new TreeMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised 4dc0247e,875ed4c8,"import java.io.*; import java.util.*; public class ComdeFormces { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); // int m=sc.nextInt(); ArrayList> ar=new ArrayList<>(); ArrayList arr=new ArrayList<>(); int c[]=new int[n]; for(int i=0;i<=n;i++) { ar.add(new ArrayList<>()); } for(int i=0;i2) { ans=false; break; } } if(ans) { for(int i=1;i<=n;i++) { if(ar.get(i).size()==1) { boolean vis[]=new boolean[n+1]; dfs(ar,2,i,vis,c); break; } } for(int i=0;i>ar ,int val,int src,boolean vis[],int c[]) { if(vis[src])return; vis[src]=true; for(int i=0;i divisors(int n){ ArrayList ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static int primeDivisor(int n){ ArrayList ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { pr=true; n/=2; } if(pr)ar.add(2); for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; pr=true; } if(pr)ar.add(i); } if(n>2) ar.add(n); return ar.size(); } static int mdlg(int num, int base) { int val=((int)(Math.ceil(Math.log(num)/Math.log(base)))); int val2=(int)Math.pow(base,val); // System.out.println(num+"" ""+Math.pow(base,val)); if(num/val2==0)return val; return val+1; // return val; } static String rev(String s) { char temp[]=s.toCharArray(); for(int i=0;imid)min=mid+1; else if(an=2;i--) { if(a[i]+val[i]>el) { if(val[i]>=el) { long df=a[i]; a[i]-=df; val[i-1]+=(df/3); val[i-2]+=2*(df/3); a[i]+=df%3; } else { long df=a[i]+val[i]-el; val[i-1]+=(df/3); val[i-2]+=2*(df/3); a[i]-=df; a[i]+=df%3; } } } for(int i=0;i> arr, int val,int el) { int s=0; int e=arr.size()-1; int ptr=0; if(val==1)ptr=1; while(s<=e) { int m=s+(e-s)/2; if(arr.get(m).get(ptr)==el)return m; else if(arr.get(m).get(ptr) arr,int el) { int start=0; int end=arr.size()-1; while(start<=end) { int mid=start+(end-start)/2; if(arr.get(mid).a==el)return mid; else if(arr.get(mid).aarr.size()-1)return -2; return -1; } static String eval(String s, long bs, long be,long k) { String ans=""""; for(int i=s.length()-1;i>=0;i--) { if(s.charAt(i)=='a') { ans=""a""+ans; } else if(be>0){ if(be>k) { for(int j=0;j>=1; if(tval==0)cnt[i][j]=cnt[i-1][j]+1; else { cnt[i][j]=cnt[i-1][j]; } j++; } } return cnt; } static long find(int s,long a[]) { if(s>=a.length)return -1; long num=a[s]; for(int i=s;i a, int k) { if(a.size()<1 )return 0; int i=a.size()-1; long ans=0; while(i>=0) { int temp=k; int prev=0; while(temp--!=0 && i>=0) { ans+=Math.abs(a.get(i)-prev); if(temp==0 || i==0)ans+=a.get(i); prev=a.get(i); i--; } } return ans; } static int bs(long a[] ,long num) { int start=0; int end=a.length-1; while(start<=end) { int mid=start+(end-start)/2; if(a[mid]==num) { return mid; } else if(a[mid]n-r)r=n-r; int ans=1; for(int i=0;i=end)return a[end]; int mid=start+(end-start)/2; int min1=mergesort(a,start,mid); int min2=mergesort(a,mid+1,end); merge(a,start,mid,end); return Math.min(min1, min2); } static void merge(int []a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; int b[]=new int[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } public int compareTo(pair b) { return b.b-this.b; } public int compareToo(pair b) { if(this.a!=b.a)return this.a-b.a; else { return b.b-this.b; } } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0){ solve(sc); } } public static void solve(FastReader sc){ int n = sc.nextInt(); ArrayList> graph = new ArrayList>(); for(int i = 0;i()); } for(int i = 0;i2){ out.println(-1);out.flush();return; }else if(graph.get(i).size()==1){ start=i; } } int val=2; int [] wgt = new int[n-1]; int curr = graph.get(start).get(0).node; wgt[graph.get(start).get(0).idx] = val; val=5; while(true){ ArrayList list = graph.get(curr); if(list.size()==1){ break; }else{ for(Edge el : list){ if(wgt[el.idx]==0){ wgt[el.idx] = val; val = 7-val; curr = el.node; } } } } for(int el : wgt){ out.print(el + "" ""); } out.println(); out.flush(); } static class Edge { int node; int idx; Edge(int src, int nbr) { this.node = src; this.idx = nbr; } } /* int [] arr = new int[n]; for(int i = 0;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{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws Exception { FastReader 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 FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextArray(int n) { int[] a = new int[n]; for (int i=0; i> t, int cur, boolean mode, int[] w) { vis[cur] = true; for (Pair p : t.get(cur)) { if (!vis[p.a]) { if (mode) { w[p.b] = 3; } else { w[p.b] = 2; } dfs(t, p.a, !mode, w); } } } public static void solve(int n, int[] u, int[] v) { ArrayList> t = new ArrayList>(n); for (int i=0; i()); } for (int i=0; i 2) { System.out.println(""-1""); return; } if (t.get(i).size() == 1) { start = i; } } vis = new boolean[n]; int[] w = new int[n-1]; dfs(t, start, false, w); StringBuilder ans = new StringBuilder(); for (int i=0; i 0) { int n = in.nextInt(); int[] u = new int[n-1]; int[] v = new int[n-1]; for (int i=0; i0){ int n = sc.nextInt(); char[] a = sc.next().toCharArray(); char[] b = sc.next().toCharArray(); int a1=0, b1=0; for(int i=0;i list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); 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 class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int 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); } } class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }","import java.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 HashMap initializeMap(int n){ HashMap hm = new HashMap<>(); for (int i = 0; i <= n; i++) { hm.put(i, 0); } return hm; } static boolean isRegular(char[] c){ Stack s = new Stack<>(); for (char value : c) { if (s.isEmpty() && value == ')') return false; if (value == '(') s.push(value); else s.pop(); } return s.isEmpty(); } static ArrayList> createAdj(int n, int e){ FastReader in = new FastReader(); ArrayList> adj = new ArrayList<>(); for (int i = 0; i < n + 1; i++) { adj.add(new ArrayList<>()); } for (int i = 0; i < e; i++) { int a = in.nextInt(), b = in.nextInt(); System.out.println(a); adj.get(a).add(b); adj.get(b).add(a); } return adj; } static int binarySearch(int[] a, int l, int r, int x){ if(r>=l){ int mid = l + (r-l)/2; if(a[mid] == x) return mid; if(a[mid] > x) return binarySearch(a, l, mid-1, x); else return binarySearch(a,mid+1, r, x); } return -1; } static boolean isPalindromeI(int n){ int d = 0; int y = n; while(y>0){ d++; y/=10; } int[] a = new int[d]; for (int i = 0; i < d; i++) { a[i] = n%10; n/=10; } System.out.println(Arrays.toString(a)); for (int i = 0; i < d / 2; i++) { if(a[i] != a[d-i-1]) return false; } return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static int exponentMod(int A, int B, int C) { // Base cases if (A == 0) return 0; if (B == 0) return 1; // If B is even long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } // If B is odd else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int) ((y + C) % C); } static class Pair implements Comparable{ char x; int y; Pair(char x, int y){ this.x = x; this.y = y; } public int compareTo(Pair o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } static class Tuple implements Comparable{ int x, y, id; Tuple(int x, int y, int id){ this.x = x; this.y = y; this.id = id; } public int compareTo(Tuple o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } // public static class Pair, V extends Comparable> implements Comparable> { // public U x; // public V y; // // public Pair(U x, V y) { // this.x = x; // this.y = y; // } // // public int hashCode() { // return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); // } // // public boolean equals(Object o) { // if (this == o) // return true; // if (o == null || getClass() != o.getClass()) // return false; // Pair p = (Pair) o; // return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); // } // // public int compareTo(Pair b) { // int cmpU = x.compareTo(b.x); // return cmpU != 0 ? cmpU : y.compareTo(b.y); // } // // public int compareToY(Pair b) { // int cmpU = y.compareTo(b.y); // return cmpU != 0 ? cmpU : x.compareTo(b.x); // } // // public String toString() { // return String.format(""(%s, %s)"", x.toString(), y.toString()); // } // // } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return next().charAt(0); } boolean nextBoolean() { return !(nextInt() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } private static int[] mergeSort(int[] array) { //array.length replaced with ctr int ctr = array.length; if (ctr <= 1) { return array; } int midpoint = ctr / 2; int[] left = new int[midpoint]; int[] right; if (ctr % 2 == 0) { right = new int[midpoint]; } else { right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } int[] result = new int[array.length]; left = mergeSort(left); right = mergeSort(right); result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right) { int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while (leftPointer < left.length || rightPointer < right.length) { if (leftPointer < left.length && rightPointer < right.length) { if (left[leftPointer] < right[rightPointer]) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } else if (leftPointer < left.length) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } return result; } public static void Sieve(int n) { Arrays.fill(primecheck, true); primecheck[0] = false; primecheck[1] = false; for (int i = 2; i * i < n + 1; i++) { if (primecheck[i]) { for (int j = i * 2; j < n + 1; j += i) { primecheck[j] = false; } } } } } ","import java.io.*; import java.util.*; public class D { static class Pair implements Comparable{ int a; char b; public Pair(int a, char b) { this.a = a; this.b = b; } @Override public int compareTo(Pair p) { if(this.b == p.b) return this.a - p.a; return this.b - p.b; } } public static void main(String[] args)throws IOException { FastScanner scan = new FastScanner(); PrintWriter output = new PrintWriter(System.out); int t = scan.nextInt(); for(int tt = 0;tt pairs = new ArrayList(); for(int i = 0;i i && pairs.get(i-1).b == 'B') { continue; } else { possible = false; break; } } output.println(possible == true ? ""YES"" : ""NO""); } output.flush(); } public static int[] sort(int arr[]) { List list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); for(int i = 0;i al = new ArrayList<>(); for(long e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i al = new ArrayList<>(); for(int e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i al = new ArrayList(); for(char cc:arr) al.add(cc); Collections.sort(al); for(int i = 0 ;i= 0) { bool[0] = false; bool[1] = false; } return bool; } static long modInverse(long a, long m) { long g = gcd(a, m); return power(a, m - 2, m); } static long lcm(long a , long b) { return (a*b)/gcd(a, b); } static int lcm(int a , int b) { return (int)((a*b)/gcd(a, b)); } static long power(long x, long y, long m){ if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (int)((p * (long)p) % m); if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); } static class Combinations{ private long[] z; private long[] z1; private long[] z2; private long mod; public Combinations(long N , long mod) { this.mod = mod; z = new long[(int)N+1]; z1 = new long[(int)N+1]; z[0] = 1; for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%mod; z2 = new long[(int)N+1]; z2[0] = z2[1] = 1; for (int i = 2; i <= N; i++) z2[i] = z2[(int)(mod % i)] * (mod - mod / i) % mod; z1[0] = z1[1] = 1; for (int i = 2; i <= N; i++) z1[i] = (z2[i] * z1[i - 1]) % mod; } long fac(long n) { return z[(int)n]; } long invrsNum(long n) { return z2[(int)n]; } long invrsFac(long n) { return invrsFac((int)n); } long ncr(long N, long R) { if(R<0 || R>N ) return 0; long ans = ((z[(int)N] * z1[(int)R]) % mod * z1[(int)(N - R)]) % mod; return ans; } } static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } } static int max(int... a ) { int max = a[0]; for(int e:a) max = Math.max(max, e); return max; } static long max(long... a ) { long max = a[0]; for(long e:a) max = Math.max(max, e); return max; } static int min(int... a ) { int min = a[0]; for(int e:a) min = Math.min(e, min); return min; } static long min(long... a ) { long min = a[0]; for(long e:a) min = Math.min(e, min); return min; } static int[] KMP(String str) { int n = str.length(); int[] kmp = new int[n]; for(int i = 1 ; i0 && str.charAt(i) != str.charAt(j)) { j = kmp[j-1]; } if(str.charAt(i) == str.charAt(j)) j++; kmp[i] = j; } return kmp; } /************************************************ Query **************************************************************************************/ /***************************************** Sparse Table ********************************************************/ static class SparseTable{ private long[][] st; SparseTable(long[] arr){ int n = arr.length; st = new long[n][25]; log = new int[n+2]; build_log(n+1); build(arr); } private void build(long[] arr) { int n = arr.length; for(int i = n-1 ; i>=0 ; i--) { for(int j = 0 ; j<25 ; j++) { int r = i + (1<=n) break; if(j == 0 ) st[i][j] = arr[i]; else st[i][j] = Math.min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] ); } } } public long gcd(long a ,long b) { if(a == 0) return b; return gcd(b%a , a); } public long query(int l ,int r) { int w = r-l+1; int power = log[w]; return Math.min(st[l][power],st[r - (1<=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); } } } /*******************************************************************************************************************************************************/ /** 1 */ ","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(); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; }}",0,Non-plagiarised 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 boolean prime(long k) { for (int i = 2; i * i <= k; i++) { if (k % i == 0) { return false; } } return true; } static long gcd(long a, long b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } static void reverseArray(Integer[] a) { for (int i = 0; i < (a.length >> 1); i++) { Integer temp = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = temp; } } static Integer[] intInput(int n, InputReader in) { Integer[] a = new Integer[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextInt(); return a; } static Long[] longInput(int n, InputReader in) { Long[] a = new Long[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextLong(); return a; } static String[] strInput(int n, InputReader in) { String[] a = new String[n]; for (int i = 0; i < a.length; i++) a[i] = in.next(); return a; } // static void sieve() { // for (int i = 2; i * i < prime.length; i++) { // if (prime[i]) // continue; // for (int j = i * i; j < prime.length; j += i) { // prime[j] = true; // } // } // } } class Data { int val; int ind; boolean positive; Data(int val, int ind) { this.val = Math.abs(val); this.ind = ind; this.positive = val >= 0; } } class compareVal implements Comparator { @Override public int compare(Data o1, Data o2) { // return (o1.val - o2.val == 0 ? o1.ind - o2.ind : o1.val - o2.val); return (o1.val - o2.val); } } class compareInd implements Comparator { @Override public int compare(Data o1, Data o2) { return o1.ind - o2.ind == 0 ? o1.val - o2.val : o1.ind - o2.ind; } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }","import java.util.*; import java.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<>(); static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } int[] readIntArray(int n){ int[] res=new int[n]; for(int i=0;i 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 int gcd(int a,int b){ if(b==0){ return a; } return gcd(b,a%b); } static void sort(int[] arr) { ArrayList ls = new ArrayList(); for(int x: arr) ls.add(x); Collections.sort(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } static void reversesort(int[] arr) { ArrayList ls = new ArrayList(); for(int x: arr) ls.add(x); Collections.sort(ls); Collections.reverse(ls); for(int i=0; i < arr.length; i++) arr[i] = ls.get(i); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static void debug(String x){ System.out.println(x); } static < E > void print(E res) { System.out.println(res); } static String rString(String s){ StringBuilder sb=new StringBuilder(); sb.append(s); return sb.reverse().toString(); } }","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; static class Pair implements Comparable { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable { int first, second,third; public Tuple(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List l = new ArrayList<>(); for (int p = 2; p*p<=n; p++) { if (prime[p] == true) { for(int i = p*p; i<=n; i += p) { prime[i] = false; } } } for (int p = 2; p<=n; p++) { if (prime[p] == true) { l.add(p); } } return l; } public static int countDivisors(int x) { int c = 0; for(int i = 1;i*i<=x;i++) { if(x%i == 0) { if(x/i != i) { c+=2; } else { c++; } } } return c; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 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 int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(long a[], long x) { int l=-1, r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(long[] a) { List l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i 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 = 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 list = new ArrayList(); int n =arr.length; for(int i=0;i map = //... private final int x; private final int y; public Pair(int 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 pair = (Pair) o; return x == pair.x && y == pair.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } } static FastScanner sc = new FastScanner(); static PrintWriter out =new PrintWriter(System.out); static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable { int first, second,third; public Tuple(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List l = new ArrayList<>(); for (int p = 2; p*p<=n; p++) { if (prime[p] == true) { for(int i = p*p; i<=n; i += p) { prime[i] = false; } } } for (int p = 2; p<=n; p++) { if (prime[p] == true) { l.add(p); } } return l; } public static int countDivisors(int x) { int c = 0; for(int i = 1;i*i<=x;i++) { if(x%i == 0) { if(x/i != i) { c+=2; } else { c++; } } } return c; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 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 int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(long a[], long x) { int l=-1, r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(long[] a) { List l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i 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 int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList arrayList2 ; public arrayListClass(ArrayList arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; 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 = 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; } public int compareTo(Pair o) { // TODO Auto-generated method stub if (this.a != o.a) return Integer.compare(this.a, o.a); else return Integer.compare(this.b, o.b); // return 0; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair) o; return p.a == a && p.b == b; } return false; } } static int binarySearch(int arr[], int first, int last, int key) { int mid = (first + last) / 2; while (first <= last) { if (arr[mid] < key) { first = mid + 1; } else if (arr[mid] == key) { return mid; } else { last = mid - 1; } mid = (first + last) / 2; } return -1; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.util.*; import java.lang.*; import java.io.*; public class Template { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null ||!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // static void 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; } @Override public int compareTo(Pair o) { return this.h - o.h; } } public static void main(String[] args) { FastReader fs=new FastReader(); int T=fs.nextInt(); for (int tt=0; tt heap = new PriorityQueue<>(); for(int i=0;i x) //// { //// System.out.println(""NO"" + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); //// flag = true; //// break; //// } // if(inc) // tower++; // else // tower--; // } // for(int i=1;i<=m;i++) // { // min = Math.min(min, towers[i]); // max = Math.max(max, towers[i]); // } // if(Math.abs(max - min) > x) // { // System.out.println(""NO"" + max+"" ""+min);// + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); // //flag = true; // continue; // } // if(flag) // continue; System.out.println(""YES""); for(int i:ans) System.out.print(i+"" ""); System.out.println(); } } } ",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 String reverse(String s) { return (new StringBuilder(s)).reverse().toString(); } static void sieveOfEratosthenes(int n, int factors[], ArrayList ar) { factors[1]=1; int p; for(p = 2; p*p <=n; p++) { if(factors[p] == 0) { ar.add(p); factors[p]=p; for(int i = p*p; i <= n; i += p) if(factors[i]==0) factors[i] = p; } } for(;p<=n;p++){ if(factors[p] == 0) { factors[p] = p; ar.add(p); } } } static void sort(int ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static void sort1(long ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static void sort2(char ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static long ncr(long n, long r, long mod) { if (r == 0) return 1; long val = ncr(n - 1, r - 1, mod); val = (n * val) % mod; val = (val * modInverse(r, mod)) % mod; return val; } static class SegTree { long tree[]; long lz[]; long r; long combine(long a, long b){ return Math.min(a,b); } void build(long a[], int v, int tl, int tr) { if (tl == tr) { tree[v] = a[tl]; } else { int tm = (tl + tr) / 2; build(a, v*2, tl, tm); build(a, v*2+1, tm+1, tr); tree[v] = combine(tree[2*v], tree[2*v+1]); } } void pointUpdate(int v, int tl, int tr, int pos, long val) { if(tl>pos||tr> 1); pointUpdate(v*2, tl, tm, pos, val); pointUpdate(v*2+1, tm+1, tr, pos, val); tree[v] = combine(tree[2*v],tree[2*v+1]); } // void push(int v, int tl, int tr){ // if(tl==tr){ // lz[v] = 0; // return; // } // tree[2*v] += lz[v]; // tree[2*v+1] += lz[v]; // lz[2*v] += lz[v]; // lz[2*v+1] += lz[v]; // lz[v] = 0; // } // void rangeUpdate(int v, int tl, int tr, int l, int r, long val) { // if(tl>r||tr=l&&tr<=r){ // tree[v] += val; // lz[v] += val; // return; // } // int tm = ((tl + tr) >> 1); // rangeUpdate(v*2, tl, tm, l, r, val); // rangeUpdate(v*2+1, tm+1, tr, l, r, val); // tree[v] = combine(tree[2*v],tree[2*v+1]); // } long get(int v, int tl, int tr, int l, int r, long val) { if(l>tr||rval){ return 0; } if (tl == tr) { tree[v] = Integer.MAX_VALUE; return 1; } int tm = ((tl + tr) >> 1); long al = get(2*v, tl, tm, l, r, val); long ar = get(2*v+1, tm+1, tr, l, r, val); tree[v] = combine(tree[2*v],tree[2*v+1]); return al+ar; } } static class BIT{ int n; long tree[]; long operate(long el, long val){ return el+val; } void update(int x, long val){ for(;x0;x-=(x&(-x))){ sum = operate(sum, tree[x]); } return sum; } } static int parent[]; static int rank[]; static long m = 0; static int find_set(int v) { if (v == parent[v]) return v; return find_set(parent[v]); } static void make_set(int v) { parent[v] = v; rank[v] = 1; } static void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (rank[a] < rank[b]){ int tmp = a; a = b; b = tmp; } parent[b] = a; // if (rank[a] == rank[b]) // rank[a]++; rank[a] += rank[b]; max1 = Math.max(max1,rank[a]); } } static int parent1[]; static int rank1[]; static int find_set1(int v) { if (v == parent1[v]) return v; return find_set1(parent1[v]); } static void make_set1(int v) { parent1[v] = v; rank1[v] = 1; } static void union_sets1(int a, int b) { a = find_set1(a); b = find_set1(b); if (a != b) { if (rank1[a] < rank1[b]){ int tmp = a; a = b; b = tmp; } parent1[b] = a; // if (rank1[a] == rank1[b]) // rank1[a]++; rank1[a] += rank1[b]; } } 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); } static void KMPSearch(char pat[], char txt[], int pres[]){ int M = pat.length; int N = txt.length; int lps[] = new int[M]; int j = 0; computeLPSArray(pat, M, lps); int i = 0; while (i < N) { if (pat[j] == txt[i]) { j++; i++; } if (j == M) { pres[i-1] = 1; j = lps[j - 1]; } else if (i < N && pat[j] != txt[i]) { if (j != 0) j = lps[j - 1]; else i = i + 1; } } } static void computeLPSArray(char pat[], int M, int lps[]) { int len = 0; int i = 1; lps[0] = 0; while (i < M) { if (pat[i] == pat[len]) { len++; lps[i] = len; i++; } else { if (len != 0) { len = lps[len - 1]; } else { lps[i] = len; i++; } } } } static long[][] matrixMult(long a[][], long b[][], long mod){ int n = a.length; int m = a[0].length; int p = b[0].length; long c[][] = new long[n][p]; for(int i=0;i pos){ for(int i=2;i*i1){ int y = pos.get(num); a[y]++; } } static void assignAnc(ArrayList ar[], int depth[], int sz[], int par[][] ,int curr, int parent, int d){ depth[curr] = d; sz[curr] = 1; par[curr][0] = parent; for(int v:ar[curr]){ if(parent==v) continue; assignAnc(ar, depth, sz, par, v, curr, d+1); sz[curr] += sz[v]; } } static int findLCA(int a, int b, int par[][], int depth[]){ if(depth[a]>depth[b]){ a = a^b; b = a^b; a = a^b; } int diff = depth[b] - depth[a]; for(int i=19;i>=0;i--){ if((diff&(1<0){ b = par[b][i]; } } if(a==b) return a; for(int i=19;i>=0;i--){ if(par[b][i]!=par[a][i]){ b = par[b][i]; a = par[a][i]; } } return par[a][0]; } static void formArrayForBinaryLifting(int n, int par[][]){ for(int j=1;j<20;j++){ for(int i=0;i { long a; long b; Pair1(long a, long b) { this.a = a; this.b = b; } public int compareTo(Pair1 p) { if(a!=p.a) return (a { int a; int b; int c; Pair(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } public int compareTo(Pair p) { if(b!=p.b) return (b-p.b); return (a-p.a); } } static class Pair2 implements Comparable { int a; int b; int c; Pair2(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } public int compareTo(Pair2 p) { return a-p.a; } } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long fast_pow(long base, long n, long M) { if (n == 0) return 1; if (n == 1) return base % M; long halfn = fast_pow(base, n / 2, M); if (n % 2 == 0) return (halfn * halfn) % M; else return (((halfn * halfn) % M) * base) % M; } static long modInverse(long n, long M) { return fast_pow(n, M - 2, M); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 9992768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }","import java.io.*; import java.util.*; public class Main { static 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""); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } "," 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; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } } ",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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } "," import java.io.*; 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); } } static void ruffleSort(int a[]) { int n = a.length; Random r = new Random(); for (int i = 0; i < n; i++) { int oi = r.nextInt(n); int temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static void ruffleSort(long a[]) { int n = a.length; Random r = new Random(); for (int i = 0; i < n; i++) { int oi = r.nextInt(n); long temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",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 { static class Pair{ long x; long y; Pair(long x,long y){ this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + "" "" + arr[i].y + "" ""); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int solve(int dp[][] , ArrayList one , ArrayList zero , int i,int j) { int n=one.size(); int m=zero.size(); if(i>=n) return 0; else if(j>=m) return Integer.MAX_VALUE; else if(dp[i][j]!=-1) return dp[i][j]; int val1 = Math.abs(one.get(i)-zero.get(j))+solve(dp, one ,zero ,i+1,j+1); int val2 = solve(dp , one , zero , i,j+1); dp[i][j]= Math.min(val1,val2); return dp[i][j]; } 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 { int first, second; public Pair(int aa, int bb) { first = aa; second = bb; } public int compareTo(Pair o) { if(this.second < o.second) return -1; if(this.second > o.second) return +1; return this.first - o.first; } } static class Tuple implements Comparable{ long first, second,third; public Tuple(long first, long second, long third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i SieveList(int n) { boolean prime[] = new boolean[n+1]; Arrays.fill(prime, true); ArrayList l = new ArrayList<>(); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for(int i=p*p; i<=n; i += p) { prime[i] = false; } } } for (int p=2; p<=n; p++) { if (prime[p] == true) { l.add(p); } } return l; } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); 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 int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(int a[], int x) { int l=-1, r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } 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; } @Override public int compareTo(Tower o) { return size - o.size; } } }","import java.util.*; import java.lang.*; import java.io.*; public class Template { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null ||!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // static void 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; } @Override public int compareTo(Pair o) { return this.h - o.h; } } public static void main(String[] args) { FastReader fs=new FastReader(); int T=fs.nextInt(); for (int tt=0; tt heap = new PriorityQueue<>(); for(int i=0;i x) //// { //// System.out.println(""NO"" + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); //// flag = true; //// break; //// } // if(inc) // tower++; // else // tower--; // } // for(int i=1;i<=m;i++) // { // min = Math.min(min, towers[i]); // max = Math.max(max, towers[i]); // } // if(Math.abs(max - min) > x) // { // System.out.println(""NO"" + max+"" ""+min);// + a[i].ind+"" ""+a[i].h +"" ""+min +"" ""+max); // //flag = true; // continue; // } // if(flag) // continue; System.out.println(""YES""); for(int i:ans) System.out.print(i+"" ""); System.out.println(); } } } ",0,Non-plagiarised 4303de0d,c9a316ca,"import java.io.*; import java.util.*; public class ParsasHumongousTree { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Output { private final PrintWriter writer; public Output(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public Output(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static class Pair { int a; int b; public Pair(int a, int b) { this.a=a; this.b=b; } } static HashMap> edge=new HashMap(); static Pair a[]; static long dp[][]; static void dfs(int node, int parent) { for(int i:edge.get(node)) { if(i!=parent) { dfs(i,node); dp[node][0]+=Math.max(Math.abs(a[node].a-a[i].a)+dp[i][0],Math.abs(a[node].a-a[i].b)+dp[i][1]); dp[node][1]+=Math.max(Math.abs(a[node].b-a[i].a)+dp[i][0],Math.abs(a[node].b-a[i].b)+dp[i][1]); } } } public static void main(String args[]) { FastReader sc=new FastReader(); Output out=new Output(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); a=new Pair[n+1]; edge.clear(); for(int i=1;i list=edge.get(u); list.add(v); edge.put(u,list); } else { List list=new ArrayList(); list.add(v); edge.put(u,list); } if(edge.containsKey(v)) { List list=edge.get(v); list.add(u); edge.put(v,list); } else { List list=new ArrayList(); list.add(u); edge.put(v,list); } } dp=new long[n+1][2]; dfs(1,0); out.printLine(((long)Math.max(dp[1][0],dp[1][1]))); out.flush(); } } }"," import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import static javax.swing.UIManager.get; import static javax.swing.UIManager.getString; public class Main { static class Pair implements Comparable { int x = 0; int y = 0; public Pair(int x1, int y1) { x = x1; y = y1; } @Override public int compareTo(Pair o) { return this.x - o.x; } } static boolean checkPallindrome(int n) { ArrayList list = new ArrayList<>(); while (n > 0) { list.add(n % 10); n /= 10; } int low = 0, high = list.size() - 1; while (low <= high) { if (list.get(low) != list.get(high)) return false; low++; high--; } return true; } static boolean check(String s) { int low = 0, high = s.length() - 1; while (low <= high) { if (s.charAt(low) != s.charAt(high)) return false; low++; high--; } return true; } class Node implements Comparable { int x = 0, y = 0, z = 0; @Override public int compareTo(Node o) { return this.y - o.y; } } static int min = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); //(1)very very important**(never take the first problem for granted, always check the test cases) take 5 minutes more and check the edge cases // 5 minutes will not decreases rating as much as a wrong submission does it is easy u just think with an open mind and u will surely get the answer //(2)let ur brain consume the problem don't just jump to the solution. after reading the problem take a pause 1 minute //(3)go through the example test cases and also at least two of ur own test cases.Think of testcases which are difficult(edge cases).dry run ur concept //(4) sometimes if else condition is not required but due to if else you miss some points and get wrong answer int t = sc.nextInt(); while (t-- > 0) { int n =sc.nextInt(); ArrayList> list = new ArrayList<>(); for(int i=0;i()); ArrayList list1 = new ArrayList<>(); for(int i=0;i> list,ArrayList list1) { for(int v:list.get(u)) { if(v==p) continue; dfs(v,u,dp,list,list1); dp[1][u]+= Math.max(Math.abs(list1.get(u).y-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).y-list1.get(v).y)+dp[1][v]); dp[0][u]+=Math.max(Math.abs(list1.get(u).x-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).x-list1.get(v).y)+dp[1][v]); } } //static int lcs( int[] X, int[] Y, int m, int n ) //{ // int L[][] = new int[m+1][n+1]; // // /* Following steps build L[m+1][n+1] in bottom up fashion. Note // that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ // for (int i=0; i<=m; i++) // { // for (int j=0; j<=n; j++) // { // if (i == 0 || j == 0) // L[i][j] = 0; // else if (X[i-1] == Y[j-1]) // L[i][j] = L[i-1][j-1] + 1; // else // L[i][j] = Math.max(L[i-1][j], L[i][j-1]); // } // } // return L[m][n]; //} // syntax of conditional operator y=(x==1)?1:0; //Things to check when u r getting wrong answer // 1- check the flow of the code //2- If ur stuck read the problem once again //3- before submitting always check the output format of ur code //4- don't check standings until problem B is done //5- if u r thinking ur concept is correct but still u r getting wrong answer try to implement it in another way //6- By default, java interpret all numeral literals as 32-bit integer values. // If you want to explicitely specify that this is something bigger then 32-bit integer you should use suffix L for long values. example long a = 600851475143L //All the functions long pow(long a,long b,long m) { a%=m; long res=1L; while(b>0) { long temp=b&1; if(temp==1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) { // Initially, all elements are in // their own set. parent[i] = i; } } // Returns representative of x's set int find(int x) { // Finds the representative of the set // that x is an element of if (parent[x] != x) { // if x is not the parent of itself // Then x is not the representative of // his set, parent[x] = find(parent[x]); // so we recursively call Find on its parent // and move i's node directly under the // representative of this set } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { // Find representatives of two sets int xRoot = find(x), yRoot = find(y); // Elements are in the same set, no need // to unite anything. if (xRoot == yRoot) return; // If x's rank is less than y's rank if (rank[xRoot] < rank[yRoot]) // Then move x under y so that depth // of tree remains less parent[xRoot] = yRoot; // Else if y's rank is less than x's rank else if (rank[yRoot] < rank[xRoot]) // Then move y under x so that depth of // tree remains less parent[yRoot] = xRoot; else // if ranks are the same { // Then move y under x (doesn't matter // which one goes where) parent[yRoot] = xRoot; // And increment the result tree's // rank by 1 rank[xRoot] = rank[xRoot] + 1; } } } static void debug(String s) { System.out.println(s); } //collections.sort use merge sort instead of quick sort but arrays.sort use quicksort whose worst time complexity is O(n^2) static int[] sort(int[] a) { ArrayList list = new ArrayList<>(); for(int i=0;i0){ int n = 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; } public int compareTo(Pair p) { if(this.first() == p.first()) { return 0; }else if(this.first() > p.first()) { return 1; }else { return -1; } } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while(st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); }catch(Exception e) { System.out.println(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String getString() { return next(); } }"," 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 @Override public int compare(Student s1, Student s2) { if (s1.i1 < s2.i1) return -1; else if (s1.i1 >s2.i1) return 1; return 0; } } /* 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 t, ArrayList m) { if (t.size() == 0 && m.size() == 0) { sd = true; return; } t.remove(0); t.remove(t.size() - 1); call(t, new ArrayList(m.subList(0, m.size() - 1))); call(t, new ArrayList(m.subList(1, m.size()))); } static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static int noofdivisors(int n) { //it counts no of divisors of every number upto number n int arr[] = new int[n + 1]; for (int i = 1; i <= (n); i++) { for (int j = i; j <= (n); j = j + i) { arr[j]++; } } return arr[0]; } static char[] reverse(char arr[]) { char[] b = new char[arr.length]; int j = arr.length; for (int i = 0; i < arr.length; i++) { b[j - 1] = arr[i]; j = j - 1; } return b; } static long factorial(int n) { long su = 1; for (int i = 1; i <= n; i++) { su *= (long) i; } return su; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); public String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } long[] readArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } } ",0,Non-plagiarised 1162c08f,6bcc5afd,"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.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 { static class Pair{ int val; char c; Pair(int a,char b){ this.val=a; this.c=b; } } public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); PrintWriter pw=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int[] a=sc.readArray(n); char[] s=sc.next().toCharArray(); boolean ok=true; ArrayList blues=new ArrayList<>(); ArrayList reds=new ArrayList<>(); for(int i=0;i(start++)){ ok=false; break; } } if(ok){ pw.println(""YES""); } else { pw.println(""NO""); } } pw.flush(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i 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]; } public static long[] radixSort(long[] f){ return radixSort(f, f.length); } public static long[] radixSort(long[] f, int n) { long[] to = new long[n]; { int[] b = new int[65537]; for(int i = 0;i < n;i++)b[1+(int)(f[i]&0xffff)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < n;i++)to[b[(int)(f[i]&0xffff)]++] = f[i]; long[] d = f; f = to;to = d; } { int[] b = new int[65537]; for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>16&0xffff)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>16&0xffff)]++] = f[i]; long[] d = f; f = to;to = d; } { int[] b = new int[65537]; for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>32&0xffff)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>32&0xffff)]++] = f[i]; long[] d = f; f = to;to = d; } { int[] b = new int[65537]; for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>48&0xffff)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>48&0xffff)]++] = f[i]; long[] d = f; f = to; to = d; } return f; } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static int lowerBound(long a[], long x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int upperBound(long a[], long x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1L; if (a[m] <= x) l = m; else r = m; } return l + 1; } static int upperBound(long[] arr, int start, int end, long k) { int N = end; while (start < end) { int mid = start + (end - start) / 2; if (k >= arr[mid]) { start = mid + 1; } else { end = mid; } } if (start < N && arr[start] <= k) { start++; } return start; } static long lowerBound(long[] arr, int start, int end, long k) { int N = end; while (start < end) { int mid = start + (end - start) / 2; if (k <= arr[mid]) { end = mid; } else { start = mid + 1; } } if (start < N && arr[start] < k) { start++; } return start; } // For Fast Input ---- static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } "," import java.io.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= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static long norm(long a, long MOD) { return ((a % MOD) + MOD) % MOD; } public static long msub(long a, long b, long MOD) { return norm(norm(a, MOD) - norm(b, MOD), MOD); } public static long madd(long a, long b, long MOD) { return norm(norm(a, MOD) + norm(b, MOD), MOD); } public static long mMul(long a, long b, long MOD) { return norm(norm(a, MOD) * norm(b, MOD), MOD); } public static long mDiv(long a, long b, long MOD) { return norm(norm(a, MOD) / norm(b, MOD), MOD); } } ",0,Non-plagiarised 3a12e509,6de04ee2,"import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } static class Pair implements Cloneable, Comparable { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+500*Math.abs(y); } @Override public String toString() { return ""(""+x+"" ""+y+"")""; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; int taxC,taxD; Node(int ver) { vertex=ver; taxD=0; taxC=0; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(nn) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ","import java.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; } public int compareTo(Pair o) { int value = ((Comparable) x).compareTo(o.x); if (value != 0) return value; return ((Comparable) y).compareTo(o.y); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return x.equals(pair.x) && y.equals(pair.y); } public int hashCode() { return Objects.hash(x, y); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } ","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 FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class Pair implements Comparable> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int compareTo(Pair o) { int value = ((Comparable) x).compareTo(o.x); if (value != 0) return value; return ((Comparable) y).compareTo(o.y); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return x.equals(pair.x) && y.equals(pair.y); } public int hashCode() { return Objects.hash(x, 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; } } class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ",0,Non-plagiarised 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; } public int compareTo(Pair o) { int value = ((Comparable) x).compareTo(o.x); if (value != 0) return value; return ((Comparable) y).compareTo(o.y); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return x.equals(pair.x) && y.equals(pair.y); } public int hashCode() { return Objects.hash(x, y); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } ",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""); } static class WithIdx implements Comparable { int val, idx; public WithIdx(int val, int idx) { this.val = val; this.idx = idx; } @Override public int compareTo(WithIdx o) { if (val == o.val) { return Integer.compare(idx, o.idx); } return Integer.compare(val, o.val); } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } String[] nextStringArray(int n) { String[] res = new String[n]; for (int i = 0; i < n; i++) res[i] = nextToken(); return res; } } static class PrefixSums { long[] sums; public PrefixSums(long[] sums) { this.sums = sums; } public long sum(int fromInclusive, int toExclusive) { if (fromInclusive > toExclusive) throw new IllegalArgumentException(""Wrong value""); return sums[toExclusive] - sums[fromInclusive]; } public static PrefixSums of(int[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } public static PrefixSums of(long[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } } static class ADUtils { static void sort(int[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } static void reverse(int[] arr) { int last = arr.length / 2; for (int i = 0; i < last; i++) { int tmp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = tmp; } } static void sort(long[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } } static class MathUtils { static long[] FIRST_PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051}; static long[] primes(int to) { long[] all = new long[to + 1]; long[] primes = new long[to + 1]; all[1] = 1; int primesLength = 0; for (int i = 2; i <= to; i++) { if (all[i] == 0) { primes[primesLength++] = i; all[i] = i; } for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) { all[(int) (i * primes[j])] = primes[j]; } } return Arrays.copyOf(primes, primesLength); } static long modpow(long b, long e, long m) { long result = 1; while (e > 0) { if ((e & 1) == 1) { /* multiply in this bit's contribution while using modulus to keep * result small */ result = (result * b) % m; } b = (b * b) % m; e >>= 1; } return result; } static long submod(long x, long y, long m) { return (x - y + m) % m; } static long modInverse(long a, long m) { long g = gcdF(a, m); if (g != 1) { throw new IllegalArgumentException(""Inverse doesn't exist""); } else { // If a and m are relatively prime, then modulo // inverse is a^(m-2) mode m return modpow(a, m - 2, m); } } static public long gcdF(long a, long b) { while (b != 0) { long na = b; long nb = a % b; a = na; b = nb; } return a; } } } /* 5 3 2 3 8 8 2 8 5 10 1 */","import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader obj = new FastReader(); PrintWriter out = new PrintWriter(System.out); int l = obj.nextInt(); while (l-- != 0) { int n = obj.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) num[i] = obj.nextInt(); Vector red = new Vector<>(); Vector blue = new Vector<>(); String s = obj.next(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'R') red.add(num[i]); else blue.add(num[i]); } Collections.sort(blue); Collections.sort(red); int c = 1, f = 0; for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < c) { f = 1; break; } c++; } for (int i = 0; i < red.size(); i++) { if (red.get(i) > c) { f = 1; break; } c++; } if (f == 0) out.println(""YES""); else out.println(""NO""); } out.flush(); } } ",1,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; } @Override public int compareTo(Range range) { if (this.low < range.low) { return -1; } else if (this.low == range.low) { return this.high - range.high; } else { return +1; } } } }","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 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static boolean[] isPrime; private static void primes(){ int num = (int)1e6; // PRIMES FROM 1 TO NUM isPrime = new boolean[num]; for (int i = 2; i< isPrime.length; i++) { isPrime[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(isPrime[i] == true) { for(int j = (i*i); j[] adj; static void getAdj(int n,int q, FastReader sc){ adj = new ArrayList[n+1]; for(int i=1;i<=n;i++){ adj[i] = new ArrayList<>(); } for(int i=0;i 0) { 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); } } } }","/* * akshaygupta26 */ 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); } } static class pair{ int x ; int y; pair(int x,int y) { this.x=x; this.y=y; } } static class Maths { static long gcd(long a, long b) { if (a < b) return gcd(b,a); if (b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } ","import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); String[] s = new String[n]; for(int i=0; i pq = new PriorityQueue<>(Collections.reverseOrder()); //Big comes in top; for(int i=0; i 0){ cur += pq.poll(); numberOfWords++; }else{ break; } } MAX = Math.max(MAX, numberOfWords); } pw.println(MAX); } pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ",0,Non-plagiarised 298ee961,392218ef,"import java.util.*; import java.io.*; public class Main { static void print(String s) { System.out.print(s); } static void printLine(String s) { System.out.println(s); } static double parseDouble(String s) { return Double.parseDouble(s.trim()); } static int parseInt(String s) { return Integer.parseInt(s.trim()); } static String[] split(String s) { return s.split(""\\s+""); } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; StringTokenizer st; int test = parseInt(br.readLine()); for (int t = 0; t < test; t++) { int n = parseInt(br.readLine()); ArrayList blue = new ArrayList(); ArrayList red = new ArrayList(); String[] toks = split(br.readLine()); String color = br.readLine(); for (int i = 0; i < n; i++) { if (color.charAt(i) == 'B') { blue.add(parseInt(toks[i])); } else { red.add(parseInt(toks[i])); } } int[] blueArr = new int[blue.size()]; int[] redArr = new int[red.size()]; for (int i = 0; i < blue.size(); i++) { blueArr[i] = blue.get(i); } for (int i = 0; i < red.size(); i++) { redArr[i] = red.get(i); } Arrays.sort(blueArr); Arrays.sort(redArr); int blueP = 0; // pointer int redP = 0; // pointer // blue -> decrease, red -> increase int start = 1; boolean unable = false; while (start <= n) { if (blueP < blueArr.length) { if (blueArr[blueP] < start) { unable = true; printLine(""NO""); break; } else { blueP++; start++; } } else { if (redArr[redP] > start) { unable = true; printLine(""NO""); break; } else { redP++; start++; } } } if (!unable) { printLine(""YES""); } } } } ","import java.util.*; import java.lang.*; import java.io.*; public class Main { static void sort(int a[]){ ArrayList arr=new ArrayList<>(); for(int i=0;i=0){ int n=Integer.parseInt(br.readLine()); int a[]=new int[n]; StringTokenizer st=new StringTokenizer(br.readLine()); for(int i=0;i inc=new ArrayList<>(); ArrayList dec=new ArrayList<>(); for(int i=0;ip)flag=true; p--; } p=1; for(int i=0;i> 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---------- static void sort(int[] a){ ArrayList L = new ArrayList<>(); for (int i : a) L.add(i); Collections.sort(L); for (int i = 0; i < a.length; i++) a[i] = L.get(i); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next(){ while (!st.hasMoreTokens()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } int[] readArray(int n){ int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong(){ return Long.parseLong(next()); } } } ","import java.util.*; 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 long inv(long a, long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } static long mi(long a) { return inv(a, mod); } static InputReader sc = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] A = new int[n]; for (int i = 0; i < A.length; i++) { A[i] = sc.nextInt(); } String word = sc.next(); ArrayList blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < word.length(); i++) { if (word.charAt(i) == 'R') { red.add(A[i]); } else { blue.add(A[i]); } } Collections.sort(blue); Collections.sort(red); boolean possible = true; int a = 1; for (int i = 0; i < blue.size(); i++, a++) { if (blue.get(i) < a) { possible = false; break; } } for (int i = 0; i < red.size(); i++, a++) { if (red.get(i) > a) { possible = false; break; } } if (possible) out.println(""YES""); else out.println(""NO""); } out.flush(); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } public static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } public static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } } ","import java.util.*; public class SolutionB { public static long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ",0,Non-plagiarised 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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ","import java.io.*; 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); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ",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 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader 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;i l = new ArrayList<>(a.length); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } //-----------PrintWriter for faster output--------------------------------- public static FastIO io = new FastIO(); //-----------MyScanner class for faster input---------- static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public String nextLine() { int c; do { c = nextByte(); } while (c < '\n'); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > '\n'); return res.toString(); } public int nextInt() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } } //-------------------------------------------------------- }",0,Non-plagiarised 6de04ee2,d9199dfd,"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'); } } }","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,"//package Div2.C; 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 */ public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList ls = new ArrayList(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + "" ""); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } public static long ceil(long x, long y){ return (x + 0l + y - 1) / y; } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream(""input.txt""); // FileOutputStream out = new FileOutputStream(""output.txt""); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }",0,Non-plagiarised 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; static void init() { fans[0] = 1; inv[0] = 1; fans[1] = 1; inv[1] = 1; for (int i = 2; i < 200001; i++) { fans[i] = ((long) i * fans[i - 1]) % mod; inv[i] = power(fans[i], mod - 2); } } static long ncr(int n, int r) { return (((fans[n] * inv[n - r]) % mod) * (inv[r])) % mod; } 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 power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = ((res % mod) * (x % mod)) % mod; // y must be even now y = y >> 1; // y = y/2 x = ((x % mod) * (x % mod)) % mod; // Change x to x^2 } return res; } 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; } static long[][] generatematrix(FastReader in, int n, int m) throws IOException { long arr[][] = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = in.nextLong(); } } return arr; } static long gcd(long a, long b) { if (a == 0) return b; else return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static void sort(long[] a) { ArrayList l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }","import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; /** * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools */ public class Main { static InputReader sc=new InputReader(System.in); public static void main(String[] args) { // Write your solution here int t=sc.nextInt(); while(t-->0){ solve(); } } private static void solve() { int n=sc.nextInt(); Node left[]=new Node[n]; int index=0; Node ini[]=new Node[n]; int tmp[]=new int[n]; for(int i=0;ileft[index].k){ left[index].k=ini[i].k; }else if(ini[i].s>left[index].k){ index++; left[index]=ini[i]; } } long ans=0; for(int i=0;i<=index;i++){ //System.out.println(left[i].k+"" ""+left[i].s); ans+=(long)(left[i].k-left[i].s+2)*(left[i].k-left[i].s+1)/2; } System.out.println(ans); } } class Node implements Comparable{ int k,s; Node(int k,int s){ this.s=s; this.k=k; } @Override public int compareTo(Node node) { return this.s-node.s; } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } ",0,Non-plagiarised 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); } } } ","/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); PrintWriter out=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int freq[][]=new int[n][5]; int rem[][]=new int[n][5]; for(int i=0;i=0;k--) { if(sum+arr[k]>0) { sum=sum+arr[k]; total++; } else { break; } } ans=Math.max(ans,total); } out.println(ans); } out.flush(); out.close(); } } ",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; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static long modpower(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // SIMPLE POWER FUNCTION=> static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } }"," import java.io.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 ; oset = new HashSet(); int f = 0; int id = 0; ArrayList al = new ArrayList(); for(int i = 0 ; i=val) { // System.out.println(arr[i][j] + "" "" + i + "" "" + j); set.add(j); al.add(arr[i][j]); } } id = i; if(set.size()>=2) { f = 1; break; }else { set.clear(); } } if(f == 0) { return false; } // System.out.println(set); // System.out.println(al); // int g = 1; for(int i = 0 ; i=val) { h = 1; break; } } if(h == 0) { return false; } } return true; } static int cntDivisors(int n){ int cnt = 0; for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { if (n/i == i) cnt++; else cnt+=2; } } return cnt; } public static long findgcd(long[] arr,int v) { int n = arr.length; long g = arr[v]; for(int i = v ; i=l && hi<=r) { for(int i = 0 ; i<27;i++) { ans[i]+= seg[idx][i]; } return ; } if(hir) { return; } int mid = (lo + hi)/2; query(seg,ans,idx*2 +1, lo, mid, l, r); query(seg,ans,idx*2 + 2, mid + 1, hi, l, r); //return Math.min(left, right); } //// for sum // public static void update(int[][]seg,char[]arr,int idx, int lo , int hi , int node , char val) { if(lo == hi) { // seg[idx] += val; seg[idx][val-'a']++; seg[idx][arr[node]-'a']--; }else { int mid = (lo + hi )/2; if(node<=mid && node>=lo) { update(seg,arr, idx * 2 +1, lo, mid, node, val); }else { update(seg,arr, idx*2 + 2, mid + 1, hi, node, val); } //seg[idx] = seg[idx*2 + 1] + seg[idx*2 + 2]; for(int i = 0 ; i<27;i++) { seg[idx][i] = seg[2*idx+1][i] + seg[2*idx + 2][i]; } } } public static int lower_bound(int array[], int low, int high, int key){ // Base Case if (low > high) { return low; } // Find the middle index int mid = low + (high - low) / 2; // If key is lesser than or equal to // array[mid] , then search // in left subarray if (key <= array[mid]) { return lower_bound(array, low, mid - 1, key); } // If key is greater than array[mid], // then find in right subarray return lower_bound(array, mid + 1, high, key); } public static int upper_bound(int arr[], int low, int high, int key){ // Base Case if (low > high || low == arr.length) return low; // Find the value of middle index int mid = low + (high - low) / 2; // If key is greater than or equal // to array[mid], then find in // right subarray if (key >= arr[mid]) { return upper_bound(arr, mid + 1, high, key); } // If key is less than array[mid], // then find in left subarray return upper_bound(arr, low, mid - 1, key); } // ----------------------------------------------------------------------------------------------------------------------------------------------- public static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- public static long modInverse(long a, long m){ long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient long q = a / m; long t = m; // m is remainder now, process // same as Euclid's algo m = a % m; a = t; t = y; // Update x and y y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } //----------------------------------------------------------------------------------------------------------------------------------- //segment tree //for finding minimum in range // public static void build(int [] seg,int []arr,int idx, int lo , int hi) { // if(lo == hi) { // seg[idx] = arr[lo]; // return; // } // int mid = (lo + hi)/2; // build(seg,arr,2*idx+1, lo, mid); // build(seg,arr,idx*2+2, mid +1, hi); // seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]); // } ////for finding minimum in range //public static int query(int[]seg,int idx , int lo , int hi , int l , int r) { // if(lo>=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]; // //} //} //--------------------------------------------------------------------------------------------------------------------------------------- static void shuffleArray(long[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } //----------------------------------------------------------------------------------------------------------------------------------------------------------- } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //------------------------------------------------------------------------------------------------------------------------------------------------------------ class SegmentTree{ int n; public SegmentTree(int[] arr,int n) { this.arr = arr; this.n = n; } int[] arr = new int[n]; // int n = arr.length; int[] seg = new int[4*n]; void build(int idx, int lo , int hi) { if(lo == hi) { seg[idx] = arr[lo]; return; } int mid = (lo + hi)/2; build(2*idx+1, lo, mid); build(idx*2+2, mid +1, hi); seg[idx] = Math.min(seg[2*idx+1],seg[2*idx+2]); } int query(int idx , int lo , int hi , int l , int r) { if(lo<=l && hi>=r) { return seg[idx]; } if(hir) { return Integer.MAX_VALUE; } int mid = (lo + hi)/2; int left = query(idx*2 +1, lo, mid, l, r); int right = query(idx*2 + 2, mid + 1, hi, l, r); return Math.min(left, right); } } //----------------------------------------------------------------------------------------------------------------------------------------------------------- class coup{ char a; int b; public coup(char a , int b) { this.a = a; this.b = b; } } class trip{ int a , b, c; public trip(int a , int b, int c) { this.a = a; this.b = b; this.c = c; } } //--------------------------------------------------------------------------------------------------------------------------------------------------------------- ",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 al=new ArrayList<>(); for(int x:a)al.add(x); Collections.sort(al); for(int i=0;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); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i 0) { 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 FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } 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 long[] longArr(int size) { long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static LinkedList[] graphD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList aa:temp) System.out.println(aa); } static long cal(long val, long pow, long mod) { if(pow == 0) return 1; long res = cal(val, pow/2, mod); long ret = (res*res)%mod; if(pow%2 == 0) return ret; return (val*ret)%mod; } static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); } } static int mod = (int) 1e9 + 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 String sortString(String s) { char temp[] = s.toCharArray(); Arrays.sort(temp); return new String(temp); } static class Pair implements Comparable { String a; int b; public Pair(String a, int b) { this.a = a; this.b = b; } // to sort first part // public int compareTo(Pair other) { // if (this.a == other.a) return other.b > this.b ? -1 : 1; // else if (this.a > other.a) return 1; // else return -1; // } public int compareTo(Pair other) { // if (this.b == other.b) return 0; if (this.b > other.b) return 1; else return -1; } //sort on the basis of first part only // public int compareTo(Pair other) { // if (this.a == other.a) return 0; // else if (this.a > other.a) return 1; // else return -1; // } } static int[] frequency(String s){ int fre[]= new int[26]; for (int i=0;i0){ long lastBit=n&1; if (lastBit==1){ ans=(int)mul(ans,a); } a=(int)mul(a,a); n>>=1; } return ans; } static int[] find(int n, int start, int diff) { int a[] = new int[n]; a[0] = start; for (int i = 1; i < n; i++) a[i] = a[i - 1] + diff; return a; } static void swap(int a, int b) { int c = a; a = b; b = c; } static void printArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } static boolean sorted(int a[]) { int n = a.length; boolean flag = true; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) flag = false; } if (flag) return true; else return false; } public static int findlog(long n) { if (n == 0) return 0; if (n == 1) return 0; if (n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if (den == 0) return 0; return (int) (num / den); } public static long gcd(long a, long b) { if (b % a == 0) return a; return gcd(b % a, a); } public static int gcdInt(int a, int b) { if (b % a == 0) return a; return gcdInt(b % a, a); } static void sortReverse(int[] a) { ArrayList l = new ArrayList<>(); for (int i : a) l.add(i); // Collections.sort.(l); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayLong(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }"," import java.io.*; import java.util.*; import java.lang.Math; public class Main { static PrintWriter pw; static Scanner sc; static StringBuilder ans; static long mod = 1000000000+7; static void pn(final Object arg) { pw.print(arg); pw.flush(); } /*-------------- for input in an value ---------------------*/ static int ni() { return sc.nextInt(); } static long nl() { return sc.nextLong(); } static double nd() { return sc.nextDouble(); } static String ns() { return sc.next(); } static void ap(int arg) { ans.append(arg); } static void ap(long arg) { ans.append(arg); } static void ap(String arg) { ans.append(arg); } static void ap(StringBuilder arg) { ans.append(arg); } /*-------------- for input in an array ---------------------*/ static void inputIntegerArray(int arr[]){ for(int i=0; i not prime // false->prime sv[0] = sv[1] = true; sv[2] = false; for(int i = 0; i< sv.length; i++) { if( !sv[i] && (long)i*(long)i < sv.length ) { for ( int j = i*i; j 0) { if ( (b & 1) > 0){ res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return res; } static long factorial(long n) { long res = 1, i; for (i = 2; i <= n; i++){ res = ((res%mod) * (i%mod))%mod; } return res; } static class Pair { int idx; int v; Pair(int idx, int v){ this.idx = idx; this.v = v; } } public static void main(String[] args) throws Exception { // runFile(); runIo(); int t; t = 1; // t = sc.nextInt(); ans = new StringBuilder(); while( t-- > 0 ) { solve(); } pn(ans+""""); } static int N ; static int M ; static ArrayList f; static ArrayList e; static long dp[][]; static long find(int i, int j ) { if( i == N ) return 0; if( j == M ) return Integer.MAX_VALUE; if (dp[i][j] != -1 ) return dp[i][j]; return dp[i][j] = Math.min( find(i, j+1), Math.abs(f.get(i)-e.get(j)) + find(i+1, j+1) ); } public static void solve() { int n = ni(); f = new ArrayList(); e = new ArrayList(); for(int i = 0; i { 0, 1, 5 } // 0s -> { 2, 3, 6, 7 } ",1,Plagiarised 3a318b43,90b71536,"import java.lang.reflect.Array; import java.util.*; import java.io.*; import java.util.regex.Pattern; public class B2 { public static int getBit(int pos,int num){ int no = 1 << pos; return no & num; } public static boolean palindrome(String s){ StringBuilder s1 = new StringBuilder(); for(int i=s.length();i>=0;i--){ s1.append(s.charAt(i)); } String s2 = s1.toString(); if(s.equals(s2)){ return true; } return false; } public static void permutation(ArrayList arr,int l, int r,String ans,HashMap map,char[] temp){ if(l>r){ //System.out.println(ans); arr.add(ans); return; } for(char c:temp) { if (map.get(c) > 0) { map.put(c, map.get(c) - 1); permutation(arr, l + 1, r, ans + c, map,temp); map.put(c, map.get(c) + 1); } } } public static long[] maxBeauty(HashMap[] arr, long[] lv,long[] rv,int start,int parent,boolean[] vis){ vis[start] = true; long[] ans = new long[2]; // System.out.println(start); ArrayList 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= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/gcd(a, b); } public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } static long func(long a[],int size,int s){ long max1=a[s]; long maxc=a[s]; for(int i=s+1;i, 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 String toString() { return String.format(""(%s, %s)"", x.toString(), y.toString()); } } static class MultiSet> { public int sz = 0; public TreeMap t; public MultiSet() { t = new TreeMap<>(); } public void add(U x) { t.put(x, t.getOrDefault(x, 0) + 1); sz++; } public void remove(U x) { if (t.get(x) == 1) t.remove(x); else t.put(x, t.get(x) - 1); sz--; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static long myceil(long a, long b){ return (a+b-1)/b; } static long C(long n,long r){ long count=0,temp=n; long ans=1; long num=n-r+1,div=1; while(num<=n){ ans*=num; //ans+=MOD; ans%=MOD; ans*=mypow(div,MOD-2); //ans+=MOD; ans%=MOD; num++; div++; } ans+=MOD; return ans%MOD; } static long fact(long a){ long i,ans=1; for(i=1;i<=a;i++){ ans*=i; ans%=MOD; } return ans%=MOD; } static void sieve(int n){ is_sieve[0]=1; is_sieve[1]=1; int i,j,k; for(i=2;in||j<0){ break; } is_sieve[j]=1; sieve[j]=i; } } } } // 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 mypow(long x,long y){ long temp; if( y == 0) return 1; temp = mypow(x, y/2); if (y%2 == 0) return (temp*temp)%MOD; else return ((x*temp)%MOD*(temp)%MOD)%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 list = new ArrayList<>(); for(long i : arr) list.add(i); Collections.sort(list); for(int i = 0; i < list.size(); i++) arr[i] = list.get(i); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st; while (t-- > 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; } ruffleSort(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 int compareTo(Pair other) { if (this.f != other.f) return this.f - other.f; return this.s - other.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 int compareTo(Pair other) { if (this.f != other.f) return this.f - other.f; return this.s - other.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 { static class Pair{ long x; long y; Pair(long x,long y){ this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + "" "" + arr[i].y + "" ""); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int solve(int dp[][] , ArrayList one , ArrayList zero , int i,int j) { int n=one.size(); int m=zero.size(); if(i>=n) return 0; else if(j>=m) return Integer.MAX_VALUE; else if(dp[i][j]!=-1) return dp[i][j]; int val1 = Math.abs(one.get(i)-zero.get(j))+solve(dp, one ,zero ,i+1,j+1); int val2 = solve(dp , one , zero , i,j+1); dp[i][j]= Math.min(val1,val2); return dp[i][j]; } 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,"//Siddhartha Bose 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 class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static 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{ private int a; private int b; private int d; private int c; pair3(int a,int b,int c,int d){ this.a=a; this.d=d; this.b=b; this.c=c; } @Override public int compareTo(pair3 c) { if(c.b-c.a!=this.b-this.a) { return Integer.compare(c.b-c.a, this.b-this.a); }else { return Integer.compare(this.c, c.c); } } } static class pair2 implements Comparable{ private int a; private int b; private int d; private int c; pair2(int a,int b,int c,int d){ this.a=a; this.d=d; this.b=b; this.c=c; } public int compareTo(pair2 c) { if(c.b!=this.b) { return Integer.compare(c.b, this.b); }else { if(c.c!=this.c) { return Integer.compare(this.c, c.c); }else { return Integer.compare(this.a, c.a); } } } } static boolean r(int k) { for(int i=2;i<=k/2;i++) { if(k%i==0) { return false; } } return true; } public static int[] is_prime=new int[100001]; public static ArrayList primes=new ArrayList<>(); public static void sieve() { long maxN=100; for(long i=1;i<=maxN;i++) { is_prime[(int) i]=1; } is_prime[0]=0; is_prime[1]=0; for(long i=2;i*i<=maxN;i++) { if(is_prime[(int) i]!=0) { primes.add( i); long c=1; for(long j=i*i;j<=maxN;j+=i) { is_prime[(int) j]++; } } } for(long i=2;i<=maxN;i++) { is_prime[(int) i]=is_prime[(int) (i-1)]+is_prime[(int) i]; } // int count=0; // for(long i=1;i<=maxN;i++) { // if(is_prime[(int) i]==1) { // count++; // } // if(is_prime[count]==1) { // arr[(int) i]=1; // }else { // arr[(int)i]=0; // } // } } public static long[] merge_sort(long[] A, int start, int end) { if (end > start) { int mid = (end + start) / 2; long[] v = merge_sort(A, start, mid); long[] o = merge_sort(A, mid + 1, end); return (merge(v, o)); } else { long[] y = new long[1]; y[0] = A[start]; return y; } } static ArrayList[] f1=new ArrayList[100001]; public static long[] merge(long a[], long b[]) { // int count=0; long[] temp = new long[a.length + b.length]; int m = a.length; int n = b.length; int i = 0; int j = 0; int c = 0; while (i < m && j < n) { if (a[i] < b[j]) { temp[c++] = a[i++]; } else { temp[c++] = b[j++]; } } while (i < m) { temp[c++] = a[i++]; } while (j < n) { temp[c++] = b[j++]; } return temp; } }","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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ",0,Non-plagiarised c9159d9c,f0ede32a,"import java.util.*; public class SolutionB { public static long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ","import java.util.*; public class 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(); } static int find(int v, int[] u) { if (v == u[v]) { return v; } return u[v] = find(u[v], u); } static int abs(int a) { return a < 0 ? -a : a; } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point { int x; int y; public Point(int start, int end) { this.x = start; this.y = end; } public String toString() { return x + "" "" + y; } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; data[index] %= MOD; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; result %= MOD; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return (val * val); } else { return (val * ((val * a))); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""input.txt"")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; public class TaskB { static long mod = 1000000007; static FastScanner scanner; static final StringBuilder result = new StringBuilder(); public static void main(String[] args) { // 2 : 1000000000 scanner = new FastScanner(); int T = scanner.nextInt(); for (int t = 0; t < T; t++) { solve(t + 1); result.append(""\n""); } System.out.println(result); } static void solve(int t) { int n = scanner.nextInt(); int[] a = scanner.nextIntArray(n); String s = scanner.nextToken(); List blue = new ArrayList<>(); List red = new ArrayList<>(); for (int i = 0; i < n; i++) { if (s.charAt(i) == 'B') { blue.add(a[i]); } else { red.add(a[i]); } } Collections.sort(blue); Collections.sort(red); for (int i = 0; i < blue.size(); i++) { if (blue.get(i) < i + 1) { result.append(""NO""); return; } } for (int i = 0; i < red.size(); i++) { if (red.get(i) > i + 1 + blue.size()) { result.append(""NO""); return; } } result.append(""YES""); } static class WithIdx implements Comparable { int val, idx; public WithIdx(int val, int idx) { this.val = val; this.idx = idx; } @Override public int compareTo(WithIdx o) { if (val == o.val) { return Integer.compare(idx, o.idx); } return Integer.compare(val, o.val); } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } String[] nextStringArray(int n) { String[] res = new String[n]; for (int i = 0; i < n; i++) res[i] = nextToken(); return res; } } static class PrefixSums { long[] sums; public PrefixSums(long[] sums) { this.sums = sums; } public long sum(int fromInclusive, int toExclusive) { if (fromInclusive > toExclusive) throw new IllegalArgumentException(""Wrong value""); return sums[toExclusive] - sums[fromInclusive]; } public static PrefixSums of(int[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } public static PrefixSums of(long[] ar) { long[] sums = new long[ar.length + 1]; for (int i = 1; i <= ar.length; i++) { sums[i] = sums[i - 1] + ar[i - 1]; } return new PrefixSums(sums); } } static class ADUtils { static void sort(int[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } static void reverse(int[] arr) { int last = arr.length / 2; for (int i = 0; i < last; i++) { int tmp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = tmp; } } static void sort(long[] ar) { Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap long a = ar[index]; ar[index] = ar[i]; ar[i] = a; } Arrays.sort(ar); } } static class MathUtils { static long[] FIRST_PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051}; static long[] primes(int to) { long[] all = new long[to + 1]; long[] primes = new long[to + 1]; all[1] = 1; int primesLength = 0; for (int i = 2; i <= to; i++) { if (all[i] == 0) { primes[primesLength++] = i; all[i] = i; } for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) { all[(int) (i * primes[j])] = primes[j]; } } return Arrays.copyOf(primes, primesLength); } static long modpow(long b, long e, long m) { long result = 1; while (e > 0) { if ((e & 1) == 1) { /* multiply in this bit's contribution while using modulus to keep * result small */ result = (result * b) % m; } b = (b * b) % m; e >>= 1; } return result; } static long submod(long x, long y, long m) { return (x - y + m) % m; } static long modInverse(long a, long m) { long g = gcdF(a, m); if (g != 1) { throw new IllegalArgumentException(""Inverse doesn't exist""); } else { // If a and m are relatively prime, then modulo // inverse is a^(m-2) mode m return modpow(a, m - 2, m); } } static public long gcdF(long a, long b) { while (b != 0) { long na = b; long nb = a % b; a = na; b = nb; } return a; } } } /* 5 3 2 3 8 8 2 8 5 10 1 */",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; } public static void sort(long[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int idx = (int) Math.random() * n; long temp = arr[i]; arr[i] = arr[idx]; arr[idx] = temp; } Arrays.sort(arr); } public static void print(long[] dp) { for (long ele : dp) { System.out.print(ele + "" ""); } System.out.println(); } public static void print(long[][] dp) { for (long[] a : dp) { for (long ele : a) { System.out.print(ele + "" ""); } System.out.println(); } } } ",0,Non-plagiarised 3b498a39,69b2fd22,"/* * HI THERE! (: * * CREATED BY : NAITIK V * * JAI HIND * */ import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static long dp[][]; static int mod=1000000007; 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 { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static 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 void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","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;i0) { int n = sc.nextInt(); char[] s = new char[n]; char[] t = new char[n]; s = sc.next().toCharArray(); t = sc.next().toCharArray(); int a = 0, b = 0, c = 0, d = 0; for(int i = 0; i < n; i++) { if(s[i] == '0' && t[i] == '0') a++; if(s[i] == '1' && t[i] == '0') b++; if(s[i] == '0' && t[i] == '1') c++; if(s[i] == '1' && t[i] == '1') d++; } int res = Integer.MAX_VALUE; if(b == c || b+1 == c) { if((b + c) % 2 == 0) { res = Math.min(res, b + c); } } if(a == d || a+1 == d) { if((a + d) % 2 == 1) { res = Math.min(res, a + d); } } if(res == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(res); } } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } } ","import java.util.*; import java.io.*; public class C { public static void main(String[] args) { FastScanner sc = new FastScanner(); int T = sc.nextInt(); while(T-->0) { int n = sc.nextInt(); char[] s = new char[n]; char[] t = new char[n]; s = sc.next().toCharArray(); t = sc.next().toCharArray(); int a = 0, b = 0, c = 0, d = 0; for(int i = 0; i < n; i++) { if(s[i] == '0' && t[i] == '0') a++; if(s[i] == '1' && t[i] == '0') b++; if(s[i] == '0' && t[i] == '1') c++; if(s[i] == '1' && t[i] == '1') d++; } int res = Integer.MAX_VALUE; if(b == c || b+1 == c) { if((b + c) % 2 == 0) { res = Math.min(res, b + c); } } if(a == d || a+1 == d) { if((a + d) % 2 == 1) { res = Math.min(res, a + d); } } if(res == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(res); } } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } } ",1,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; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int ni() throws IOException { return Integer.parseInt(next()); } public long nl() throws IOException { return Long.parseLong(next()); } public int[] nia(int n) throws IOException { int a[] = new int[n]; String sa[] = br.readLine().split("" ""); for (int i = 0; i < n; i++) a[i] = Integer.parseInt(sa[i]); return a; } public long[] nla(int n) throws IOException { long a[] = new long[n]; String sa[] = br.readLine().split("" ""); for (int i = 0; i < n; i++) a[i] = Long.parseLong(sa[i]); return a; } public void sort(int[] a) { ArrayList l = new ArrayList<>(); for (int v : a) l.add(v); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public void sort(long[] a) { ArrayList l = new ArrayList<>(); for (long v : a) l.add(v); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } } }"," 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()); } static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i{ A first; B second; public Pair(A first, B second){ this.first = first; this.second = second; } } static long mod(String num, long a) { // Initialize result long res = 0; // One by one process all digits of 'num' for (int i = 0; i < num.length(); i++) res = (res*10 + num.charAt(i) - '0') %a; return res; } static long binomialCoeff(long n, long k, long MOD) { long res = 1; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); res %= MOD; } return res; } static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more than or // equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static long modInverse(long n, long p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static long nCrModPFermat(int n, int r, long p) { // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r long[] fac = new long[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } } ",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;in) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long pow(long a,long b) { long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i= 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; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }",0,Non-plagiarised c9159d9c,fae0662f,"import java.util.*; public class SolutionB { public static long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ","import java.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(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } String nextLine() throws IOException { return br.readLine(); } } } ",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 '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } ",0,Non-plagiarised d12f26f0,df594a00,"import java.io.*; import java.util.*; public class AirConditioners { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int q = readInt(); while (q-- > 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 long readLong() throws IOException { return Long.parseLong(next()); } static int readInt() throws IOException { return Integer.parseInt(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readCharacter() throws IOException { return next().charAt(0); } 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= size[setB]) { parent[setB] = setA; size[setA] += size[setB]; } else { parent[setA] = setB; size[setB] += size[setA]; } } } /* ======================================================== */ static class Pair implements Comparator { long x; long y; // Constructor public Pair(long x, long y) { this.x = x; this.y = y; } public Pair() { } @Override public int compare(Main.Pair o1, Main.Pair o2) { return ((int) (o1.x - o2.x)); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] intArr(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] longArr(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } static FastReader f = new FastReader(); static BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int LowerBound(int a[], int x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long power(long x, long y) { long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int power(int x, int y) { int res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } /* * ===========Modular Operations================== */ static long modInverse(long n, long p) { return power(n, p - 2, p); } static long modAdd(long a, long b) { return (a % mod + b % mod) % mod; } static long modMul(long a, long b) { return ((a % mod) * (b % mod)) % mod; } static long nCrModPFermat(int n, int r) { long p = 1000000007; if (r == 0) return 1; long[] fac = new long[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } /* * =============================================== */ static List removeDup(ArrayList list) { List newList = list.stream().distinct().collect(Collectors.toList()); return newList; } static void ruffleSort(long[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } /* * ===========Dynamic prog Recur Section=========== */ static int DP[][]; static ArrayList> g; static int count = 0; static ArrayList bitMask(ArrayList ar, int n) { ArrayList ans = new ArrayList<>(); for (int mask = 0; mask <= Math.pow(2, n) - 1; mask++) { long sum = 0; for (int i = 0; i < n; i++) { if (((1 << i) & mask) > 0) { sum += ar.get(i); } } ans.add(sum); } return ans; } /* * ====================================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 long gcd(long a, long b){ if(b==0){ return a; } return gcd(b, a%b); } public static long gcdSum(long b){ long a = 0; long temp = b; while(temp!=0){ a = a + temp%10; temp = temp/10; } return gcd(a,b); } public static class Pair{ Long a; Long b; public Pair(Long a, Long b) { this.a = a; this.b = b; } } public static long factorial (long n){ if(n==0) return 1; else if(n==1) return n; return n * factorial(n-1); } public static long lcm (long n){ if(n<3) return n; return lcmForBig(n,n-1); } private static long lcmForBig(long n, long l) { if(l==1) return n; n = (n * l) / gcd(n, l); return lcmForBig(n, l-1); } public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int i =0;i blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for(int j=0;jcounter){ counter++; } else{ ans=""NO""; break; } } if(ans==""NO""){ System.out.println(ans); } else{ int tempCounter = n+1; Collections.sort(red); for(int j=red.size()-1;j>=0;j--){ int current = red.get(j); if(current>=tempCounter){ ans=""NO""; break; } else{ tempCounter--; } } if(tempCounter-counter!=1) System.out.println(""NO""); else System.out.println(ans); } } return; } } ","import java.util.*; public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i R=new Vector<>(); Vector B=new Vector<>(); for(int i=0;in+1){System.out.println(""NO"");yes=false;break;} } } if(yes)System.out.println(""YES""); } sc.close(); } } ",0,Non-plagiarised 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); static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); 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; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } static long modpower(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // SIMPLE POWER FUNCTION=> static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } }","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n, _00 = 0, _01 = 0, _11 = 0, _10 = 0; n = in.nextInt(); char[] s = in.next().toCharArray(); char[] s1 = in.next().toCharArray(); for (int i = 0; i < n; i++) { if(s[i]==s1[i]){ if(s[i]=='0'){ _00++; } else{ _11++; } } else{ if(s[i]=='0'){ _01++; } else{ _10++; } } } int ans = Integer.MAX_VALUE; if(_10 ==_01){ ans = 2*_01; } if(_11 == _00 + 1){ ans = Math.min(ans, 2*_00 + 1); } if(ans == Integer.MAX_VALUE){ out.println(-1); } else{ out.println(ans); } } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } } static class arrayListClass { ArrayList arrayList2 ; public arrayListClass(ArrayList arrayList) { this.arrayList2 = arrayList; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 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); } static void B2() { int n = sc.nextInt(); int k = sc.nextInt(); ArrayList> al = new ArrayList<>(); for (int i = 0; i <= n; i++) { al.add(new ArrayList<>()); } int ans[] = new int[n + 1]; for (int i = 0; i < n; i++) { int x = sc.nextInt(); al.get(x).add(i + 1); } ArrayList temp = new ArrayList<>(); for (ArrayList ind : al) { if (ind.size() >= k) { for (int i = 0; i < k; i++) { ans[ind.get(i)] = i + 1; } } else { temp.addAll(ind); } } int color = 0; for (int i = 0; i < temp.size() / k; i++) { for (int j = i * k; j < i * k + k; j++) { ans[temp.get(j)] = ++color; if (color == k) color = 0; } } for (int i = 1; i <= n; i++) { System.out.print(ans[i] + "" ""); } System.out.println(); } static void B1() { String s = sc.next(); HashMap map = new HashMap<>(); for (char ch : s.toCharArray()) { map.put(ch, map.getOrDefault(ch, 0) + 1); } if (s.length() < 2) { System.out.println(0); return; } int s1 = 0; for (int v : map.values()) { if (v > 2) { s1 += 2; } else { s1 += v; } } System.out.println(s1 / 2); } static void A() { int n = sc.nextInt(); if (n % 3 == 0) { System.out.println(n / 3 + "" "" + n / 3); } else if (n % 3 == 1) { System.out.println((n / 3 + 1) + "" "" + (n / 3)); } else { System.out.println((n / 3) + "" "" + (n / 3 + 1)); } } static boolean[] seiveOfEratosthenes(int n) { boolean[] isPrime = new boolean[n + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n; i++) { for (int j = i * i; j <= n; j += i) { isPrime[j] = false; } } return isPrime; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static boolean isPrime(long n) { if (n < 2) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(next()); } return a; } void printIntArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } long[] readLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = Long.parseLong(next()); } return a; } void printLongArray(long a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ","import java.io.*; import java.util.*; public class 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{ private int[] aI(InputReader in, int n) { int A[]= new int[n]; for(int i=0; i{ private final F first; //first member of pair private final S second; //second member of pair private Pair(F first, S second) { this.first = first; this.second = second; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; if(!first.equals(pair.first)) return false; return second.equals(pair.second); } @Override public int hashCode() { return 31 * first.hashCode() + second.hashCode(); } @Override public String toString() { return ""("" + first +"", ""+ second +"")""; } public static Pair of(F a, S b) { return new Pair<>(a,b); } public F getFirst() { return first; } public S getSecond() { return second; } } // Comparator for using in Sorting On integers static class PairCompare implements Comparator> { @Override public int compare(Pair p1, Pair p2) { int diff = Integer.compare(p1.first, p2.first); if(diff == 0) { return Integer.compare(p1.second, p2.second); } else return diff; } } public static void main(String[] args) throws IOException { //initialize InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Code solver = new Code(); solver.solve(in, out); out.flush(); out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private InputReader(InputStream stream) { this.stream = stream; } private int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } private String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } private long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } private double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } private boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public String next() { return readString(); } private static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; private OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter( outputStream))); } private OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } private void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } writer.flush(); } private void printLine(Object... objects) { print(objects); writer.println(); writer.flush(); } private void printLine(int i) { writer.println(i); } private void close() { writer.close(); } private void flush() { writer.flush(); } } static class IOUtils { private static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } private static long[] readLongArray(InputReader in, int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) array[i] = in.readLong(); return array; } private static char[] readCharArray(InputReader in, int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) array[i] = in.readCharacter(); return array; } private static char[][] readTable(InputReader in, int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readCharArray(in, columnCount); return table; } } static class ArrayUtils { private static void fill(int[][] array, int value) { for (int[] row : array) Arrays.fill(row, value); } } static class MiscUtils { private static final int[] DX4 = {1, 0, -1, 0}; private static final int[] DY4 = {0, -1, 0, 1}; private static boolean isValidCell(int row, int column, int rowCount, int columnCount) { return row >= 0 && row < rowCount && column >= 0 && column < columnCount; } } }",1,Plagiarised 4da08761,a5d5a95f,"import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; /** * Built using CHelper plug-in * Actual solution is at the top */ 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); Main solver = new Main(); boolean multipleTC = true; int testCount = multipleTC ? Integer.parseInt(in.next()) : 1; for (int i = 1; i <= testCount; i++) solver.solve(in, out, i); out.close(); } static class Main { PrintWriter out; InputReader in; public void solve(InputReader in, PrintWriter out, int test) { this.out = out; this.in = in; int n = ni(); String[] arr = new String[n]; int[][] freq = new int[n][5]; int[][] rem = new int[n][5]; for(int i = 0; i < n; i++){ arr[i] = n(); for(int j = 0; j < arr[i].length(); j++) freq[i][arr[i].charAt(j) - 'a']++; for(int j = 0; j < 5; j++) rem[i][j] = arr[i].length() - freq[i][j]; } int ans = 0; for(int i = 0; i < 5; i++){ int[] vals = new int[n]; for(int j = 0; j < n; j++) vals[j] = freq[j][i] - rem[j][i]; Arrays.sort(vals); int sum = 0, x = 0; for(int j = n - 1; j >= 0; j--){ if(sum + vals[j] > 0){ x++; sum += vals[j]; } else { break; } } if(x > ans) { ans = x; } } pn(ans); } int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } String n(){ return in.next(); } int ni() { return in.nextInt(); } long nl() { return in.nextLong(); } void pn(long zx) { out.println(zx); } void pn(String sz) { out.println(sz); } void pn(double dx){ out.println(dx); } class Tuple { long x; long y; Tuple(long a, long b) { x = a; y = b; } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new UnknownError(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new UnknownError(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }","import java.util.*; import java.io.*; public class Main { // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try {br = new BufferedReader( new FileReader(""input.txt"")); PrintStream out = new PrintStream(new FileOutputStream(""output.txt"")); System.setOut(out);} catch(Exception e) { br = new BufferedReader(new InputStreamReader(System.in));} } String next() { while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace();} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() {return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of fast i/o code public static void main(String[] args) { FastReader reader = new FastReader(); int Q = reader.nextInt(); outer: for (int q = 0; q < Q; q++) { int N = reader.nextInt(); int[][] scores = new int[5][N]; for (int i = 0; i < N; i++) { int[] occurs = new int[5]; String word = reader.next(); for (int j = 0; j < word.length(); j++) { occurs[word.charAt(j) - 'a']++; } for (int j = 0; j < 5; j++) { scores[j][i] = occurs[j] - (word.length() - occurs[j]) ; } } int bestCount = 0; for (int i = 0; i < 5; i++) { int[] curr = scores[i]; Arrays.sort(curr); int currentCount = 1; int currentScore = curr[curr.length - 1]; for (int j = curr.length - 2; j >= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ",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; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try{ st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }","import java.util.*; 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 static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try {br = new BufferedReader( new FileReader(""input.txt"")); PrintStream out = new PrintStream(new FileOutputStream(""output.txt"")); System.setOut(out);} catch(Exception e) { br = new BufferedReader(new InputStreamReader(System.in));} } String next() { while (st == null || !st.hasMoreElements()) { try {st = new StringTokenizer(br.readLine());} catch (IOException e) { e.printStackTrace();} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() {return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of fast i/o code public static void main(String[] args) { FastReader reader = new FastReader(); int Q = reader.nextInt(); outer: for (int q = 0; q < Q; q++) { int N = reader.nextInt(); int[][] scores = new int[5][N]; for (int i = 0; i < N; i++) { int[] occurs = new int[5]; String word = reader.next(); for (int j = 0; j < word.length(); j++) { occurs[word.charAt(j) - 'a']++; } for (int j = 0; j < 5; j++) { scores[j][i] = occurs[j] - (word.length() - occurs[j]) ; } } int bestCount = 0; for (int i = 0; i < 5; i++) { int[] curr = scores[i]; Arrays.sort(curr); int currentCount = 1; int currentScore = curr[curr.length - 1]; for (int j = curr.length - 2; j >= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ","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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ",0,Non-plagiarised 0588b869,69b2fd22,"import java.util.*; import java.io.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static final long mod=(long)1e9+7; public static long pow(long a,int p) { long res=1; while(p>0) { if(p%2==1) { p--; res*=a; res%=mod; } else { a*=a; a%=mod; p/=2; } } return res; } static class Pair { int u,v,w; Pair(int u,int v,int w) { this.u=u; this.v=v; this.w=w; } } /*static class Pair implements Comparable { int v,l; Pair(int v,int l) { this.v=v; this.l=l; } public int compareTo(Pair p) { return l-p.l; } }*/ static int gcd(int a,int b) { if(b%a==0) return a; return gcd(b%a,a); } public static void dfs(int u,int dist[],int sub[],int mxv[],int par[],ArrayList edge[]) { sub[u]=1; for(int v:edge[u]) { if(dist[v]==-1) { par[v]=u; dist[v]=dist[u]+1; dfs(v,dist,sub,mxv,par,edge); if(sub[v]+1>sub[u]) { sub[u]=sub[v]+1; mxv[u]=v; } } } } public static void main(String args[])throws Exception { FastReader fs=new FastReader(); PrintWriter pw=new PrintWriter(System.out); //int tc=fs.nextInt(); int n=fs.nextInt(); int a[]=new int[n]; for(int i=0;i o=new ArrayList<>(); ArrayList z=new ArrayList<>(); for(int i=0;i0) { int n=input.nextInt(); int a[]=new int[n]; ArrayList list=new ArrayList<>(); ArrayList space=new ArrayList<>(); for(int i=0;i> 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]); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ",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;i { @Override public int compare(Pair a, Pair b) { if(a.x!=b.x) { return (int)(a.x - b.x); } else { return (int)(a.y-b.y); } } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + "" "" + arr[i].y + "" ""); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuilder res = new StringBuilder(); int tc = sc.nextInt(); while(tc-->0) { 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); } public static void fac(int n) { BigInteger b = new BigInteger(""1""); for (int i = 1; i <= n; i++) { b = b.multiply(BigInteger.valueOf(i)); } System.out.println(b); } static void ruffleSort(long[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } } class pm { int ini, fin; pm(int a, int b) { this.ini = a; this.fin = b; } } class surt implements Comparator { @Override public int compare(pm o1, pm o2) { // TODO Auto-generated method stub int a = o1.ini - o2.ini, b = o1.fin - o2.fin; if (a < 0) return -1; if (a == 0) { if (b < 0) return -1; else return 1; } else return 1; } } class pair { int x, y; pair(int a, int b) { this.x = a; this.y = b; } public int hashCode() { return x * 31 + y * 31; } public boolean equals(Object other) { if (this == other) return true; if (other instanceof pair) { pair pt = (pair) other; return pt.x == this.x && pt.y == this.y; } else return false; } } class sort implements Comparator { @Override public int compare(pair o1, pair o2) { // TODO Auto-generated method stub long a = o1.x - o2.x, b = o1.y - o2.y; if (b < 0) return -1; else if (a == 0) { if (a < 0) return -1; else return 1; } else return 1; } }","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 jdk.nashorn.internal.parser.Scanner; 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 ; public static long dp (int idx,int time){ if ( idx == n){ return 0; } if (memo[idx][time] != -1){ return memo[idx][time]; } long take = 0; if (3 * w*depth[idx] <= time){ take = values[idx]+ dp(idx+1, time-3*w*depth[idx]); } long leave = dp(idx+1, time); return memo[idx][time]=Math.max(take, leave); } static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Object o){ Pair p = (Pair) o; return p.y -y; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public boolean hasNext() { // TODO Auto-generated method stub return false; } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder(""0""); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder(""0""); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } } ","//import jdk.nashorn.internal.parser.Scanner; 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 ; public static long dp (int idx,int time){ if ( idx == n){ return 0; } if (memo[idx][time] != -1){ return memo[idx][time]; } long take = 0; if (3 * w*depth[idx] <= time){ take = values[idx]+ dp(idx+1, time-3*w*depth[idx]); } long leave = dp(idx+1, time); return memo[idx][time]=Math.max(take, leave); } static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Object o){ Pair p = (Pair) o; return p.y -y; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public boolean hasNext() { // TODO Auto-generated method stub return false; } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder(""0""); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder(""0""); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } } ",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; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream i) { br = new BufferedReader(new InputStreamReader(i)); st = new StringTokenizer(""""); } public String next() throws IOException { if (st.hasMoreTokens()) return st.nextToken(); else st = new StringTokenizer(br.readLine()); return next(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } } } ","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=x; } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList add(int id,int c) { ArrayList newArr=new ArrayList<>(); for(int i=0;i arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } static int lower(ArrayList arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } static int N = 501; // 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet factors(int x) { HashSet a=new HashSet(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap findFactors(long n2) { HashMap ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i primes; static HashSet primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? ""YES"" : ""NO""); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static 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 double sum[]; static long cnt; // 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; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } "," 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); static int[] sp; static int size=(int)1e6; static int[] arInt; static long[] arLong; 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=x; } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList add(int id,int c) { ArrayList newArr=new ArrayList<>(); for(int i=0;i arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } static int lower(ArrayList arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } static int N = 501; // 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet factors(int x) { HashSet a=new HashSet(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap findFactors(long n2) { HashMap ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i primes; static HashSet primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? ""YES"" : ""NO""); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static 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 double sum[]; static long cnt; // 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; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } ",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{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){br = new BufferedReader( new InputStreamReader(System.in));} String next(){ while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) {e.printStackTrace();}} return st.nextToken();} int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next());} float nextFloat() {return Float.parseFloat(next());} String nextLine() { String str = """"; try {str = br.readLine();} catch (IOException e) { e.printStackTrace();} return str; }} static boolean isBracketSequence(String s, int a, int b) { Stack ss = new Stack<>(); boolean hachu = true; for(int i = a; i <= b; i++) { if(s.charAt(i) == ')' && ss.isEmpty()) {hachu = false; break;} if(s.charAt(i) == '(') ss.add('('); else ss.pop(); } return ss.empty() && hachu; } static String reverseOfString(String a) { StringBuilder ssd = new StringBuilder(); for(int i = a.length() - 1; i >= 0; i--) { ssd.append(a.charAt(i)); } return ssd.toString(); } static char[] reverseOfChar(char a[]) { char b[] = new char[a.length]; int j = 0; for(int i = a.length - 1; i >= 0; i--) { b[i] = a[j]; j++; } return b; } static boolean isPalindrome(char a[]) { boolean hachu = true; for(int i = 0; i <= a.length / 2; i++) { if(a[i] != a[a.length - 1 - i]) { hachu = false; break; } } return hachu; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long powermod(long x, long y, long mod){ long ans = 1; x = x % mod; if (x == 0) return 0; int i = 1; while (y > 0){ if ((y & 1) != 0) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } static long power(long x, long y){ long ans = 1; if (x == 0) return 0; int i = 1; while (y > 0){ if ((y & 1) != 0) ans = (ans * x); y = y >> 1; x = (x * x); } return ans; } static boolean check(String a) { boolean hachu = true; for(int i = 0; i < a.length(); i++) { if(a.charAt(0) != a.charAt(i)) {hachu = false; break;} } return hachu; } public static class Pair implements Comparable { public int index; public int value; public Pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { return -1 * Integer.valueOf(this.value).compareTo(other.value); } } static boolean equalString(int i, int j, int arr[], String b) { int brr[] = new int[26]; for(int k = i; k <= j; k++) brr[b.charAt(k) - 'a']++; for(int k = 0; k < 26; k++) { if(arr[k] != brr[k]) return false; } return true; } static boolean cequalArray(String a, String b) { int count[] = new int[26]; int count1[] = new int[26]; for(int i = 0; i < a.length(); i++) count[a.charAt(i) - 'a']++; for(int i = 0; i < a.length(); i++) count1[b.charAt(i) - 'a']++; for(int i = 0; i < 26; i++) if(count[i] != count1[i]) return false; return true; } static boolean isPrime(long d) { if(d == 1) return true; for(int i = 2; i <= (long)Math.sqrt(d); i++) { if(d % i == 0) return false; } return true; } 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 FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } 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 long[] longArr(int size) { long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static LinkedList[] graphD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList aa:temp) System.out.println(aa); } static long cal(long val, long pow) { if(pow == 0) return 1; long res = cal(val, pow/2); // long ret = (res*res)%mod; // if(pow%2 == 0) return ret; // return (val*ret)%mod; long ret = res*res; if(pow%2 == 0) return ret; return val*ret; } static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); } } 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 ArrayList g[]; static long mod=(long)1e9+7,INF=Long.MAX_VALUE; static boolean set[],col[]; static int par[],tot[],partial[]; static int D[],P[][]; static long dp[][],sum=0,max=0,size[]; // 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 int OR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""OR ""+i+"" ""+j); return i(); } static int AND(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""AND ""+i+"" ""+j); return i(); } static int XOR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""XOR ""+i+"" ""+j); return i(); } static boolean f1(int l,char X[]) { int i=0; for(; l0; a++) { if(GCD(i,a)==1)return i; } return 0; } static int min(char X[],char str[],int N) { int s=0; for(int i=0; i=b && a>=c)return 'R'; if(b>=a && b>=c)return 'B'; return 'G'; } static void f1(int n,int p,long sum,int N) { for(int c:g[n]) { if(c==p)continue; long s=sum+N-2*size[c]; f1(c,n,s,N); max=Math.max(max, s); } } static long f(int i,int j,ArrayList A) { if(i+1==A.size()) { return j; } int moves=1+A.get(i); if(j==1)return 1+f(i+1,moves,A); if(j>0 && dp[i][j-1]==0)f(i,j-1,A); return dp[i][j]=dp[i][j-1]+f(i+1,j+moves,A); } // 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 long f(long l,long r,long a,long b,long N) { while(r-l>1) { long m=(l+r)/2; long x=m*b; if(N1) { long m=(l+r)/2; if(x-m*s>max)l=m; else r=m; } return l+1; } static int f(long A[],long x) { int l=-1,r=A.length; while(r-l>1) { int m=(l+r)/2; if(A[m]>=x)r=m; else l=m; } return r; } static int bin(int x,ArrayList A) { int l=0,r=A.size()-1; while(l<=r) { int m=(l+r)/2; int a=A.get(m); if(a==x)return m; if(a A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a<=x)l=m; else r=m; } return l; } static int right(int x,ArrayList A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a Hash(int A[]) { HashMap mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static long mul(long a, long b) { return ( a %mod * 1L * b%mod )%mod; } static void swap(int A[],int a,int b) { int t=A[a]; A[a]=A[b]; A[b]=t; } static int find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; par[b]=a; } } static boolean isSorted(int A[]) { for(int i=1; i high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static String f(String A) { String X=""""; for(int i=A.length()-1; i>=0; i--) { int c=A.charAt(i)-'0'; X+=(c+1)%2; } return X; } static void sort(long[] a) //check for long { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i(); D[i]=Integer.MAX_VALUE; //D2[i]=INF; } } static long pow(long a,long b) { //long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1< l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i A) { for(int a:A)System.out.print(a+"" ""); System.out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i { 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; } public int compareTo(node1 x) { if(this.a==x.a)return 0; else if(this.a 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); } } class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }"," //package eround101; 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); final static int MOD = 1000000007; 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)) { pl(""NO""); return; } if(col[i] == 'B') { if(arr[i] > n) continue; cB[arr[i]]++; if(cB[arr[i]] > arr[i]) { pl(""NO""); return; } } else { if(arr[i] < 1) continue; cR[arr[i]]++; if(cR[arr[i]] > (n-(arr[i]-1))) { pl(""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) { pl(""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))) { pl(""NO""); return; } } // pa(psum1); pl(""YES""); } ///////////////////////////////////////////////////////////////////////////////// static class FenwickTree { // Binary Index Tree int[] tree; static int size; public FenwickTree(int size) { this.size = size; tree = new int[size + 5]; } public void add(int i, int val) { while (i <= size) { tree[i] += val; i += i & -i; // adding the decimal value of the last set bit. } } public int sum(int i) { int res = 0; while (i >= 1) { res += tree[i]; i -= i & -i; // deleting the last set bit } return res; } public int sum(int l, int r) { return sum(r) - sum(l - 1); } } ///////////////////////////////////////////////////////////////////////////////// static int[] nextIntArray(int n) { int[] arr = new int[n]; int i = 0; while (i < n) { arr[i++] = ni(); } return arr; } static long[] nextLongArray(int n) { long[] arr = new long[n]; int i = 0; while (i < n) { arr[i++] = nl(); } return arr; } static int[] nextIntArray1(int n) { int[] arr = new int[n + 1]; int i = 1; while (i <= n) { arr[i++] = ni(); } return arr; } ///////////////////////////////////////////////////////////////////////////////// static int ni() { return sc.nextInt(); } static long nl() { return sc.nextLong(); } static double nd() { return sc.nextDouble(); } ///////////////////////////////////////////////////////////////////////////////// static void pl() { pw.println(); } static void p(Object o) { pw.print(o + "" ""); } static void pl(Object o) { pw.println(o); } static void psb(StringBuilder sb) { pw.print(sb); } static void pa(Object arr[]) { for (Object o : arr) { p(o); } pl(); } static void pa(int arr[]) { for (int o : arr) { p(o); } pl(); } static void pa(long arr[]) { for (long o : arr) { p(o); } pl(); } static void pa(double arr[]) { for (double o : arr) { p(o); } pl(); } static void pa(char arr[]) { for (char o : arr) { p(o); } pl(); } static void pa(List list) { for (Object o : list) { p(o); } pl(); } static void pa(Object[][] arr) { for (int i = 0; i < arr.length; ++i) { for (Object o : arr[i]) { p(o); } pl(); } } static void pa(int[][] arr) { for (int i = 0; i < arr.length; ++i) { for (int o : arr[i]) { p(o); } pl(); } } static void pa(long[][] arr) { for (int i = 0; i < arr.length; ++i) { for (long o : arr[i]) { p(o); } pl(); } } static void pa(char[][] arr) { for (int i = 0; i < arr.length; ++i) { for (char o : arr[i]) { p(o); } pl(); } } static void pa(double[][] arr) { for (int i = 0; i < arr.length; ++i) { for (double o : arr[i]) { p(o); } pl(); } } ///////////////////////////////////////////////////////////////////////////////// static void print(Object s) { System.out.println(s); } ///////////////////////////////////////////////////////////////////////////////// //-----------HritikScanner class for faster input----------// static class HritikScanner { BufferedReader br; StringTokenizer st; public HritikScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ////////////////////////////////////////////////////////////////// public static class Pair implements Comparable { int num, row, col; Pair(int num, int row, int col) { this.num = num; this.row = row; this.col = col; } public int get1() { return num; } public int get2() { return row; } public int compareTo(Pair A) { return this.num - A.num; } public String toString() { return num + "" "" + row + "" "" + col; } } ////////////////////////////////////////////////////////////////// // Function to return gcd of a and b time complexity O(log(a+b)) static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } ////////////////////////////////////////////////////////////////// static boolean isPrime(long n) { // Corner cases if (n <= 1) { return false; } if (n <= 3) { return true; } // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) { return false; } for (long i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } ////////////////////////////////////////////////////////////////// static boolean isPowerOfTwo(long n) { if (n == 0) { return false; } return (long) (Math.ceil((Math.log(n) / Math.log(2)))) == (long) (Math.floor(((Math.log(n) / Math.log(2))))); } public static long getFact(int n) { long ans = 1; while (n > 0) { ans *= n; ans %= MOD; n--; } return ans; } public static long pow(long n, int pow) { if (pow == 0) { return 1; } long temp = pow(n, pow / 2) % MOD; temp *= temp; temp %= MOD; if (pow % 2 == 1) { temp *= n; } temp %= MOD; return temp; } public static long nCr(int n, int r) { long ans = 1; int temp = n - r; while (n > temp) { ans *= n; ans %= MOD; n--; } ans *= pow(getFact(r) % MOD, MOD - 2) % MOD; ans %= MOD; return ans; } ////////////////////////////////////////////////////////////////// // method returns Nth power of A static double nthRoot(int A, int N) { // intially guessing a random number between // 0 and 9 double xPre = Math.random() % 10; // smaller eps, denotes more accuracy double eps = 0.001; // initializing difference between two // roots by INT_MAX double delX = 2147483647; // xK denotes current value of x double xK = 0.0; // loop untill we reach desired accuracy while (delX > eps) { // calculating current value from previous // value by newton's method xK = ((N - 1.0) * xPre + (double) A / Math.pow(xPre, N - 1)) / (double) N; delX = Math.abs(xK - xPre); xPre = xK; } return xK; } } ",0,Non-plagiarised 73f57af1,ac8ef97c,"/*input 3 2 1 6 3 8 1 2 3 1 3 4 6 7 9 1 2 2 3 6 3 14 12 20 12 19 2 12 10 17 3 17 3 2 6 5 1 5 2 6 4 6 */ import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out; static int MOD = 1000000007; static FastReader scan; /*-------- I/O usaing short named function ---------*/ public static String ns(){return scan.next();} public static int ni(){return scan.nextInt();} public static long nl(){return scan.nextLong();} public static double nd(){return scan.nextDouble();} public static String nln(){return scan.nextLine();} public static void p(Object o){out.print(o);} public static void ps(Object o){out.print(o + "" "");} public static void pn(Object o){out.println(o);} /*-------- for output of an array ---------------------*/ static void iPA(int arr []){ StringBuilder output = new StringBuilder(); for(int i=0; i0){ int n = ni(); l = new long[n]; r = new long[n]; for(int i=0; i adj[] = new ArrayList[n]; for(int i=0; i(); for(int i=0; i adj[], int vertex, int prev, boolean visited[]){ visited[vertex] = true; if(dp[vertex][prev] != null) return dp[vertex][prev]; long ans = 0; for(int x : adj[vertex]){ if(!visited[x]){ if(prev == 0){ ans += Math.max(Math.abs(l[vertex] - l[x]) + solve(adj, x, 0, visited), Math.abs(l[vertex] - r[x]) + solve(adj, x, 1, visited)); //pn(vertex + "" "" + x + "" "" + ans); }else{ ans += Math.max(Math.abs(r[vertex] - l[x]) + solve(adj, x, 0, visited), Math.abs(r[vertex] - r[x]) + solve(adj, x, 1, visited)); //pn(vertex + "" "" + x + "" "" + ans); } } } visited[vertex] = false; //pn(ans); return dp[vertex][prev] = ans; } } ","import java.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); } 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 compareTo(pair other) { int i = x.compareTo(other.x); if (i != 0) return i; return y.compareTo(other.y); } public String toString() { return x.toString() + "" "" + y.toString(); } public boolean equals(Object obj) { if (this.getClass() != obj.getClass()) return false; pair other = (pair) obj; return x.equals(other.x) && y.equals(other.y); } public int hashCode() { return 31 * x.hashCode() + y.hashCode(); } } static void sort(int[] a) { ArrayList l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((p & 1) > 0) { ans = (ans * a) % mod; } a = (a * a) % mod; p = p >> 1; } return ans % mod; } static long mod = 1000000007; static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } static long fast_powerNumbers(long a, long n) { if (n == 1) { return a; } long ans = fast_powerNumbers(a, n / 2); if (n % 2 == 0) { return (ans * ans); } else { return ((ans * ans) * (a)); } } static void dfs_helper(int[][] arr, int i, int j, int team, int n, int m) { arr[i][j] = team; if (i - 1 >= 0 && arr[i - 1][j] == 1) { dfs(arr, i - 1, j, team, n, m); } if (j - 1 >= 0 && arr[i][j - 1] == 1) { dfs(arr, i, j - 1, team, n, m); } if (i + 1 < n && arr[i + 1][j] == 1) { dfs(arr, i + 1, j, team, n, m); } if (j + 1 < m && arr[i][j + 1] == 1) { dfs(arr, i, j + 1, team, n, m); } } static void dfs(int[][] arr, int i, int j, int team, int n, int m) { dfs_helper(arr, i, j, team, n, m); } static int parent[]; static int rank[]; static int find(int i) { if (parent[i] == -1) { parent[i] = i; return i; } if (parent[i] == i) { return i; } else { parent[i] = find(parent[i]); } return parent[i]; } static void unite(int s1, int s2) { if (rank[s1] > rank[s2]) { parent[s2] = s1; rank[s1] += rank[s2]; } else { parent[s1] = s2; rank[s2] += rank[s1]; } } 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; // } // // } // } // } static void seive(int n) { arr1=new int[n+1]; arr1[0]=arr1[1]=1; for (int i = 4; i <=n ; i+=2) { arr1[i]=1; } for (int i = 3; i*i <=n ; i+=2) { if (arr1[i] == 0) { for (int j = i*i; j <=n ; j+=i) { arr1[j]=1; } } } } public static boolean ccw(Point a,Point b,Point c) { long s1=(c.x-b.x)*(b.y-a.y) ; long s2 = (c.y-b.y)*(b.x-a.x); if(s1rank[p2]) { parent[p2]=p1; rank[p1]+=rank[p2]; // System.out.println(arr[p2]); sum[p1]+=sum[p2]; //sum[p2]+=sum[p1]; } else { parent[p1]=p2; rank[p2]+=rank[p1]; //System.out.println(arr[p1]); sum[p2]+=sum[p1]; //sum[p1]+=sum[p2]; } } } class Gaph { HashMap> hm; Gaph() { hm = new HashMap<>(); } Gaph(int n) { hm = new HashMap<>(); for (int i = 0; i < n; i++) { hm.put(i, new ArrayList()); } } // function for adding an edge................................................. public void addEdge(int a, int b, boolean isDir) { if (isDir) { if (hm.containsKey(a)) { hm.get(a).add(b); } else { hm.put(a, new ArrayList<>(Arrays.asList(b))); } } else { if (hm.containsKey(a)) { hm.get(a).add(b); } else if (!hm.containsKey(a)) { hm.put(a, new ArrayList<>(Arrays.asList(b))); } if (hm.containsKey(b)) { hm.get(b).add(a); } else if (!hm.containsKey(b)) { hm.put(b, new ArrayList<>(Arrays.asList(a))); } } } } // out.println(al.toString().replaceAll(""[\\[|\\]|,]"","""")); ",0,Non-plagiarised 0ca738ce,931faca2,"import java.io.*; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class G { public static void main(String[] args) { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); Task solver = new Task(); int t = 1; for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out); out.close(); } static class Task { static int max = (int) (4e5), MOD = 998244353; static long[] fact = new long[max+1], invFact = new long[max+1], naturalInverse = new long[max+1]; public void solve(int testNumber, FastReader scan, PrintWriter out) { int n = scan.nextInt(), k = scan.nextInt(); Item[] lanterns = new Item[2 * n]; for(int i = 0; i < n; i++) { int l = scan.nextInt(), r = scan.nextInt(); lanterns[i * 2] = new Item(l, 0); lanterns[i * 2 + 1] = new Item(r, 1); } Arrays.sort(lanterns); precomp(); int have = 0; long ans = 0; for(Item x : lanterns) { if(x.start == 1) have--; else { ans = (ans + binomial(have, k - 1)) % MOD; have++; } } out.println(ans); } static class Item implements Comparable { int val; int start; public Item(int a, int b) { val = a; start = b; } @Override public int compareTo(Item item) { int ret = Integer.compare(val, item.val); if(ret == 0) ret = Integer.compare(start, item.start); return ret; } } static void precomp() { fact[0] = invFact[0] = invFact[1] = naturalInverse[0] = naturalInverse[1] = 1; for(int i = 1; i <= max; i++) { fact[i] = (fact[i-1]*i)%MOD; if(i == 1) continue; naturalInverse[i] = naturalInverse[MOD % i] * (MOD - MOD/i) % MOD; invFact[i] = (invFact[i-1]*naturalInverse[i])%MOD; } } static long binomial(int a, int b) { if(a < b) return 0; return ((fact[a]*invFact[b])%MOD*invFact[a-b])%MOD; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[][][][]; static int mod=1000000007; static int mod1=998244353; static int max; static long bit[]; static long seg[]; static long fact[]; static long A[]; static long[] fac = new long[300001]; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { //CHECK FOR N=1 //CHECK FOR N=1 //StringBuffer sb=new StringBuffer(""""); int ttt=1; // ttt =i(); fac[0] = 1; for (int i = 1; i <= 300000; i++) fac[i] = fac[i - 1] * i % mod1; outer :while (ttt-- > 0) { int n=i(); int k=i(); Pair P[]=new Pair[2*n]; int c=0; for(int i=0;i { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return +1; else if(this.xo.y) return +1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END //static void add(int v) { // if(!map.containsKey(v)) { // map.put(v, 1); // } // else { // map.put(v, map.get(v)+1); // } //} //static void remove(int v) { // if(map.containsKey(v)) { // map.put(v, map.get(v)-1); // if(map.get(v)==0) // map.remove(v); // } //} public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised 0c00d532,521c5645,"import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class First { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); //int a = 1; int t; t = in.nextInt(); //t = 1; while (t > 0) { //out.print(""Case #""+(a++)+"": ""); solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); int[] arr = new int[n]; 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 int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a; int b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return this.a - o.a; } } static class answer1 implements Comparable{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { return this.a - o.a; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i0) { int n=sc.nextInt(); int 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 al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al); for(int i=0;i al=new ArrayList<>(); for(long i:a)al.add(i); Collections.sort(al); for(int i=0;i al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al,Collections.reverseOrder()); 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.io.*; import java.util.*; public class A734C { public static void main(String[] args) { JS scan = new JS(); int t = scan.nextInt(); loop:while(t-->0){ int n = scan.nextInt(); String[] arr= new String[n]; Integer[][] counts = new Integer[5][n]; for(int i = 0;i<5;i++){ for(int j = 0;j=0;j--){ extra+=counts[i][j]; if(extra>0)curr++; } best = Math.max(best,curr); } System.out.println(best); } } static class JS { public int BS = 1 << 16; public char NC = (char) 0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public long nextLong() { num = 1; boolean neg = false; if (c == NC) c = nextChar(); for (; (c < '0' || c > '9'); c = nextChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; num *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / num; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c > 32) { res.append(c); c = nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c != '\n') { res.append(c); c = nextChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = nextChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ",1,Plagiarised 80881cae,f8e7b886,"//package Codeforces; import java.io.*; import java.util.*; public class CP { static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException, CloneNotSupportedException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } // @Override // public boolean equals(Object obj) // { // if(obj instanceof Pair) // { // Pair p=(Pair)obj; // return p.x==this.x && p.y==this.y; // } // return false; // } // @Override // public int hashCode() // { // return Math.abs(x)+500*Math.abs(y); // } // @Override // public String toString() // { // return ""(""+x+"" ""+y+"")""; // } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } // public void swap() // { // this.y=this.y+this.x; // this.x=this.y-this.x; // this.y=this.y-this.x; // } } }","import java.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 boolean overlapping(pair p1, pair p2) { if((p2.f >= p1.f && p1.s >= p2.f) || (p2.s >= p1.f && p1.s >= p2.s)) { return true; } return false; } 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 String toString() { StringBuilder sb = new StringBuilder(); sb.append(""{"" + f + "","" + s + ""}""); return sb.toString(); } @Override public int compareTo(pair o) { return f - o.f; } 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); } } public static void print(long a, long b, long c, PrintWriter pw) { pw.println(a + "" "" + b + "" "" + c); return; } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[][] read2Array(int n, int m) { int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } } }",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(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable{ long wt; long idx; Pair(long x,long y){ this.wt=x; this.idx=y; } @Override public int compareTo(Pair x){ return (int)(this.wt-x.wt); } public String toString(){ return ""( ""+wt+"" ""+idx+"" )""; } } static void printLong(long []arr){ for(long x:arr)System.out.print(x+"" ""); } static void printInt(int []arr){ for(int x:arr)System.out.print(x+"" ""); } static void scanInt(int []arr){ for(int i=0;i 0){ if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static long add(long a,long b,long mod){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod; } static long sub(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod; } static long mul(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } static long mminvprime(long a, long b,long mod) { return power(a, b - 2,mod); } } ","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;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (char i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i { if(x[c]>y[c]) { return 1; }else { return -1; } }); } public static void printb(boolean ans) { if(ans) { System.out.println(""Yes""); }else { System.out.println(""No""); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i{ int a , b; Pair(int x , int y){ a=x; b=y; } public int compareTo(Pair o) { return a != o.a ? a - o.a : b - o.b; } } } ",0,Non-plagiarised 9be0602e,c4ca2ff3,"import java.io.*; import java.util.*; public class Codeforce { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int mod = (int) (1e9 + 7); public static class pair implements Comparator { int x; int y; public pair() { } public pair(int x, int y) { this.x = x; this.y = y; } @Override public int compare(pair o1, pair o2) { return o1.y - o2.y; } } public static long modularpow(long a, long b) { long res = 1; if (b == 0) return res; else { while (b > 0) { if (b % 2 == 1) { res *= a; res %= mod; } a = a * a; a %= mod; b /= 2; } return res % mod; } } public static int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } public static String binary(int a) { String s1 = """"; while (a > 0) { s1 = a % 2 + s1; a /= 2; } return s1; } public static int Lower_Bound(long a[], int l, int r, long k) { while (r - l > 1) { int mid = l + (r - l) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l; } public static int Upper_Bound(int a[], int l, int r, int k) { while (r - l > 1) { int mid = (l + r) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l + 1; } public static int fun(int ch,int a[][],int tot[],int n){ ArrayListar=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; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i0){ int n = fs.nextInt(), k = fs.nextInt(); int[] positions = fs.readArray(k), temps = fs.readArray(k); int[] forced = new int[n]; Arrays.fill(forced, Integer.MAX_VALUE/2); for(int i=0; i=0; i--) forced[i] = Math.min(forced[i], forced[i+1]+1); for(int i=0; i ""+a); } public static void debug(long a, long b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(char a, char b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(int[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(char[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(HashMap map){ System.out.print(""Map--> ""+map.toString()); } } } ",1,Plagiarised 086f0f90,4a570de6,"import java.io.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int t=sc.nextInt(); while (t-->=1) { int n = sc.nextInt(),m=sc.nextInt(), x = sc.nextInt(); int a[] = sc.readArray(n); PriorityQueue pq=new PriorityQueue<>(); for (int i=0;i l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static String sortString(String s) { char temp[] = s.toCharArray(); Arrays.sort(temp); return new String(temp); } static class Pair implements Comparable { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } // to sort first part // public int compareTo(Pair other) { // if (this.a == other.a) return other.b > this.b ? -1 : 1; // else if (this.a > other.a) return 1; // else return -1; // } // public int compareTo(Pair other) { // if (this.b == other.b) return 0; // if (this.b < other.b) return 1; // else return -1; // } //sort on the basis of first part only public int compareTo(Pair other) { if (this.a == other.a) return 0; else if (this.a > other.a) return 1; else return -1; } } static int[] frequency(String s){ int fre[]= new int[26]; for (int i=0;i0){ long lastBit=n&1; if (lastBit==1){ ans=(int)mul(ans,a); } a=(int)mul(a,a); n>>=1; } return ans; } static int[] find(int n, int start, int diff) { int a[] = new int[n]; a[0] = start; for (int i = 1; i < n; i++) a[i] = a[i - 1] + diff; return a; } static void swap(int a, int b) { int c = a; a = b; b = c; } static void printArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + "" ""); } } static boolean sorted(int a[]) { int n = a.length; boolean flag = true; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) flag = false; } if (flag) return true; else return false; } public static int findlog(long n) { if (n == 0) return 0; if (n == 1) return 0; if (n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if (den == 0) return 0; return (int) (num / den); } public static long gcd(long a, long b) { if (b % a == 0) return a; return gcd(b % a, a); } public static int gcdInt(int a, int b) { if (b % a == 0) return a; return gcdInt(b % a, a); } static void sortReverse(int[] a) { ArrayList l = new ArrayList<>(); for (int i : a) l.add(i); // Collections.sort.(l); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayLong(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }","import java.io.*; import java.lang.*; import java.util.*; public class c { static class FastScanner { InputStreamReader is; BufferedReader br; StringTokenizer st; public FastScanner() { is = new InputStreamReader(System.in); br = new BufferedReader(is); } String next() throws Exception { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int ni() throws Exception { return Integer.parseInt(next()); } long nextLong() throws Exception { return Long.parseLong(next()); } int[] readArray(int num) throws Exception { int arr[]=new int[num]; for(int i=0;i= 0) { double i= Math.sqrt(x); if(i%1!=0) { return false; } return ((i * i) == x); } return false; } public static int[] ia(int n) { int ar[]=new int[n]; return ar; } public static long[] la(int n) { long ar[]=new long[n]; return ar; } static class pair implements Comparable{ int ht; int id; pair(int ht, int id) { this.ht=ht; this.id=id; } public int compareTo(pair p) { return this.ht-p.ht; } } public static void main(String args[]) throws java.lang.Exception { FastScanner sc=new FastScanner(); int t=sc.ni(); while(t-->0) { int n=sc.ni(); int m=sc.ni(); int x=sc.ni(); int ar[]=ia(n); for(int i=0;i pq=new PriorityQueue<>(); for(int i=0;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; } static class JS { public int BS = 1 << 16; public char NC = (char) 0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public long nextLong() { num = 1; boolean neg = false; if (c == NC) c = nextChar(); for (; (c < '0' || c > '9'); c = nextChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; num *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / num; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c > 32) { res.append(c); c = nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c != '\n') { res.append(c); c = nextChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = nextChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ","import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static int dp[]; static boolean v[]; // static int mod=998244353;; static int mod=1000000007; static int max; static int bit[]; //static long fact[]; // static long A[]; static HashMap map; //static StringBuffer sb=new StringBuffer(""""); //static HashMap map; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); long A[]=inputL(n); long B[]=inputL(n); long C[]=new long[n]; for(int i=0;i=0;i--) { if(C[i]>min) { continue; } if(A[i] { int x; int y; int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int find(int A[],int a) { if(A[a]==a) return a; return A[a]=find(A, A[a]); } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return find(A, A[a]); //} //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void print(int A[]) { for(int i : A) { out.print(i+"" ""); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static HashMap hash(long A[]){ HashMap map=new HashMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(long A[]){ TreeMap map=new TreeMap(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised 5f3a196a,d76e3b9d,"import java.io.*; import java.util.*; public class MonstersAndSpells { public static PrintWriter out; public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); out=new PrintWriter(System.out); int t=Integer.parseInt(st.nextToken()); while(t-->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; } public int compareTo(State o) { return x-o.x; } } } ","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,"//package codeforces.globalround18; import java.io.*; import java.util.*; import static java.lang.Math.*; //Think through the entire logic before jump into coding! //If you are out of ideas, take a guess! It is better than doing nothing! //Read both C and D, it is possible that D is easier than C for you! //Be aware of integer overflow! //If you find an answer and want to return immediately, don't forget to flush before return! public class C { static InputReader in; static PrintWriter out; public static void main(String[] args) { //initReaderPrinter(true); initReaderPrinter(false); solve(in.nextInt()); //solve(1); } static void solve(int testCnt) { for (int testNumber = 0; testNumber < testCnt; testNumber++) { int n = in.nextInt(); char[] a = in.next().toCharArray(), b = in.next().toCharArray(); int match0 = 0, match1 = 0, mismatch10 = 0, mismatch01 = 0; for(int i = 0; i < n; i++) { if(a[i] == b[i]) { if(a[i] == '0') match0++; else match1++; } else { if(a[i] == '0') mismatch01++; else mismatch10++; } } if(mismatch01 + mismatch10 == 0) out.println(0); else { if(match1 - match0 == 1 && mismatch01 == mismatch10) { out.println(min(match0 + match1, mismatch01 + mismatch10)); } else if(match1 - match0 == 1) { out.println(match0 + match1); } else if(mismatch01 == mismatch10) { out.println(mismatch01 + mismatch10); } else out.println(-1); } } out.close(); } static void initReaderPrinter(boolean test) { if (test) { try { in = new InputReader(new FileInputStream(""src/input.in"")); out = new PrintWriter(new FileOutputStream(""src/output.out"")); } catch (IOException e) { e.printStackTrace(); } } else { in = new InputReader(System.in); out = new PrintWriter(System.out); } } static class InputReader { BufferedReader br; StringTokenizer st; InputReader(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream), 32768); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } Integer[] nextIntArray(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitive(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArrayPrimitiveOneIndexed(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } Long[] nextLongArray(int n) { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long[] nextLongArrayPrimitive(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long[] nextLongArrayPrimitiveOneIndexed(int n) { long[] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextLong(); return a; } String[] nextStringArray(int n) { String[] g = new String[n]; for (int i = 0; i < n; i++) g[i] = next(); return g; } List[] readGraphOneIndexed(int n, int m) { List[] adj = new List[n + 1]; for (int i = 0; i <= n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt(); int v = nextInt(); adj[u].add(v); adj[v].add(u); } return adj; } List[] readGraphZeroIndexed(int n, int m) { List[] adj = new List[n]; for (int i = 0; i < n; i++) { adj[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; adj[u].add(v); adj[v].add(u); } return adj; } /* A more efficient way of building a graph using int[] instead of ArrayList to store each node's neighboring nodes. 1-indexed. */ int[][] buildGraph(int nodeCnt, int edgeCnt) { int[] end1 = new int[edgeCnt], end2 = new int[edgeCnt]; int[] edgeCntForEachNode = new int[nodeCnt + 1], idxForEachNode = new int[nodeCnt + 1]; for (int i = 0; i < edgeCnt; i++) { int u = in.nextInt(), v = in.nextInt(); edgeCntForEachNode[u]++; edgeCntForEachNode[v]++; end1[i] = u; end2[i] = v; } int[][] adj = new int[nodeCnt + 1][]; for (int i = 1; i <= nodeCnt; i++) { adj[i] = new int[edgeCntForEachNode[i]]; } for (int i = 0; i < edgeCnt; i++) { adj[end1[i]][idxForEachNode[end1[i]]] = end2[i]; idxForEachNode[end1[i]]++; adj[end2[i]][idxForEachNode[end2[i]]] = end1[i]; idxForEachNode[end2[i]]++; } return adj; } } }","import java.util.*; import java.io.*; public class C1615{ static FastScanner fs = null; public static void main(String[] args) { fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-->0) { int n = fs.nextInt(); String a = fs.next(); String b = fs.next(); char ch1[] = a.toCharArray(); char ch2[] = b.toCharArray(); int c00 = 0; int c01 = 0; int c10 = 0; int c11 = 0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i 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 { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair a) { return a.y-y; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String s=""""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class CF { private static FS sc = new FS(); private static class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } 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 long[] longArr(int size) { long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } } static long count = 0; 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); 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 class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env = System.getProperty(""ONLINE_JUDGE"") != null; // env=true; if (!env) { try { br = new BufferedReader(new FileReader(""src/input.txt"")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static 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;in) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long pow(long a,long b) { long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i0) { if (e%2==1) x=(b*x)%m; b=(b*b)%m; e=e/2; } return x; } static long mod=1000000007; // Global vars static BufferedWriter out; static InputReader reader; static int pgcd(int a,int b){ if (a ts=new TreeSet(); ts.add(b[0]); ts.add(NX); ts.add(PX); int core=b[0]; boolean ok=true; for (int i=1;ix) { ok=false; //log(""fail 1""); break; } //log(""core:""+core+"" x:""+x+"" y:""+y); core=x; ts.add(x); } else { int y=ts.higher(core); if (y= numChars) { curChar = 0; numChars = stream.read(buf); if (numChars <= 0) { return -1; } } return buf[curChar++]; } public final String readString() throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final String readString(int L) throws IOException { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(L); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final int readInt() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log(""d:""+d); if (d == '-') { neg = true; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log(""res:""+res); if (neg) return -res; return res; } public final long readLong() throws IOException { int c = read(); boolean neg = false; while (isSpaceChar(c)) { c = read(); } char d = (char) c; // log(""d:""+d); if (d == '-') { neg = true; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); // log(""res:""+res); if (neg) return -res; return res; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }","import java.util.Scanner; import java.util.TreeSet; public class D { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int test = scn.nextInt(); for (int t = 0; t < test; t++) { int n = scn.nextInt(); int[] b = new int[n]; TreeSet ts = new TreeSet<>(); int lastAdded = -1; boolean ans = true; for (int i = 0; i < n; i++) { b[i] = scn.nextInt(); } for (int val : b) { if (t == 4) { int x = 2; } if (val > lastAdded) { Integer between = ts.higher(lastAdded); if (between != null && between < val) { ans = false; break; } } if (val < lastAdded) { Integer between = ts.lower(lastAdded); if (between != null && between > val) { ans = false; break; } } ts.add(val); lastAdded = val; } if (ans) System.out.println(""YES""); else System.out.println(""NO""); } } boolean between(int mid, int a, int b) { return a >= mid && mid >= b || a <= mid && mid <= b; } } ",0,Non-plagiarised 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(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }",0,Non-plagiarised 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 ArrayList g[]; static long mod=(long)1e9+7,INF=Long.MAX_VALUE; static boolean set[],col[]; static int par[],tot[],partial[]; static int D[],P[][]; static long dp[][],sum=0,max=0,size[]; // 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 int OR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""OR ""+i+"" ""+j); return i(); } static int AND(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""AND ""+i+"" ""+j); return i(); } static int XOR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""XOR ""+i+"" ""+j); return i(); } static boolean f1(int l,char X[]) { int i=0; for(; l0; a++) { if(GCD(i,a)==1)return i; } return 0; } static int min(char X[],char str[],int N) { int s=0; for(int i=0; i=b && a>=c)return 'R'; if(b>=a && b>=c)return 'B'; return 'G'; } static void f1(int n,int p,long sum,int N) { for(int c:g[n]) { if(c==p)continue; long s=sum+N-2*size[c]; f1(c,n,s,N); max=Math.max(max, s); } } static long f(int i,int j,ArrayList A) { if(i+1==A.size()) { return j; } int moves=1+A.get(i); if(j==1)return 1+f(i+1,moves,A); if(j>0 && dp[i][j-1]==0)f(i,j-1,A); return dp[i][j]=dp[i][j-1]+f(i+1,j+moves,A); } // 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 long f(long l,long r,long a,long b,long N) { while(r-l>1) { long m=(l+r)/2; long x=m*b; if(N1) { long m=(l+r)/2; if(x-m*s>max)l=m; else r=m; } return l+1; } static int f(long A[],long x) { int l=-1,r=A.length; while(r-l>1) { int m=(l+r)/2; if(A[m]>=x)r=m; else l=m; } return r; } static int bin(int x,ArrayList A) { int l=0,r=A.size()-1; while(l<=r) { int m=(l+r)/2; int a=A.get(m); if(a==x)return m; if(a A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a<=x)l=m; else r=m; } return l; } static int right(int x,ArrayList A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a Hash(int A[]) { HashMap mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static long mul(long a, long b) { return ( a %mod * 1L * b%mod )%mod; } static void swap(int A[],int a,int b) { int t=A[a]; A[a]=A[b]; A[b]=t; } static int find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; par[b]=a; } } static boolean isSorted(int A[]) { for(int i=1; i high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static String f(String A) { String X=""""; for(int i=A.length()-1; i>=0; i--) { int c=A.charAt(i)-'0'; X+=(c+1)%2; } return X; } static void sort(long[] a) //check for long { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i(); D[i]=Integer.MAX_VALUE; //D2[i]=INF; } } static long pow(long a,long b) { //long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1< l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i A) { for(int a:A)System.out.print(a+"" ""); System.out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i { 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; } public int compareTo(node1 x) { if(this.a==x.a)return 0; else if(this.a g[]; static long mod=(long)1e9+7,INF=Long.MAX_VALUE; static boolean set[],col[]; static int par[],tot[],partial[]; static int D[],P[][]; static long dp[][],sum=0,max=0,size[]; // 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 int OR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""OR ""+i+"" ""+j); return i(); } static int AND(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""AND ""+i+"" ""+j); return i(); } static int XOR(int i,int j) { if(i>j) { int t=i; i=j; j=t; } System.out.println(""XOR ""+i+"" ""+j); return i(); } static boolean f1(int l,char X[]) { int i=0; for(; l0; a++) { if(GCD(i,a)==1)return i; } return 0; } static int min(char X[],char str[],int N) { int s=0; for(int i=0; i=b && a>=c)return 'R'; if(b>=a && b>=c)return 'B'; return 'G'; } static void f1(int n,int p,long sum,int N) { for(int c:g[n]) { if(c==p)continue; long s=sum+N-2*size[c]; f1(c,n,s,N); max=Math.max(max, s); } } static long f(int i,int j,ArrayList A) { if(i+1==A.size()) { return j; } int moves=1+A.get(i); if(j==1)return 1+f(i+1,moves,A); if(j>0 && dp[i][j-1]==0)f(i,j-1,A); return dp[i][j]=dp[i][j-1]+f(i+1,j+moves,A); } // 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 long f(long l,long r,long a,long b,long N) { while(r-l>1) { long m=(l+r)/2; long x=m*b; if(N1) { long m=(l+r)/2; if(x-m*s>max)l=m; else r=m; } return l+1; } static int f(long A[],long x) { int l=-1,r=A.length; while(r-l>1) { int m=(l+r)/2; if(A[m]>=x)r=m; else l=m; } return r; } static int bin(int x,ArrayList A) { int l=0,r=A.size()-1; while(l<=r) { int m=(l+r)/2; int a=A.get(m); if(a==x)return m; if(a A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a<=x)l=m; else r=m; } return l; } static int right(int x,ArrayList A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(a Hash(int A[]) { HashMap mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static long mul(long a, long b) { return ( a %mod * 1L * b%mod )%mod; } static void swap(int A[],int a,int b) { int t=A[a]; A[a]=A[b]; A[b]=t; } static int find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; par[b]=a; } } static boolean isSorted(int A[]) { for(int i=1; i high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static String f(String A) { String X=""""; for(int i=A.length()-1; i>=0; i--) { int c=A.charAt(i)-'0'; X+=(c+1)%2; } return X; } static void sort(long[] a) //check for long { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i(); D[i]=Integer.MAX_VALUE; //D2[i]=INF; } } static long pow(long a,long b) { //long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1< l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i A) { for(int a:A)System.out.print(a+"" ""); System.out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i { 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; } public int compareTo(node1 x) { if(this.a==x.a)return 0; else if(this.a 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 @Override public int compare(Student s1, Student s2) { if (s1.i1 < s2.i1) return -1; else if (s1.i1 >s2.i1) return 1; return 0; } } /* 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 t, ArrayList m) { if (t.size() == 0 && m.size() == 0) { sd = true; return; } t.remove(0); t.remove(t.size() - 1); call(t, new ArrayList(m.subList(0, m.size() - 1))); call(t, new ArrayList(m.subList(1, m.size()))); } static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static int noofdivisors(int n) { //it counts no of divisors of every number upto number n int arr[] = new int[n + 1]; for (int i = 1; i <= (n); i++) { for (int j = i; j <= (n); j = j + i) { arr[j]++; } } return arr[0]; } static char[] reverse(char arr[]) { char[] b = new char[arr.length]; int j = arr.length; for (int i = 0; i < arr.length; i++) { b[j - 1] = arr[i]; j = j - 1; } return b; } static long factorial(int n) { long su = 1; for (int i = 1; i <= n; i++) { su *= (long) i; } return su; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); public String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } long[] readArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } } ","//package Practice; import java.io.*; import java.util.*; public class codefor { static class height implements Comparable { int h,index; height(int hi,int i) { h=hi; index=i; } public int compareTo(height a) { return this.h-a.h; } public String toString() { return ""(""+this.h+"",""+this.index+"") ""; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc=new FastReader(); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),i; ArrayList arr=new ArrayList<>(); int ans[]=new int[n]; PriorityQueue tower=new PriorityQueue(); for(i=0;i() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + "" "" + arr[i].y + "" ""); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int solve(int dp[][] , ArrayList one , ArrayList zero , int i,int j) { int n=one.size(); int m=zero.size(); if(i>=n) return 0; else if(j>=m) return Integer.MAX_VALUE; else if(dp[i][j]!=-1) return dp[i][j]; int val1 = Math.abs(one.get(i)-zero.get(j))+solve(dp, one ,zero ,i+1,j+1); int val2 = solve(dp , one , zero , i,j+1); dp[i][j]= Math.min(val1,val2); return dp[i][j]; } 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(), 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,"/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static int mod=10000007; static StringBuilder sb=new StringBuilder(); /* start */ public static void main(String [] args) { int t = i(); while(t-->0) { int n = i(); int a[] = input(n); char c[] = inputC(); ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); for(int i=0;in-i) { is = false; break; } } out.println(is==true?""YES"":""NO""); } out.close(); } /* end */ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static char[] inputC() { String s = sc.nextLine(); return s.toCharArray(); } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } //pair class private static class Pair implements Comparable { int first, second; public Pair(int f, int s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }","import java.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'); } } }",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; } public int compareTo(Tower o) {return w - o.w;} } static class Block implements Comparable{ int i, w; public Block(int a, int b) { i=a; w=b; } public int compareTo(Block o) {return o.w-w;} } static PriorityQueue towers; static PriorityQueue blocks; static int[] par; static void solve() { while (!blocks.isEmpty()) { Block h = blocks.poll(); Tower t = towers.poll(); par[h.i] = t.i; t.w += h.w; towers.add(t); } List res = new ArrayList(towers); Collections.sort(res); boolean works = true; for (int i =1 ; i < m; i++) { if (Math.abs(res.get(i-1).w - res.get(i).w) > x) works = false; } if (works) { out.println(""YES""); for (int i = 0; i < n; i++) out.print(par[i] + 1 + "" ""); out.println(); } else out.println(""NO""); } static int n,m,x; public static void readInput() throws IOException { // br = new BufferedReader(new FileReader("".in"")); // out = new PrintWriter(new FileWriter("".out"")); int t = Integer.parseInt(br.readLine()); while (t-->0) { StringTokenizer st= new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); x = Integer.parseInt(st.nextToken()); towers = new PriorityQueue(); blocks = new PriorityQueue(); par = new int[n]; st = new StringTokenizer(br.readLine()); for (int i= 0 ; i < n; i++) { blocks.add(new Block(i,Integer.parseInt(st.nextToken()))); } for (int i =0 ; i < m; i++) { towers.add(new Tower(i, 0)); } solve(); } } } ","/* bts songs to dance to: I need U Run ON Filter I'm fine */ import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class x1515C { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int X = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); ArrayList ls = new ArrayList(); for(int i=0; i < N; i++) ls.add(new Unit(arr[i], i)); Collections.sort(ls); int[] res = new int[N]; PriorityQueue pq = new PriorityQueue(Comparator.reverseOrder()); for(int i=1; i <= M; i++) pq.add(new Unit(0, i)); for(Unit add: ls) { Unit tower = pq.poll(); tower.height += add.height; res[add.id] = tower.id; pq.add(tower); } int min = pq.poll().height; int max = min; while(pq.size() > 0) max = max(max, pq.poll().height); if(max-min > X) sb.append(""NO\n""); else { sb.append(""YES\n""); for(int x: res) sb.append(x+"" ""); sb.append(""\n""); } } System.out.print(sb); } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } } class Unit implements Comparable { public int id; public int height; public Unit(int h, int i) { height = h; id = i; } public int compareTo(Unit oth) { return oth.height-height; } }",0,Non-plagiarised 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 al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al); for(int i=0;i cycle = new ArrayList<>(); cycle.add(query(i)); while (cycle.size() == 1 || !cycle.get(0).equals(cycle.get(cycle.size() - 1))) { cycle.add(query(i)); } cycle.remove(cycle.size() - 1); for(int j = 0; j < cycle.size() - 1; j++){ p[cycle.get(j)] = cycle.get(j + 1); } p[cycle.get(cycle.size() - 1)] = cycle.get(0); //System.out.println(Arrays.toString(p)); } StringBuilder b = new StringBuilder(); b.append(""! ""); for (int i = 0; i < n; i++) { b.append((p[i] + 1) + (i < n - 1 ? "" "" : ""\n"")); } System.out.print(b); System.out.flush(); } in.close(); out.close(); } public static int query(int i) throws Exception { System.out.println(""? "" + (i + 1)); System.out.flush(); int k = Integer.parseInt(in.readLine()); return k - 1; } } ","import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class C { private static StringTokenizer st; private static BufferedReader br; private static PrintWriter out; static boolean[]used; static int[]p; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t = nextInt(); while (t --> 0) { int n = nextInt(); used = new boolean[n+1]; p = new int[n+1]; for (int i = 1; i <= n; i++) { if (!used[i]) { go(i); } } System.out.print(""! ""); for (int i = 1; i <= n; i++) { System.out.print(p[i]+"" ""); } System.out.println(); } out.close(); } private static void go(int i) throws IOException { List inCycle = new ArrayList<>(); int first = -1; while (true) { System.out.println(""? "" + i); int x = nextInt(); used[x] = true; if (x == first) { break; } if (first == -1) { first = x; } inCycle.add(x); } List numbers = new ArrayList<>(); for (int j = 0; j < inCycle.size(); j++) { if (inCycle.get(j) == i) { for (int k = j; k < inCycle.size(); k++) { numbers.add(inCycle.get(k)); } for (int k = 0; k < j; k++) { numbers.add(inCycle.get(k)); } break; } } if (numbers.size() == 1) { p[numbers.get(0)] = numbers.get(0); } else { for (int j = 0; j < numbers.size()-1; j++) { p[numbers.get(j)] = numbers.get(j+1); } p[numbers.get(numbers.size()-1)] = numbers.get(0); } } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String next() throws IOException { while (st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } }",0,Non-plagiarised 26e699de,f229aa7f,"//package Task1; 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(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }",0,Non-plagiarised 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 static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }"," import java.io.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 print(Object o) { System.out.println(String.valueOf(o)); } static int[] toIntArr(String s){ int[] val= new int[s.length()]; for(int i=0;i list= new ArrayList<>(); for(int i=0;i list= new ArrayList<>(); for(int i=0;i { public int compare(pair p1, pair p2) { if (p1.yy > p2.yy) { return 1; } else if (p1.yy == p2.yy) { if (p1.xx > p2.xx) { return 1; } else if (p1.xx < p2.xx) { return -1; } return 0; } return -1; } } class sortX implements Comparator { public int compare(pair p1, pair p2) { if (p1.xx > p2.xx) { return 1; } else if (p1.xx == p2.xx) { if (p1.yy > p2.yy) { return 1; } else if (p1.yy < p2.yy) { return -1; } return 0; } return -1; } } class debug { static void print1d(long[] arr) { System.out.println(); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + "" ""); } } static void print1d(int[] arr) { System.out.println(); for (int i = 0; i < arr.length; i++) { System.out.println(i+"" = ""+arr[i]); } } static void print1d(boolean[] arr) { System.out.println(); for (int i = 0; i < arr.length; i++) { System.out.println(i + ""= "" + arr[i]); } } static void print2d(int[][] arr) { System.out.println(); int n = arr.length; int n2 = arr[0].length; for (int i = 0; i < n; i++) { for (int j = 0; j < n2; j++) { System.out.print(arr[i][j] + "" ""); } System.out.println(); } } static void print2d(boolean[][] arr) { System.out.println(); int n = arr.length; int n2 = arr[0].length; for (int i = 0; i < n; i++) { for (int j = 0; j < n2; j++) { System.out.print(arr[i][j] + "" ""); } System.out.println(); } } static void print2d(long[][] arr) { System.out.println(); int n = arr.length; int n2 = arr[0].length; for (int i = 0; i < n; i++) { for (int j = 0; j < n2; j++) { System.out.print(arr[i][j] + "" ""); } System.out.println(); } } static void printPair(ArrayList list) { if(list.size()==0){ System.out.println(""empty list""); return; } System.out.println(); for(int i=0;i= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } class MultiTreeSet { TreeMap freqTreeMap = new TreeMap(); int size; public MultiTreeSet() {} public MultiTreeSet(Collection c) { for(E element : c) add(element); } public int size() { return size; } public void add(E element) { Integer freq = freqTreeMap.get(element); if(freq==null) freqTreeMap.put(element, 1); else freqTreeMap.put(element,freq+1); ++size; } public void remove(E element) { Integer freq = freqTreeMap.get(element); if(freq!=null) { if(freq==1) freqTreeMap.remove(element); else freqTreeMap.put(element, freq-1); --size; } } public int get(E element) { Integer freq = freqTreeMap.get(element); if(freq==null) return 0; return freq; } public boolean contains(E element) { return get(element)>0; } public boolean isEmpty() { return size==0; } public E first() { return freqTreeMap.firstKey(); } public E last() { return freqTreeMap.lastKey(); } public E ceiling(E element) { return freqTreeMap.ceilingKey(element); } public E floor(E element) { return freqTreeMap.floorKey(element); } public E higher(E element) { return freqTreeMap.higherKey(element); } public E lower(E element) { return freqTreeMap.lowerKey(element); } } ",0,Non-plagiarised 28d8c381,417833c3,"import java.io.*; import java.sql.SQLOutput; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int i = 0; i < numCases; i++) { int length = Integer.parseInt(br.readLine()); int found = 0; int[] ret = new int[length + 1]; for (int j = 1; j <= length; j++) { if (found == length - 1) { break; } if (ret[j] == 0) { System.out.println(""? "" + j); System.out.flush(); int start = Integer.parseInt(br.readLine()); int lastNum = start; boolean cont = true; while (cont) { System.out.println(""? "" + j); System.out.flush(); int num = Integer.parseInt(br.readLine()); ret[lastNum] = num; found++; lastNum = num; if (num == start) cont = false; } } } for (int j = 0; j <= length; j++) if (ret[j] == 0) ret[j] = j; System.out.print(""! ""); for (int j = 1; j <= length; j++) System.out.print(ret[j] + "" ""); System.out.println(); } br.close(); } }","import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; 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 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 boolean f(String A,String B) { char X[]=A.toCharArray(),Y[]=B.toCharArray(); if(X[X.length-1]=='0' && A.length()==B.length()) { return A.equals(B); } else if(X[X.length-1]=='0') { for(int i=0; i ""+x.ch+"" ""+t); return true; } } } if(cnt==0)return true; return false; } static boolean f(Trie root) { if(root==null)return false; // int cnt=0; for(Trie x:root.A) { if(x!=null) { // cnt++; if(!f(x)) { return true; } } } return false; } static void insert(String X,Trie head) { Trie root=head; for(char x:X.toCharArray()) { int a=x-'a'; if(root.A[a]==null)root.A[a]=new Trie(); root=root.A[a]; root.ch=x; } root.ends=true; } static boolean search(String X,Trie head) { Trie root=head; for(char x:X.toCharArray()) { int a=x-'a'; if(root.A[a]==null)return false; root=root.A[a]; } return root.ends; } static boolean starts_with(String X,Trie head) { Trie root=head; for(char x:X.toCharArray()) { int a=x-'a'; if(root.A[a]==null)return false; root=root.A[a]; } return true; } static int lower(ArrayListA,int i) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; if(A.get(m)>i)r=m; else l=m; } return r; } static int upper(ArrayListA,int i) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; if(A.get(m)0)X.append(""0""); return X.toString(); } static long f(int i,int g,int x,int left) { if(x<=1)return left; if(i<0 || g==1)return left; // System.out.println(i+"" ""+g); if(dp[i][g]==0) { int next=min[i]; int new_gcd=(int)GCD(g,x); //System.out.println("" factor--> ""+x+"" gcd--> ""+g+"" new--> ""+new_gcd); long s=0; int c=0; for(int j=next+1; j<=i; j++) { if(A[i]%new_gcd==0) { s+=new_gcd; c--; } } long a=0,b=0; a=f(i,g,x-1,left); b=s+f(next,new_gcd,x-1,left-c); dp[i][g]=Math.max(a, b); } return dp[i][g]; } static boolean f(int A[],int B[],int x) { int c=0; int N=A.length; int l=0,r=x-1; for(int i=0; i=r && B[i]>=l) { r--; l++; c++; } if(c>=x)return true; } return false; } static boolean isPalindrome(int A[]) { int i=0,j=A.length-1; while(i A,int x) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; if(A.get(m)1) { int m=(l+r)/2; if(A[m]<=a)l=m; else r=m; } return A[l]; } static void build(int v,int tl,int tr,int A[]) { if(tl==tr) { seg[v]=A[tl]; return; } 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 void update(int v,int tl,int tr,int index,int x) { if(tl==tr && tl==index) { seg[v]=x; return; } int tm=(tl+tr)/2; if(index<=tm)update(v*2,tl,tm,index,x); else update(v*2+1,tm+1,tr,index,x); seg[v]=Math.min(seg[v*2], seg[v*2+1]); } 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 find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; par[b]=a; } } static int ask(int a,int b) { System.out.println(""? ""+a+"" ""+b); return i(); } static long and(int i,int j) { System.out.println(""and ""+i+"" ""+j); return l(); } static long or(int i,int j) { System.out.println(""or ""+i+"" ""+j); return l(); } static boolean is_Sorted(int A[]) { int N=A.length; for(int i=1; i<=N; i++)if(A[i-1]!=i)return false; return true; } static boolean f(StringBuilder sb,String Y,String order) { StringBuilder res=new StringBuilder(sb.toString()); HashSet set=new HashSet<>(); for(char ch:order.toCharArray()) { set.add(ch); for(int i=0; i0) { x*=10; x+=a; } return x; } static int count(String X) { HashSet set=new HashSet<>(); for(char x:X.toCharArray())set.add(x-'0'); return set.size(); } // 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 [] sub(int A[],int B[]) { int N=A.length; int f[]=new int[N]; for(int i=N-1; i>=0; i--) { if(B[i] Hash(int A[]) { HashMap mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static long mul(long a, long b) { return ( a %mod * 1L * b%mod )%mod; } static void swap(int A[],int a,int b) { int t=A[a]; A[a]=A[b]; A[b]=t; } static boolean isSorted(int A[]) { for(int i=1; i high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static String f(String A) { String X=""""; for(int i=A.length()-1; i>=0; i--) { int c=A.charAt(i)-'0'; X+=(c+1)%2; } return X; } static void sort(long[] a) //check for long { ArrayList l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i(); Days[i]=-1; D[i]=Integer.MAX_VALUE; //D2[i]=INF; } } static long pow(long a,long b) { long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1< l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i A) { for(int a:A)System.out.print(a+"" ""); System.out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i0){ int n = scanner.nextInt(); int k = scanner.nextInt(); int[] c = new int[n]; Arrays.fill(c,inf); int[] a = new int[k]; int[] b = new int[k]; for(int i=0;i=0;--i){ c[i] = Math.min(c[i],c[i+1]+1); } for(int i=0;i=0;i--){ 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=x; } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList add(int id,int c) { ArrayList newArr=new ArrayList<>(); for(int i=0;i arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } static int lower(ArrayList arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } static int N = 501; // 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet factors(int x) { HashSet a=new HashSet(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap findFactors(long n2) { HashMap ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i primes; static HashSet primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? ""YES"" : ""NO""); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static 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 double sum[]; static long cnt; // 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; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } ","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 boolean overlapping(pair p1, pair p2) { if((p2.f >= p1.f && p1.s >= p2.f) || (p2.s >= p1.f && p1.s >= p2.s)) { return true; } return false; } 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 String toString() { StringBuilder sb = new StringBuilder(); sb.append(""{"" + f + "","" + s + ""}""); return sb.toString(); } @Override public int compareTo(pair o) { return f - o.f; } 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); } } public static void print(long a, long b, long c, PrintWriter pw) { pw.println(a + "" "" + b + "" "" + c); return; } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[][] read2Array(int n, int m) { int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } } }",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 l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); 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; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }",0,Non-plagiarised abd16ff0,db1ef8b3,"import java.util.*; public class Solve{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long ans=Long.MAX_VALUE; long pre=0; PriorityQueue epq=new PriorityQueue<>(); PriorityQueue opq=new PriorityQueue<>(); for(int i=0;i0) ans=Math.min(ans,pre+opq.peek()*(n-opq.size())+epq.peek()*(n-epq.size())); } System.out.println(ans); } } }","import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ public class C { private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; public static void process() throws IOException { int n = sc.nextInt(); PriorityQueue odd = new PriorityQueue(); PriorityQueue even = new PriorityQueue(); int arr[] = sc.readArray(n); long min = INF; long sumOdd = 0; long sumEven = 0; for (int i = 0; i < n; i++) { int x = arr[i]; if (i % 2 == 0) { even.add(x); sumEven += x; } else { odd.add(x); sumOdd += x; } if (i > 0) { long ans = 0; ans += 1l * even.peek() * (n - (even.size())); ans += 1l * odd.peek() * (n - (odd.size())); ans += sumOdd + sumEven; min = Math.min(ans, min); } } System.out.println(min); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= static FastScanner sc; static PrintWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new PrintWriter(System.out); } else { sc = new FastScanner(100); out = new PrintWriter(""output.txt""); } int t = 1; t = sc.nextInt(); while (t-- > 0) { process(); } out.flush(); out.close(); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader(""input.txt"")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } } ",0,Non-plagiarised 2560850b,76791c9f,"//package notassigning; 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 int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable{ int a, b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return Integer.compare(this.a, o.a); } } static class answer1 implements Comparable{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { return (o.a - this.a); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList l = new ArrayList<>(); for (Long i:a) l.add(i); l.sort(Collections.reverseOrder()); for (int i=0; i 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 ; public static long dp (int idx,int time){ if ( idx == n){ return 0; } if (memo[idx][time] != -1){ return memo[idx][time]; } long take = 0; if (3 * w*depth[idx] <= time){ take = values[idx]+ dp(idx+1, time-3*w*depth[idx]); } long leave = dp(idx+1, time); return memo[idx][time]=Math.max(take, leave); } static class Pair implements Comparable { String x; int y; public Pair (String x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Object o){ Pair p = (Pair) o; return p.y -y; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public boolean hasNext() { // TODO Auto-generated method stub return false; } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder(""0""); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder(""0""); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } } ",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 long gcd(long a,long b) { return b==0 ? a:gcd(b,a%b); } /* 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; } } */ public static void ncr() { cr[0][0]=1; for(int i=1;i<=1000;i++) { cr[i][0]=1; for(int j=1;j { int a;int b; pair(int a,int b) { this.b=b; this.a=a; } } class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return """"; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i0) { 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); } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i lt1=new ArrayList<>(); ArrayList lt0=new ArrayList<>(); for(int i=0;i() { @Override public int compare(Pair p1, Pair p2) { if(p1.x!=p2.x) { return (int)(p1.x - p2.x); } else { return (int)(p1.y - p2.y); } } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + "" "" + arr[i].y + "" ""); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int solve(int dp[][] , ArrayList one , ArrayList zero , int i,int j) { int n=one.size(); int m=zero.size(); if(i>=n) return 0; else if(j>=m) return Integer.MAX_VALUE; else if(dp[i][j]!=-1) return dp[i][j]; int val1 = Math.abs(one.get(i)-zero.get(j))+solve(dp, one ,zero ,i+1,j+1); int val2 = solve(dp , one , zero , i,j+1); dp[i][j]= Math.min(val1,val2); return dp[i][j]; } 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[] 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 int getLeftId(int nodeId) { return tree[nodeId].left; } private static int getRightId(int nodeId) { return tree[nodeId].right; } private static Integer getInt(BufferedReader br) throws Exception { return Integer.parseInt(br.readLine()); } private static Long getLong(BufferedReader br) throws Exception { return Long.parseLong(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 int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static int[] sp; static int size=(int)1e6; static int[] arInt; static long[] arLong; 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=x; } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList add(int id,int c) { ArrayList newArr=new ArrayList<>(); for(int i=0;i arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } static int lower(ArrayList arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } static int N = 501; // 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet factors(int x) { HashSet a=new HashSet(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap findFactors(long n2) { HashMap ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i primes; static HashSet primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? ""YES"" : ""NO""); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static 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 double sum[]; static long cnt; // 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; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } ","import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); // static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException, CloneNotSupportedException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); for(int i=1;i<=t;i++) solve(i); out.close(); out.flush(); // System.out.flush(); // System.exit(0); } static void solve(int CASENO) throws IOException, CloneNotSupportedException { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+500*Math.abs(y); } @Override public String toString() { return ""(""+x+"" ""+y+"")""; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a,Comparator.reverseOrder()); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; Node(int ver) { vertex=ver; dis=-1; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res%mod; } static long binomialCoeff(long n, long k) { if(n n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ",1,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;iy) return gcd(x%y,y); else return gcd(x,y%x); } public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub br=new BufferedReader(new InputStreamReader(System.in)); pr=new PrintWriter(new OutputStreamWriter(System.out)); int cases=cin(); while(cases!=0) { cases--; int[]ar=split(); int n=ar[0]; int m=ar[1]; int[][]mat=new int[n][m]; for(int i=0;ians=new ArrayList<>(); for(int i=0;iy) return gcd(x%y,y); else return gcd(x,y%x); } public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub br=new BufferedReader(new InputStreamReader(System.in)); pr=new PrintWriter(new OutputStreamWriter(System.out)); int cases=cin(); while(cases!=0) { cases--; int[]ar=split(); int n=ar[0]; int m=ar[1]; int[][]mat=new int[n][m]; for(int i=0;ians=new ArrayList<>(); for(int i=0;i= 0) { bool[0] = false; bool[1] = false; } return bool; } /* ***************************************************************************************************************************************************/ static FR sc = new FR(); static StringBuilder sb = new StringBuilder(); public static void main(String args[]) { int tc = sc.nextInt(); while(tc-- > 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) public void sieve() { spf[1] = 1; for (int i=2; i getFactorization(int x) { if(dp.containsKey(x)) return dp.get(x); Set ret = new HashSet<>(); while (x != 1) { if(spf[x]!=2) ret.add(spf[x]); x = x / spf[x]; } dp.put(x,ret); return ret; } // function to find first index >= x public int lowerIndex(List arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y public int upperIndex(List arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } // function to count elements within given range public int countInRange(List arr, int n, int x, int y) { // initialize result int count = 0; count = upperIndex(arr, n, y) - lowerIndex(arr, n, x) + 1; return count; } 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; // } // } public int _gcd(int a, int b) { if(b == 0) { return a; } else { return _gcd(b, a % b); } } } // static class Data{ // List arr; // BigInteger prod=new BigInteger(-1); // public Data(List arr, BigInteger prod) { // this.arr= arr; // this.prod= prod; // } // } static class Tuple implements Comparable{ int x, y, z; public Tuple(int x, int y, int z){ this.x= x; this.y= y; this.z=z; } @Override public int compareTo(Tuple o){ return this.x-o.x; } } static class Pair implements Comparable{ public int x; public int y; public Pair(int x, int y){ this.x= x; this.y= y; } @Override public int compareTo(Pair o) { return this.x-o.x; } } // fast input reader class; static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { String line = null; try { line = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble(){ return Double.parseDouble(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } } }",0,Non-plagiarised a60fba84,c695a974,"/*input 3 2 13 88 3 2 3 1 5 4 3 2 1 4 */ import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out; static int MOD = 1000000007; static FastReader scan; /*-------- I/O using short named function ---------*/ public static String ns(){return scan.next();} public static int ni(){return scan.nextInt();} public static long nl(){return scan.nextLong();} public static double nd(){return scan.nextDouble();} public static String nln(){return scan.nextLine();} public static void p(Object o){out.print(o);} public static void ps(Object o){out.print(o + "" "");} public static void pn(Object o){out.println(o);} /*-------- for output of an array ---------------------*/ static void iPA(int arr []){ StringBuilder output = new StringBuilder(); for(int i=0; i0){ int n = ni(); 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; } public int compare(String a, String b) { double cnt1 = 0; double cnt2 = 0; for (int i=0; i0){ 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 void mergeSort(int arr[]){ int n= arr.length; for (int sz= 1; sz<=n-1; sz=2*sz){ for (int l= 0; l 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""); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised 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); } } static class InputReader { private static final int BUFFER_LENGTH = 1 << 10; private InputStream stream; private byte[] buf = new byte[BUFFER_LENGTH]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int nextC() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String next() { int c = nextC(); while (isSpaceChar(c)) { c = nextC(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = nextC(); } while (!isSpaceChar(c)); return res.toString(); } public int nextInt() { int c = skipWhileSpace(); int sgn = 1; if (c == '-') { sgn = -1; c = nextC(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = nextC(); } while (!isSpaceChar(c)); return res * sgn; } public int skipWhileSpace() { int c = nextC(); while (isSpaceChar(c)) { c = nextC(); } return c; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } } ","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] temp = new ArrayList<>(); for(long x:arr) temp.add(x); Collections.sort(temp); int i=0; for(long x:temp){ arr[i++]=x; } return arr; } public static int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public int[] readIntArray(int n){ int[] arr=new int[n]; for(int i=0;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); } public static void sort(long[] a) { List list = new ArrayList(); for (int i = 0; i < a.length; i++) { list.add(a[i]); } Collections.sort(list); for (int i = 0; i < a.length; i++) { a[i] = list.get(i); } } public static long gcd(long n1, long n2) { if (n2 == 0) { return n1; } return gcd(n2, n1 % n2); } } class UnionFind16 { int[] id; public UnionFind16(int size) { id = new int[size]; for (int i = 0; i < size; i++) { id[i] = i; } } public int find(int p) { int root = p; while (root != id[root]) { root = id[root]; } while (p != root) { int next = id[p]; id[p] = root; p = next; } return root; } public void union(int p, int q) { int a = find(p), b = find(q); if (a == b) { return; } id[b] = a; } } class FastScanner57 { BufferedReader br; StringTokenizer st; public FastScanner57() { br = new BufferedReader(new InputStreamReader(System.in), 32768); st = null; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) { ret[i] = ni(); } return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) { ret[i] = nl(); } return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ","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}; } } class SpeedScanner { BufferedReader in; StringTokenizer splitter; public SpeedScanner() { in = new BufferedReader(new InputStreamReader(System.in)); } String next() { while(splitter == null || !splitter.hasMoreElements()) try { splitter = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } return splitter.nextToken(); } String nextLine() { String s = """"; try { s = in.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } ",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 class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int mod = (int)(1e9+7); public static long pow(long a,long b) { long ans = 1; while(b> 0) { if((b & 1)==1){ ans = (ans*a) % mod; } a = (a*a) % mod; b = b>>1; } return ans; } 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); } } static class Reader { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; String next() { while(st==null||!st.hasMoreTokens()) { try { st=new StringTokenizer(in.readLine()); } catch(Exception e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } } ","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; } } static int BS(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] == element) { return low; } else if (arr[high] == element) { return high; } return -1; } static int lower_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] >= element) { return low; } else if (arr[high] >= element) { return high; } return -1; } static int upper_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] <= element) { low = mid + 1; } else { high = mid; } } if (arr[low] > element) { return low; } else if (arr[high] > element) { return high; } return -1; } public static long gcd_long(long a,long b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_long(b, a%b); } public static int gcd_int(int a,int b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_int(b, a%b); } public static int lcm(int a,int b){ int gcd=gcd_int(a, b); return (a*b)/gcd; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String s = """"; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } Long nextLong() { return Long.parseLong(next()); } } } /* * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){ * return true; } if(n<1 || m<1 || k<0){ return false; } boolean * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; } * return false; } */ ",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 al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al); for(int i=0;i 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; } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) { writer.print(' '); } writer.print(array[i]); } } public void println(int[] array) { print(array); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } } ",0,Non-plagiarised 1c4d348d,565f77b7,"/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Solution { public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class SortbyHeight implements Comparator { public int compare(Struct a, Struct b) { return a.h - b.h; } } 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; } public int compareTo(Pair o) { return Long.compare(value, o.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); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ","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(); } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } static final long mod = 1000000007; static long pow_mod(long a, long b) { long result = 1; while (b != 0) { if ((b & 1) != 0) result = (result * a) % mod; a = (a * a) % mod; b >>= 1; } return result; } private static long multiplied_mod(long... longs) { long ans = 1; for (long now : longs) { ans = (ans * now) % mod; } return ans; } @SuppressWarnings(""FieldCanBeLocal"") private static Reader in; private static PrintWriter out; private static int[] read_int_array(int len) throws IOException { int[] a = new int[len]; for (int i = 0; i < len; i++) { a[i] = in.nextInt(); } return a; } private static long[] read_long_array(int len) throws IOException { long[] a = new long[len]; for (int i = 0; i < len; i++) { a[i] = in.nextLong(); } return a; } private static void print_array(int[] array) { for (int now : array) { out.print(now); out.print(' '); } out.println(); } private static void print_array(long[] array) { for (long now : array) { out.print(now); out.print(' '); } out.println(); } static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { final byte[] buf = new byte[1024]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextSign() throws IOException { byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } }",0,Non-plagiarised 47d54299,da0b7cb2,"// package com.company.Codechef; // import com.sun.security.jgss.GSSUtil; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class a { static int depth[]; static ArrayList tree[]; static int diameter=0; public static void main(String[] args) { FastReader input=new FastReader(); int t=input.nextInt(); while (t-->0){ diameter=0; int n=input.nextInt(); int a=input.nextInt(); int b=input.nextInt(); int da=input.nextInt(); int db=input.nextInt(); depth=new int[n+1]; tree=new ArrayList[n+1]; for (int i = 0; i <=n ; i++) { tree[i]=new ArrayList<>(); } for (int i = 0; i = Math.min(diameter, db) ||depth[b]<=da){ System.out.println(""Alice""); }else { System.out.println(""Bob""); } } } private static int dfs(int root, int p) { int len=0; for(int child:tree[root]){ if (child!=p){ depth[child]=depth[root]+1; int curr=1+dfs(child,root); diameter=Math.max(diameter,curr+len); len=Math.max(len,curr); } } return len; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }","import java.io.*; import java.util.*; import static java.lang.Math.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Codeforces { public static void main(String[] args) throws IOException { // InputStream inputStream = new FileInputStream(""input.txt""); // OutputStream outputStream = new FileOutputStream(""output.txt""); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in.nextInt(), in, out); out.close(); } static class TaskA { long mod = (long)(1000000007); long fact[]; int depth[]; int parentTable[][]; int degree[]; ArrayList leaves; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; int diam = 0; public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException { while(testNumber-->0){ int n = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); int na = in.nextInt(); int nb = in.nextInt(); ArrayList> g = new ArrayList<>(); for(int i=0;i<=n;i++) g.add(new ArrayList<>()); for(int i=1;i=nb){ out.println(""Alice""); continue; } // parentTable = new int[n+1][31]; depth = new int[n+1]; diam = 0; dfs(g , a , 0); int distance = depth[b]; // out.println(distance); if(distance <= na){ out.println(""Alice""); continue; } if(2*na >= min(nb , diam)) out.println(""Alice""); else out.println(""Bob""); // max = Integer.MIN_VALUE; // int diameter = diameter(g , 1 , 0); // int height = 0; // for(int i=1;i<=n;i++) // height = max(height , depth[i]); // // out.println(""diameter"" + diameter); // // out.println(""height"" + height); // // out.println(""max"" + max); // diameter = max(diameter-1 , height-1); // // diameter = max(diameter , max-1); // nb = min(nb , diameter); // na = min(na , diameter); // if(na*2 >= nb) // out.println(""Alice""); // else // out.println(""Bob""); } } int dfs(ArrayList> a , int x, int p) { int len = 0; for(int y : a.get(x)) { if(y != p) { depth[y] = depth[x] + 1; int cur = 1 + dfs(a , y, x); diam = max(diam, cur + len); len = max(len, cur); } } return len; } public int diameter(ArrayList> a , int index , int parent){ if(index == parent) return 0; // if(a.get(index).size() == 1 && a.get(index).get(0) == parent) // return 1; ArrayList x = new ArrayList<>(); x.add(0); x.add(0); for(int i=0;i= 4){ int n = x.size(); max = max(max , 1+x.get(n-1) + x.get(n-2)); } return 1 + x.get(x.size()-1); } // public void dfs(ArrayList> a , int index , int parent){ // parentTable[index][0] = parent; // for(int i=1;i<31;i++) // parentTable[index][i] = parentTable[parentTable[parent][i-1]][i-1]; // depth[index] = 1+depth[parent]; // int l = a.get(index).size(); // for(int i=0;i> a , int u , int v){ return depth[u]+depth[v] - 2*depth[lca(a , u , v)]; } public int lca(ArrayList> a , int u , int v){ if(depth[v]>i)&1) == 1) v = parentTable[v][i]; } if(v == u) return v; for(int i=parentTable[v].length-1;i>=0;i--){ if(parentTable[u][i] != parentTable[v][i]){ v = parentTable[v][i]; u = parentTable[u][i]; } } return parentTable[u][0]; } class Pair{ int start; int end; int index; public Pair(int a , int b , int c){ start = a; end = b; end = c; } } class Node{ char value; Node left; Node right; public Node(char value){ this.value = value; left = null; right = null; } } public int[][] multiply(int a[][] , int b[][]){ int c[][] = new int[a.length][b[0].length]; for(int i=0;i0){ if((b&1) == 1) res = multiply(res , a , 10); a = multiply(a , a , 10); b>>=1; } return res; } // for the min max problems public void build(int lookup[][] , int arr[], int n) { for (int i = 0; i < n; i++) lookup[i][0] = arr[i]; for (int j = 1; (1 << j) <= n; j++) { for (int i = 0; (i + (1 << j) - 1) < n; i++) { if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1]) lookup[i][j] = lookup[i][j - 1]; else lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1]; } } } public int query(int lookup[][] , int L, int R) { int j = (int)(Math.log(R - L + 1)/Math.log(2)); if (lookup[L][j] >= lookup[R - (1 << j) + 1][j]) return lookup[L][j]; else return lookup[R - (1 << j) + 1][j]; } // for printing purposes public void print1d(int a[] , PrintWriter out){ for(int i=0;i 0) { long x = b&1; if (x == 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } public long pow(long a, long b) { long res = 1; while (b > 0) { long x = b&1; if (x == 1) res = res * a; a = a * a; b >>= 1; } return res; } public void sortedArrayToBST(TreeSet a , int start, int end) { if (start > end) { return; } int mid = (start + end) / 2; a.add(mid); sortedArrayToBST(a, start, mid - 1); sortedArrayToBST(a, mid + 1, end); } class Combine{ int value; int delete; Combine(int val , int delete){ this.value = val; this.delete = delete; } } class Sort2 implements Comparator{ public int compare(Combine a , Combine b){ if(a.value > b.value) return 1; else if(a.value == b.value && a.delete>b.delete) return 1; else if(a.value == b.value && a.delete == b.delete) return 0; return -1; } } public int lowerLastBound(ArrayList a , int x){ int l = 0; int r = a.size()-1; if(a.get(l)>=x) return -1; if(a.get(r)=x) r = mid-1; else if(a.get(mid)=x) return mid; else if(a.get(mid) a , Integer x){ int l = 0; int r = a.size()-1; if(a.get(l)>x) return l; if(a.get(r)<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a.get(mid) == x && a.get(mid+1)>x) return mid+1; else if(a.get(mid)<=x) l = mid+1; else if(a.get(mid)>x && a.get(mid-1)<=x) return mid; else if(a.get(mid)>x && a.get(mid-1)>x) r = mid-1; } return mid; } public int lowerLastBound(int a[] , int x){ int l = 0; int r = a.length-1; if(a[l]>=x) return -1; if(a[r]=x) r = mid-1; else if(a[mid]=x) return mid; else if(a[mid]x) return l; if(a[r]<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a[mid] == x && a[mid+1]>x) return mid+1; else if(a[mid]<=x) l = mid+1; else if(a[mid]>x && a[mid-1]<=x) return mid; else if(a[mid]>x && a[mid-1]>x) r = mid-1; } return mid; } public long log(float number , int base){ return (long) Math.ceil((Math.log(number) / Math.log(base)) + 1e-9); } public long gcd(long a , long b){ if(agcd 1->xValue 2->yValue return new long[] { d, a, b }; } public void sievePhi(int a[]){ a[0] = 0; a[1] = 1; for(int i=2;i p = new HashSet<>(); static boolean debug =true; // Arrays.sort(time , (a1,a2) -> (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=max(max,cnt); } System.out.println(max); } } public static void print(String var ,E e){ if(debug==true){ System.out.println(var +"" ""+e); } } private static long[] sort(long[] e){ ArrayList x=new ArrayList<>(); for(long c:e){ x.add(c); } Collections.sort(x); long[] y = new long[e.length]; for(int i=0;i b) return gcd(a % b, b); return gcd(a, b % a); } public static long min(long a, long b) { return Math.min(a, b); } public static int min(int a, int b) { return Math.min(a, b); } public static void sieve() { int[] pf = new int[100000000 + 1]; //0 prime //1 not prime pf[0] = 1; pf[1] = 1; for (int j = 2; j <= 10000; j++) { if (pf[j] == 0) { p.add(j); for (int k = j * j; k < pf.length; k += j) { pf[k] = 1; } } } } public static int[] readArray(int n, int x, int z) throws Exception { int[] arr = new int[n]; String[] ar = cinA(); for (int i = x; i < n + x; i++) { arr[i] = getI(ar[i - x]); } return arr; } public static long[] readArray(int n, int x) throws Exception { long[] arr = new long[n]; String[] ar = cinA(); for (int i = x; i < n + x; i++) { arr[i] = getL(ar[i - x]); } return arr; } public static void arrinit(String[] a, long[] b) throws Exception { for (int i = 0; i < a.length; i++) { b[i] = Long.parseLong(a[i]); } } public static HashSet[] Graph(int n, int edge, int directed) throws Exception { HashSet[] tree = new HashSet[n]; for (int j = 0; j < edge; j++) { String[] uv = cinA(); int u = getI(uv[0]); int v = getI(uv[1]); if (directed == 0) { tree[v].add(u); } tree[u].add(v); } return tree; } public static void arrinit(String[] a, int[] b) throws Exception { for (int i = 0; i < a.length; i++) { b[i] = Integer.parseInt(a[i]); } } static double findRoots(int a, int b, int c) { // If a is 0, then equation is not //quadratic, but linear int d = b * b - 4 * a * c; double sqrt_val = Math.sqrt(Math.abs(d)); // System.out.println(""Roots are real and different \n""); return Math.max((double) (-b + sqrt_val) / (2 * a), (double) (-b - sqrt_val) / (2 * a)); } public static String cin() throws Exception { return br.readLine(); } public static String[] cinA() throws Exception { return br.readLine().split("" ""); } public static String[] cinA(int x) throws Exception { return br.readLine().split(""""); } public static String ToString(Long x) { return Long.toBinaryString(x); } public static void cout(String s) { System.out.println(s); } public static Integer cinI() throws Exception { return Integer.parseInt(br.readLine()); } public static int getI(String s) throws Exception { return Integer.parseInt(s); } public static long getL(String s) throws Exception { return Long.parseLong(s); } public static long max(long a, long b) { return Math.max(a, b); } public static int max(int a, int b) { return Math.max(a, b); } public static void coutI(int x) { System.out.println(String.valueOf(x)); } public static void coutI(long x) { System.out.println(String.valueOf(x)); } public static Long cinL() throws Exception { return Long.parseLong(br.readLine()); } public static void arrInit(String[] arr, int[] arr1) throws Exception { for (int i = 0; i < arr.length; i++) { arr1[i] = getI(arr[i]); } } }","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; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ",0,Non-plagiarised 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]); } } } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } } ",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""); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class D { static class Pair{ int val; char c; Pair(int a,char b){ this.val=a; this.c=b; } } public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); PrintWriter pw=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int[] a=sc.readArray(n); char[] s=sc.next().toCharArray(); boolean ok=true; ArrayList blues=new ArrayList<>(); ArrayList reds=new ArrayList<>(); for(int i=0;i(start++)){ ok=false; break; } } if(ok){ pw.println(""YES""); } else { pw.println(""NO""); } } pw.flush(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i0;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;ikey) return i; while (i arr, long n) { arr.sort(new Comparator() { @Override public int compare(Pair p1, Pair p2) { return (int) (p1.first - p2.first); } }); } } public static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st==null || !st.hasMoreElements()){ try{ st=new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ String str=""""; try{ str=br.readLine(); }catch (Exception e){ e.printStackTrace(); } return str; } } }","import java.io.*; import java.util.*; import java.lang.*; public class codeforces { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; if (System.getProperty(""ONLINE_JUDGE"") == null) { long startTime = System.currentTimeMillis(); try { sc = new InputReader(new FileInputStream(""input.txt"")); out = new PrintWriter(new FileOutputStream(""output.txt"")); pr = new PrintWriter(new FileOutputStream(""error.txt"")); } catch (Exception ignored) { } int t = 1; int tt = t; t = sc.nextInt(); while (t-- > 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 static class Pair { int first, second; Pair(int x, int y) { this.first = x; this.second = y; } } // FastReader Class static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } // Req Functions public static void fill(int[][] dp, int x) { for (int i = 0; i < dp.length; ++i) { for (int j = 0; j < dp[0].length; ++j) { dp[i][j] = x; } } } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static long nCr(int n, int k) { long ans = 1L; k = k > n - k ? n - k : k; int j = 1; for (; j <= k; j++, n--) { if (n % j == 0) { ans *= n / j; } else if (ans % j == 0) { ans = ans / j * n; } else { ans = (ans * n) / j; } } return ans; } public static String reverseString(String input) { StringBuilder str = new StringBuilder(""""); for (int i = input.length() - 1; i >= 0; i--) { str.append(input.charAt(i)); } return str.toString(); } public static int maxOf3(int x, int y, int z) { return Math.max(x, Math.max(y, z)); } public static int minof3(int x, int y, int z) { return Math.min(x, Math.min(y, z)); } public static long maxOf3(long x, long y, long z) { return Math.max(x, Math.max(y, z)); } public static long minof3(long x, long y, long z) { return Math.min(x, Math.min(y, z)); } public static void arrInput(int[] arr, int n) { for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); } public static void arrInput(long[] arr, int n) { for (int i = 0; i < n; i++) arr[i] = sc.nextLong(); } public static void arrInput(Pair[] pair, int n) { for (int i = 0; i < n; i++) pair[i] = new Pair(sc.nextInt(), sc.nextInt()); } public static int maxarrInput(int[] arr, int n) { int max = minf; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); max = Math.max(max, arr[i]); } return max; } public static long maxarrInput(long[] arr, int n) { long max = minf; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); max = Math.max(max, arr[i]); } return max; } public static int minarrInput(int[] arr, int n) { int min = inf; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); min = Math.max(min, arr[i]); } return min; } public static long minarrInput(long[] arr, int n) { long min = inf; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); min = Math.max(min, arr[i]); } return min; } public static int lowerBound(int[] arr, int x) { int l = -1, r = arr.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (arr[m] >= x) r = m; else l = m; } return r; } public static int upperBound(int[] arr, int x) { int l = -1, r = arr.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (arr[m] <= x) l = m; else r = m; } return l + 1; } public static void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int[n1]; int R[] = new int[n2]; for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] >= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } public static void reversesort(int arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; reversesort(arr, l, m); reversesort(arr, m + 1, r); merge(arr, l, m, r); } } public 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++; } } public static void reversesort(long arr[], int l, int r) { if (l < r) { int m = l + (r - l) / 2; reversesort(arr, l, m); reversesort(arr, m + 1, r); merge(arr, l, m, r); } } // debug public static boolean sysFlag = System.getProperty(""ONLINE_JUDGE"") == null; public static void debug(int[][] dp) { if (sysFlag) { for (int i = 0; i < dp.length; ++i) { pr.print(i + ""--> ""); for (int j = 0; j < dp[0].length; ++j) { pr.print(dp[i][j] + "" ""); } pr.println(""""); } } } public static void debug(long[][] dp) { if (sysFlag) { for (int i = 0; i < dp.length; ++i) { pr.print(i + ""--> ""); for (int j = 0; j < dp[0].length; ++j) { pr.print(dp[i][j] + "" ""); } pr.println(""""); } } } public static void debug(int x) { if (sysFlag) pr.println(""Int-Ele: "" + x); } public static void debug(String x) { if (sysFlag) pr.println(""String: "" + x); } public static void debug(char x) { if (sysFlag) pr.println(""Char: "" + x); } public static void debug(long x) { if (sysFlag) pr.println(""Long-Ele: "" + x); } public static void debug(int[] arr, int n) { if (sysFlag) { for (int i = 0; i < n; ++i) { pr.println(i + "" -> "" + arr[i]); } } } public static void debug(char[] arr) { if (sysFlag) { for (int i = 0; i < arr.length; ++i) { pr.println(i + "" -> "" + arr[i]); } } } public static void debug(long[] arr, int n) { if (sysFlag) { for (int i = 0; i < n; ++i) { pr.println(i + "" -> "" + arr[i]); } } } public static void debug(ArrayList list) { if (sysFlag) { for (int i = 0; i < list.size(); ++i) { pr.println(i + "" -> "" + list.get(i)); } } } public static void Ldebug(ArrayList list) { if (sysFlag) { for (int i = 0; i < list.size(); ++i) { pr.println(i + "" -> "" + list.get(i)); } } } public static void debugmapII(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapLI(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapLL(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapIL(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapSL(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapCL(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapSI(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debugmapCI(HashMap map) { if (sysFlag) { for (Map.Entry entry : map.entrySet()) pr.println(""Key => "" + entry.getKey() + "", Value => "" + entry.getValue()); } } public static void debug(Set set) { if (sysFlag) { Iterator value = set.iterator(); int i = 1; while (value.hasNext()) { pr.println((i++) + ""-> "" + value.next()); } } } } ",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 { private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static String solution(int [] arr, int n, String st) { ArrayList red = new ArrayList<>(); ArrayList blue = new ArrayList<>(); for(int i = 0; i=0; j--) { if(red.get(j)>cr) return ""NO""; cr--; } return ""YES""; } private static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { MyScanner s = new MyScanner(); int t = s.nextInt(); for(int j = 0; j0) { int n=s.nextInt(); int c[]=new int[n]; for(int i=0;i=arr[i-1]==false) { return false; } } return true; } static int setBit(int S, int j) { return S | 1 << j; } static int clearBit(int S, int j) { return S & ~(1 << j); } static int toggleBit(int S, int j) { return S ^ 1 << j; } static boolean isOn(int S, int j) { return (S & 1 << j) != 0; } static int turnOnLastZero(int S) { return S | S + 1; } static int turnOnLastConsecutiveZeroes(int S) { return S | S - 1; } static int turnOffLastBit(int S) { return S & S - 1; } static int turnOffLastConsecutiveBits(int S) { return S & S + 1; } static int lowBit(int S) { return S & -S; } static int setAll(int N) { return (1 << N) - 1; } static int modulo(int S, int N) { return (S & N - 1); } //S%N, N is a power of 2 static boolean isPowerOfTwo(int S) { return (S & S - 1) == 0; } static boolean isWithin(long x, long y, long d, long k) { return x*k*x*k + y*k*y*k <= d*d; } static long modFact(long n, long p) { if (n >= p) return 0; long result = 1; for (int i = 1; i <= n; i++) result = (result * i) % p; return result; } static int sum(int[] arr, int n) { int inc[]=new int[n+1]; int dec[]=new int[n+1]; inc[0] = arr[0]; dec[0] = arr[0]; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (arr[j] > arr[i]) { dec[i] = max(dec[i], inc[j] + arr[i]); } else if (arr[i] > arr[j]) { inc[i] = max(inc[i], dec[j] + arr[i]); } } } return max(inc[n - 1], dec[n - 1]); } static long nc2(long a) { return a*(a-1)/2; } public static int numberOfprimeFactors(int n) { // Print the number of 2s that divide n HashSet hs = new HashSet(); while (n%2==0) { hs.add(2); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { hs.add(i); n /= i; } } // This condition is to handle the case whien // n is a prime number greater than 2 if (n > 2) hs.add(n); return hs.size(); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static void reverse(int arr[],int start, int end) { int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } static void reverse(long arr[],int start, int end) { long temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int p2(int n) { int k=0; while(n>1) { if(n%2!=0) return k; n/=2; k++; } return k; } static boolean isp2(int n) { while(n>1) { if(n%2==1) return false; n/=2; } return true; } static int binarySearch(int arr[], int first, int last, int key){ int mid = (first + last)/2; while( first <= last ){ if ( arr[mid] < key ){ first = mid + 1; }else if ( arr[mid] == key ){ return mid; }else{ last = mid - 1; } mid = (first + last)/2; } return -1; } static void print(int a[][]) { for(int i=0;i y)? x : y; } static int search(Pair[] p, Pair pair) { int l=0, r=p.length; while (l <= r) { int m = l + (r - l) / 2; if (p[m].compareTo(pair)==0) return m; if (p[m].compareTo(pair)<0) l = m + 1; else r = m - 1; } return -1; } static void pa(int a[]) { for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return power(n, p-2, p); } static long nCrModP(long n, long r, long p) { if(r>n) return 0; if (r == 0) return 1; long[] fac = new long[(int) (n+1)]; fac[0] = 1; for (int i = 1 ;i <= n; i++) fac[i] = fac[i-1] * i % p; return (fac[(int) n]* modInverse(fac[(int) r], p) % p * modInverse(fac[(int) (n-r)], p) % p) % p; } static String reverse(String str) { return new StringBuffer(str).reverse().toString(); } static long fastpow(long x, long y, long m) { if (y == 0) return 1; long p = fastpow(x, y / 2, m) % m; p = (p * p) % m; if (y % 2 == 0) return p; else return (x * p) % m; } static boolean isPerfectSquare(long l) { return Math.pow((long)Math.sqrt(l),2)==l; } static void merge(long[] arr, int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long [n1]; long R[] = new long [n2]; /*Copy data to temp arrays*/ for (int i=0; i{ int a; int b; Pair(int a,int b){ this.a=a; this.b=b; } public int compareTo(Pair p){ if(a>p.a) return 1; if(a==p.a) return (b-p.b); return -1; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[128]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }","//package Current; import java.util.*; public class test { static final long mod = (long) 1e9 + 7; static class pair { int x, y; public pair(int x, int y) { this.x = x; this.y = y; } } public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = 1; t = sc.nextInt(); while (t-- > 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 print(Object o) { System.out.print(o + "" ""); } static void println(Object o) { System.out.println(o); } static void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static ArrayList factorial(int num) { ArrayList fac = new ArrayList<>(); fac.add((long) 0); fac.add((long) 1); for (int i = 2; i < num; i++) { fac.add((fac.get(i - 1) * i) % mod); } return fac; } static long ncr(long x, long y, ArrayList fac) { if (y >= x) return (long) 1; long res = fac.get((int) x); long z = (fac.get((int) y) * fac.get((int) (x - y))) % mod; z = modInv(z); res = (res * z) % mod; return res; } static long modInv(long x) { return modExpo(x, mod - 2); } static long modExpo(long x, long y) { long res = 1; x = x % mod; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; y = y / 2; x = (x * x) % mod; } return res; } static int lowerBound(int n, long[] arr, long value) { int res = (int) 1e7; int l = 0, r = n - 1; while (l <= r) { int mid = l + (r - l) / 2; if (arr[mid] >= value) { res = mid; r = mid - 1; } else l = mid + 1; } return res; } } ",0,Non-plagiarised 07043d35,97a7fab5,"// Piyush Nagpal import java.util.*; import java.io.*; public class C{ static int MOD=1000000007; static PrintWriter pw; static FastReader sc; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){return Double.parseDouble(next());} public char nextChar() throws IOException {return next().charAt(0);} String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] intArr(int n) throws IOException {int[]in=new int[n];for(int i=0;ia ){return gcd(b,a);}if( b==0 ){return a;} return gcd(b,a%b);} public static long expo( long a,long b,long M ){long result=1;while(b>0){if( b%2==1 ){result=(result*a)%M;}a=(a*a)%M;b=b/2;}return result%M;} public static ArrayList Sieve(int n){boolean [] arr= new boolean[n+1];Arrays.fill(arr, true);ArrayList list= new ArrayList<>();for(int i=2;i<=n;i++){if( arr[i]==true ){list.add((long)i);}for(int j=2*i;j<=n;j+=i){arr[j]=false;}}return list;} public static void printarr(int [] arr){for(int i=0;i> 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(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() throws IOException { return reader.readLine().trim(); } } } ",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<>(); pl(""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) { p(ele + "" ""); } pl(); } ///////////////////////////////////////////////////////////////////////////////// static int[] nextIntArray(int n) { int[] arr = new int[n]; int i = 0; while (i < n) { arr[i++] = ni(); } return arr; } static long[] nextLongArray(int n) { long[] arr = new long[n]; int i = 0; while (i < n) { arr[i++] = nl(); } return arr; } static int[] nextIntArray1(int n) { int[] arr = new int[n + 1]; int i = 1; while (i <= n) { arr[i++] = ni(); } return arr; } ///////////////////////////////////////////////////////////////////////////////// static int ni() { return sc.nextInt(); } static long nl() { return sc.nextLong(); } static double nd() { return sc.nextDouble(); } ///////////////////////////////////////////////////////////////////////////////// static void pl() { pw.println(); } static void p(Object o) { pw.print(o); } static void pl(Object o) { pw.println(o); } static void psb(StringBuilder sb) { pw.print(sb); } static void pa(Object arr[]) { for (Object o : arr) { p(o); } pl(); } static void pa(int arr[]) { for (int o : arr) { p(o); } pl(); } static void pa(long arr[]) { for (long o : arr) { p(o); } pl(); } static void pa(double arr[]) { for (double o : arr) { p(o); } pl(); } static void pa(char arr[]) { for (char o : arr) { p(o); } pl(); } static void pa(List list) { for (Object o : list) { p(o); } pl(); } static void pa(Object[][] arr) { for (int i = 0; i < arr.length; ++i) { for (Object o : arr[i]) { p(o); } pl(); } } static void pa(int[][] arr) { for (int i = 0; i < arr.length; ++i) { for (int o : arr[i]) { p(o); } pl(); } } static void pa(long[][] arr) { for (int i = 0; i < arr.length; ++i) { for (long o : arr[i]) { p(o); } pl(); } } static void pa(char[][] arr) { for (int i = 0; i < arr.length; ++i) { for (char o : arr[i]) { p(o); } pl(); } } static void pa(double[][] arr) { for (int i = 0; i < arr.length; ++i) { for (double o : arr[i]) { p(o); } pl(); } } ///////////////////////////////////////////////////////////////////////////////// static void print(Object s) { System.out.println(s); } ///////////////////////////////////////////////////////////////////////////////// //-----------HritikScanner class for faster input----------// static class HritikScanner { BufferedReader br; StringTokenizer st; public HritikScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ////////////////////////////////////////////////////////////////// public static class Pair implements Comparable { int num, row,col; Pair(int num, int row, int col) { this.num = num; this.row = row; this.col = col; } public int get1() { return num; } public int get2() { return row; } public int compareTo(Pair A) { return this.num - A.num; } public String toString() { return num +"" ""+ row+"" ""+col; } } ////////////////////////////////////////////////////////////////// // Function to return gcd of a and b time complexity O(log(a+b)) static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } // method to return LCM of two numbers static long lcm(int a, int b) { return (a / gcd(a, b)) * b; } ////////////////////////////////////////////////////////////////// static boolean isPrime(long n) { // Corner cases if (n <= 1) { return false; } if (n <= 3) { return true; } // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) { return false; } for (long i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } ////////////////////////////////////////////////////////////////// static boolean isPowerOfTwo(long n) { if (n == 0) { return false; } return (long) (Math.ceil((Math.log(n) / Math.log(2)))) == (long) (Math.floor(((Math.log(n) / Math.log(2))))); } public static long getFact(int n) { long ans = 1; while (n > 0) { ans *= n; ans %= MOD; n--; } return ans; } public static long pow(long n, int pow) { if (pow == 0) { return 1; } long temp = pow(n, pow / 2) % MOD; temp *= temp; temp %= MOD; if (pow % 2 == 1) { temp *= n; } temp %= MOD; return temp; } public static long nCr(int n, int r) { long ans = 1; int temp = n - r; while (n > temp) { ans *= n; ans %= MOD; n--; } ans *= pow(getFact(r) % MOD, MOD - 2) % MOD; ans %= MOD; return ans; } ////////////////////////////////////////////////////////////////// // method returns Nth power of A static double nthRoot(int A, int N) { // intially guessing a random number between // 0 and 9 double xPre = Math.random() % 10; // smaller eps, denotes more accuracy double eps = 0.001; // initializing difference between two // roots by INT_MAX double delX = 2147483647; // xK denotes current value of x double xK = 0.0; // loop untill we reach desired accuracy while (delX > eps) { // calculating current value from previous // value by newton's method xK = ((N - 1.0) * xPre + (double) A / Math.pow(xPre, N - 1)) / (double) N; delX = Math.abs(xK - xPre); xPre = xK; } return xK; } } ",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; } } ","//package currentContest; 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for (int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long) (p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for (int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for (int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long) i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } 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(); public static void solvegraph() { int n = sc.nextInt(); int edge[][] = new int[n - 1][2]; for (int i = 0; i < n - 1; i++) { edge[i][0] = sc.nextInt() - 1; edge[i][1] = sc.nextInt() - 1; } ArrayList> ad = new ArrayList<>(); for (int i = 0; i < n; i++) { ad.add(new ArrayList()); } for (int i = 0; i < n - 1; i++) { ad.get(edge[i][0]).add(edge[i][1]); ad.get(edge[i][1]).add(edge[i][0]); } int parent[] = new int[n]; Arrays.fill(parent, -1); parent[0] = n; ArrayDeque queue = new ArrayDeque<>(); queue.add(0); int child[] = new int[n]; Arrays.fill(child, 0); ArrayList lv = new ArrayList(); while (!queue.isEmpty()) { int toget = queue.getFirst(); queue.removeFirst(); child[toget] = ad.get(toget).size() - 1; for (int i = 0; i < ad.get(toget).size(); i++) { if (parent[ad.get(toget).get(i)] == -1) { parent[ad.get(toget).get(i)] = toget; queue.addLast(ad.get(toget).get(i)); } } lv.add(toget); } child[0]++; } 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(); } public static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised 3dd65549,c1638a45,"import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); char[] a=sc.next().toCharArray(); char[] b=sc.next().toCharArray(); int e0=0; int e1=0; int o0=0; int o1=0; for(int i=0;i { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }","import java.io.*; import java.util.*; public class qC { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while(T-- > 0) { int N = Integer.parseInt(br.readLine()); char[] curr = br.readLine().toCharArray(); char[] sol = br.readLine().toCharArray(); // int oddP = 0; // int evenP = 0; // int even1 = 0; // int odd1 = 0; // int even0 = 0; // int odd0 = 0; // boolean alreadySolved = true; // for(int i = 0;i < N;i++) { // if(curr[i] == sol[i]) { // evenP++; // if(curr[i] == '1') even1++; // else even0++; // } // else { // oddP++; // if(curr[i] == '1') odd1++; // else odd0++; // alreadySolved = false; // } // } // // if(alreadySolved) { // System.out.println(0); // continue; // } // int minSwaps = Integer.MAX_VALUE; // if(N % 2 == 1) { // if(evenP % 2 == 1 && Math.abs(odd1 - odd0) <= 1 && odd1 > 0 && odd0 > 0) { // minSwaps = Math.min(minSwaps, oddP); // } // if(oddP % 2 == 0 && Math.abs(even1 - even0) <= 1 && even1 > 0 && even1 > 0) { // minSwaps = Math.min(minSwaps, evenP); // } // } // else { // if(evenP % 2 == 0 && Math.abs(odd1 - odd0) <= 1 && odd1 > 0 && odd0 > 0) { // minSwaps = Math.min(minSwaps, oddP); // } // if(oddP % 2 == 1 && Math.abs(even1 - even0) <= 1 && even1 > 0 && even1 > 0) { // minSwaps = Math.min(minSwaps, evenP); // } // } // System.out.println((minSwaps == Integer.MAX_VALUE) ? -1: minSwaps); int curr1 = 0; int sol1 = 0; int mismatch = 0; for(int i = 0;i < N;i++) { if(curr[i] == '1') curr1++; if(sol[i] == '1') sol1++; if(curr[i] != sol[i]) mismatch++; } int minAns = Integer.MAX_VALUE; //even operations if(curr1 == sol1 && mismatch % 2 == 0) { minAns = Math.min(mismatch, minAns); } //odd operations for(int i = 0;i < N;i++) { if(curr[i] == '1') { int tempcurr1 = N - curr1 + 1; int tempmismatch; if(sol[i] == '0') { tempmismatch = N - mismatch; } else { tempmismatch = N - mismatch - 1; } if(tempcurr1 == sol1 && tempmismatch % 2 == 0) { minAns = Math.min(minAns, tempmismatch + 1); } } } System.out.println((minAns == Integer.MAX_VALUE) ? -1 : minAns); } } } ",0,Non-plagiarised 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= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } static class FastWriter { BufferedWriter writer; StringBuilder sb; public FastWriter() throws IOException { if (INPUT_FROM_FILE) writer = new BufferedWriter(new FileWriter(OUTPUT_FILE)); else writer = new BufferedWriter(new PrintWriter(System.out)); sb = new StringBuilder(); } public void print(Object obj) { sb.append(obj); } public void println(Object obj) { sb.append(obj).append('\n'); } public void close() throws IOException { writer.write(sb.toString()); writer.close(); } } } "," import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import static javax.swing.UIManager.get; import static javax.swing.UIManager.getString; public class Main { static class Pair implements Comparable { int x = 0; int y = 0; public Pair(int x1, int y1) { x = x1; y = y1; } @Override public int compareTo(Pair o) { return this.x - o.x; } } static boolean checkPallindrome(int n) { ArrayList list = new ArrayList<>(); while (n > 0) { list.add(n % 10); n /= 10; } int low = 0, high = list.size() - 1; while (low <= high) { if (list.get(low) != list.get(high)) return false; low++; high--; } return true; } static boolean check(String s) { int low = 0, high = s.length() - 1; while (low <= high) { if (s.charAt(low) != s.charAt(high)) return false; low++; high--; } return true; } class Node implements Comparable { int x = 0, y = 0, z = 0; @Override public int compareTo(Node o) { return this.y - o.y; } } static int min = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); //(1)very very important**(never take the first problem for granted, always check the test cases) take 5 minutes more and check the edge cases // 5 minutes will not decreases rating as much as a wrong submission does it is easy u just think with an open mind and u will surely get the answer //(2)let ur brain consume the problem don't just jump to the solution. after reading the problem take a pause 1 minute //(3)go through the example test cases and also at least two of ur own test cases.Think of testcases which are difficult(edge cases).dry run ur concept //(4) sometimes if else condition is not required but due to if else you miss some points and get wrong answer int t = sc.nextInt(); while (t-- > 0) { int n =sc.nextInt(); ArrayList> list = new ArrayList<>(); for(int i=0;i()); ArrayList list1 = new ArrayList<>(); for(int i=0;i> list,ArrayList list1) { for(int v:list.get(u)) { if(v==p) continue; dfs(v,u,dp,list,list1); dp[1][u]+= Math.max(Math.abs(list1.get(u).y-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).y-list1.get(v).y)+dp[1][v]); dp[0][u]+=Math.max(Math.abs(list1.get(u).x-list1.get(v).x)+dp[0][v],Math.abs(list1.get(u).x-list1.get(v).y)+dp[1][v]); } } //static int lcs( int[] X, int[] Y, int m, int n ) //{ // int L[][] = new int[m+1][n+1]; // // /* Following steps build L[m+1][n+1] in bottom up fashion. Note // that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ // for (int i=0; i<=m; i++) // { // for (int j=0; j<=n; j++) // { // if (i == 0 || j == 0) // L[i][j] = 0; // else if (X[i-1] == Y[j-1]) // L[i][j] = L[i-1][j-1] + 1; // else // L[i][j] = Math.max(L[i-1][j], L[i][j-1]); // } // } // return L[m][n]; //} // syntax of conditional operator y=(x==1)?1:0; //Things to check when u r getting wrong answer // 1- check the flow of the code //2- If ur stuck read the problem once again //3- before submitting always check the output format of ur code //4- don't check standings until problem B is done //5- if u r thinking ur concept is correct but still u r getting wrong answer try to implement it in another way //6- By default, java interpret all numeral literals as 32-bit integer values. // If you want to explicitely specify that this is something bigger then 32-bit integer you should use suffix L for long values. example long a = 600851475143L //All the functions long pow(long a,long b,long m) { a%=m; long res=1L; while(b>0) { long temp=b&1; if(temp==1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) { // Initially, all elements are in // their own set. parent[i] = i; } } // Returns representative of x's set int find(int x) { // Finds the representative of the set // that x is an element of if (parent[x] != x) { // if x is not the parent of itself // Then x is not the representative of // his set, parent[x] = find(parent[x]); // so we recursively call Find on its parent // and move i's node directly under the // representative of this set } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { // Find representatives of two sets int xRoot = find(x), yRoot = find(y); // Elements are in the same set, no need // to unite anything. if (xRoot == yRoot) return; // If x's rank is less than y's rank if (rank[xRoot] < rank[yRoot]) // Then move x under y so that depth // of tree remains less parent[xRoot] = yRoot; // Else if y's rank is less than x's rank else if (rank[yRoot] < rank[xRoot]) // Then move y under x so that depth of // tree remains less parent[yRoot] = xRoot; else // if ranks are the same { // Then move y under x (doesn't matter // which one goes where) parent[yRoot] = xRoot; // And increment the result tree's // rank by 1 rank[xRoot] = rank[xRoot] + 1; } } } static void debug(String s) { System.out.println(s); } //collections.sort use merge sort instead of quick sort but arrays.sort use quicksort whose worst time complexity is O(n^2) static int[] sort(int[] a) { ArrayList list = new ArrayList<>(); for(int i=0;ires; 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;i= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int mod = (int)(1e9+7); public static long pow(long a,long b) { long ans = 1; while(b> 0) { if((b & 1)==1){ ans = (ans*a) % mod; } a = (a*a) % mod; b = b>>1; } return ans; } static void sort(int[] a) { ArrayList l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); 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 class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/gcd(a, b); } public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } static long func(long a[],int size,int s){ long max1=a[s]; long maxc=a[s]; for(int i=s+1;i, 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 String toString() { return String.format(""(%s, %s)"", x.toString(), y.toString()); } } static class MultiSet> { public int sz = 0; public TreeMap t; public MultiSet() { t = new TreeMap<>(); } public void add(U x) { t.put(x, t.getOrDefault(x, 0) + 1); sz++; } public void remove(U x) { if (t.get(x) == 1) t.remove(x); else t.put(x, t.get(x) - 1); sz--; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static long myceil(long a, long b){ return (a+b-1)/b; } static long C(long n,long r){ long count=0,temp=n; long ans=1; long num=n-r+1,div=1; while(num<=n){ ans*=num; //ans+=MOD; ans%=MOD; ans*=mypow(div,MOD-2); //ans+=MOD; ans%=MOD; num++; div++; } ans+=MOD; return ans%MOD; } static long fact(long a){ long i,ans=1; for(i=1;i<=a;i++){ ans*=i; ans%=MOD; } return ans%=MOD; } static void sieve(int n){ is_sieve[0]=1; is_sieve[1]=1; int i,j,k; for(i=2;in||j<0){ break; } is_sieve[j]=1; sieve[j]=i; } } } } // 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 mypow(long x,long y){ long temp; if( y == 0) return 1; temp = mypow(x, y/2); if (y%2 == 0) return (temp*temp)%MOD; else return ((x*temp)%MOD*(temp)%MOD)%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= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/gcd(a, b); } public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } static long func(long a[],int size,int s){ long max1=a[s]; long maxc=a[s]; for(int i=s+1;i, 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 String toString() { return String.format(""(%s, %s)"", x.toString(), y.toString()); } } static class MultiSet> { public int sz = 0; public TreeMap t; public MultiSet() { t = new TreeMap<>(); } public void add(U x) { t.put(x, t.getOrDefault(x, 0) + 1); sz++; } public void remove(U x) { if (t.get(x) == 1) t.remove(x); else t.put(x, t.get(x) - 1); sz--; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static long myceil(long a, long b){ return (a+b-1)/b; } static long C(long n,long r){ long count=0,temp=n; long ans=1; long num=n-r+1,div=1; while(num<=n){ ans*=num; //ans+=MOD; ans%=MOD; ans*=mypow(div,MOD-2); //ans+=MOD; ans%=MOD; num++; div++; } ans+=MOD; return ans%MOD; } static long fact(long a){ long i,ans=1; for(i=1;i<=a;i++){ ans*=i; ans%=MOD; } return ans%=MOD; } static void sieve(int n){ is_sieve[0]=1; is_sieve[1]=1; int i,j,k; for(i=2;in||j<0){ break; } is_sieve[j]=1; sieve[j]=i; } } } } // 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 mypow(long x,long y){ long temp; if( y == 0) return 1; temp = mypow(x, y/2); if (y%2 == 0) return (temp*temp)%MOD; else return ((x*temp)%MOD*(temp)%MOD)%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; } @Override public int compareTo(Pair o) { if(this.x==o.x)return this.y-o.y; return this.x-o.x; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder(""0""); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder(""0""); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } } ",0,Non-plagiarised 354d060f,e1c4f3db,"import java.util.*; import java.io.*; public class CodeForces { // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader( new FileReader(""input.txt"")); PrintStream out = new PrintStream(new FileOutputStream(""output.txt"")); System.setOut(out); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // end of fast i/o code public static void main(String[] args) { FastReader 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,"// package com.company; import java.util.Scanner; public class Main { public static void solution1(){ Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t-- != 0){ int n, k1, k2, w, b; n = scanner.nextInt(); k1 = scanner.nextInt(); k2 = scanner.nextInt(); w = scanner.nextInt(); b = scanner.nextInt(); if (k1 < k2){ int temp = k1; k1 = k2; k2 = temp; } int white_dominoes = k2 + (k1 - k2) / 2; int black_dominoes = (n - k1) + (k1 - k2) / 2; if (white_dominoes >= w && black_dominoes >= b) { System.out.println(""YES""); } else System.out.println(""NO""); } scanner.close(); } public static void solution2(){ Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); scanner.nextLine(); while (t-- != 0) { String s; s = scanner.nextLine(); boolean flag = true; int first_ones = -1, last_zeroes = -1; for (int i=0; i0; i--){ if (s.charAt(i) == '0' && s.charAt(i-1) == '0'){ last_zeroes = i-1; break; } } if (first_ones != -1 && last_zeroes != -1 && first_ones < last_zeroes) flag = false; if (flag) System.out.println(""YES""); else System.out.println(""NO""); } scanner.close(); } 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 0){ if (b%2 == 1){ ans *= a; } a *= a; b >>= 1; } return ans; } public static void main(String[] args) { solution3(); } }"," // import java.util.Vector; import java.util.*; import java.lang.Math; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.management.Query; import java.io.*; import java.math.BigInteger; public class Main { static int mod = 1000000007; /* ======================DSU===================== */ static class dsu { static int parent[], n;// min[],value[]; static long size[]; dsu(int n) { parent = new int[n + 1]; size = new long[n + 1]; // min=new int[n+1]; // value=new int[n+1]; this.n = n; makeSet(); } static void makeSet() { for (int i = 1; i <= n; i++) { parent[i] = i; size[i] = 1; // min[i]=i; } } static int find(int a) { if (parent[a] == a) return a; else { return parent[a] = find(parent[a]);// Path Compression } } static void union(int a, int b) { int setA = find(a); int setB = find(b); if (setA == setB) return; if (size[setA] >= size[setB]) { parent[setB] = setA; size[setA] += size[setB]; } else { parent[setA] = setB; size[setB] += size[setA]; } } } /* ======================================================== */ static class Pair implements Comparator { long x; long y; // Constructor public Pair(long x, long y) { this.x = x; this.y = y; } public Pair() { } @Override public int compare(Main.Pair o1, Main.Pair o2) { return ((int) (o1.x - o2.x)); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] intArr(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] longArr(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } static FastReader f = new FastReader(); static BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int LowerBound(int a[], int x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long power(long x, long y) { long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int power(int x, int y) { int res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y >>= 1; x = (x * x); } return res; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } /* * ===========Modular Operations================== */ static long modInverse(long n, long p) { return power(n, p - 2, p); } static long modAdd(long a, long b) { return (a % mod + b % mod) % mod; } static long modMul(long a, long b) { return ((a % mod) * (b % mod)) % mod; } static long nCrModPFermat(int n, int r) { long p = 1000000007; if (r == 0) return 1; long[] fac = new long[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } /* * =============================================== */ static List removeDup(ArrayList list) { List newList = list.stream().distinct().collect(Collectors.toList()); return newList; } static void ruffleSort(long[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } /* * ===========Dynamic prog Recur Section=========== */ static int DP[][]; static ArrayList> g; static int count = 0; static ArrayList bitMask(ArrayList ar, int n) { ArrayList ans = new ArrayList<>(); for (int mask = 0; mask <= Math.pow(2, n) - 1; mask++) { long sum = 0; for (int i = 0; i < n; i++) { if (((1 << i) & mask) > 0) { sum += ar.get(i); } } ans.add(sum); } return ans; } /* * ====================================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; i '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } "," 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(); 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 tabulation() { return tabulation(x, y); } int tabulation(int x, int y) { int[][] dp = new int[x+1][y+1]; for (int i = 0; i <= x; i++) { Arrays.fill(dp[i], Integer.MAX_VALUE/2); } for (int i = 0; i <= x; i++) { dp[i][0] = 0; } for (int i = 0; i <= y; i++) { dp[0][i] = 0; } for (int i = 1; i <= x; i++) { for (int j = 1; j <= y; j++) { if(i == j) { dp[i][j] = dp[i-1][j-1] + Math.abs(occupied.get(i-1) - vacant.get(j-1)); } else { dp[i][j] = Math.min(dp[i][j-1], dp[i-1][j-1] + Math.abs(occupied.get(i-1) - vacant.get(j-1))); } } } return dp[x][y]; } int memoization() { int[][] dp = new int[x][y]; for (int i = 0; i < x; i++) { Arrays.fill(dp[i], -1); } return memoization(dp, x-1, y-1); } int memoization(int[][] dp, int n, int m) { if(n < 0) { return 0; } if(m < n) { return Integer.MAX_VALUE; } if(dp[n][m] != -1) { return dp[n][m]; } int first = memoization(dp, n, m-1); int second = memoization(dp, n-1, m-1) + Math.abs(occupied.get(n) - vacant.get(m)); dp[n][m] = Math.min(first, second); return dp[n][m]; } }",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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ","import java.util.*; import java.io.*; import java.lang.*; import static java.lang.Math.*; public class cp{ static BufferedReader br; static StringTokenizer st; public static void main(String[] args)throws IOException{ br = new BufferedReader(new InputStreamReader(System.in)); List answer = new ArrayList(); for(int t=Integer.parseInt(br.readLine()); t>0; t--){ st = readLine(); int n = tokenInt(); String[] words = new String[n]; int i=0; while(n-- >0){ words[i] = br.readLine(); i++; } answer.add(new Solver().solve(words)); } for (int ans : answer ) System.out.println(ans); } static StringTokenizer readLine() throws IOException { return new StringTokenizer(br.readLine()); } static int tokenInt() { return Integer.parseInt(st.nextToken()); } static long tokenLong(){ return Long.parseLong(st.nextToken()); } static double tokenDouble(){ return Double.parseDouble(st.nextToken()); } static char[] tokenChar(){ return st.nextToken().toCharArray(); } static int[] readIntArray(int n) { int[] a=new int[n]; for (int i=0; i=0; i--){ val += ar[i]; if(val>0) counter++; else break; } ans[m] = counter; m++; } return Arrays.stream(ans).max().getAsInt(); } } /* bac aaada e */ ",0,Non-plagiarised 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(); } public static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n) throws IOException { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) array[i] = new Integer(nextInt()); return array; } public long[] nextLongArray(int n) throws IOException { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } public double[] nextDoubleArray(int n) throws IOException { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } public static int[] shuffle(int[] a) { int n = a.length; Random rand = new Random(); for (int i = 0; i < n; i++) { int tmpIdx = rand.nextInt(n); int tmp = a[i]; a[i] = a[tmpIdx]; a[tmpIdx] = tmp; } return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } } ","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[]; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair{ int first; int second; Pair(int first, int second){ this.first = first; this.second = second; } @Override public boolean equals(Object b) { Pair a = (Pair)b; if(this.first == a.first && this.second==a.second) { return true; } return false; } } class PairSorter implements Comparator{ public int compare(Pair a, Pair b) { if(a.first!=b.first) { return a.first-b.first; } return a.second-b.second; } } class IndexSorter implements Comparator{ public int compare(Integer a, Integer b) { //desc if(arrForIndexSort[b]==arrForIndexSort[a]) { return b-a; } return arrForIndexSort[b]-arrForIndexSort[a]; } } class ListSorter implements Comparator{ public int compare(List a, List b) { return b.size()-a.size(); } } static class DisjointSet{ int[] dsu; public DisjointSet(int n) { makeSet(n); } public void makeSet(int n) { dsu = new int[n+1]; //*** 1 Based indexing *** for(int i=1;i<=n;i++) { dsu[i] = -1; } } public int find(int i) { while(dsu[i] > 0) { i = dsu[i]; } return i; } public void union(int i, int j) { int iRep = find(i); int jRep = find(j); if(iRep == jRep) { return; } if(dsu[iRep]>dsu[jRep]) { dsu[jRep] += dsu[iRep]; dsu[iRep] = jRep; } else { dsu[iRep] += dsu[jRep]; dsu[jRep] = iRep; } } } 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(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }","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; static class Pair implements Comparable { int first, second; public Pair(int aa, int bb) { first = aa; second = bb; } public int compareTo(Pair o) { if(this.second < o.second) return -1; if(this.second > o.second) return +1; return this.first - o.first; } } static class Tuple implements Comparable{ long first, second,third; public Tuple(long first, long second, long third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int[] parent; int[] rank; //Size of the trees is used as the rank public DSU(int n) { parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) //finding through path compression { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public boolean union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return false; //if they are already connected we exit by returning false. // if a's parent is less than b's parent if(rank[a] < rank[b]) { //then move a under b parent[a] = b; } //else if rank of j's parent is less than i's parent else if(rank[a] > rank[b]) { //then move b under a parent[b] = a; } //if both have the same rank. else { //move a under b (it doesnt matter if its the other way around. parent[b] = a; rank[a] = 1 + rank[a]; } return true; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i SieveList(int n) { boolean prime[] = new boolean[n+1]; Arrays.fill(prime, true); ArrayList l = new ArrayList<>(); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for(int i=p*p; i<=n; i += p) { prime[i] = false; } } } for (int p=2; p<=n; p++) { if (prime[p] == true) { l.add(p); } } return l; } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long modPow(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return modPow(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); 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 int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(int a[], int x) { int l=-1, r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } 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,"/* * HI THERE! (: * * CREATED BY : NAITIK V * * JAI HIND * */ import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static long dp[][]; static int mod=1000000007; 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 { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static 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 void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; public class Main { static final long MOD=1000000007; static final long MOD1=998244353; static long ans=0; //static ArrayList 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()]); } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return false; } return true; } private int readByte() { if (hasNextByte()) return buffer[curbuf++]; else return -1; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) curbuf++; } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) map[i] = next().toCharArray(); return map; } } } ",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 class pair{ int x;int y; pair(int x,int y){ this.x=x;this.y=y; } } static class triplet{ int x; long y; int z; triplet(int x,long y,int z){ this.x=x; this.y=y; this.z=z; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } long gcd(long a,long b){ if(b==0) { return a; } return gcd(b,a%b); } int[] sort(int a[]) { int multiplier = 1, len = a.length, max = Integer.MIN_VALUE; int b[] = new int[len]; int bucket[]; for (int i = 0; i < len; i++) if (max < a[i]) max = a[i]; while (max / multiplier > 0) { bucket = new int[10]; for (int i = 0; i < len; i++) bucket[(a[i] / multiplier) % 10]++; for (int i = 1; i < 10; i++) bucket[i] += (bucket[i - 1]); for (int i = len - 1; i >= 0; i--) b[--bucket[(a[i] / multiplier) % 10]] = a[i]; for (int i = 0; i < len; i++) a[i] = b[i]; multiplier *= 10; } return a; } long modPow(long base,long exp) { if(exp==0) { return 1; } if(exp%2==0) { long res=(modPow(base,exp/2)); return (res*res); } return (base*modPow(base,exp-1)); } int []reverse(int a[]){ int b[]=new int[a.length]; int index=0; for(int i=a.length-1;i>=0;i--) { b[index]=a[i]; } return b; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i>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(); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader(""input.txt"")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } } "," 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' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } ",0,Non-plagiarised 23594fdf,b185d034," import java.io.*; import java.util.*; public class Main { public static class StringPair implements Comparable{ String s; Integer charCount; public StringPair(String s, Integer charCount){ this.s = s; this.charCount = charCount; } @Override public int compareTo(Object o) { StringPair f = (StringPair) o; if(f.charCount < this.charCount){ return 1; } else if(f.charCount == this.charCount){ if(f.s.length() - f.charCount > this.s.length() - this.charCount){ return -1; } else if(f.s.length() - f.charCount < this.s.length() - this.charCount){ return 1; } else{ return 0; } } else{ return -1; } } } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); 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); } } static class JS { public int BS = 1 << 16; public char NC = (char) 0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public long nextLong() { num = 1; boolean neg = false; if (c == NC) c = nextChar(); for (; (c < '0' || c > '9'); c = nextChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; num *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / num; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c > 32) { res.append(c); c = nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = nextChar(); while (c != '\n') { res.append(c); c = nextChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = nextChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ",0,Non-plagiarised 90f01508,e00b1794,"// import java.io.DataInputStream; // import java.io.FileInputStream; // import java.io.IOException; 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 int[] input(int size){ int arr[]=new int[size]; for(int i=0;i0){ // 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<>(); static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } int[] readIntArray(int n){ int[] res=new int[n]; for(int i=0;i 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; } } static int gcd(int a,int b){ if(b==0){ return a; } return gcd(b,a%b); } }",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 list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); 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(); } public static class tuble implements Comparable { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + "" "" + y + "" "" + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } public static class pair implements Comparable { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + "" "" + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }",0,Non-plagiarised 54d7c21e,80881cae," 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); static int[] sp; static int size=(int)1e6; static int[] arInt; static long[] arLong; 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=x; } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList add(int id,int c) { ArrayList newArr=new ArrayList<>(); for(int i=0;i arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } static int lower(ArrayList arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } static int N = 501; // 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 public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet factors(int x) { HashSet a=new HashSet(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap findFactors(long n2) { HashMap ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i primes; static HashSet primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? ""YES"" : ""NO""); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i al) { int si=al.size(); for(int i=0;i al) { int si=al.size(); for(int i=0;i>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static 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 double sum[]; static long cnt; // 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; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; } ","//package Codeforces; import java.io.*; import java.util.*; public class CP { static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException, CloneNotSupportedException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } // @Override // public boolean equals(Object obj) // { // if(obj instanceof Pair) // { // Pair p=(Pair)obj; // return p.x==this.x && p.y==this.y; // } // return false; // } // @Override // public int hashCode() // { // return Math.abs(x)+500*Math.abs(y); // } // @Override // public String toString() // { // return ""(""+x+"" ""+y+"")""; // } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } // public void swap() // { // this.y=this.y+this.x; // this.x=this.y-this.x; // this.y=this.y-this.x; // } } }",1,Plagiarised 45e38fad,ec8566b8,"import java.util.*; import java.io.*; public class C_Not_Assigning { // For fast input output static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader( new FileReader(""input.txt"")); PrintStream out = new PrintStream(new FileOutputStream(""output.txt"")); System.setOut(out); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } 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; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; W w = (W) o; return u == w.u && v == w.v; } @Override public int hashCode() { return Objects.hash(u, v); } } static void dfs(C v, List[] g, int[] ans, int prev, Set seen) { if (v.i != -1) { ans[v.i] = prev == 2 ? 3 : 2; } seen.add(v.v); int next = prev == 2 ? 3 : 2; for (C c : g[v.v]) { if (!seen.contains(c.v)) { dfs(c, g, ans, next, seen); } next = next == 2 ? 3 : 2; } } static class C { int i; int v; public C(int i, int v) { this.i = i; 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); } } static void shuffleArray(int[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } void nextLine() throws IOException { br.readLine(); } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int[] readArrayInt(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }",0,Non-plagiarised a368f345,e5d02e93,"import java.util.*; import java.io.*; public class codeforces { static class Pair { char type; int L; int R; Pair(char type, int L, int R) { this.type = type; this.L = L; this.R = R; } } static FastReader fr; static StringBuilder res; static class FastReader { BufferedReader br; StringTokenizer st; BufferedWriter bw; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); bw = new BufferedWriter(new OutputStreamWriter(System.out)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } char nextChar() { return next().charAt(0); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } void write(String str) { try { bw.write(str); } catch (IOException e) { e.printStackTrace(); } } void close() { try { bw.close(); } catch (IOException e) { e.printStackTrace(); } } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws java.lang.Exception { 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 sieve() { for (int i = 2; i * i <= M; i++) { if (!primes[i]) { for (int j = i * i; j < M; j += i) { primes[j] = true; } } } for (int i = 5; i < 1000001; i++) { if (!primes[i] && !primes[i - 2]) dp[i] = dp[i - 1] + 1; else dp[i] = dp[i - 1]; } } 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""); } public static int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = fr.nextInt(); } return arr; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static List readArrayList(int n) { List arr = new ArrayList<>(); for (int i = 0; i < n; i++) { arr.add(fr.nextInt()); } return arr; } } ","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(); } public static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n) throws IOException { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) array[i] = new Integer(nextInt()); return array; } public long[] nextLongArray(int n) throws IOException { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } public double[] nextDoubleArray(int n) throws IOException { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } public static int[] shuffle(int[] a) { int n = a.length; Random rand = new Random(); for (int i = 0; i < n; i++) { int tmpIdx = rand.nextInt(n); int tmp = a[i]; a[i] = a[tmpIdx]; a[tmpIdx] = tmp; } return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } } ",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 { @Override public int compare(Pair o1, Pair o2) { return (int) (o1.first - o2.first); } } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int[] nextSortedIntArray(int n) { int[] array = nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n) { int[] array = new int[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public long[] nextSumLongArray(int n) { long[] array = new long[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextSortedLongArray(int n) { long[] array = nextLongArray(n); Arrays.sort(array); return array; } } class Pair implements Comparable { long first, second; public Pair(long first, long second) { this.first = first; this.second = second; } @Override public int compareTo(Pair o) { return (int) (this.second - o.second); } } class Utils { static void swap(int[] res, int i, int j) { int temp = res[i]; res[i] = res[j]; res[j] = temp; } static long pow(long num, int n, long mod) { long res = num % mod; while (n > 0) { if ((n & 1) != 0) { res = (res * num) % mod; } num = (num * num) % mod; n >>= 1; } return res; } } class Graph { public ArrayList[] 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; } } class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }",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; } } // private static long getGCD(long l, long m) { // // long t1 = Math.min(l, m); // long t2 = Math.max(l, m); // while (true) { // long temp = t2 % t1; // if (temp == 0) { // return t1; // } // t2 = t1; // t1 = temp; // } // } ",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 l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i=0;i--){ ans[i]=Math.min(ans[i],ans[i+1]+1); } for(int i=0;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (char i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i { if(x[c]>y[c]) { return 1; }else { return -1; } }); } public static void printb(boolean ans) { if(ans) { System.out.println(""Yes""); }else { System.out.println(""No""); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i{ int a , b; Pair(int x , int y){ a=x; b=y; } public int compareTo(Pair o) { return a != o.a ? a - o.a : b - o.b; } } } ",1,Plagiarised 8d6f1bf5,dc281165,"//package Div2.C; 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--; } } } ","/** * 12/24/21 morning * https://codeforces.com/contest/1615/problem/C */ // package codeforce.global.r18; 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""; void read_write_file() { FileInputStream instream = null; PrintStream outstream = null; try { instream = new FileInputStream(INPUT); outstream = new PrintStream(new FileOutputStream(OUTPUT)); System.setIn(instream); System.setOut(outstream); } catch (Exception e) { } } 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); } class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } void tr(Object... o) { pw.println(Arrays.deepToString(o)); } }",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 l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); 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(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } public static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } public static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } } ","import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.io.*; public class Div2 { private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static String solution(int [] arr, int n, String st) { ArrayList red = new ArrayList<>(); ArrayList blue = new ArrayList<>(); for(int i = 0; i=0; j--) { if(red.get(j)>cr) return ""NO""; cr--; } return ""YES""; } private static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { MyScanner s = new MyScanner(); int t = s.nextInt(); for(int j = 0; j= 0 && currentScore > 0; j--) { currentScore += curr[j]; currentCount++; } if (currentScore <= 0) currentCount--; bestCount = Math.max(currentCount, bestCount); } System.out.println(bestCount); } } } ","/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); PrintWriter out=new PrintWriter(System.out); while(t-->0) { int n=sc.nextInt(); int freq[][]=new int[n][5]; int rem[][]=new int[n][5]; for(int i=0;i=0;k--) { if(sum+arr[k]>0) { sum=sum+arr[k]; total++; } else { break; } } ans=Math.max(ans,total); } out.println(ans); } out.flush(); out.close(); } } ",0,Non-plagiarised 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 long LCM(long a,long b){ return (Math.abs(a*b))/gcd(a,b); } public static int upperBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = low+(high-low) / 2; if ( array[mid]>value) { high = mid ; } else { low = mid+1; } } return low; } static long gcd(long a, long b) { if(a!=0&&b!=0) while((a%=b)!=0&&(b%=a)!=0); return a^b; } static int countSetBits(int n) { int count = 0; while (n > 0) { if((n&1)!=1) count++; //count += n & 1; n >>= 1; } return count; } static void sieve(long n) { prime = new boolean[(int)n+1]; for(int i=0;iinters=new ArrayList(); static StringBuilder sb; static void swap(int i,int j,StringBuilder st) { char tmp=st.charAt(i); st.setCharAt(i,st.charAt(j)); st.setCharAt(j,tmp); } private static int next(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to right side if target is // greater. if(arr[mid]==target) return mid; if (arr[mid] { public int compare(String o1,String o2){ return o1.length()-o2.length(); } } public static class comp2 implements Comparator{ public int compare(String o1,String o2){ return o1.compareTo(o2); } } static StringBuilder a,b; static boolean isPowerOfTwo(int n) { if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static ArrayListv; static ArrayListpows; static void block(long x) { v = new ArrayList(); pows=new ArrayList(); while (x > 0) { v.add((int)x % 3); x = x / 3; } // Displaying the output when // the bit is '1' in binary // equivalent of number. for (int i = 0; i < v.size(); i++) { if (v.get(i)==1||v.get(i)==0) { pows.add(i); } } } static long mod=(long)(1e9)+7; static int countWaysUtil(int x, int n, int num) { // Base cases int val = (int) (x - Math.pow(num, n)); if (val == 0) return 1; if (val < 0) return 0; // Consider two possibilities, num is // included and num is not included. return countWaysUtil(val, n, num + 1) + countWaysUtil(x, n, num + 1); } static int countWays(int x, int n) { return countWaysUtil(x, n, 1); } static int dp[][]; static int n; static int arr[]; static int rec(int i,int prev) { if(i==n) return 0; if(dp[i][prev]!=-1){ //out.println(""FUCK""); return dp[i][prev]; } if(i==0) return dp[i][prev]=Math.max(rec(i+1,1),rec(i+1,0)); else return dp[i][prev]=Math.max(rec(i+1,0)+Math.abs(arr[i]-(prev==0?arr[i-1]:1)),rec(i+1,1)+Math.abs(1-(prev==0?arr[i-1]:1))); } static boolean can(int i,int j) { int x=i,y=j; int x2=Math.abs(y-x),y2=y+x; if(x>=x2&&y<=y2) return true; return false; } public static void main(String[] args) throws Exception { //SUCK IT UP AND DO IT ALRIGHT //scan=new FastReader(""div7.in""); //out = new PrintWriter(""div7.out""); //System.out.println(countSetBits(2015)); //int elem[]={1,2,3,4,5}; //System.out.println(""avjsmlfpb"".compareTo(""avjsmbpfl"")); int tt=1; /*for(int i=0;i<=100;i++) if(prime[i]) arr.add(i); System.out.println(arr.size());*/ // check(new StringBuilder(""05:11"")); // System.out.println(26010000000000L%150); tt=scan.nextInt(); outer:while(tt-->0) { int n=scan.nextInt(),m=scan.nextInt(); char board[][]=new char[n][m]; for(int i=0;ires[]=new ArrayList[3*n*m]; for(int i=0;i<3*n*m;i++) res[i]=new ArrayList(); int k=0; for(int i=0;iarr=new ArrayList(); ArrayListarr2=new ArrayList(); if(i+1 0) { if (e % 2 == 1) r = r * b ; b = b * b; e >>= 1; } return r; } private static void sort(long[] arr) { List list = new ArrayList<>(); for (long object : arr) list.add(object); Collections.sort(list); //Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } private static void sort2(long[] arr) { List list = new ArrayList<>(); for (long object : arr) list.add(object); Collections.sort(list); Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } public static class FastReader { BufferedReader br; StringTokenizer root; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } FastReader(String filename)throws Exception { br=new BufferedReader(new FileReader(filename)); } boolean hasNext(){ String line; while(root.hasMoreTokens()) return true; return false; } String next() { while (root == null || !root.hasMoreTokens()) { try { root = new StringTokenizer(br.readLine()); } catch (Exception addd) { addd.printStackTrace(); } } return root.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (Exception addd) { addd.printStackTrace(); } return str; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextInt(); } return array; } } static class Pair implements Comparable{ public int x, y; public Pair(int x1, int y1) { x=x1; y=y1; } @Override public int hashCode() { return (int)(x + 31 * y); } public String toString() { return x + "" "" + y; } @Override public boolean equals(Object o){ if (o == this) return true; if (o.getClass() != getClass()) return false; Pair t = (Pair)o; return t.x == x && t.y == y; } public int compareTo(Pair o) { return (o.y-y); } static class pair{ int i; int j; pair(int i,int j){ this.i=i; this.j=j; }}} static class tuple{ int x,y,z; tuple(int a,int b,int c){ x=a; y=b; z=c; } } static class Edge{ int d,w; Edge(int d,int w) { this.d=d; this.w=w; } } } ","import java.util.*; import java.io.*; import java.math.*; import java.lang.*; public class BinaryTable { // static int mod = 998244353; static int mod = 1000000007; private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws Exception { FastReader scn = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = scn.nextInt(); outer : while(t-->0){ int n = scn.nextInt(); int m = scn.nextInt(); int[][] arr = new int[n][m]; for(int i=0; i list = new ArrayList<>(); if(n % 2 == 0 && m % 2 == 0){ for(int i=0; i list = new ArrayList<>(); for (int i=0; i list = new ArrayList<>(); for(int i=0; i list = new ArrayList<>(); // for(int i=0; i list = new ArrayList<>(); for (int i=0; i list = new ArrayList<>(); for (int i=0; i list){ Collections.sort(list, Collections.reverseOrder()); } private static int lowerBound(int[] arr, int x){ int n = arr.length, si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(arr[mid] == x){ if(mid-1 >= 0 && arr[mid-1] == arr[mid]){ ei = mid-1; }else{ return mid; } }else if(arr[mid] > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } private static int upperBound(int[] arr, int x){ int n = arr.length, si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(arr[mid] == x){ if(mid+1 < n && arr[mid+1] == arr[mid]){ si = mid+1; }else{ return mid + 1; } }else if(arr[mid] > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } private static int upperBound(ArrayList list, int x){ int n = list.size(), si = 0, ei = n - 1; while(si <= ei){ int mid = si + (ei - si)/2; if(list.get(mid) == x){ if(mid+1 < n && list.get(mid+1) == list.get(mid)){ si = mid+1; }else{ return mid + 1; } }else if(list.get(mid) > x){ ei = mid - 1; }else{ si = mid+1; } } return si; } // (x^y)%p in O(logy) private static long power(long x, long y){ long res = 1; x = x % mod; while(y > 0){ if ((y & 1) == 1){ res = (res * x) % mod; } y = y >> 1; x = (x * x) % mod; } return res; } public static boolean nextPermutation(int[] arr) { if(arr == null || arr.length <= 1){ return false; } int last = arr.length-2; while(last >= 0){ if(arr[last] < arr[last+1]){ break; } last--; } if (last < 0){ return false; } if(last >= 0){ int nextGreater = arr.length-1; for(int i=arr.length-1; i>last; i--){ if(arr[i] > arr[last]){ nextGreater = i; break; } } swap(arr, last, nextGreater); } reverse(arr, last+1, arr.length-1); return true; } private static void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } private static void reverse(int[] arr, int i, int j){ while(i < j){ swap(arr, i++, j--); } } private static String reverseStr(String s){ StringBuilder sb = new StringBuilder(s); return sb.reverse().toString(); } // TC- O(logmax(a,b)) private static int gcd(int a, int b) { if(a == 0){ return b; } return gcd(b%a, a); } private static long gcd(long a, long b) { if(a == 0L){ return b; } return gcd(b%a, a); } private static long lcm(long a, long b) { return a / gcd(a, b) * b; } // TC- O(logmax(a,b)) private static int lcm(int a, int b) { return a / gcd(a, b) * b; } private static long inv(long x){ return power(x, mod - 2); } private static long summation(long n){ return (n * (n + 1L)) >> 1; } }",0,Non-plagiarised 35f0c004,8d6f1bf5,"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 = 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,"/*==========================================================================*/ /* * AUTHOR: RonWonWon * CREATED: 02.05.2021 20:16:37 * EMAIL: rachitpts.2454@gmail.com */ /*==========================================================================*/ 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; } @Override public int compareTo(Pair o) { if(o.y - this.y>0) return -1; else if(o.y - this.y<0) return 1; else return 0; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return """"; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i0) { 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; } @Override public int compareTo(Pair o) { if(o.y - this.y>0) return -1; else if(o.y - this.y<0) return 1; else return 0; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return """"; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;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 0) { int n = sc.nextInt(); String a = sc.next(); String b = sc.next(); char ch1[] = a.toCharArray(); char ch2[] = b.toCharArray(); int zz = 0; int oz = 0; int zo = 0; int oo = 0; for (int i = 0; i < n; i++) { if (ch1[i] == '0') { if (ch2[i] == '0') { zz += 1; } else { oz += 1; } } else { if (ch2[i] == '0') { zo += 1; } else { oo += 1; } } } int ans = -1; if ((oo - zz) == 1 || zo == oz) { int s1 = (int) 1e7; int s2 = (int) 1e7; if ((oo - zz) == 1) { s1 = oo + zz; } if (zo == oz) s2 = zo + oz; ans = Math.min(s1, s2); } System.out.println(ans); } } } //9 //001011011 //011010101 3 2 2 2 //9 //100010111 //101101100 2 1 3 3",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(); } } ","/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=(long)1e9+7; /* start */ public static void main(String [] args) { // int testcases = 1; int testcases = i(); while(testcases-->0) { solve(); } out.flush(); out.close(); } static void solve() { int n = i(); char c[] = inputC(); char d[] = inputC(); int x01=0,x10=0,x00=0,x11=0; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long[] sort(long a[]) { ArrayList arr = new ArrayList<>(); for(long i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } static int[] sort(int a[]) { ArrayList arr = new ArrayList<>(); for(Integer i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } //pair class private static class Pair implements Comparable { long first, second; public Pair(long f, long s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }",0,Non-plagiarised 3b498a39,ae775964,"/* * HI THERE! (: * * CREATED BY : NAITIK V * * JAI HIND * */ import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc=new FastReader(); static long dp[][]; static int mod=1000000007; 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 { int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.xo.y) return 1; else if(this.y o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static 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 void print(int A[]) { for(int i : A) { System.out.print(i+"" ""); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+"" ""); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i hash(int A[]){ HashMap map=new HashMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap tree(int A[]){ TreeMap map=new TreeMap(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } "," import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.ObjectInputStream.GetField; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Hashtable; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import javax.sound.sampled.ReverbType; public class Edu109 { static PrintWriter out; static Scanner sc; static ArrayListq,w,x; static ArrayListadj[]; static HashSetprimesH; static boolean prime[]; //static ArrayLista; static HashSettmp; static int[][][]dist; static boolean[]v; static int[]a,b,c,d; static Boolean[][]dp; static char[][]mp; static int A,B,n,m,h,ans,sum; //static String a,b; static long oo=(long)1e9+7; public static void main(String[]args) throws IOException { sc=new Scanner(System.in); out=new PrintWriter(System.out); //A(); //B(); //C(); D(); //E(); //F(); //G(); out.close(); } private static void A() throws IOException { int t=ni(); while(t-->0) { int k=ni(); int ans=0; for(int i=1;i<=100;i++) { if((i*100)%k==0) { ans=i*100/k;break; } } ol(ans); } } static void B() throws IOException { int t=ni(); while(t-->0) { int n=ni(); a=nai(n); boolean isSorted=true,one=a[0]==1; int pos=0; for(int i=1;i0) { int n=ni(); int m=ni(); a=nai(n); TreeMaptr=new TreeMap(); for(int i=0;ilodd=new PriorityQueue(); PriorityQueuelev=new PriorityQueue(); PriorityQueuerodd=new PriorityQueue(); PriorityQueuerev=new PriorityQueue(); for(int i=0;ipar[]=new PriorityQueue[4]; par[0]=rev;par[1]=rodd;par[2]=lev;par[3]=lodd; for(int i=0;i<2;i++){ while(par[i].size()>=1&&par[i+2].size()>=1) { int r=par[i].poll(),l=par[i+2].poll(); int d1=(l-r)/2; if(l1) { int x=par[i].poll(),y=par[i].poll(); int val=0; if(i<2) { val=m-y+(y-x)/2; }else { val=(x+y)/2; } ans[tr.get(x)]=ans[tr.get(y)]=val; } } for(int i=0;im-r) { ans+=l; b2=2*m - l -r;// m-(l-m+r) -> m-l+m-r }else { ans+=m-r; b1=m-r-l; } return ans+(b2-b1)/2; } private static Boolean dp(int i, int j) { if(j>sum/2)return false; if(i==x.size()) { return sum/2==j; } if(dp[i][j]!=null)return dp[i][j]; return dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j); } static boolean isPrime(long n) { if(n==2)return true; if(n<2||n%2==0)return false; for(long i=3L;i*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; } private static int bfs(int i, int j,int k) { boolean [][]vis=new boolean[dist.length][dist[0].length]; Queueq=new LinkedList(); int mn=Integer.MAX_VALUE; q.add(new int[] {i,j,0,0}); int[]dx=new int[] {-1,1,0,0}; int[]dy=new int[] {0,0,1,-1}; while(!q.isEmpty()) { int []x=q.poll(); vis[x[0]][x[1]]=true; int c=x[2]; if(c>k/2)continue; if(c>0&&k%c==0&&(k/c)%2==0) { mn=Math.min(mn,x[3]*k/c ); } for(int a=0;a<4;a++) { int nx=x[0]+dx[a]; int ny=x[1]+dy[a]; if(valid(nx,ny)&&!vis[nx][ny]) { q.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]}); } } } return mn; } private static boolean valid(int nx, int ny) { return nx>=0&&nx=0&&ny0) { } } static void F() throws IOException { int t=ni(); while(t-->0) { } } static void CC() throws IOException { for(int kk=2;kk<21;kk++) { ol(kk+"" -------""); int n=kk; int k=n-2; int msk=1<>j)&1)!=0) { prod*=a[j]; cnt++; } } if(cnt>=mx&&prod%n==1) { mx=cnt; ms=i; } } ol(mx==1?mx:mx+1); out.print(1+"" ""); long pr=1; for(int j=0;j>j)&1)!=0) { out.print(a[j]+"" ""); pr*=a[j]; } } ol(""""); ol(""Prod: ""+pr); ol(n+""*""+((pr-1)/n)+"" + ""+1); } } static int ni() throws IOException { return sc.nextInt(); } static double nd() throws IOException { return sc.nextDouble(); } static long nl() throws IOException { return sc.nextLong(); } static String ns() throws IOException { return sc.next(); } 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; } static long[] nal(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextLong(); return a; } static int[][] nmi(int n,int m) throws IOException{ int[][]a=new int[n][m]; for(int i=0;i0) { 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; } @Override public int compareTo(Node node) { return this.s-node.s; } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } ",0,Non-plagiarised 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; } @Override public int compareTo(Pair x){ return this.wt-x.wt; } public String toString(){ return ""(""+wt+"" ""+idx+"")""; } } 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; } @Override public int compareTo(Pair x){ return this.first-x.first; } } 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]; static void seive(int n) { int maxn = n; //int maxn = 1000000 ; A[0] = A[1] = true; for (int i = 2; i * i <= maxn; i++) { if (!A[i]) { for (int j = i * i; j <= maxn; j += i) A[j] = true; } } for (int i = 2; i <= maxn; i++) if (!A[i]) list.add(i); } static int findLCA(int a, int b, int par[][], int depth[]) { if (depth[a] > depth[b]) { a = a ^ b; b = a ^ b; a = a ^ b; } int diff = depth[b] - depth[a]; for (int i = 19; i >= 0; i--) { if ((diff & (1 << i)) > 0) { b = par[b][i]; } } if (a == b) return a; for (int i = 19; i >= 0; i--) { if (par[b][i] != par[a][i]) { b = par[b][i]; a = par[a][i]; } } return par[a][0]; } static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } static void formArrayForBinaryLifting(int n, int par[][]) { for (int j = 1; j < 20; j++) { for (int i = 0; i < n; i++) { if (par[i][j - 1] == -1) continue; par[i][j] = par[par[i][j - 1]][j - 1]; } } } static void sort(int ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static void sort1(long ar[]) { int n = ar.length; ArrayList a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(ar[i]); Collections.sort(a); for (int i = 0; i < n; i++) ar[i] = a.get(i); } static long ncr(long n, long r, long mod) { if (r == 0) return 1; long val = ncr(n - 1, r - 1, mod); val = (n * val) % mod; val = (val * modInverse(r, mod)) % mod; return val; } static long fast_pow(long base, long n, long M) { if (n == 0) return 1; if (n == 1) return base % M; long halfn = fast_pow(base, n / 2, M); if (n % 2 == 0) return (halfn * halfn) % M; else return (((halfn * halfn) % M) * base) % M; } static long modInverse(long n, long M) { return fast_pow(n, M - 2, M); } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 32 << 10; private final Writer os; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(long c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println() { return append(System.lineSeparator()); } public FastOutput flush() { try { // boolean success = false; // if (stringBuilderValueField != null) { // try { // char[] value = (char[]) stringBuilderValueField.get(cache); // os.write(value, 0, cache.length()); // success = true; // } catch (Exception e) { // } // } // if (!success) { os.append(cache); // } os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } } ","//package currentContest; 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; } @Override public int compareTo(Main.Pair o) { return Long.compare(this.val, o.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 Reader { static BufferedReader br; static StringTokenizer st; public Reader() { this.br = new BufferedReader(new InputStreamReader(System.in)); } public Reader(String f){ try { this.br = new BufferedReader(new FileReader(f)); } catch (IOException e) { e.printStackTrace(); } } public int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nd(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nl(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[] nca() { return next().toCharArray(); } public String[] ns(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int nextInt() { ensureNext(); return Integer.parseInt(st.nextToken()); } public double nextDouble() { ensureNext(); return Double.parseDouble(st.nextToken()); } public Long nextLong() { ensureNext(); return Long.parseLong(st.nextToken()); } public String next() { ensureNext(); return st.nextToken(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); return null; } } private void ensureNext() { if (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } } } static class Util{ private static Random random = new Random(); static long[] fact; public static void initFactorial(int n, long mod) { fact = new long[n+1]; fact[0] = 1; for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod; } public static long modInverse(long a, long MOD) { long[] gcdE = gcdExtended(a, MOD); if (gcdE[0] != 1) return -1; // Inverted doesn't exist long x = gcdE[1]; return (x % MOD + MOD) % MOD; } public static long[] gcdExtended(long p, long q) { if (q == 0) return new long[] { p, 1, 0 }; long[] vals = gcdExtended(q, p % q); long tmp = vals[2]; vals[2] = vals[1] - (p / q) * vals[2]; vals[1] = tmp; return vals; } public static long nCr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nCr(int n, int r) { return (fact[n]/fact[r])/fact[n-r]; } public static long nPr(int n, int r, long MOD) { if (r == 0) return 1; return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD; } public static long nPr(int n, int r) { return fact[n]/fact[n-r]; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean[] getSieve(int n) { boolean[] isPrime = new boolean[n+1]; for (int i = 2; i <= n; i++) isPrime[i] = true; for (int i = 2; i*i <= n; i++) if (isPrime[i]) for (int j = i; i*j <= n; j++) isPrime[i*j] = false; return isPrime; } public static int gcd(int a, int b) { int tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static long gcd(long a, long b) { long tmp = 0; while(b != 0) { tmp = b; b = a%b; a = tmp; } return a; } public static int random(int min, int max) { return random.nextInt(max-min+1)+min; } public static void dbg(Object... o) { System.out.println(Arrays.deepToString(o)); } public static void reverse(int[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { int tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(int[] s) { reverse(s, 0, s.length-1); } public static void reverse(long[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { long tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(long[] s) { reverse(s, 0, s.length-1); } public static void reverse(float[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { float tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(float[] s) { reverse(s, 0, s.length-1); } public static void reverse(double[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { double tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(double[] s) { reverse(s, 0, s.length-1); } public static void reverse(char[] s, int l , int r) { for(int i = l; i<=(l+r)/2; i++) { char tmp = s[i]; s[i] = s[r+l-i]; s[r+l-i] = tmp; } } public static void reverse(char[] s) { reverse(s, 0, s.length-1); } public static 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); } } static class Writer { private PrintWriter pw; public Writer(){ pw = new PrintWriter(System.out); } public Writer(String f){ try { pw = new PrintWriter(new FileWriter(f)); } catch (IOException e) { e.printStackTrace(); } } public void printArray(int[] a) { for(int 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; } public int compareTo(Pair o) { return Long.compare(value, o.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; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class NotAssigning { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextArray(int n) { int[] a = new int[n]; for (int i=0; i> t, int cur, boolean mode, int[] w) { vis[cur] = true; for (Pair p : t.get(cur)) { if (!vis[p.a]) { if (mode) { w[p.b] = 3; } else { w[p.b] = 2; } dfs(t, p.a, !mode, w); } } } public static void solve(int n, int[] u, int[] v) { ArrayList> t = new ArrayList>(n); for (int i=0; i()); } for (int i=0; i 2) { System.out.println(""-1""); return; } if (t.get(i).size() == 1) { start = i; } } vis = new boolean[n]; int[] w = new int[n-1]; dfs(t, start, false, w); StringBuilder ans = new StringBuilder(); for (int i=0; i 0) { int n = in.nextInt(); int[] u = new int[n-1]; int[] v = new int[n-1]; for (int i=0; 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= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } ","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; tt0){ if ((b&1)== 1){ res= (res * a % mod)%mod; } a=(a%mod * a%mod)%mod; b=b>>1; } return res; } boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n+1]; for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } return prime; } static void sort(int[] a) { ArrayList l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i{ int x,y; public Pair(int x, int y){ this.x = x; this.y = y; } public int compareTo(Pair o){ return -this.x+o.x; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i long ArrayList arr=new ArrayList<>(); // Integer -> Long for(int i=0;i0){ res++; n/=2; } return res; } static int mod = (int)1e9+7; static int INF = Integer.MAX_VALUE; static PrintWriter out; static FastReader sc ; public static void main(String[] args) throws IOException { sc = new FastReader(); out = new PrintWriter(System.out); // primes(); // ================================ // int test = sc.nextInt(); while (test-- > 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; tt0){ if ((b&1)== 1){ res= (res * a % mod)%mod; } a=(a%mod * a%mod)%mod; b=b>>1; } return res; } boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n+1]; for(int i=0;i<=n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } return prime; } static void sort(int[] a) { ArrayList l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i{ int x,y; public Pair(int x, int y){ this.x = x; this.y = y; } public int compareTo(Pair o){ return -this.x+o.x; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i B = new ArrayList<>(); ArrayList R = new ArrayList<>(); for(int i = 0; i < n; i++) { if (s[i] == 'B') B.add(arr[i]); else R.add(arr[i]); } Collections.sort(B); Collections.sort(R); // debug(B); long last = n; for (int i = R.size() - 1; i >= 0; i--) { long v = R.get(i); if (v > last) { return false; } last--; } long first = 1; int size = B.size(); for (int i = 0; i < size; i++) { long v = B.get(i); // debug(v, first); if (v < first) return false; first++; } return true; } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } } ","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; i ""+a); } public static void debug(long a, long b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(char a, char b){ System.out.println(""--> ""+ a +"" + "" + b); } public static void debug(int[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(char[] array){ System.out.print(""Array--> ""); System.out.println(Arrays.toString(array)); } public static void debug(HashMap map){ System.out.print(""Map--> ""+map.toString()); } } } "," import java.io.*; import java.util.*; public class E { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Reader sc=new Reader(); PrintWriter pw=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); int[] idxes=new int[k]; int[] temps=new int[k]; for(int i=0;i=0;i--) { ans[i]=Math.min(ans[i], ans[i+1]+1); } for(int i=0;i= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } } ",1,Plagiarised 558df7d4,d8654140,"import java.io.*; import java.util.*; public class Pupsen { public static void main(String[] args) throws Exception { FastIO in = new FastIO(); int t = in.nextInt(); for (int tc=0; tc[] adj; static boolean vst[]; static int dp[]; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); while(t-->0) { int n=fs.nextInt(); int arr[]=fs.readArray(n); int ans[]=new int[n]; if(n%2==0) { for(int i=0;i>1; } return res; } static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } static class Pair implements Cloneable, Comparable { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+500*Math.abs(y); } @Override public String toString() { return ""(""+x+"" ""+y+"")""; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; int taxC,taxD; Node(int ver) { vertex=ver; taxD=0; taxC=0; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(nn) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ","import java.io.*; 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(); public static void solvegraph() { int n = sc.nextInt(); int edge[][] = new int[n - 1][2]; for (int i = 0; i < n - 1; i++) { edge[i][0] = sc.nextInt() - 1; edge[i][1] = sc.nextInt() - 1; } ArrayList> ad = new ArrayList<>(); for (int i = 0; i < n; i++) { ad.add(new ArrayList()); } for (int i = 0; i < n - 1; i++) { ad.get(edge[i][0]).add(edge[i][1]); ad.get(edge[i][1]).add(edge[i][0]); } int parent[] = new int[n]; Arrays.fill(parent, -1); parent[0] = n; ArrayDeque queue = new ArrayDeque<>(); queue.add(0); int child[] = new int[n]; Arrays.fill(child, 0); ArrayList lv = new ArrayList(); while (!queue.isEmpty()) { int toget = queue.getFirst(); queue.removeFirst(); child[toget] = ad.get(toget).size() - 1; for (int i = 0; i < ad.get(toget).size(); i++) { if (parent[ad.get(toget).get(i)] == -1) { parent[ad.get(toget).get(i)] = toget; queue.addLast(ad.get(toget).get(i)); } } lv.add(toget); } child[0]++; } 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(); } public static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",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 long nextLong() { try { in.nextToken(); } catch (IOException e) { e.printStackTrace(); } return (long) 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(); } static void shuffleArrayL(long[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //-------------------------------------------------------- }",1,Plagiarised 80881cae,9555b9d1,"//package Codeforces; import java.io.*; import java.util.*; public class CP { static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException, CloneNotSupportedException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k[]=new int[n]; int h[]=new int[n]; for(int i=0;i interval=new ArrayList(); ArrayList act=new ArrayList(); for(int i=0;i { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } // @Override // public boolean equals(Object obj) // { // if(obj instanceof Pair) // { // Pair p=(Pair)obj; // return p.x==this.x && p.y==this.y; // } // return false; // } // @Override // public int hashCode() // { // return Math.abs(x)+500*Math.abs(y); // } // @Override // public String toString() // { // return ""(""+x+"" ""+y+"")""; // } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { long t=(this.x-a.x); if(t!=0) return t>0?1:-1; else return (int)(this.y-a.y); } // public void swap() // { // this.y=this.y+this.x; // this.x=this.y-this.x; // this.y=this.y-this.x; // } } }","import java.io.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 long inv(long a, long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } static long mi(long a) { return inv(a, mod); } static InputReader sc = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] A = new int[n]; for (int i = 0; i < A.length; i++) { A[i] = sc.nextInt(); } String word = sc.next(); ArrayList blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < word.length(); i++) { if (word.charAt(i) == 'R') { red.add(A[i]); } else { blue.add(A[i]); } } Collections.sort(blue); Collections.sort(red); boolean possible = true; int a = 1; for (int i = 0; i < blue.size(); i++, a++) { if (blue.get(i) < a) { possible = false; break; } } for (int i = 0; i < red.size(); i++, a++) { if (red.get(i) > a) { possible = false; break; } } if (possible) out.println(""YES""); else out.println(""NO""); } out.flush(); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } public static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } public static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } } ","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{ class Element{ int x; char c; public Element(int y,char k) { x=y; c=k; } } 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 long ans(long l,long r,long x,long y) { long mid=(r-l)/2+l; long a=mid%x; long b=y%mid; long c=0; if(l>r) { return 0; } if(a==b) { return mid; } else if(a= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static void dfs(int n , LinkedList 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); } } ","// ""static void main"" must be defined in a public class. import java.util.*; import java.io.*; public class Main { static long[][]dp; static ArrayList[]adj; static int[][]arr; static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); arr=new int[n][2]; adj=new ArrayList[n]; for(int i=0;i(); } for(int i=0;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(); } static class Pair { X x; Y y; public Pair(X x, Y y) { this.x = x; this.y = y; } } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }",1,Plagiarised 47d54299,63bfa731,"// package com.company.Codechef; // import com.sun.security.jgss.GSSUtil; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class a { static int depth[]; static ArrayList tree[]; static int diameter=0; public static void main(String[] args) { FastReader input=new FastReader(); int t=input.nextInt(); while (t-->0){ diameter=0; int n=input.nextInt(); int a=input.nextInt(); int b=input.nextInt(); int da=input.nextInt(); int db=input.nextInt(); depth=new int[n+1]; tree=new ArrayList[n+1]; for (int i = 0; i <=n ; i++) { tree[i]=new ArrayList<>(); } for (int i = 0; i = Math.min(diameter, db) ||depth[b]<=da){ System.out.println(""Alice""); }else { System.out.println(""Bob""); } } } private static int dfs(int root, int p) { int len=0; for(int child:tree[root]){ if (child!=p){ depth[child]=depth[root]+1; int curr=1+dfs(child,root); diameter=Math.max(diameter,curr+len); len=Math.max(len,curr); } } return len; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }"," import java.util.*; import java.io.*; public class D { static ArrayList adj[] = new ArrayList[(int)1e5+7]; static int diameter = 0; static int[] depth = new int[(int)1e5 + 7]; public static void main(String[] args) { FastReader in = new FastReader(); int t = in.nextInt(); while(t-- > 0){ int n = in.nextInt(); int a = in.nextInt(), b = in.nextInt(), da = in.nextInt(), db = in.nextInt(); for(int i = 1; i <= n; i++){ adj[i] = new ArrayList<>(); } for(int i = 1; i <=n; i++){ adj[i].clear(); } for(int i = 0; i < n- 1; i++){ int u = in.nextInt(); int v = in.nextInt(); adj[u].add(v); adj[v].add(u); } diameter = 0; depth[a] = 0; dfs(a, -1); System.out.println(2 * da >= Math.min(diameter, db) || depth[b] <= da ? ""Alice"" : ""Bob""); } } static int dfs(int node, int parent){ int len = 0; for(int x : adj[node]){ if(x != parent){ depth[x] = depth[node] + 1; int cur = 1 + dfs(x, node); diameter = Math.max(diameter, cur + len); len = Math.max(len, cur); // System.out.print(""x "" + x + "" node "" + node + "" par "" + parent); // System.out.println("" cur "" + cur + "" len "" + len + "" diam "" + diameter); } } return len; } static long getDigitSum(long n) { long sum = 0; while (n > 0) { sum = sum + n % 10; n = n/10; } return sum; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n){ int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = nextInt(); } return a; } } } ",1,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(); private static class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } 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 long[] longArr(int size) { Scanner scc = new Scanner(System.in); long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static LinkedList[] graphD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList aa:temp) System.out.println(aa); } static long cal(long val, long pow, long mod) { if(pow == 0) return 1; long res = cal(val, pow/2, mod); long ret = (res*res)%mod; if(pow%2 == 0) return ret; return (val*ret)%mod; } static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); } } static int mod = (int) 1e9; static LinkedList[] temp, idx; static long inf = (long) Long.MAX_VALUE; // static long inf = Long.MAX_VALUE; // static int max; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); String a = sc.next(), b = sc.next(); int _00 = 0, _01 = 0, _10 = 0, _11 = 0; for(int i = 0; i < n; i++) { if(a.charAt(i) == '0' && b.charAt(i) == '0') _00++; if(a.charAt(i) == '0' && b.charAt(i) == '1') _01++; if(a.charAt(i) == '1' && b.charAt(i) == '0') _10++; if(a.charAt(i) == '1' && b.charAt(i) == '1') _11++; } int ans = Integer.MAX_VALUE; if(_10 == _01) ans = _01 + _10; if(_10 > 0) { int n00 = _10 - 1; int n01 = _11; int n10 = _00 + 1; int n11 = _01; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } if(_11 > 0) { int n00 = _10; int n01 = _11 - 1; int n10 = _00; int n11 = _01 + 1; if (n01 == n10) { ans = Math.min(ans, 1 + n01 + n10); } } ret.append(ans == Integer.MAX_VALUE ? -1 : ans); ret.append(""\n""); } System.out.println(ret); } } ","import javax.swing.plaf.IconUIResource; import java.lang.reflect.Array; import java.text.CollationElementIterator; import java.util.*; import java.io.*; //Timus judge id- 323935JJ public class Main { //---------------------------------------------------------------------------------------------- public static class Pair implements Comparable { int x=0,y=0; int z=0; public Pair(int a, int b) { this.x=a; this.y=b; } public int compareTo(Pair o) { return this.x - o.x; } } public static int mod = (int) (1e9 + 7); static int ans = Integer.MAX_VALUE; public static void main(String hi[]) throws Exception { FastReader sc = new FastReader(); int t =sc.nextInt(); while(t-->0) { int n =sc.nextInt(); String a = sc.nextLine(),b=sc.nextLine(); int count1=0,count2=0,count3=0,count4=0; for(int i=0;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); } }*/ static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder(""0""); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder(""0""); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }","import java.io.*; import java.util.*; public class Solution{ public static int in = 0, count=0; static class comparator implements Comparator{ public int compare(int[] arr1 ,int[] arr2){ int gain1 =0, gain2=0; for(int i:arr1) gain1+=i; for(int i:arr2) gain2+=i; if((gain1-2*arr1[in])>(gain2-2*arr2[in])) return 1; else if((gain1-2*arr1[in])==(gain2-2*arr2[in])) { count++; return 0; } return -1; } } 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;i l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (char i:a) l.add(i); Collections.sort(l); for (int i=0; i l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i { if(x[c]>y[c]) { return 1; }else { return -1; } }); } public static void printb(boolean ans) { if(ans) { System.out.println(""Yes""); }else { System.out.println(""No""); } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i{ int a , b; Pair(int x , int y){ a=x; b=y; } public int compareTo(Pair o) { return a != o.a ? a - o.a : b - o.b; } } } ","import java.util.*; public class Solution{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); long max=(long)1e18; StringBuilder sb=new StringBuilder(); while(t-->0){ 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); } } static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sort(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int[] nextSortedIntArray(int n) { int array[] = nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n) { int[] array = new int[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public long[] nextSumLongArray(int n) { long[] array = new long[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextSortedLongArray(int n) { long array[] = nextLongArray(n); Arrays.sort(array); return array; } } } ","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); } 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 compareTo(pair other) { int i = x.compareTo(other.x); if (i != 0) return i; return y.compareTo(other.y); } public String toString() { return x.toString() + "" "" + y.toString(); } public boolean equals(Object obj) { if (this.getClass() != obj.getClass()) return false; pair other = (pair) obj; return x.equals(other.x) && y.equals(other.y); } public int hashCode() { return 31 * x.hashCode() + y.hashCode(); } } static void sort(int[] a) { ArrayList l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i odd = new PriorityQueue(); PriorityQueue even = new PriorityQueue(); int arr[] = sc.readArray(n); long min = INF; long sumOdd = 0; long sumEven = 0; for (int i = 0; i < n; i++) { int x = arr[i]; if (i % 2 == 0) { even.add(x); sumEven += x; } else { odd.add(x); sumOdd += x; } if (i > 0) { long ans = 0; ans += 1l * even.peek() * (n - (even.size())); ans += 1l * odd.peek() * (n - (odd.size())); ans += sumOdd + sumEven; min = Math.min(ans, min); } } System.out.println(min); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= static FastScanner sc; static PrintWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new PrintWriter(System.out); } else { sc = new FastScanner(100); out = new PrintWriter(""output.txt""); } int t = 1; t = sc.nextInt(); while (t-- > 0) { process(); } out.flush(); out.close(); } static class Pair implements Comparable { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader(""input.txt"")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } } ",0,Non-plagiarised 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(); } static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } 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(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[5]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String stock = """"; try { stock = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return stock; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }","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); } void println(T[] s) { if (err == null)return; err.println(Arrays.toString(s)); } void println(T s) { if (err == null)return; err.println(s); } void println(int s) { if (err == null)return; err.println(s); } void println(int[] a) { if (err == null)return; println(Arrays.toString(a)); } int[] array(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } int[] array1(int n) { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) { a[i] = in.nextInt(); } return a; } int max(int[] a) { int max = a[0]; for (int i = 0; i < a.length; i++)max = Math.max(max, a[i]); return max; } int min(int[] a) { int min = a[0]; for (int i = 0; i < a.length; i++)min = Math.min(min, a[i]); return min; } int count(int[] a, int x) { int count = 0; for (int i = 0; i < a.length; i++)if (x == a[i])count++; return count; } void printArray(int[] a) { for (int ele : a)out.append(ele + "" ""); out.append(""\n""); } 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; } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Pair implements Comparable { int first , second; Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair b) { return this.first - b.first; } public String toString() { String s = ""{ "" + Integer.toString(first) + "" , "" + Integer.toString(second) + "" }""; return s; } } } ","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; } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } ",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; } } public static int lowerbound(long[] ar,int k) { int s=0; int e=ar.length; while (s !=e) { int mid = s+e>>1; if (ar[mid] 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] == element) { return low; } else if (arr[high] == element) { return high; } return -1; } static int lower_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] >= element) { return low; } else if (arr[high] >= element) { return high; } return -1; } static int upper_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] <= element) { low = mid + 1; } else { high = mid; } } if (arr[low] > element) { return low; } else if (arr[high] > element) { return high; } return -1; } public static int upperbound(long[] arr, int k) { int s = 0; int e = arr.length; while (s != e) { int mid = s + e >> 1; if (arr[mid] <= k) { s = mid + 1; } else { e = mid; } } if (s == arr.length) { return -1; } return s; } public static long pow(long x,long y,long mod){ if(x==0)return 0l; if(y==0)return 1l; //(x^y)%mod if(y%2l==1l){ return ((x%mod)*(pow(x,y-1l,mod)%mod))%mod; } return pow(((x%mod)*(x%mod))%mod,y/2l,mod); } public static long gcd_long(long a, long b) { // a/b,a-> dividant b-> divisor if (b == 0) return a; return gcd_long(b, a % b); } public static int gcd_int(int a, int b) { // a/b,a-> dividant b-> divisor if (b == 0) return a; return gcd_int(b, a % b); } public static int lcm(int a, int b) { int gcd = gcd_int(a, b); return (a * b) / gcd; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String s = """"; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } Long nextLong() { return Long.parseLong(next()); } } } /* * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){ * return true; } if(n<1 || m<1 || k<0){ return false; } boolean * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; } * return false; } */ ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = fastReader.nextInt(); } ArrayList b = new ArrayList<>(); ArrayList r = new ArrayList<>(); char c[] = fastReader.next().toCharArray(); for (int i = 0; i < n; i++) { if (c[i] == 'B') { b.add(a[i]); } else { r.add(a[i]); } } Collections.sort(b); Collections.sort(r); int sizeb = b.size(); boolean isValid = true; for (int i = 1 , j = 0; i <=sizeb; i++ , j++){ if (b.get(j) < i){ isValid =false; } } for (int i = sizeb+1 , j = 0; i <=n && j < r.size(); i++ , j++){ if (r.get(j) > i){ isValid =false; } } if (isValid){ System.out.println(""YES""); }else{ System.out.println(""NO""); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } ",0,Non-plagiarised ac180326,b1e9f1f6,"//This code is written by प्रविण शंखपाळ //package wizard; 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; } public int compareTo(Pair o) { // TODO Auto-generated method stub if (this.a != o.a) return Integer.compare(this.a, o.a); else return Integer.compare(this.b, o.b); // return 0; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair) o; return p.a == a && p.b == b; } return false; } } static int binarySearch(int arr[], int first, int last, int key) { int mid = (first + last) / 2; while (first <= last) { if (arr[mid] < key) { first = mid + 1; } else if (arr[mid] == key) { return mid; } else { last = mid - 1; } mid = (first + last) / 2; } return -1; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } "," import java.io.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; } @Override public int compareTo(Pair o) { return this.val - o.val; } } 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; } @Override public int compareTo(pair o) { // if(this.a!=o.a){ // return o.a-this.a; // }else // return this.b-o.b; return -(this.a-this.b)+(o.a-o.b); } } class Input{ BufferedReader br; StringTokenizer st; Input(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""""); } public int[] readArray() throws Exception{ st=new StringTokenizer(br.readLine()); int a[]=new int[st.countTokens()]; for(int i=0;i total) { ret++; } else { return ret; } } return ret; } static class Comp implements Comparator { char c; public Comp (char c) { this.c = c; } public int compare(String a, String b) { double cnt1 = 0; double cnt2 = 0; for (int i=0; i0) { 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); } } } class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } ",0,Non-plagiarised 30e0cc81,b55888de,"import java.io.*; import java.util.*; import java.math.BigInteger; import java.lang.*; public class Main { static class sortLong implements Comparator{ public int compare(long[] a,long[] b){ if(a[0] > b[0]) return 1;return -1; } } static class sortInt implements Comparator{ public int compare(int[] a,int[] b){ if(a[1] > b[1]) return 1;return -1; } } 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 prW(PrintWriter out,Object o) { out.print(o.toString());//out.flush(); } public static int intIn(String st) { return Integer.parseInt(st); } public static void pr(Object o) { System.out.println(o.toString()); } public static void prW(Object o) { System.out.print(o.toString()); } public static int inInt(String s) { return Integer.parseInt(s); } public static long in(String s) { return Long.parseLong(s); } static int[] toIntArray(String[] m) { int[] p=new int[m.length]; for(int o=0;o 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long __gcd(long n1, long n2) { if(n1==0l) return n2; if(n2==0l) return n1; if(n1==1l || n2==1l) return 1l; // long gcd = 1; if(n1 == n2) return n1; if(n1>n2) return __gcd(n1%n2,n2); return __gcd(n1,n2%n1); } 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;w y) ? x : y; } int getMid(int s, int e) { return s + (e - s) / 2; } int RMQUtil(int ss, int se, int qs, int qe, int index) { if (qs <= ss && qe >= se) return st[index]; // If segment of this node is outside the given range if (se < qs || ss > qe) return Integer.MIN_VALUE; // If a part of this segment overlaps with the given range int mid = getMid(ss, se); return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); } // Return minimum of elements in range from index qs (query // start) to qe (query end). It mainly uses RMQUtil() int RMQ(int n, int qs, int qe) { // Check for erroneous input values return RMQUtil(0, n - 1, qs, qe, 0); } // A recursive function that constructs Segment Tree for // array[ss..se]. si is index of current node in segment tree st int constructSTUtil(int arr[], int ss, int se, int si) { // If there is one element in array, store it in current // node of segment tree and return if (ss == se) { st[si] = arr[ss]; return arr[ss]; } // If there are more than one elements, then recur for left and // right subtrees and store the minimum of two values in this node int mid = getMid(ss, se); st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), constructSTUtil(arr, mid + 1, se, si * 2 + 2)); return st[si]; } void con(int arr[]) { // Allocate memory for segment tree //Height of segment tree int n = (arr.length); int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); //Maximum size of segment tree int max_size = 2 * (int) Math.pow(2, x) - 1; st = new int[max_size]; // allocate memory // Fill the allocated memory st constructSTUtil(arr, 0, n - 1, 0); } } static class DSU { int[] p;int[] sz;int op;int c;; int[] last; public void G(int n) { last=new int[n]; p=new int[n]; sz=new int[n];c=n; op=n; for(int h=0;hsz[y]) { p[y] = x; sz[x]+=sz[y]; last[x]=Math.max(last[x],last[y]); } else { p[x]=y;sz[y]+=sz[x]; last[y]=Math.max(last[y],last[x]); } c--; }} static long pow(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0l; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static int gcd(int a, int b,int o) { if (b == 0) return a; return gcd(b, a % b,o); } Geometric median public static double F(double[] x,double[] w) { double d1,d2; double S=0.00; for(double dp : w) S += dp; int k = 0; double sum = S - w[0]; // sum is the total weight of all `x[i] > x[k]` while(sum > S/2) { ++k; sum -= w[k]; } d1=x[k]; return d1; k = w.length-1; sum = S - w[k]; // sum is the total weight of all `x[i] > x[k]` while(sum > S/2) { --k; sum -= w[k]; } d2=x[k]; return new double[]{d1,d2}; } */","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(); } }",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 sieveOfEratosthenes(int n) { // Create a boolean array // ""prime[0..n]"" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } ArrayList arr = new ArrayList<>(); // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } // Method to check if x is power of 2 static boolean isPowerOfTwo(int x) { return x != 0 && ((x & (x - 1)) == 0); } //Method to return lcm of two numbers static int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } //Method to count digit of a number static int countDigit(long n) { String sex = Long.toString(n); return sex.length(); } static void reverse(int a[]) { int i, k, t; int n = a.length; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static final Random random = new Random(); //Method for sorting static void ruffleSort(int[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int j = random.nextInt(n); int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static void sortadv(long[] a) { ArrayList l = new ArrayList<>(); for (long value : a) { l.add(value); } Collections.sort(l); for (int i = 0; i < l.size(); i++) a[i] = l.get(i); } //Method for checking if a number is prime or not static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static 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(); int k=ni(); int[] a=new int[k]; int[] temp=new int[k]; iIA(a); iIA(temp); long dp[]=new long[n]; Arrays.fill(dp,Integer.MAX_VALUE); 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; } @Override public int compareTo(Pair o) { if(o.color==this.color) { return this.number-o.number; } else { return this.color-o.color; } } public String toString() { return number+""-""+color+"".""; } } } ","import java.io.*; import java.util.*; public class Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream(""input.txt"")); // System.setOut(new PrintStream(""output.txt"")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i blue=new ArrayList(); ArrayList red=new ArrayList(); for(int i=0;ii+1+blue.size()) { out.println(""NO""); return; } } out.println(""YES""); } static class Pair implements Cloneable, Comparable { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+500*Math.abs(y); } @Override public String toString() { return ""(""+x+"" ""+y+"")""; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; int taxC,taxD; Node(int ver) { vertex=ver; taxD=0; taxC=0; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(nn) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ",0,Non-plagiarised 1ea771ea,2f8c3bf3," import java.io.*; import java.util.*; public class CODECHEF { static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static long MOD=1000000000; static class Pair{ long a; int b; Pair(long i,int j){ a=i; b=j; } } static long[] solve(int[] pos,long[] arr,int n,int k){ long[] ans=new long[n]; long[] left=new long[n]; long[] right=new long[n]; long min=Integer.MAX_VALUE; for(int i=0;i=0;i--){ min=Math.min(min+1,arr[i]); right[i]=min; } for(int i=0;i0){ int n=fs.nextInt(); int k=fs.nextInt(); int[] pos=new int[k]; for(int i=0;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; } } static int BS(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] == element) { return low; } else if (arr[high] == element) { return high; } return -1; } static int lower_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] >= element) { return low; } else if (arr[high] >= element) { return high; } return -1; } static int upper_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] <= element) { low = mid + 1; } else { high = mid; } } if (arr[low] > element) { return low; } else if (arr[high] > element) { return high; } return -1; } public static long gcd_long(long a,long b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_long(b, a%b); } public static int gcd_int(int a,int b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_int(b, a%b); } public static int lcm(int a,int b){ int gcd=gcd_int(a, b); return (a*b)/gcd; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String s = """"; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } Long nextLong() { return Long.parseLong(next()); } } } /* * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){ * return true; } if(n<1 || m<1 || k<0){ return false; } boolean * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; } * return false; } */ ",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(); } } static class pair{ int x ; int y; pair(int x,int y) { this.x=x; this.y=y; } } static class Maths { static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static long factorial(int n) { long fact = 1; for (int i = 1; i <= n; i++) { fact *= i; } return fact; } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } ",0,Non-plagiarised 3c74c140,732c98a0," //package com.company; import java.math.*; import java.util.*; import java.lang.*; import java.io.*; public final class Main { FastReader s; public static void main (String[] args) throws java.lang.Exception { new Main().run(); } void run() { s = new FastReader(); solve(); } StringBuffer sb; // int counter; void solve() { sb = new StringBuffer(); for(int T = s.nextInt();T > 0;T--) { start(); } // System.out.print(sb); } void start() { int n = s.nextInt(); int mat[][] = new int[n][5]; for(int i = 0; i x = new ArrayList<>(); for(int j = 0; j=0) { int u = x.get(l); if(s+u>0) { s+=u; cnt++; } else break; l--; } return cnt; } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } long power(long x, long y, long p) { long res = 1; // Initialize result // Update x if it is more // than or equal to p x = x % p; while (y > 0) { // If y is odd, multiply // x with the result if ((y & 1) > 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } int lower_bound(int [] arr , int key) { int i = 0; int j = arr.length-1; //if(arr[i] > key)return -1; if(arr[j] < key)return -1; while(i0;t--) solve(); out.print(sb); } void solve(){ int n = in.nextInt(); int[][] mat = new int[n][5]; for(int i = 0; i x = new ArrayList<>(); for(int j = 0; j=0) { int u = x.get(l); if(s+u>0) { s+=u; cnt++; } else break; l--; } return cnt; } long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int upper_bound(long[] arr, int key) { int i=0, j=arr.length-1; if (arr[j]<=key) return j+1; if(arr[i]>key) return i; while (i arr, long n) { arr.sort(new Comparator() { @Override public int compare(Pair p1, Pair p2) { return (int) (p2.first - p1.first); } }); } } public static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st==null || !st.hasMoreElements()){ try{ st=new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ String str=""""; try{ str=br.readLine(); }catch (Exception e){ e.printStackTrace(); } return str; } } }",1,Plagiarised 2915ac5b,9b8c6bd7,"import java.util.*; import java.lang.*; import java.io.*; public class Main { // static Scanner sc=new Scanner(System.in); // static ArrayList 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])); // } // } // } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ","import java.util.*; import java.io.*; 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(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }",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; } @Override public int compareTo(Pair x){ return this.first-x.first; } } 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 @Override public int compare(Student s1, Student s2) { if (s1.i1 < s2.i1) return -1; else if (s1.i1 >s2.i1) return 1; return 0; } } /* 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 t, ArrayList m) { if (t.size() == 0 && m.size() == 0) { sd = true; return; } t.remove(0); t.remove(t.size() - 1); call(t, new ArrayList(m.subList(0, m.size() - 1))); call(t, new ArrayList(m.subList(1, m.size()))); } static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static int noofdivisors(int n) { //it counts no of divisors of every number upto number n int arr[] = new int[n + 1]; for (int i = 1; i <= (n); i++) { for (int j = i; j <= (n); j = j + i) { arr[j]++; } } return arr[0]; } static char[] reverse(char arr[]) { char[] b = new char[arr.length]; int j = arr.length; for (int i = 0; i < arr.length; i++) { b[j - 1] = arr[i]; j = j - 1; } return b; } static long factorial(int n) { long su = 1; for (int i = 1; i <= n; i++) { su *= (long) i; } return su; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); public String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } long[] readArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } } ",0,Non-plagiarised 5af25bd7,fa1bf524,"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.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' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int mod = (int) (1e9 + 7); public static class pair implements Comparator { int x; int y; public pair() { } public pair(int x, int y) { this.x = x; this.y = y; } @Override public int compare(pair o1, pair o2) { return o1.y - o2.y; } } public static long modularpow(long a, long b) { long res = 1; if (b == 0) return res; else { while (b > 0) { if (b % 2 == 1) { res *= a; res %= mod; } a = a * a; a %= mod; b /= 2; } return res % mod; } } public static int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } public static String binary(int a) { String s1 = """"; while (a > 0) { s1 = a % 2 + s1; a /= 2; } return s1; } public static int Lower_Bound(long a[], int l, int r, long k) { while (r - l > 1) { int mid = l + (r - l) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l; } public static int Upper_Bound(int a[], int l, int r, int k) { while (r - l > 1) { int mid = (l + r) / 2; if (a[mid] <= k) l = mid; else r = mid; } return l + 1; } public static void main(String arg[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { br.readLine(); String s[]=br.readLine().split("" ""); int n=Integer.parseInt(s[0]); int k=Integer.parseInt(s[1]); long a[]=new long[n]; long b[]=new long[n]; long c[]=new long[n]; Arrays.fill(c,Integer.MAX_VALUE); String s1[]=br.readLine().split("" ""); s=br.readLine().split("" ""); for(int i=0;i=0;i--){ p=Math.min(p+1,c[i]); b[i]=p; } for(int i=0;i> dp= new HashMap<>(); // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) public void sieve() { spf[1] = 1; for (int i=2; i getFactorization(int x) { if(dp.containsKey(x)) return dp.get(x); Set ret = new HashSet<>(); while (x != 1) { if(spf[x]!=2) ret.add(spf[x]); x = x / spf[x]; } dp.put(x,ret); return ret; } // function to find first index >= x public int lowerIndex(List arr, int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y public int upperIndex(List arr, int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr.get(mid) <= y) l = mid + 1; else h = mid - 1; } return h; } // function to count elements within given range public int countInRange(List arr, int n, int x, int y) { // initialize result int count = 0; count = upperIndex(arr, n, y) - lowerIndex(arr, n, x) + 1; return count; } public int add(int a, int b){ a+=b; if(a>=MOD) a-=MOD; else if(a<0) a+=MOD; return a; } public int mul(int a, int b){ long res= (long)a*(long)b; return (int)(res%MOD); } public int power(int a, int b) { int ans=1; while(b>0){ if((b&1)!=0) ans= mul(ans,a); b>>=1; a= mul(a,a); } return ans; } int[] fact= new int[MAXN]; int[] inv= new int[MAXN]; public int Ckn(int n, int k){ if(k<0 || n<0) return 0; return mul(mul(fact[n],inv[k]),inv[n-k]); } public int inverse(int a){ return power(a,MOD-2); } public void preprocess() { fact[0]=1; for(int i=1;i=0;i--){ inv[i]= mul(inv[i+1],i+1); } } public void solve(InputReader in, PrintWriter out) { int test= in.nextInt(); while(test-->0){ int n= in.nextInt(), k= in.nextInt(); int[] a= new int[k]; int[] t= new int[k]; for(int i=0;i=0;i--){ p= Math.min(p+1,c[i]); R[i]=(int)p; } for(int i=0;i{ // @Override // public int compare(Tuple t1, Tuple t2) { // return t2.l - t1.l; // } // } public int _gcd(int a, int b) { if(b == 0) { return a; } else { return _gcd(b, a % b); } } } static class Venice{ public Map m= new HashMap<>(); public long base=0; public long totalValue=0; private int M= 1000000007; private long addMod(long a, long b){ a+=b; if(a>=M) a-=M; return a; } public void reset(){ m= new HashMap<>(); base=0; totalValue=0; } public void update(long add){ base= base+ add; } public void add(long key, long val){ long newKey= key-base; m.put(newKey, addMod(m.getOrDefault(newKey,(long)0),val)); } } static class Tuple implements Comparable{ int x, y, z; public Tuple(int x, int y, int z){ this.x= x; this.y= y; this.z=z; } @Override public int compareTo(Tuple o){ return this.x-o.x; } } static class Pair implements Comparable{ public int x; public int y; public Pair(int x, int y){ this.x= x; this.y= y; } @Override public int compareTo(Pair o) { return this.x-o.x; } } // fast input reader class; static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { String line = null; try { line = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble(){ return Double.parseDouble(nextToken()); } public long nextLong(){ return Long.parseLong(nextToken()); } } }",1,Plagiarised 0b5cff5a,4fb09c5f,"import java.io.*; import java.text.DecimalFormat; import java.util.*; public class E { static long mod=(long)1e9+7; static long mod1=998244353; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int t= in.nextInt(); while(t-->0) { int n = in.nextInt(); int k = in.nextInt(); int[] a= in.readArray(k); int[] temp = in.readArray(k); int[] pre = new int[n]; Arrays.fill(pre,Integer.MAX_VALUE); int[] suf = new int[n]; Arrays.fill(suf,Integer.MAX_VALUE); for(int i = 0;i=0;i--){ min = Math.min(min,suf[i]); suf[i] = min; min++; } for(int i=0;i 0){ if(b%2 == 1) x=(x*y)%c; y = (y*y)%c; b = b>>1; } return x%c; } public static void debug(Object... o){ System.err.println(Arrays.deepToString(o)); } static int upper_bound(int[] arr,int n,int x){ int mid; int low=0; int high=n; while(low=arr[mid]) low=mid+1; else high=mid; } return low; } static int lower_bound(int[] arr,int n,int x){ int mid; int low=0; int high=n; while(low 0) { int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[k]; int[] t = new int[k]; HashMap hm = new HashMap<>(); for (int i = 0; i < k; i++) { arr[i] = sc.nextInt() - 1; } for (int i = 0; i < k; i++) { t[i] = sc.nextInt(); hm.put(arr[i], t[i]); } int[] left = new int[n]; int[] right = new int[n]; left[0] = hm.getOrDefault(0, -1); right[n - 1] = hm.getOrDefault(n - 1, -1); for (int i = 1; i < n; i++) { if (hm.containsKey(i)) { if (left[i - 1] < 0) { left[i] = hm.get(i); } else { left[i] = Math.min(hm.get(i), left[i - 1] + 1); } } else { left[i] = left[i - 1] < 0 ? -1 : left[i - 1] + 1; } } for (int i = n - 2; i >= 0; i--) { if (hm.containsKey(i)) { if (right[i + 1] < 0) { right[i] = hm.get(i); } else { right[i] = Math.min(hm.get(i), right[i + 1] + 1); } } else { right[i] = right[i + 1] < 0 ? -1 : right[i + 1] + 1; } } for (int i = 0; i < n; i++) { if (left[i] < 0) { pw.print(right[i] + "" ""); } else if (right[i] < 0) { pw.print(left[i] + "" ""); } else { pw.print(Math.min(left[i], right[i]) + "" ""); } } pw.println(); } pw.flush(); pw.close(); } // inclusive private static void rotate(int[] arr, int l, int r) { int temp = arr[r]; for (int i = r - 1; i >= l; i--) { arr[i + 1] = arr[i]; } arr[l] = temp; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream System) throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() { for (long i = 0; i < 3e9; i++) ; } } static class Pair { int a; int b; boolean asc; Pair(int a, int b, boolean asc) { this.a = a; this.b = b; this.asc = asc; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return a == pair.a && b == pair.b && asc == pair.asc; } @Override public int hashCode() { return Objects.hash(a, b, asc); } } } ",0,Non-plagiarised 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; } public static void sort(long[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int idx = (int) (Math.random() * n); long temp = arr[i]; arr[i] = arr[idx]; arr[idx] = temp; } Arrays.sort(arr); } public static void sort(int[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int idx = (int) (Math.random() * n); int temp = arr[i]; arr[i] = arr[idx]; arr[idx] = temp; } Arrays.sort(arr); } public static void print(long[][] dp) { for (long[] a : dp) { for (long ele : a) { System.out.print(ele + "" ""); } System.out.println(); } } public static void print(int[][] dp) { for (int[] a : dp) { for (int ele : a) { System.out.print(ele + "" ""); } System.out.println(); } } public static void print(int[] dp) { for (int ele : dp) { System.out.print(ele + "" ""); } System.out.println(); } public static void print(long[] dp) { for (long ele : dp) { System.out.print(ele + "" ""); } System.out.println(); } } "," 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; } public static void sort(long[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int idx = (int) (Math.random() * n); long temp = arr[i]; arr[i] = arr[idx]; arr[idx] = temp; } Arrays.sort(arr); } public static void sort(int[] arr) { int n = arr.length; for (int i = 0; i < n; i++) { int idx = (int) (Math.random() * n); int temp = arr[i]; arr[i] = arr[idx]; arr[idx] = temp; } Arrays.sort(arr); } public static void print(long[][] dp) { for (long[] a : dp) { for (long ele : a) { System.out.print(ele + "" ""); } System.out.println(); } } public static void print(int[][] dp) { for (int[] a : dp) { for (int ele : a) { System.out.print(ele + "" ""); } System.out.println(); } } public static void print(int[] dp) { for (int ele : dp) { System.out.print(ele + "" ""); } System.out.println(); } public static void print(long[] dp) { for (long ele : dp) { System.out.print(ele + "" ""); } System.out.println(); } } ",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(); } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } static final long mod = 1000000007; static long pow_mod(long a, long b) { long result = 1; while (b != 0) { if ((b & 1) != 0) result = (result * a) % mod; a = (a * a) % mod; b >>= 1; } return result; } private static long multiplied_mod(long... longs) { long ans = 1; for (long now : longs) { ans = (ans * now) % mod; } return ans; } @SuppressWarnings(""FieldCanBeLocal"") private static Reader in; private static PrintWriter out; private static int[] read_int_array(int len) throws IOException { int[] a = new int[len]; for (int i = 0; i < len; i++) { a[i] = in.nextInt(); } return a; } private static long[] read_long_array(int len) throws IOException { long[] a = new long[len]; for (int i = 0; i < len; i++) { a[i] = in.nextLong(); } return a; } private static void print_array(int[] array) { for (int now : array) { out.print(now); out.print(' '); } out.println(); } private static void print_array(long[] array) { for (long now : array) { out.print(now); out.print(' '); } out.println(); } static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { final byte[] buf = new byte[1024]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextSign() throws IOException { byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } }"," 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(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } } ",0,Non-plagiarised 74f4382e,bd584714," import java.io.*; import java.util.*; public class Solution { static long modInverse(long a, long m) { long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long q = a / m; long t = m; m = a % m; a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } static void pla() { int a = 0; int b = 2; int c = 0; int d = 0; a = (int) Math.pow(2, 32); c = a + b; b = c / a; d = a + b + c; } 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]; static void sieve() { pri[1] = pri[0] = 1; for (int i = 2; i < pri.length; i++) { pri[i] = i; } for (int i = 2; i < Math.sqrt(pri.length); i++) { if (pri[i] != i) continue; for (int j = i * i; j < pri.length; j += i) { if (pri[j] == j) pri[j] = i; } } } 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 static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } 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 al = new ArrayList<>(); for (int i = 0; i < n; i++) { al.add(a[i]); } Collections.sort(al); for (int i = 0; i < n; i++) { a[i] = al.get(i); } } static void sort(long a[], int n) { ArrayList al = new ArrayList<>(); for (int i = 0; i < n; i++) { al.add(a[i]); } Collections.sort(al); for (int i = 0; i < n; i++) { a[i] = al.get(i); } } static Reader sc = new Reader(); static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }","import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStream; 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); CParsasHumongousTree solver = new CParsasHumongousTree(); solver.solve(1, in, out); out.close(); } static class CParsasHumongousTree { int n; long[] l; long[] r; ArrayList[] 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; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ",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; private static void google(int tt) { System.out.print(""Case #"" + (tt) + "": ""); } 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; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Long.compare(this.x, o.x); } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap map, int k, int v) { //map[k] += v; if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } // compress Big value to Time Limit public static int[] compress(int[] arr) { ArrayList ls = new ArrayList(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap map = new HashMap(); int boof = 1; //min value for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } // Fast Writer public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException(""FastWriter""); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("""" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("".""); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException(""innerflush""); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException(""flush""); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } // Fast Inputs static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ","import 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; private static void google(int tt) { System.out.print(""Case #"" + (tt) + "": ""); } 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; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Long.compare(this.x, o.x); } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap map, int k, int v) { //map[k] += v; if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } // compress Big value to Time Limit public static int[] compress(int[] arr) { ArrayList ls = new ArrayList(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap map = new HashMap(); int boof = 1; //min value for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } // Fast Writer public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException(""FastWriter""); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("""" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("".""); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException(""innerflush""); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException(""flush""); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } // Fast Inputs static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } } ",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); } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readIntArr(int n) { int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = Integer.parseInt(next()); } return result; } long[] readLongArr(int n) { long[] result = new long[n]; for (int i = 0; i < n; i++) { result[i] = Long.parseLong(next()); } return result; } void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } long nextLong() { return Long.parseLong(next()); } } } ","import java.io.*; 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;i '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } ",0,Non-plagiarised 6b83b22e,c59194c7,"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 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(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.*; public class Main{ static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] nextArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] nextArray(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static class FastWriter extends PrintWriter { FastWriter(){ super(System.out); } void println(int[] array) { for(int i=0; i0){ int n=in.nextInt(); String[] ar=new String[n]; for (int i = 0; i < n; i++) { ar[i]=in.next(); } int ans=0; for(char ch='a';ch<='e';ch++){ int[] res=new int[n]; for (int i = 0; i < n; i++) { String ss=ar[i]; for (int j = 0; j < ss.length(); j++) { if(ss.charAt(j)==ch){ res[i]++; }else { res[i]--; } } } Arrays.sort(res);int max=0,nn=0; for (int i = n-1; i>=0; i--) { max+=res[i]; if(max>0){ nn++; }else { break; } } ans=Math.max(ans,nn); } out.println(ans); } out.close(); } //Arrays.sort(a, (o1, o2) -> (o1[0] - o2[0])); static int totalPrimeFactors(int n) { int cnt=0; while (n%2==0) { cnt++; n /= 2; } int num= (int) Math.sqrt(n); for (int i = 3; i <= num; i+= 2) { while (n%i == 0) { cnt++; n /= i; num=(int)Math.sqrt(n); } } if (n > 2){ cnt++; } return cnt; } static char get(int i){ return (char)(i+'a'); } static boolean distinct(int num){ HashSet set=new HashSet<>(); int len=String.valueOf(num).length(); while (num!=0){ set.add(num%10); num/=10; } return set.size()==len; } static int maxSubArraySum(int a[],int st,int en) { int max_s = Integer.MIN_VALUE, max_e = 0,ind=0,ind1=1; for (int i = st; i <= en; i++) { max_e+= a[i]; if (max_s < max_e){ max_s = max_e; ind=ind1; } if (max_e < 0){ max_e = 0; ind1=i+1; } } if(st==0){ return max_s; } if(ind==1){ return a[0]+2*max_s; }else { return 2*max_s+maxSubArraySum(a,0,ind-1); } //return max_s; } static void segmentedSieve(ArrayList res,int low, int high) { if(low < 2){ low = 2; } ArrayList prime = new ArrayList<>(); sS2(high, prime); boolean[] mark = new boolean[high - low + 1]; Arrays.fill(mark, true); for (int i = 0; i < prime.size(); i++) { int loLim = (low / prime.get(i)) * prime.get(i); if (loLim < low){ loLim += prime.get(i); } if (loLim == prime.get(i)){ loLim += prime.get(i); } for (int j = loLim; j <= high; j += prime.get(i)) { mark[j - low] = false; } } for (int i = low; i <= high; i++) { if (mark[i - low]){ System.out.println(i); res.add(i); } } } static void sS2(int limit, ArrayList prime) { int bound = (int)Math.sqrt(limit); boolean[] mark = new boolean[bound + 1]; for (int i = 0; i <= bound; i++){ mark[i] = true; } for (int i = 2; i * i <= bound; i++) { if (mark[i]) { for (int j = i * i; j <= bound; j += i){ mark[j] = false; } } } for (int i = 2; i <= bound; i++) { if (mark[i]){ prime.add(i); } } } static boolean[] sieveOfEratosthenes(int n){ boolean[] prime = new boolean[n + 1]; Arrays.fill(prime,true); prime[0]=false;prime[1]=false; for (int p = 2; p * p <= n; p++) { if(prime[p]){ for (int i = p * p; i <= n; i += p){ prime[i] = false; } } } return prime; } static int highestPowerOf2(int n) { if (n < 1){ return 0; } int res = 1; for (int i = 0; i < 8 * Integer.BYTES; i++) { int curr = 1 << i; if (curr > n){ break; } res = curr; } return res; } static int reduceFraction(int x, int y) { int d= gcd(x, y); return x/d+y/d; } static boolean subset(int[] ar,int n,int sum){ if(sum==0){ return true; } if(n<0||sum<0){ return false; } return subset(ar,n-1,sum)||subset(ar,n-1,sum-ar[n]); } static boolean isPrime(int n){ if(n<=1) return false; for(int i = 2;i<=Math.sqrt(n);i++){ if (n % i == 0) return false; } return true; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static int lcm(int a, int b) { return (a * b) / gcd(a, b); } static boolean isPowerOfTwo(long n) { if(n==0){ return false; } while (n%2==0){ n/=2; } return n==1; } static boolean isPerfectSquare(int x){ if (x >= 0) { int sr = (int)Math.sqrt(x); return ((sr * sr) == x); } return false; } static int lower_bound(int[] arr, int x) { int low_limit = 0, high_limit = arr.length, mid; while (low_limit < high_limit) { mid = (low_limit + high_limit) / 2; if (arr[mid] >= x){ high_limit = mid; }else{ low_limit = mid + 1; } } return low_limit; } static int upper_bound(int[] arr, int x) { int low_limit = 0, high_limit = arr.length, mid; while (low_limit < high_limit) { mid = (low_limit + high_limit) / 2; if (arr[mid] > x){ high_limit = mid; }else{ low_limit = mid + 1; } } return low_limit; } static int binarySearch(int[] ar,int n,int num){ int low=0,high=n-1; while (low<=high){ int mid=(low+high)/2; if(ar[mid]==num){ return mid; }else if(ar[mid]>num){ high=mid-1; }else { low=mid+1; } } return -1; } static int fib(int n) { long[][] F = new long[][]{{1,1},{1,0}}; if (n == 0){ return 0; } power(F, n-1); return (int)F[0][0]; } static void multiply(long F[][], long M[][]) { long x = (F[0][0]*M[0][0])%1000000007 + (F[0][1]*M[1][0])%1000000007; long y = (F[0][0]*M[0][1])%1000000007 + (F[0][1]*M[1][1])%1000000007; long z = (F[1][0]*M[0][0])%1000000007 + (F[1][1]*M[1][0])%1000000007; long w = (F[1][0]*M[0][1])%1000000007 + (F[1][1]*M[1][1])%1000000007; F[0][0] = x%1000000007; F[0][1] = y%1000000007; F[1][0] = z%1000000007; F[1][1] = w%1000000007; } static void power(long F[][], int n) { if( n == 0 || n == 1){ return; } long M[][] = new long[][]{{1,1},{1,0}}; power(F, n/2); multiply(F, F); if (n%2 != 0){ multiply(F, M); } } static int binaryExponentiation(int x,int n){ int ans=1; while (n>0){ if(n%2!=0){ ans=(ans*x)%MOD; } x=(x*x)%MOD; n/=2; } return ans; } static void bfs(ArrayList[] ar,int node){ boolean[] visited=new boolean[ar.length]; Queue queue=new LinkedList<>(); visited[node]=true; queue.add(node); while(!queue.isEmpty()){ int nn=queue.poll(); System.out.print(nn+"" ""); for(int n : ar[nn]) { if (!visited[n]) { visited[n] = true; queue.add(n); } } } System.out.println(); } static void dfs(ArrayList[] ar,int node){ boolean[] visited=new boolean[ar.length]; dfsUtil(ar,node,visited); System.out.println(); } static void dfsUtil(ArrayList[] ar,int node,boolean[] visited){ visited[node]=true; //System.out.print(node+"" ""); for(Integer n:ar[node]){ if(!visited[n]){ dfsUtil(ar,n,visited); } } } }",0,Non-plagiarised 11373c16,69b2fd22,"/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be ""Main"" only if the class is public. */ public class Codechef {static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } 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;i { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair a) { return a.y-y; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String s=""""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } "," import java.io.*; import java.util.*; public class test3 { public static void main(String[] args) throws IOException { FastReader f = new FastReader(); int t = f.nextInt(); while(t-->0) { int n = f.nextInt(); int C[] = new int[n]; long ans=Long.MAX_VALUE,pre = 0; PriorityQueue epq = new PriorityQueue(); PriorityQueue opq = new PriorityQueue(); for(int i = 0;i0) { ans = Math.min(ans,pre+ ((long)n-(long)epq.size())*(long)epq.peek() + ((long)n-(long)opq.size())*(long)opq.peek()); } } System.out.println(ans); } } static boolean isPrime(int n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static void print(int x,int y,int d,int n) { int i = 0; System.out.print(x+"" ""+y+"" ""); for(int j = x+d;j0;j-=d) { if(i==n)return; System.out.print(j+"" ""); i++; } for(int j = y+d;j<1000000000;j+=d) { if(i==n)return; System.out.print(j+"" ""); i++; } } static int prime(int n){ int ret = 0; while(n%2==0){ ret++; n/=2; } for(int i=3;i<=Math.sqrt(n);i+=2){ while(n%i==0){ ret++; n/=i; } } if(n>2)ret++; return ret; } static long nCr(int n, int r) { if(n 0; j--) C[j] = (C[j] + C[j-1]); } return C[r]; } static int power(int a,int n, int p) { int res = 1; a = a % p; while (n > 0) { if ((n & 1) == 1) res = (res * a) % p; n = n >> 1; a = (a * a) % p; } return res; } static boolean isPrime(int n, int k) { if (n <= 1 || n == 4) return false; if (n <= 3) return true; while (k > 0) { int a = 2 + (int)(Math.random() % (n - 4)); if (power(a, n - 1, n) != 1) return false; k--; } return true; } static long GCD(long a,long b) { if(a%b==0)return b; else return GCD(b,a%b); } static ArrayList readArray(FastReader f,int size){ ArrayList ret = new ArrayList(); for(int i=0;i0){ 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; static class FastScanner { BufferedReader br; StringTokenizer st ; FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""""); } FastScanner(String file) { try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); st = new StringTokenizer(""""); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println(""file not found""); e.printStackTrace(); } } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } String readLine() throws IOException{ return br.readLine(); } } static class Pair{ T first; X second; Pair(T first,X second){ this.first = first; this.second = second; } @Override public int hashCode(){ return Objects.hash(first,second); } @Override public boolean equals(Object obj){ return obj.hashCode() == this.hashCode(); } } 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 0l){ long bit = pow & 1l; if(bit == 1){ ans = (ans * (val%mod))%mod; } val = (val * val) % mod; pow = pow >> 1; } return ans; } public static char get(int n){ return (char)('a' + n); } public static long[] sort(long arr[]){ List list = new ArrayList<>(); for(long n : arr){list.add(n);} Collections.sort(list); for(int i=0;i list = new ArrayList<>(); for(int n : arr){list.add(n);} Collections.sort(list); for(int i=0;i= num){ e = mid - 1; }else{ ans = mid; st = mid + 1; } } return ans + 1; } //return (index of just greater element) //count of elements smaller than or equal to num public static int justGreater(long arr[],long num){ int st = 0; int e = arr.length - 1; int ans = arr.length; while(st <= e){ int mid = (st + e)/2; if(arr[mid] <= num){ st = mid + 1; }else{ ans = mid; e = mid - 1; } } return ans; } public static void println(Object obj){ System.out.println(obj.toString()); } public static void print(Object obj){ System.out.print(obj.toString()); } public static int gcd(int a,int b){ if(b == 0){return a;} return gcd(b,a%b); } public static long gcd(long a,long b){ if(b == 0l){ return a; } return gcd(b,a%b); } public static int find(int parent[],int v){ if(parent[v] == v){ return v; } return parent[v] = find(parent, parent[v]); } public static List sieve(){ List prime = new ArrayList<>(); int arr[] = new int[100001]; Arrays.fill(arr,1); arr[1] = 0; arr[2] = 1; for(int i=2;i<=100000;i++){ if(arr[i] == 1){ prime.add(i); for(long j = (i*1l*i);j<100001;j+=i){ arr[(int)j] = 0; } } } return prime; } static boolean isPower(long n,long a){ long log = (long)(Math.log(n)/Math.log(a)); long power = (long)Math.pow(a,log); if(power == n){return true;} return false; } private static int mergeAndCount(int[] arr, int l,int m, int r) { // Left subarray int[] left = Arrays.copyOfRange(arr, l, m + 1); // Right subarray int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); int i = 0, j = 0, k = l, swaps = 0; while (i < left.length && j < right.length) { if (left[i] <= right[j]) arr[k++] = left[i++]; else { arr[k++] = right[j++]; swaps += (m + 1) - (l + i); } } while (i < left.length) arr[k++] = left[i++]; while (j < right.length) arr[k++] = right[j++]; return swaps; } // Merge sort function private static int mergeSortAndCount(int[] arr, int l,int r) { // Keeps track of the inversion count at a // particular node of the recursion tree int count = 0; if (l < r) { int m = (l + r) / 2; // Total inversion count = left subarray count // + right subarray count + merge count // Left subarray count count += mergeSortAndCount(arr, l, m); // Right subarray count count += mergeSortAndCount(arr, m + 1, r); // Merge count count += mergeAndCount(arr, l, m, r); } return count; } static class Debug{ //change to System.getProperty(""ONLINE_JUDGE"")==null; for CodeForces public static final boolean LOCAL = System.getProperty(""ONLINE_JUDGE"")==null; private static String ts(T t) { if(t==null) { return ""null""; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return ""{""+s.substring(1, s.length()-1)+""}\n""; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return ""{""+s.substring(1, s.length()-1)+""}\n""; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return ""{""+s.substring(1, s.length()-1)+""}\n""; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return ""{""+s.substring(1, s.length()-1)+""}\n""; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return ""{""+s.substring(1, s.length()-1)+""}\n""; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append(""{""); boolean first = true; for(T t: arr) { if(!first) { ret.append("", ""); } first = false; ret.append(ts(t)); } ret.append(""}""); return ret.toString(); } private static String ts(Iterable iter) { StringBuilder ret = new StringBuilder(); ret.append(""{""); boolean first = true; for(T t: iter) { if(!first) { ret.append("", ""); } first = false; ret.append(ts(t)); } ret.append(""}""); return ret.toString(); } public static void dbg(PrintStream ps,Object... o) throws Exception { if(LOCAL) { System.setErr(ps); System.err.print(""Line #""+Thread.currentThread().getStackTrace()[2].getLineNumber()+"": [""); for(int i = 0; i 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); } } class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }"," import java.io.*; import java.util.*; public class Main { static long mod = 1000000007; static long inv(long a, long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } static long mi(long a) { return inv(a, mod); } static InputReader sc = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] A = new int[n]; for (int i = 0; i < A.length; i++) { A[i] = sc.nextInt(); } String word = sc.next(); ArrayList blue = new ArrayList<>(); ArrayList red = new ArrayList<>(); for (int i = 0; i < word.length(); i++) { if (word.charAt(i) == 'R') { red.add(A[i]); } else { blue.add(A[i]); } } Collections.sort(blue); Collections.sort(red); boolean possible = true; int a = 1; for (int i = 0; i < blue.size(); i++, a++) { if (blue.get(i) < a) { possible = false; break; } } for (int i = 0; i < red.size(); i++, a++) { if (red.get(i) > a) { possible = false; break; } } if (possible) out.println(""YES""); else out.println(""NO""); } out.flush(); out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } public static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } public static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } } ",1,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); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } }","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); } } public static int solve(int start[], int end[], int n) { int distance[][]=new int[n][n]; int r=n; int c=n; boolean visited[][]=new boolean[n][n]; int startx=start[0]; int starty=start[1]; int endx=end[0]; int endy=end[1]; Pair tmp=new Pair(startx,starty); Queue q=new LinkedList<>(); q.add(tmp); visited[startx][starty]=true; distance[startx][starty]=0; int dx[]={-2,-1,1,2,2,1,-1,-2}; int dy[]={1,2,2,1,-1,-2,-2,-1}; while(!q.isEmpty()) { Pair cell=q.poll(); int x=cell.x; int y=cell.y; int d=distance[x][y]; for(int i=0;i<8;i++) { int childx=x+dx[i]; int childy=y+dy[i]; if(valid(childx,childy,r,c,visited)) { visited[childx][childy]=true; distance[childx][childy]=d+1; q.add(new Pair(childx,childy)); } } } return distance[endx][endy]; } public static boolean valid(int x,int y,int r,int c,boolean visited[][]) { if(x<0||y<0||x>=r||y>=c) return false; if(visited[x][y]) return false; return true; } public static int knight(int i,int j){ if(i==dest1 && j==dest2) return 0; if(i<1 || j<1) return 0; if(i>8 || j>8) return 0; if(i<1 || j>8) return 0; if(i>8 || j<1) return 0; int min=0; if(i-1>=1 && j-2>=1) min+=1+knight(i-1,j-2); if(i-1>=1 && j+2<=8) min+=1+knight(i-1,j+2); if(i-2>=1 && j-1>=1) min+=1+knight(i-2,j-1); if(i-2>=1 && j+1<=8) min+=1+knight(i-2,j+1); if(i+1<=8 && j-2>=1) min+=1+knight(i+1,j-2); if(i+1<=8 && j+2<=8) min+=1+knight(i+1,j+2); if(i+2<=8 && j-1>=1) min+=1+knight(i+2,j-1); if(i+2<=8 && j+1<=8) min+=1+knight(i+2,j+1); return min; } } class FastScanner { java.io.BufferedReader br = new java.io.BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } class Pair { int x; int y; Pair(int i,int j) { x=i; y=j; } } ",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); } } static boolean isPrime(int n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static void print(int x,int y,int d,int n) { int i = 0; System.out.print(x+"" ""+y+"" ""); for(int j = x+d;j0;j-=d) { if(i==n)return; System.out.print(j+"" ""); i++; } for(int j = y+d;j<1000000000;j+=d) { if(i==n)return; System.out.print(j+"" ""); i++; } } static int prime(int n){ int ret = 0; while(n%2==0){ ret++; n/=2; } for(int i=3;i<=Math.sqrt(n);i+=2){ while(n%i==0){ ret++; n/=i; } } if(n>2)ret++; return ret; } static long nCr(int n, int r) { if(n 0; j--) C[j] = (C[j] + C[j-1]); } return C[r]; } static int power(int a,int n, int p) { int res = 1; a = a % p; while (n > 0) { if ((n & 1) == 1) res = (res * a) % p; n = n >> 1; a = (a * a) % p; } return res; } static boolean isPrime(int n, int k) { if (n <= 1 || n == 4) return false; if (n <= 3) return true; while (k > 0) { int a = 2 + (int)(Math.random() % (n - 4)); if (power(a, n - 1, n) != 1) return false; k--; } return true; } static long GCD(long a,long b) { if(a%b==0)return b; else return GCD(b,a%b); } static ArrayList readArray(FastReader f,int size){ ArrayList ret = new ArrayList(); for(int i=0;i 0){ int n = 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); } } } static class FastScanner { private BufferedReader in; private StringTokenizer st; public FastScanner(InputStream stream) { try { in = new BufferedReader(new InputStreamReader(stream, ""UTF-8"")); } catch (Exception e) { throw new AssertionError(); } } public String next() { while (st == null || !st.hasMoreTokens()) { try { String rl = in.readLine(); if (rl == null) { return null; } st = new StringTokenizer(rl); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } } ","/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=(long)1e9+7; /* start */ public static void main(String [] args) { // int testcases = 1; int testcases = i(); while(testcases-->0) { solve(); } out.flush(); out.close(); } static void solve() { int n = i(); char c[] = inputC(); char d[] = inputC(); int x01=0,x10=0,x00=0,x11=0; for(int i=0;i 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long[] sort(long a[]) { ArrayList arr = new ArrayList<>(); for(long i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } static int[] sort(int a[]) { ArrayList arr = new ArrayList<>(); for(Integer i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } //pair class private static class Pair implements Comparable { long first, second; public Pair(long f, long s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second > p.second) return 1; else if (second < p.second) return -1; else return 0; } } } }",0,Non-plagiarised 1eda0725,d2901569,"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(); 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[] resize(int[] a) { int[] r = new int[a.length * 2]; for(int i = 0; i < a.length; i++) { r[i] = a[i]; } return r; } static int pint(BufferedReader in) throws IOException {return Integer.parseInt(in.readLine());} static int pint(StringTokenizer st) {return Integer.parseInt(st.nextToken());} }","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]); } } // a[i] // // // 6 7 6 2 //3 5 6 4 5 6 3",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; } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } } ",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; } public static class Pair{ public int x; public int y; public Pair(int x,int y){ this.x=x; this.y=y; } } public static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i0) { 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 R)return 0; int j = log[R - L + 1]; if(a[dp[L][j]] < a[dp[R - (1 << j) + 1][j]])return dp[L][j]; return dp[R-(1 << j) + 1][j]; } } class Solver { static final int M = 998244353; void solve(FastReader io) { int t = io.nextInt(); while(t-- > 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 int lower_bound(int a[], int val) { int low = 0, high = a.length - 1, ret = -1; while (low <= high) { int mid = (low + high) / 2; if (a[mid] < val) low = mid + 1; else { ret = mid; high = mid - 1; } } return ret; } // returns the first key strictly greater than val int upper_bound(int a[], int val) { int low = 0, high = a.length - 1, ret = -1; while (low <= high) { int mid = (low + high) / 2; if (a[mid] <= val) low = mid + 1; else { ret = mid; high = mid - 1; } } return ret; } long modexp(long n, int m) { if (m == 0) return 1; else if (m == 1) return n; else { long p = modexp(n, m / 2); if (m % 2 == 1) return (((p * p) % M) * n) % M; else return (p * p) % M; } } long exp(long n, long m) { if (m == 0) return 1; if (m == 1) return n; long p = exp(n, m / 2); if (m % 2 == 1) return p * p * n; else return p * p; } long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } long inv(long n) { return modexp(n, M - 2); } long lcm(long a, long b) { return a * b / gcd(a, b); } long factorial(long fact[], int n) { fact[0] = 1; fact[1] = 1; long prod = 1; for (int i = 2; i <= n; i++) { prod = (prod * i) % M; fact[i] = prod; } return prod; } boolean isPrime(long n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }","import java.util.*; import java.io.*; public class Solution { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static int parent(int a , int p[]) { if(a == p[a]) return a; return p[a] = parent(p[a],p); } static void union(int a , int b , int p[] , int size[]) { a = parent(a,p); b = parent(b,p); if(a == b) return; if(size[a] < size[b]) { int temp = a; a = b; b = temp; } p[b] = a; size[a] += size[b]; } static long dp[][]; static long f(int n , int m) { if(m == 0) return 1; if(dp[n][m] != -1) return dp[n][m]; if(n < 9) dp[n][m] = f(n+1,m-1); else dp[n][m] = f(0,m-1)+f(1,m-1); dp[n][m] %= 1000000007; return dp[n][m]; } static long getSum(int index , long BITree[]) { long sum = 0; // Iniialize result // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse ancestors of BITree[index] while(index>0) { // Add current element of BITree // to sum sum += BITree[index]; // Move index to parent node in // getSum View index -= index & (-index); } return sum; } // Updates a node in Binary Index Tree (BITree) // at given index in BITree. The given value // 'val' is added to BITree[i] and all of // its ancestors in tree. public static void updateBIT(int n, int index, long val , long BITree[]) { // index in BITree[] is 1 more than // the index in arr[] // index = index + 1; // Traverse all ancestors and add 'val' while(index <= n) { // Add 'val' to current node of BIT Tree BITree[index] += val; // Update index to that of parent // in update View index += index & (-index); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } 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{ public static int GCD(int a, int b) { if (b == 0) return a; return GCD(b, a % b); } //@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); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() throws IOException { return br.readLine(); } } } ","// Working program with FastReader import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; // public class Example { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t= sc.nextInt(); while(t>0){ 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); } private static boolean possible(int a, int b, int c, int mid) { int min=Math.min(a,Math.min(b,c)); if(3*mid<=(c)){ c=c-3*mid; a=a+2*mid; b=b+mid; int min1=Math.min(a,Math.min(b,c)); if(min1>min){ return true; }else{ return false; } }else{ return false; } } } ",1,Plagiarised 624b8db5,e9986d44,"//created by Whiplash99 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 test) { health = health - test; }else { health = health - (arr[i + 1] - arr[i]); } if(health <= 0) return true; } return false; } static long binarySearchModified(long n, long [] arr) { long start = 0, end = n, ans = n; while(start < end) { long mid = (start + end) / 2; if(BinaryCheck(mid, arr, n)) { ans = Math.min(ans, mid); end = mid; }else { start = mid + 1; } } return ans; } /*BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH * BINARY SEARCH BINARY SEARCH METHODS END HERE*/ /*RECURSIVE FUNCTION START HERE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE */ static int recurse(int x, int y, int n, int steps1, Integer [][] dp) { if(x > n || y > n) return 0; if(dp[x][y] != null) { return dp[x][y]; } else if(x == n || y == n) { return steps1; } return dp[x][y] = Math.max(recurse(x + y, y, n, steps1 + 1, dp), recurse(x, x + y, n, steps1 + 1, dp)); } /*RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE * RECURSIVE RECURSIVE FUNCTION END HERE*/ /*GRAPH FUNCTIONS START HERE * GRAPH * GRAPH * GRAPH * GRAPH * */ static class edge{ int from, to, weight; public edge(int x, int y, int z) { this.from = x; this.to = y; this.weight = z; } } static void addEdge(ArrayList> 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; } } } static void bfs(ArrayList> graph, int vertex, boolean [] visited, int [] toReturn, Queue q, int weight) { if(visited[vertex]) return; visited[vertex] = true; if(graph.get(vertex).size() > 2) return; int first = weight; for(int i = 0; i < graph.get(vertex).size(); i++) { edge temp = graph.get(vertex).get(i); if(!visited[temp.to]) { q.add(temp.to); toReturn[temp.weight] = weight; weight = 5 - weight; } } if(!q.isEmpty())bfs(graph, q.poll(), visited, toReturn, q, 5 - first); } static void topoSort(ArrayList> graph, int vertex, boolean [] visited, ArrayList toReturn) { if(visited[vertex]) return; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(!visited[graph.get(vertex).get(i)]) topoSort(graph, graph.get(vertex).get(i), visited, toReturn); } toReturn.add(vertex); } static boolean isCyclicDirected(ArrayList> graph, int vertex, boolean [] visited, boolean [] reStack) { if(reStack[vertex]) return true; if(visited[vertex]) return false; reStack[vertex] = true; visited[vertex] = true; for(int i = 0; i < graph.get(vertex).size(); i++) { if(isCyclicDirected(graph, graph.get(vertex).get(i), visited, reStack)) return true; } reStack[vertex] = false; return false; } /*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; static int parent(int [] parent, int x) { if(parent[x] == x) return x; else return parent[x] = parent(parent, parent[x]); } static void union(int x, int y, int [] rank, int [] parent) { if(parent(parent, x) == parent(parent, y)) { return; } if(rank[x] > rank[y]) { swap(x, y, rank); } rank[x] += rank[y]; parent[x] = y; } /*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 long nexLong() throws NumberFormatException, IOException { return Long.parseLong(sc.readLine()); } static long [] inputLongArr() throws NumberFormatException, IOException{ String [] s = sc.readLine().split("" ""); long [] toReturn = new long[s.length]; for(int i = 0; i < s.length; i++) { toReturn[i] = Long.parseLong(s[i]); } return toReturn; } 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(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable{ long wt; long idx; Pair(long x,long y){ this.wt=x; this.idx=y; } @Override public int compareTo(Pair x){ return (int)(this.wt-x.wt); } public String toString(){ return ""( ""+wt+"" ""+idx+"" )""; } } static void printLong(long []arr){ for(long x:arr)System.out.print(x+"" ""); } static void printInt(int []arr){ for(int x:arr)System.out.print(x+"" ""); } static void scanInt(int []arr){ for(int i=0;i 0){ if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static long add(long a,long b,long mod){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod; } static long sub(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod; } static long mul(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } static long mminvprime(long a, long b,long mod) { return power(a, b - 2,mod); } } "," 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(); } private static void takeinput(int[] arr, int k) { for (int i = 0; i < k; i++) { arr[i] = in.nextInt(); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public String nextLine() throws IOException { return reader.readLine().trim(); } } } ",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(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } String nextLine() throws IOException { return br.readLine(); } } } ",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 mod=(long)(1e9+7); static int D1[],D2[],par[]; static boolean set[]; static int value[]; static long INF=Long.MAX_VALUE; static int N,M; static long L[],R[],dp[][]; static int s=1; 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; iA[i+1])return false; } return true; } static int f1(int x,ArrayList A) { int l=-1,r=A.size(); while(r-l>1) { int m=(l+r)/2; int a=A.get(m); if(aend)return 0; int a=0,b=0,c=0; if(d>1)a=f(st+d-1,end,d-1); b=f(st+d,end,d); c=f(st+d+1,end,d+1); return value[st]+max(a,b,c); } static int max(int a,int b,int c) { return Math.max(a, Math.max(c, b)); } static int value(char X[],char Y[]) { int c=0; for(int i=0; i<7; i++) { if(Y[i]=='1' && X[i]=='0')return -1; if(X[i]=='1' && Y[i]=='0')c++; } return c; } static boolean isValid(int i,int j) { if(i<0 || i>=N)return false; if(j<0 || j>=M)return false; return true; } static long fact(long N) { long num=1L; while(N>=1) { num=((num%mod)*(N%mod))%mod; N--; } return num; } static boolean reverse(long A[],int l,int r) { while(l l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i(); } } static long pow(long a,long b) { long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1< l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i A) { for(int a:A)System.out.print(a+"" ""); System.out.println(); } //Debugging Functions END //---------------------- //IO FUNCTIONS STARTS static HashMap Hash(int A[]) { HashMap mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i { int x,index; boolean right; node(int x,boolean right,int index) { this.x=x; this.right=right; this.index=index; } public int compareTo(node X) { return this.x-X.x; } } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(st==null || !st.hasMoreElements()) { try { st=new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } //gey double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }","import java.io.*; import java.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(); static void ruffleSort(int[] a) { int n = a.length;//shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static long gcd(long x, long y) { if (x == 0) return y; if (y == 0) return x; long r = 0, a, b; a = Math.max(x, y); b = Math.min(x, y); r = b; while (a % b != 0) { r = a % b; a = b; b = r; } return r; } static long modulo(long a, long b, long c) { long x = 1, y = a % c; while (b > 0) { if (b % 2 == 1) x = (x * y) % c; y = (y * y) % c; b = b >> 1; } return x % c; } public static void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } static int upper_bound(int[] arr, int n, int x) { int mid; int low = 0; int high = n; while (low < high) { mid = low + (high - low) / 2; if (x >= arr[mid]) low = mid + 1; else high = mid; } return low; } static int lower_bound(int[] arr, int n, int x) { int mid; int low = 0; int high = n; while (low < high) { mid = low + (high - low) / 2; if (x <= arr[mid]) high = mid; else low = mid + 1; } return low; } static String printPrecision(double d) { DecimalFormat ft = new DecimalFormat(""0.00000000000""); return String.valueOf(ft.format(d)); } static int countBit(long mask) { int ans = 0; while (mask != 0) { mask &= (mask - 1); ans++; } return ans; } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }",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""); } static class Pair implements Cloneable, Comparable { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+500*Math.abs(y); } @Override public String toString() { return ""(""+x+"" ""+y+"")""; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } public void swap() { this.y=this.y+this.x; this.x=this.y-this.x; this.y=this.y-this.x; } } static class Tuple implements Cloneable, Comparable { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public int hashCode() { return (this.x+501*this.y); } @Override public String toString() { return ""(""+x+"",""+y+"",""+z+"")""; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.z-a.z; if(x!=0) return x; int X= this.x-a.x; if(X!=0) return X; return a.y-this.y; } } static void arraySort(int arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList a=new ArrayList(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet primeFactors(int n) { HashSet ans=new HashSet(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList(); for (int i=2; i adj; int taxC,taxD; Node(int ver) { vertex=ver; taxD=0; taxC=0; adj=new HashSet(); } @Override public String toString() { return vertex+"" ""; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return ""(""+to.vertex+"",""+cost+"") ""; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(nn) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } public void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+"" ""); System.out.println(); } } } ","import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.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(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } String nextLine() throws IOException { return br.readLine(); } } } ",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; } } public static int lowerbound(long[] ar,int k) { int s=0; int e=ar.length; while (s !=e) { int mid = s+e>>1; if (ar[mid] 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] == element) { return low; } else if (arr[high] == element) { return high; } return -1; } static int lower_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] >= element) { return low; } else if (arr[high] >= element) { return high; } return -1; } static int upper_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] <= element) { low = mid + 1; } else { high = mid; } } if (arr[low] > element) { return low; } else if (arr[high] > element) { return high; } return -1; } public static int upperbound(long[] arr, int k) { int s = 0; int e = arr.length; while (s != e) { int mid = s + e >> 1; if (arr[mid] <= k) { s = mid + 1; } else { e = mid; } } if (s == arr.length) { return -1; } return s; } public static long pow(long x,long y,long mod){ if(x==0)return 0l; if(y==0)return 1l; //(x^y)%mod if(y%2l==1l){ return ((x%mod)*(pow(x,y-1l,mod)%mod))%mod; } return pow(((x%mod)*(x%mod))%mod,y/2l,mod); } public static long gcd_long(long a, long b) { // a/b,a-> dividant b-> divisor if (b == 0) return a; return gcd_long(b, a % b); } public static int gcd_int(int a, int b) { // a/b,a-> dividant b-> divisor if (b == 0) return a; return gcd_int(b, a % b); } public static int lcm(int a, int b) { int gcd = gcd_int(a, b); return (a * b) / gcd; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String s = """"; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } Long nextLong() { return Long.parseLong(next()); } } } /* * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){ * return true; } if(n<1 || m<1 || k<0){ return false; } boolean * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; } * return false; } */ ",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; } @Override public int compareTo(Pair o) { if (x == o.x) return Integer.compare(y, o.y); return Integer.compare(x, o.x); } } }","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; } } static class Scanner { BufferedReader in; StringTokenizer st; public Scanner() { this.in = new BufferedReader(new InputStreamReader(System.in)); } public Scanner(FileReader f) { this.in = new BufferedReader(f); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public void close() throws IOException { in.close(); } } } ",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<>(); static boolean seive(int n){ Arrays.fill(primes,true); primes[0]=primes[1]=false; for(int i=2;i*i<=n;i++){ if(primes[i]==true){ for(int p=i*i;p<=n;p+=i){ primes[p]=false; } } } if(n<1000007){ for(int i=2;i<=n;i++) { if(primes[i]) b.add(i); } return primes[n]; } return false; } static int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } static long GCD(long a,long b){ if(b==0) return a; return GCD(b,a%b); } static ArrayList segseive(int l,int r){ ArrayList isprime=new ArrayList(); boolean p[]=new boolean[r-l+1]; Arrays.fill(p, true); for(int i=0;b.get(i)*b.get(i)<=r;i++) { int currprime=b.get(i); int base=(l/currprime)*currprime; if(base>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } }","// Working program with FastReader import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class aa { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = """"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static int findIndex(long arr[], long t) { // if array is Null if (arr == null) { return -1; } // find length of array int len = arr.length; int i = 0; // traverse in the array while (i < len) { // if the i-th element is t // then return the index if (arr[i] == t) { return i; } else { i = i + 1; } } return -1; } 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); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } } ","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()); } long nl() throws IOException { return Long.parseLong(next()); } long mod=1000000007; void solve() throws IOException { for (int tc=ni();tc>0;tc--) { int n=ni(); int[]A=new int[n]; long[]T=new long[n]; A[0]=ni(); T[0]=A[0]; long total=0; for (int i=1;i0) { if ((p&1)==1) r=(r*a)%mod; p>>=1; a=(a*a)%mod; } return r; } public static void main(String[] args) throws IOException { new Main().solve(); } }","//Praise our lord and saviour qlf9 //DecimalFormat f = new DecimalFormat(""##.00""); import java.util.*; import java.io.*; import java.math.*; import java.text.*; public class C{ public static void main(String[] omkar) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); StringBuilder sb = new StringBuilder(); int cases = Integer.parseInt(st.nextToken()); for(int i = 0; i < cases; i++) { solve(in, st, sb); } System.out.println(sb); } public static void solve(BufferedReader in, StringTokenizer st, StringBuilder sb) throws Exception { st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int[] arr = readArr(n, in, st); int[] mins = new int[n]; mins[0] = arr[0]; mins[1] = arr[1]; for(int i = 2; i < n; i++) { mins[i] = Math.min(arr[i], mins[i-2]); } long[] sums = new long[n]; sums[0] = (long)(arr[0]); for(int i = 1; i < n; i++) { sums[i] = sums[i-1]+(long)(arr[i]); } long minc = Long.MAX_VALUE; long temp; for(int i = 1; i < n; i++) { temp = sums[i]; temp += (long)(mins[i])*(long)(n-(i+2)/2); temp += (long)(mins[i-1])*(long)(n-(i+1)/2); minc = Math.min(minc, temp); } sb.append(minc+""\n""); } public static int[] readArr(int N, BufferedReader in, StringTokenizer st) throws Exception { int[] arr = new int[N]; st = new StringTokenizer(in.readLine()); for(int i=0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); return arr; } }",0,Non-plagiarised 25597bcb,86232d21,"import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeSet; public class PhoenixAndTowers { // Template for CF public static class ListComparator implements Comparator> { @Override public int compare(List l1, List l2) { for (int i = 0; i < l1.size(); ++i) { if (l1.get(i).compareTo(l2.get(i)) != 0) { return l1.get(i).compareTo(l2.get(i)); } } return 0; } } public static class Pair { int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } public int getFirst() { return first; } public int getSecond() { return second; } public void setFirst(int a) { first = a; } @Override public String toString() { return first + "" "" + second; } } 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; } public int compareTo(Token o) { return h - o.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 long scanLong() throws IOException { return parseLong(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