fukk , now everyone is going to get plagiarized .🐸
@SharpXAi3 күн бұрын
Great 🔥🔥
@sasikaladhar7333 күн бұрын
bro give the code bro plss
@_Optimization3 күн бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here 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<n;i++){ int val = sc.nextInt(); arr[i] = val; } Stack<Integer> values = new Stack<>(); Stack<Integer> indexs = new Stack<>(); values.push(arr[0]); indexs.push(0); int max = 0; for(int i=1;i<n;i++){ int val = arr[i]; while(values.size()>0){ int top = values.peek(); if(top<val){ values.pop(); indexs.pop(); }else{ break; } } if(values.size()>0){ int topInedx = indexs.peek(); int diff = i - topInedx; diff--; if(diff>max) max = diff; }else{ max = i; } values.push(val); indexs.push(i); } System.out.println(max); t--; } } }
@jishnusaha244621 күн бұрын
Apparently the brute force solution of using a for loop and iterating from 1 to n actually gets submitted if instead of iterating till n you only iterate till 45.
@rockstar-ki1rkАй бұрын
import java.util.HashMap; 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(); HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { int val = scanner.nextInt(); map.put(val, map.getOrDefault(val, 0) + 1); } int values = n - 2; int row = 0, col = 0; for (int i = 1; i <= 200000; i++) { if (map.containsKey(i)) { int rowCount = map.get(i); int div = values / i; int rem = values % i; if (rem == 0 && map.containsKey(div)) { int colCount = map.get(div); if (i == div) { if (colCount >= 2) { row = i; col = div; break; } } else { row = i; col = div; break; } } } } System.out.println(row + " " + col); } } }
@obadajoba9506Ай бұрын
thanks do you solve c or d ??
@obadajoba9506Ай бұрын
past it here please
@joemamaligmaballs7737Ай бұрын
yo can you give link to text file
@DhruvParmar-gm4ke7 ай бұрын
If a thousand people watched the solution, and given the situation that Problem 3 was not solved for an hour or so, and then the number of submitted solutions exponentially increased from 150 to 1000+ submissions in just 10-15 minutes, shows that over 70-80% of people copied the code. Codechef is so rigged.
@yuvrajveerdhawan81967 ай бұрын
in c++ can u give?
@vanshsharma62127 ай бұрын
what if i get a plagarism ?
@AvijitPatra-c5w7 ай бұрын
Tle?
@_Optimization7 ай бұрын
Working fine just submit
@_Optimization7 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n = sc.nextInt(); int arr[] = new int[n+1]; for(int i=1;i<=n;i++){ arr[i] = sc.nextInt(); } long ans = 0; // 2 7 2 3 for(int i=1;i<=n;i++){ long left =(long) arr[i]; if(left==1){ ans=ans+(long)n; }else{ long power = 1; for(int j=1;j<=n;j++){ power = left * power; if(power>1000000000L){ break; }else{ long right = (long) arr[j]; if(power<=right){ // System.out.println(i+" "+j); ans++; } } } } } System.out.println(ans); t--; } } }
@_Optimization7 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n = sc.nextInt(); PriorityQueue<Integer> max = new PriorityQueue<>(Collections.reverseOrder()); PriorityQueue<Integer> min = new PriorityQueue<>(); for(int i=0;i<n;i++){ int val = sc.nextInt(); max.add(val); min.add(val); } int ans = 0; int till = n/2; while(till>0){ int gre = max.poll(); int small = min.poll(); int df = gre - small; ans+=df; till--; } if(n%2!=0){ ans+=min.poll(); } System.out.println(ans); t--; } } }
@MonikaDawkhar8 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); String s=sc.next(); int ans = 0; int flip =0; char prev = s.charAt(0); for(int i=1;i<n;i++){ char c = s.charAt(i); if(flip==1){ if(c=='1') c='0'; else c='1'; } // 0010 if(c==prev){ ans++; if(flip==0){ flip=1; }else{ flip=0; } if(c=='1') prev='0'; else prev='1'; }else{ prev =c; } } System.out.println(ans); t--; } } }
@Orange-wq8qf8 ай бұрын
hey did you solve the make equal one ?
@kingprashanthyadavkpy21578 ай бұрын
E code
@_Optimization8 ай бұрын
//package org.example; import javafx.print.Collation; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int arr[] ={100000, 11111, 11110, 11101, 11100, 11011, 11010, 11001, 11000, 10111, 10110, 10101, 10100, 10011, 10010, 10001, 10000, 1111, 1110, 1101, 1100, 1011, 1010, 1001, 1000, 111, 110, 101, 100, 11, 10 }; int t = sc.nextInt(); while(t>0){ int val = sc.nextInt(); // List<Integer> li = new ArrayList<>(); // for(int i=2;i<=100000;i++){ // String no = i+""; // // int isAllOneOrZeros = 1; // for(int j=0;j<no.length();j++){ // char c= no.charAt(j); // if(c=='1' || c=='0'){ // // }else // isAllOneOrZeros = 0; // } // if(isAllOneOrZeros==1){ // li.add(i); // } // } String ans = "yes"; int past = val; // Collections.sort(li, Collections.reverseOrder()); // System.out.println(li); while(true){ int got = 0; for(int i=0;i<arr.length;i++){ int num = arr[i]; if(val>=num) { if (val % num == 0) { // System.out.println(val +" / "+num+" = "+val/num); past = val; val = val / num; got = 1; break; } } } if(got==0){ //System.out.println(val); if(val==1){ ans = "yes"; }else ans = "no"; break; }else{ if(val<=0){ break; }else{ if(past==val){ // System.out.println(past); ans= "no"; break; } } } } System.out.println(ans); t--; } } }
@_Optimization8 ай бұрын
//package org.example; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t = sc.nextInt(); while(t>0){ String time = sc.next(); String timeDivide [] = time.split(":"); int hour = Integer.parseInt(timeDivide[0]); int min2 = Integer.parseInt(timeDivide[1]); String min = timeDivide[1]; if(hour==0){ System.out.println("12:"+min+" AM"); t--; continue; } int nhour = 0; int nmin = 0; String ans = ""; String leftPart = ""; String amOrPm = ""; if(hour<12){ // pm String p = ""; if(hour<10) p = "0"; leftPart = p+hour+":"+min; amOrPm = "AM"; ans= leftPart+" "+amOrPm; }else{ if(hour==12){ leftPart = ""+hour+":"+min; amOrPm = "PM"; ans= leftPart+" "+amOrPm; }else{ int hour2 = hour - 12; String p = ""; if(hour2<10) p = "0"; leftPart = p+hour2+":"+min; amOrPm = "PM"; ans= leftPart+" "+amOrPm; } } System.out.println(ans); t--; } } }
@_Optimization8 ай бұрын
//package org.example; import java.util.ArrayList; import java.util.List; import java.util.Scanner; 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 rowSize = n*2; int colSize = n*2; int row = 0; int col = 0; char arr[][] = new char [rowSize][colSize]; char turn = '#'; while(row<rowSize){ char start = turn; while(col<colSize){ if(start=='#'){ arr[row][col] = '#'; arr[row][col+1] = '#'; arr[row+1][col] = '#'; arr[row+1][col+1] = '#'; start = '.'; }else{ arr[row][col] = '.'; arr[row][col+1] = '.'; arr[row+1][col] = '.'; arr[row+1][col+1] = '.'; start = '#'; } col+=2; } if(turn=='#') turn='.'; else turn = '#'; row+=2; col = 0; } for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[0].length;j++){ System.out.print(arr[i][j]); } System.out.println(); } t--; } } }
@kingprashanthyadavkpy21579 ай бұрын
getting TLE for freedom problem
@sakethbharatula91419 ай бұрын
freedom problem answer pls
@jovitha-m2s9 ай бұрын
Sale code
@Akash-dd6ev9 ай бұрын
thanks bro
@sakethbharatula91419 ай бұрын
permutation disturbance code pls
@_Optimization9 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here 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<n;i++){ arr[i] = sc.nextInt()-1; } int start = 0; int ans = 0; for(int i=0;i<n-1;i++){ if(arr[i]==i){ int temp = arr[i+1]; arr[i+1] = arr[i]; arr[i] = temp; ans++; } } if(arr[n-1]==n-1) ans++; System.out.println(ans); t--; } } }
@_Optimization9 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here 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<n;i++){ arr[i] = sc.nextInt(); } long max =arr[0]*2L; long sum =arr[0]; for(int i=1;i<n;i++){ long val =(long) arr[i]; long mul = val * 2L; long sum2 = sum + mul; if(sum2>max) max = sum2; sum+=val; } System.out.println(max); t--; } } }
@venkadeshb79739 ай бұрын
I had the same idea but was not able to implement it completely
@_Optimization9 ай бұрын
class Solution { public long[] unmarkedSumArray(int[] nums, int[][] queries) { int len = nums.length; HashSet<Integer> ind = new HashSet<>(); PriorityQueue<Integer> pq =new PriorityQueue<>(); long sumOfNums= 0 ; for(int i=0;i<len;i++){ ind.add(i); pq.add(nums[i]); sumOfNums+=nums[i]; } int lent = queries.length; HashMap<Integer,Queue<Integer>> h = new HashMap<>(); for(int i=0;i<len;i++){ int val = nums[i]; if(h.get(val)==null){ Queue<Integer> q = new LinkedList<>(); q.add(i); h.put(val,q); }else{ Queue<Integer> q= h.get(val); q.add(i); } } long ans[] = new long[lent]; for(int i=0;i<lent;i++){ int left = queries[i][0]; int right = queries[i][1]; long sum = 0; if(ind.contains(left)){ ind.remove(left); sumOfNums-=nums[left]; } while(right>0){ if(pq.size()>0){ int minval = pq.poll(); Queue<Integer> indexes = h.get(minval); int minInd = indexes.remove(); if(ind.contains(minInd)){ right--; ind.remove(minInd); sumOfNums-=nums[minInd]; }else{ } }else { break; } } ans[i] = sumOfNums; } return ans; } }
@jeevaprakashm88959 ай бұрын
Where is the code?
@b_chatan_169 ай бұрын
code bro
@_Optimization9 ай бұрын
import java.util.Scanner; 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(); String arr[] = new String[n]; for(int i=0;i<n;i++){ arr[i] = sc.nextInt()+""; } String ans ="YES"; int prev = 0; String first = arr[0]; if(first.length()==1){ prev = first.charAt(0)-48; }else{ int val1 = first.charAt(0)-48; int val2 = first.charAt(1)-48; if(val1<=val2){ prev = val2; }else prev = Integer.parseInt(first); } for(int i=1;i<n;i++){ String s = arr[i]; if(s.length()==1){ int val = s.charAt(0)-48; if(val<prev){ ans = "NO"; break; }else{ prev = val; } }else{ int val1 = s.charAt(0)-48; int val2 = s.charAt(1)-48; int both = Integer.parseInt(s); if(val1<=val2){ if(prev<=val1){ prev=val2; }else{ if(both>=prev){ prev = both; }else{ ans = "NO"; } } }else{ if(both>=prev){ prev = both; }else{ ans = "NO"; } } } } System.out.println(ans); t--; } } }
@_Optimization9 ай бұрын
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t2=sc.nextInt(); while(t2>0){ int n=sc.nextInt(); int ans = 1; while(ans<n){ ans = ans*2; if(ans>n) { ans = ans / 2; break; } } System.out.println(ans); t2--; } } }
@_Optimization9 ай бұрын
//package CoreJava; import java.util.*; public class pop{ public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int n=sc.nextInt(); long arr[] = new long[n]; //long prefix[] = new long[n]; int ans = 0; long sum = 0; for(int i=0;i<n;i++) { int val = sc.nextInt(); arr[i] = (long)val; sum+=val; //prefix[i] = sum; } if(sum%3==0) System.out.println(0); else { int got2 = 0; for(int i=0;i<n;i++) { long rem = sum-arr[i]; if(rem%3==0) { got2 =1; break; } } if(got2==1) { System.out.println(1); }else { long rem = sum%3; rem = 3-rem; if(rem<2) System.out.println(1); else System.out.println(2); } } t--; } } }
@maronbablo10 ай бұрын
B
@_Optimization10 ай бұрын
import java.util.*; import java.math.BigInteger; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ long n = sc.nextLong(); long m = sc.nextLong(); long x = sc.nextLong(); long y = sc.nextLong(); long dist = sc.nextLong(); long leftDistY = y; leftDistY --; long rightDistY = m - y; // rightDistY--; long div1 = leftDistY / dist; long div2 = rightDistY / dist; long tot = div1 + div2 + 1L; //System.out.println(div1 +" "+div2); long upDistX = x; upDistX --; long downDistX = n - x; // downDistX--; long div3 = upDistX / dist; long div4 = downDistX / dist; long tot2 = div4 + div3 + 1L; System.out.println(tot * tot2); t--; } } }
@codescontest10 ай бұрын
d pls
@kingprashanthyadavkpy215710 ай бұрын
c plz
@_Optimization10 ай бұрын
//package CoreJava; import java.util.*; public class pop{ 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][n]; List<String> li = new ArrayList<>(); for(int i=0;i<n;i++) { li.add(sc.next()); } for(int i=0;i<li.size();i++) { String s = li.get(i); for(int j=0;j<n;j++) { char c= s.charAt(j); if(c=='1') { arr[i][j] = 1; }else { arr[i][j] = 0; } } } int tringle = 0; for(int i=0;i<n;i++) { for(int j=1;j<n-1;j++) { if(arr[i][j]==1) { if(arr[i][j-1]==0 && arr[i][j+1]==0) { tringle = 1; break; } } } } if(tringle==1) { System.out.println("TRIANGLE"); }else { System.out.println("SQUARE"); } t--; } } }
@_Optimization10 ай бұрын
//package CoreJava; import java.util.*; public class pop{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { int n = sc.nextInt(); String s= sc.next(); int ans = 0; int till = n; for(int i=0;i<n-1;i++) { char c=s.charAt(i); char next = s.charAt(i+1); if(c==next && c=='*') { till = i; break; } } for(int i=0;i<till;i++) { char c=s.charAt(i); if(c=='@') ans++; } System.out.println(ans); t--; } } }
@_Optimization10 ай бұрын
class Solution { public String lastNonEmptyString(String s) { int lent = s.length(); int max = 0; HashMap<Character,Integer> h = new HashMap<>(); HashMap<Character,Integer> lastInd = new HashMap<>(); for(int i=0;i<lent;i++){ char c= s.charAt(i); if(h.get(c) == null){ h.put(c,1); }else{ int p = h.get(c); p++; h.put(c,p); } lastInd.put(c,i); } // System.out.println(h); List<Character> li = new ArrayList<>(); HashSet<Character> ht = new HashSet<>(); for (Map.Entry<Character, Integer> entry : h.entrySet()) { char key = entry.getKey(); // Corrected method name int count = entry.getValue(); if(count>max){ li = new ArrayList<>(); ht = new HashSet<>(); max = count; li.add(key); ht.add(key); }else if(count == max){ li.add(key); ht.add(key); } } // System.out.println(lastInd); HashMap<Integer,Character> hp = new HashMap<>(); List<Integer> lk = new ArrayList<>(); for (Map.Entry<Character, Integer> entry : lastInd.entrySet()) { char key = entry.getKey(); // Corrected method name int count = entry.getValue(); if(ht.contains(key)){ lk.add(count); hp.put(count,key); } } Collections.sort(lk); // System.out.println(hp); String ans = ""; for(int i=0;i<lk.size();i++){ int ind = lk.get(i); //value = hp.get(ind); // System.out.println(ind +" -= "+value); char m = s.charAt(ind); ans = ans + hp.get(ind)+""; } return ans; } }
@codescontest10 ай бұрын
f pls
@_Optimization10 ай бұрын
import java.util.*; public class a{ public static void main(String args[]){ Scanner sct = new Scanner(System.in); int t = sct.nextInt(); while (t > 0) { int n = sct.nextInt(); HashMap<Character,Integer> h = new HashMap<>(); char c = 'a'; StringBuilder ans = new StringBuilder(); for (int i = 0; i < n; i++) { int val = sct.nextInt(); if(h.size()==0){ h.put(c,1); ans.append(c+""); }else{ if(val==0){ c++; h.put(c,1); ans.append(c+""); }else{ for(Map.Entry<Character,Integer> map : h.entrySet()){ char key = map.getKey(); int value = map.getValue(); if(value==val){ h.put(key,value+1); ans.append(key+""); break; } } } } } System.out.println(ans.toString()); t--; } } }
@_Optimization10 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; import java.util.Map.Entry; class Codechef { public static int get(HashMap<Character,Integer> h) { int ans = Integer.MIN_VALUE; // Initialize ans to the smallest possible value for (Entry<Character,Integer> e : h.entrySet()) { int val = e.getValue(); if (val > ans) ans = val; } return ans; } public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int q=sc.nextInt(); String s = sc.next(); int ans = 1; HashMap<Character,Integer> ht = new HashMap<>(); int count=1; for(int i=0;i<s.length()-1;i++){ char prev=s.charAt(i); char next=s.charAt(i+1); if(prev==next){ count++; if(count>ans) ans=count; }else{ count=1; } } System.out.print(ans+" "); int continueCount = 1; char prev = s.charAt(s.length()-1); for(int i=s.length()-1;i>0;i--){ char next = s.charAt(i); char pre = s.charAt(i-1); if(next==pre){ continueCount++; }else{ break; } } ////System.out.print(continueCount+" "); int cp = 1; for(int i=0;i<q;i++){ char current=sc.next().charAt(0); if(current==prev){ continueCount++; if(continueCount>ans) ans=continueCount; }else{ continueCount=1; } prev= current; System.out.print(ans+" "); } System.out.println(); t--; } } }
@_Optimization10 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int k =sc.nextInt(); boolean got = false; int ans = -2; for(int i=0;i<n;i++){ int p = sc.nextInt(); if(p>=k){ int rem = p%k; if(ans==-2){ ans=rem; got =true; }else{ if(rem<ans) { ans = rem; got =true; } } } } if(got){ System.out.println(ans); }else{ System.out.println(-1); } t--; } } }
@_Optimization11 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); String s= sc.next(); int len=s.length(); StringBuilder ans = new StringBuilder(); int got = 0; int ind =0; for(int i=0;i<len-1;i++){ if(s.charAt(i)>s.charAt(i+1)){ got =1; ind = i+1; break; }else{ char c=s.charAt(i); ans.append(c+""); } } if(got==1){ for(int i=ind;i<len;i++){ char c=s.charAt(i); ans.append(c+""); } } System.out.println(ans.toString()); t--; } } }
@zafarahmad22611 ай бұрын
Thnx
@_Optimization11 ай бұрын
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int h=sc.nextInt(); int gun=sc.nextInt(); int y1=sc.nextInt(); int y2=sc.nextInt(); int k=sc.nextInt(); int ans1 = h/gun; if(h%gun!=0) ans1++; int tot = y1*k; if(tot==h){ if(k<ans1) System.out.println(k); else System.out.println(ans1); }else if(tot<h){ int remH = h-tot; int p = remH/y2; p = p + k; if(remH%y2!=0) p++; if(p<ans1) System.out.println(p); else System.out.println(ans1); }else if(tot>h){ int p = h/y1; if(h%y1!=0) p++; if(p<ans1) System.out.println(p); else System.out.println(ans1); } t--; } } }
@SriniketKumar-b3j Жыл бұрын
5th code please
@_Optimization Жыл бұрын
/* 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. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); boolean got=false; if(n%3==0 || n%4==0) got=true; int p=n; if(got==false){ while(p>0){ p=p-3; if(p%4==0){ got=true; } } } if(got) System.out.println("YES"); else System.out.println("NO"); t--; } } }
@anil89131 Жыл бұрын
Bro 5th one please Minimise maximum subarray sum
@SaiKumar-cs6sf Жыл бұрын
It shows error :reached end of file while parsing
@_Optimization Жыл бұрын
/* 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. */ class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here 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<n;i++){ int val=sc.nextInt(); arr[i]=val; } // 2 5 3 4 // 3 4 3 4 3 boolean same=true; int first=arr[0]; for(int i=1;i<n;i++){ if(arr[i]!=first) same=false; } if(same){ System.out.println("NO"); }else{ if(n==4){ if(arr[0]+arr[1] == arr[2]+arr[3]){ System.out.println("NO"); }else{ System.out.println("YES"); } }else{ System.out.println("YES"); } } t--; } } }