Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Negi is fascinated with the binary representation of the number. Tell him the number of set bits (ones) in the binary representation of an integer N.The first line of the input contains single integer N. Constraints 1 <= N <= 1000000000000The output should contain a single integer, the number of set bits (ones) in the binary representation of an integer N.Sample Input 7 Sample Output 3 Sample Input 16 Sample Output 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n = Long.parseLong(br.readLine()); int count = 0; try{ while (n > 0) { count += n & 1; n >>= 1; } }catch(Exception e){ return ; } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Negi is fascinated with the binary representation of the number. Tell him the number of set bits (ones) in the binary representation of an integer N.The first line of the input contains single integer N. Constraints 1 <= N <= 1000000000000The output should contain a single integer, the number of set bits (ones) in the binary representation of an integer N.Sample Input 7 Sample Output 3 Sample Input 16 Sample Output 1, I have written this Solution Code: a=int(input()) l=bin(a) print(l.count('1')), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Negi is fascinated with the binary representation of the number. Tell him the number of set bits (ones) in the binary representation of an integer N.The first line of the input contains single integer N. Constraints 1 <= N <= 1000000000000The output should contain a single integer, the number of set bits (ones) in the binary representation of an integer N.Sample Input 7 Sample Output 3 Sample Input 16 Sample Output 1, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 #define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout); #define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout); #define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout); #define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout); #define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout); #define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); signed main() { int n; cin>>n; int cnt=0; while(n>0) { int p=n%2LL; cnt+=p; n/=2LL; } cout<<cnt<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int size = Integer.parseInt(line); String str = br.readLine(); String[] strArray = str.split(" "); int[] array = new int[size]; for (int i = -0; i < size; i++) { array[i] = Integer.parseInt(strArray[i]); } int count = largestSubarray(array,size); System.out.println(count); } static int largestSubarray(int[] array,int size){ int count = -1; int sum = 0; Map<Integer,Integer> mymap = new HashMap<>(); mymap.put(0,-1); for(int i=0; i<array.length; i++){ sum += array[i]; if(mymap.containsKey(sum)){ count = Math.max(count, i-mymap.get(sum)); } else{ mymap.put(sum,i); } } if(count > 0){ return count; } else{ return -1; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: def maxLen(arr,n,k): mydict = dict() sum = 0 maxLen = 0 for i in range(n): sum += arr[i] if (sum == k): maxLen = i + 1 elif (sum - k) in mydict: maxLen = max(maxLen, i - mydict[sum - k]) if sum not in mydict: mydict[sum] = i return maxLen n=int(input()) arr=input().split() for i in range(0,n): arr[i]=int(arr[i]) max_len=maxLen(arr,n,0) if(max_len==0): print ("-1") else: print (max_len), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ unordered_map<long long,int> m; int n,k; cin>>n; long a[n]; int ans=-1; for(int i=0;i<n;i++){cin>>a[i];if(a[i]==0){ans=1;}} long long sum=0; for(int i=0;i<n;i++){ sum+=a[i]; if(sum==0){ans=max(i+1,ans);} if(m.find(sum)==m.end()){m[sum]=i;} else{ ans=max(i-m[sum],ans); } } cout<<ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number 'N'. The task is to find the Nth number whose each digit is a prime number(<10) i.e 2, 3, 5, 7. In other words you have to find nth number of this sequence : 2, 3, 5, 7, 22, 23 ,.. and so on.The first line contains a single integer T i.e. the number of test cases. The first and only line of each test case consists of a single integer N. Constraints: 1 <= T <= 100 1 <= N <= 100000For each testcase print the nth number of the given sequence made of prime digits in a new line.Input: 2 10 21 Output: 33 222 Explanation: Testcase 1: 10th number in the sequence of numbers whose each digit is prime is 33. Testcase 2: 21th number in the sequence of numbers whose each digit is prime is 222., I have written this Solution Code: import java.io.*; import java.util.*; class Main { 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 ans = check(n); StringBuffer sbr = new StringBuffer(ans); System.out.println(sbr.reverse()); } } static String check(int x) { String ans=""; while(x>0) { switch(x%4) { case 1:ans +="2"; break; case 2:ans +="3"; break; case 3:ans+="5"; break; case 0:ans+="7"; break; } if(x%4==0) x--; x/=4; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number 'N'. The task is to find the Nth number whose each digit is a prime number(<10) i.e 2, 3, 5, 7. In other words you have to find nth number of this sequence : 2, 3, 5, 7, 22, 23 ,.. and so on.The first line contains a single integer T i.e. the number of test cases. The first and only line of each test case consists of a single integer N. Constraints: 1 <= T <= 100 1 <= N <= 100000For each testcase print the nth number of the given sequence made of prime digits in a new line.Input: 2 10 21 Output: 33 222 Explanation: Testcase 1: 10th number in the sequence of numbers whose each digit is prime is 33. Testcase 2: 21th number in the sequence of numbers whose each digit is prime is 222., I have written this Solution Code: def nthprimedigitsnumber(number): num="" while (number > 0): rem = number % 4 if (rem == 1): num += '2' if (rem == 2): num += '3' if (rem == 3): num += '5' if (rem == 0): num += '7' if (number % 4 == 0): number = number - 1 number = number // 4 return num[::-1] T=int(input()) for i in range(T): number = int(input()) print(nthprimedigitsnumber(number)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number 'N'. The task is to find the Nth number whose each digit is a prime number(<10) i.e 2, 3, 5, 7. In other words you have to find nth number of this sequence : 2, 3, 5, 7, 22, 23 ,.. and so on.The first line contains a single integer T i.e. the number of test cases. The first and only line of each test case consists of a single integer N. Constraints: 1 <= T <= 100 1 <= N <= 100000For each testcase print the nth number of the given sequence made of prime digits in a new line.Input: 2 10 21 Output: 33 222 Explanation: Testcase 1: 10th number in the sequence of numbers whose each digit is prime is 33. Testcase 2: 21th number in the sequence of numbers whose each digit is prime is 222., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; void nthprimedigitsnumber(long long n) { long long len = 1; long long prev_count = 0; while (true) { long long curr_count = prev_count + pow(4, len); if (prev_count < n && curr_count >= n) break; len++; prev_count = curr_count; } for (int i = 1; i <= len; i++) { for (long long j = 1; j <= 4; j++) { if (prev_count + pow(4, len - i) < n) prev_count += pow(4, len - i); else { if (j == 1) cout << "2"; else if (j == 2) cout << "3"; else if (j == 3) cout << "5"; else if (j == 4) cout << "7"; break; } } } cout << endl; } int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; nthprimedigitsnumber(n); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: public static long SumOfDivisors(long N){ long sum=0; long c=(long)Math.sqrt(N); for(long i=1;i<=c;i++){ if(N%i==0){ sum+=i; if(i*i!=N){sum+=N/i;} } } return sum; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: long long SumOfDivisors(long long N){ long long sum=0; long sq=sqrt(N); for(long i=1;i<=sq;i++){ if(N%i==0){ sum+=i; if(i*i!=N){ sum+=N/i; } } } return sum; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: long long SumOfDivisors(long long N){ long long sum=0; long sq=sqrt(N); for(long i=1;i<=sq;i++){ if(N%i==0){ sum+=i; if(i*i!=N){ sum+=N/i; } } } return sum; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: def SumOfDivisors(num) : # Final result of summation of divisors result = 0 # find all divisors which divides 'num' i = 1 while i<= (math.sqrt(num)) : # if 'i' is divisor of 'num' if (num % i == 0) : # if both divisors are same then # add it only once else add both if (i == (num / i)) : result = result + i; else : result = result + (i + num/i); i = i + 1 # Add 1 to the result as 1 is also # a divisor return (result); , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes. <strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases. The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes <strong>Constraints</strong>: 1 <= T <= 100 1 <= N, X <= 10000 1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space. Assume 0-indexingInput: 2 5 6 2 3 6 5 6 4 3 2 4 6 5 Output: 2 4 Not found, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int t; cin >> t; while(t--){ vector<int> v; int n, x; cin >> n >> x; for(int i = 1; i <= n; i++){ int p; cin >> p; if(p == x) v.push_back(i-1); } if(v.size() == 0) cout << "Not found\n"; else{ for(auto i: v) cout << i << " "; cout << endl; } } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes. <strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases. The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes <strong>Constraints</strong>: 1 <= T <= 100 1 <= N, X <= 10000 1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space. Assume 0-indexingInput: 2 5 6 2 3 6 5 6 4 3 2 4 6 5 Output: 2 4 Not found, I have written this Solution Code: def position(n,arr,x): res = [] cnt = 0 for i in arr: if(i == x): res.append(cnt) cnt += 1 return res , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array <strong>arr[]</strong> of size <strong>N</strong> and an element <strong>X</strong>. The task is to find and print the indices of the given element if it is present in array if not then print “<strong>Not found</strong>” without quotes. <strong>Note</strong>: The elements may be present more than once.The first line of input contains T, denoting the number of test cases. The first line of each test case contains N and X, N is the size of array and X is an element. Second line contains elements of array space separated. If not present then print "Not found" without quotes <strong>Constraints</strong>: 1 <= T <= 100 1 <= N, X <= 10000 1 <= arr[i] <= 100000For each test case in new line you need to print all the positions where you find the X separated by space. Assume 0-indexingInput: 2 5 6 2 3 6 5 6 4 3 2 4 6 5 Output: 2 4 Not found, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t =Integer.parseInt(read.readLine()); while(t-- > 0) { String str[] = read.readLine().trim().split(" "); int n = Integer.parseInt(str[0]); int x = Integer.parseInt(str[1]); int arr[] = new int[n]; str = read.readLine().trim().split(" "); for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); findPositions(arr, n, x); } } static void findPositions(int arr[], int n, int x) { boolean flag = false; StringBuffer sb = new StringBuffer(); for(int i = 0; i < n; i++) { if(arr[i] == x) { sb.append(i + " "); flag = true; } } if(flag ==true) System.out.println(sb.toString()); else System.out.println("Not found"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int n=Integer.parseInt(br.readLine().trim()); if(n%3==1) System.out.println("Dead"); else System.out.println("Alive"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: n = int(input().strip()) if n%3 == 1: print("Dead") else: print("Alive"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; if(n%3==1) cout<<"Dead"; else cout<<"Alive"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is learning chess for the first time, So his father first starts his training with the piece <b>Knight</b>. His father gave Ram 2 random points ((x, y) and (a, b)), ie position of any piece on a 8x8 chess board and then asks Ram can he put the knight on the board so that both of the pieces get attacked at the same time? If yes then print "YES" we can otherwise "NO".The first line of the input contains a space separated integer T. The first line of each test case contains two space separated integer x, y. The second line of each test case contains two space separated integer a, b. <b>Constraints</b> 1 ≤ T ≤ 5000 1 ≤ x, y ≤ 8 1 ≤ a, b ≤ 8 Both the cells are distinctPrint "YES" if the fork exists otherwise print "NO".Sample Input 3 8 1 7 3 3 7 5 2 3 5 2 2 Sample Output NO NO YES <b>Explanation</b> For test cases 1 and 2 no such point exists, but for test case 3 (1, 4) is the point that can cause a fork., I have written this Solution Code: import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.io.PrintStream; 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); TheAttackOfKnight solver = new TheAttackOfKnight(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class TheAttackOfKnight { public void solve(int testNumber, FastReader in, PrintWriter out) { int i, j, k; int x1 = in.nextInt(); int y1 = in.nextInt(); int x2 = in.nextInt(); int y2 = in.nextInt(); HashSet<String> hs = new HashSet<>(); HashSet<String> hs2 = new HashSet<>(); int a1 = x1, b1 = y1; int a2 = x2, b2 = y2; if (a1 + 2 < 9) { if (b1 + 1 < 9) hs.add((a1 + 2) + " " + (b1 + 1)); if (b1 - 1 > 0) hs.add((a1 + 2) + " " + (b1 - 1)); } if (a1 + 1 < 9) { if (b1 + 2 < 9) hs.add((a1 + 1) + " " + (b1 + 2)); if (b1 - 2 > 0) hs.add((a1 + 1) + " " + (b1 - 2)); } if (a1 - 2 > 0) { if (b1 + 1 < 9) hs.add((a1 - 2) + " " + (b1 + 1)); if (b1 - 1 > 0) hs.add((a1 - 2) + " " + (b1 - 1)); } if (a1 - 1 > 0) { if (b1 + 2 < 9) hs.add((a1 - 1) + " " + (b1 + 2)); if (b1 - 2 > 0) hs.add((a1 - 1) + " " + (b1 - 2)); } boolean b = false; if (a2 + 2 < 9) { if (b2 + 1 < 9) { if (hs.contains((a2 + 2) + " " + (b2 + 1))) b = true; } if (b2 - 1 > 0) { if (hs.contains((a2 + 2) + " " + (b2 - 1))) b = true; } } if (a2 + 1 < 9) { if (b2 + 2 < 9) { if (hs.contains((a2 + 1) + " " + (b2 + 2))) b = true; } if (b2 - 2 > 0) { if (hs.contains((a2 + 1) + " " + (b2 - 2))) b = true; } } if (a2 - 2 > 0) { if (b2 + 1 < 9) { if (hs.contains((a2 - 2) + " " + (b2 + 1))) b = true; } if (b2 - 1 > 0) { if (hs.contains((a2 - 2) + " " + (b2 - 1))) b = true; } } if (a2 - 1 > 0) { if (b2 + 2 < 9) { if (hs.contains((a2 - 1) + " " + (b2 + 2))) b = true; } if (b2 - 2 > 0) { if (hs.contains((a2 - 1) + " " + (b2 - 2))) b = true; } } if (b) out.println("YES"); else out.println("NO"); } } static class FastReader { static final int BUFSIZE = 1 << 20; static byte[] buf; static int index; static int total; static InputStream in; public FastReader(InputStream is) { try { in = is; buf = new byte[BUFSIZE]; } catch (Exception e) { } } private int scan() { try { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } catch (Exception | Error e) { System.err.println(e.getMessage()); return 13 / 0; } } public String next() { 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(); } public int nextInt() { 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; } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is learning chess for the first time, So his father first starts his training with the piece <b>Knight</b>. His father gave Ram 2 random points ((x, y) and (a, b)), ie position of any piece on a 8x8 chess board and then asks Ram can he put the knight on the board so that both of the pieces get attacked at the same time? If yes then print "YES" we can otherwise "NO".The first line of the input contains a space separated integer T. The first line of each test case contains two space separated integer x, y. The second line of each test case contains two space separated integer a, b. <b>Constraints</b> 1 ≤ T ≤ 5000 1 ≤ x, y ≤ 8 1 ≤ a, b ≤ 8 Both the cells are distinctPrint "YES" if the fork exists otherwise print "NO".Sample Input 3 8 1 7 3 3 7 5 2 3 5 2 2 Sample Output NO NO YES <b>Explanation</b> For test cases 1 and 2 no such point exists, but for test case 3 (1, 4) is the point that can cause a fork., I have written this Solution Code: def chess(x,y): pos1=((x+2),(y+1)) pos2=((x+2),(y-1)) pos3=((x-2),(y+1)) pos4=((x-2),(y-1)) pos5=((x+1),(y+2)) pos6=((x-1),(y+2)) pos7=((x+1),(y-2)) pos8=((x-1),(y-2)) arr=[pos1,pos2,pos3,pos4,pos5,pos6,pos7,pos8] final=[] for i in range(len(arr)): if (arr[i][0] > 0 and arr[i][0] < 9 ) and (arr[i][1] > 0 and arr[i][1] < 9) : final.append(arr[i]) return final t=int(input()) while t>0 : x,y = list(map(int,input().split())) point1 = chess(x,y) p,q = list(map(int,input().split())) point2 = chess(p,q) flag= True for i in (point1): for j in (point2): if i==j : print("YES") flag = False break if flag == False: break else: print("NO") t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is learning chess for the first time, So his father first starts his training with the piece <b>Knight</b>. His father gave Ram 2 random points ((x, y) and (a, b)), ie position of any piece on a 8x8 chess board and then asks Ram can he put the knight on the board so that both of the pieces get attacked at the same time? If yes then print "YES" we can otherwise "NO".The first line of the input contains a space separated integer T. The first line of each test case contains two space separated integer x, y. The second line of each test case contains two space separated integer a, b. <b>Constraints</b> 1 ≤ T ≤ 5000 1 ≤ x, y ≤ 8 1 ≤ a, b ≤ 8 Both the cells are distinctPrint "YES" if the fork exists otherwise print "NO".Sample Input 3 8 1 7 3 3 7 5 2 3 5 2 2 Sample Output NO NO YES <b>Explanation</b> For test cases 1 and 2 no such point exists, but for test case 3 (1, 4) is the point that can cause a fork., I have written this Solution Code: /** * author: tourist1256 * created: 2022-06-14 14:26:47 **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif #define int long long mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } void solve() { pair<int, int> a, b; cin >> a.first >> a.second >> b.first >> b.second; set<pair<int, int>> pointA, pointB; auto getPoints = [&](int x, int y) -> set<pair<int, int>> { set<pair<int, int>> tempPoints; // Top Left tempPoints.insert({x - 1, y + 2}); tempPoints.insert({x - 2, y + 1}); // Top Right tempPoints.insert({x + 1, y + 2}); tempPoints.insert({x + 2, y + 1}); // Bottom Left tempPoints.insert({x - 2, y - 1}); tempPoints.insert({x - 1, y - 2}); // Bottom Right tempPoints.insert({x + 2, y - 1}); tempPoints.insert({x + 1, y - 2}); return tempPoints; }; pointA = getPoints(a.first, a.second); pointB = getPoints(b.first, b.second); for (auto &it : pointA) { if (it.first < 1 or it.first > 8) { continue; } if (it.second < 1 or it.second > 8) { continue; } if (pointB.find(it) != pointB.end()) { debug(it.first, it.second); cout << "YES" << endl; return; } } cout << "NO\n"; } int32_t main() { int tt; cin >> tt; while (tt--) { solve(); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N cakes and there are K people. You want to distribute cake among these K people such that following conditions are satisfied: > You cannot give N cakes to a single person. > All the people who get atleast one cake should all get same number of cakes. > You must distribute all N cakes. Find out if it is possible to distribute the cakes.Input contains two integers N and K. Constraints: 1 <= N <= 10^18 1 <= K <= 10^6If it is possible to distribute cakes print "Yes" else print "No".Sample Input 1 10 3 Sample Output 1 Yes Explanation: We can give 5 cakes to person 1 and 5 to person 2 and no cake to person 3. Sample Input 2 5 4 Sample Output 2 No, I have written this Solution Code: import java.io.*; import java.util.*; import java.io.IOException; class Main { static boolean call(long n1, long n2){ if((n1%3== 0 && n2>3) || (n1%5== 0 && n2>5) || (n1%7== 0 && n2>7) || (n1%9== 0 && n2>9)) return true; for(int i=11;i<n2;i+=2){ if(n1%i== 0){ return true; } } return false; } public static void main (String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String[] input= br.readLine().split(" "); Long n1= Long.parseLong(input[0]); Long n2= Long.parseLong(input[1]); if(n2<2){ System.out.print("No"); } else if(n1%n2== 0 || n1%2==0 || n1<n2){ System.out.print("Yes"); } else if(call(n1,n2)){ System.out.print("Yes"); } else{ System.out.print("No"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N cakes and there are K people. You want to distribute cake among these K people such that following conditions are satisfied: > You cannot give N cakes to a single person. > All the people who get atleast one cake should all get same number of cakes. > You must distribute all N cakes. Find out if it is possible to distribute the cakes.Input contains two integers N and K. Constraints: 1 <= N <= 10^18 1 <= K <= 10^6If it is possible to distribute cakes print "Yes" else print "No".Sample Input 1 10 3 Sample Output 1 Yes Explanation: We can give 5 cakes to person 1 and 5 to person 2 and no cake to person 3. Sample Input 2 5 4 Sample Output 2 No, I have written this Solution Code: l=list(map(int,input().split())) flag=0 for i in range(2,l[1]+1): if(l[0]%i==0): flag=1 print("Yes") break if(flag==0): print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N cakes and there are K people. You want to distribute cake among these K people such that following conditions are satisfied: > You cannot give N cakes to a single person. > All the people who get atleast one cake should all get same number of cakes. > You must distribute all N cakes. Find out if it is possible to distribute the cakes.Input contains two integers N and K. Constraints: 1 <= N <= 10^18 1 <= K <= 10^6If it is possible to distribute cakes print "Yes" else print "No".Sample Input 1 10 3 Sample Output 1 Yes Explanation: We can give 5 cakes to person 1 and 5 to person 2 and no cake to person 3. Sample Input 2 5 4 Sample Output 2 No, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n,k; cin>>n>>k; for(int i=2;i<=k;++i){ if(n%i==0){ cout<<"Yes"; return 0; } } cout<<"No"; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a Binary Search Tree. The task is to find the <b>minimum element</b> in this given BST. If the tree is empty, there is no minimum element, so print <b>-1</b> in that case.<b>User Task:</b> Since this will be a functional problem. You don't have to take input. You just have to complete the function <b>minValue()</b> that takes "root" node as parameter and returns the minimum value(-1 in case tree is empty). The printing is done by the driver code. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^3 1 <= node values <= 10^4 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the minimum element in BST.Input: 2 5 4 6 3 N N 7 1 9 N 10 N 11 Output: 1 9 Explanation: Testcase 1: We construct the following BST by inserting given values one by one in an empty BST. 5 / \ 4 6 / \ 3 7 / 1 The minimum value in the given BST is 1. Testcase 2: We construct the following BST by inserting given values one by one in an empty BST. 9 \ 10 \ 11 The minimum value in the given BST is 9., I have written this Solution Code: static int minValue(Node node) { // base case if(node==null) return -1; Node current = node; // iterate left till node is not null while (current.left != null) { current = current.left; } return (current.data); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){ int x=N; while(D-->0){ x-=x/2; x*=3; } System.out.println(x); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } cout << x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } printf("%d", x); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D): ans = N while D > 0: ans = ans - ans//2 ans = ans*3 D = D-1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let us create a table 'STORY' from existing table 'POSTS' which will contain the information about the stories users will create on LinkedIn. This table 'story' will contain the fields (USERNAME, DATETIME_CREATED, PHOTO) of the table 'posts' ( USE ONLY UPPERCASE LETTERS FOR CODE) <schema>[{'name': 'STORY', 'columns': [{'name': 'USERNAME', 'type': 'VARCHAR(24)'}, {'name': 'DATETIME_CREATED', 'type': 'TEXT'}, {'name': 'PHOTO', 'type': 'BLOB'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE STORY AS SELECT USERNAME, DATETIME_CREATED, PHOTO FROM POST; , In this Programming Language: SQL, Now tell me if this Code is compilable or not?
Compilable
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet. Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number. Constraints 2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1 2 Sample Output 1 21 Sample Input 2 4 Sample Output 1008 Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in)); long n = Long.parseLong(rdr.readLine()); if(n==0 || n==1){ return ; } if(n==2){ System.out.println(21); } else{ StringBuilder str= new StringBuilder(); str.append("1"); for(long i=0;i<n-3;i++){ str.append("0"); } if(n%6==0){ str.append("02"); System.out.println(str.toString()); } else if(n%6==1){ str.append("20"); System.out.println(str.toString()); } else if(n%6==2){ str.append("11"); System.out.println(str.toString()); } else if(n%6==3){ str.append("05"); System.out.println(str.toString()); } if(n%6==4){ str.append("08"); System.out.println(str.toString()); return; } else if(n%6==5){ str.append("17"); System.out.println(str.toString()); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet. Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number. Constraints 2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1 2 Sample Output 1 21 Sample Input 2 4 Sample Output 1008 Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: n = input() n=int(n) n1=10**(n-1) n2=10**(n) while(n1<n2): if((n1%3==0) and (n1%7==0)): print(n1) break n1 = n1+1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet. Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number. Constraints 2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1 2 Sample Output 1 21 Sample Input 2 4 Sample Output 1008 Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(ll i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define int long long #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define MOD 1000000007 #define INF 1000000000000000007LL const int N = 100005; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif signed main() { fast int n; cin>>n; if(n==2){ cout<<"21"; return 0; } int mod=1; for(int i=2; i<=n; i++){ mod = (mod*10)%7; } int av = 2; mod = (mod+2)%7; while(mod != 0){ av += 3; mod = (mod+3)%7; } string sav = to_string(av); if(sz(sav)==1){ sav.insert(sav.begin(), '0'); } string ans = "1"; for(int i=0; i<n-3; i++){ ans += '0'; } ans += sav; cout<<ans; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of size N and Q queries of two types: 1 U X - change the value at index U to X 2 L R - print the sum of elements in the range L to R. Print a single integer corresponding to every query of type 2.The first line of input contains two integers N and Q denoting the number of elements in the array and type of queries respectively. The next line contains N integers denoting the elements of the array A. The next Q lines contain three integers T L R denoting the queries. 1 <= N, Q <= 100000 1 <= A[i] <= 100000 1 <= T <= 2 1 <= U, X <= 100000 1 <= L <= R <= 100000Print a single integer corresponding to every query of type 2 in a separate line. Since the answer can be large print ans modulo (10^9 + 7)Sample Input: 5 6 2 1 3 5 4 2 3 5 1 2 7 1 4 2 2 2 4 1 5 3 2 1 5 Sample Output: 12 12 17 Explanation: Array after 2nd query: [2, 7, 3, 5, 4] Array after 3rd query: [2, 7, 3, 2, 4] Array after 5th query: [2, 7, 3, 2, 3], I have written this Solution Code: import java.io.*; import java.util.*; class Main { int st[]; Main(int arr[], int n) { int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); int max_size = 2 * (int) Math.pow(2, x) - 1; st = new int[max_size]; constructSTUtil(arr, 0, n - 1, 0); } int getMid(int s, int e) { return s + (e - s) / 2; } int getSumUtil(int ss, int se, int qs, int qe, int si) { if (qs <= ss && qe >= se) return st[si]; if (se < qs || ss > qe) return 0; int mid = getMid(ss, se); return (getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2))%1000000007; } void updateValueUtil(int ss, int se, int i, int diff, int si) { if (i < ss || i > se) return; st[si] = (st[si] + diff)%1000000007; if (se != ss) { int mid = getMid(ss, se); updateValueUtil(ss, mid, i, diff, 2 * si + 1); updateValueUtil(mid + 1, se, i, diff, 2 * si + 2); } } void updateValue(int arr[], int n, int i, int new_val) { if (i < 0 || i > n - 1) { System.out.println("Invalid Input"); return; } int diff = new_val - arr[i]; arr[i] = new_val; updateValueUtil(0, n - 1, i, diff, 0); } int getSum(int n, int qs, int qe) { return getSumUtil(0, n - 1, qs, qe, 0); } int constructSTUtil(int arr[], int ss, int se, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = getMid(ss, se); st[si] = (constructSTUtil(arr, ss, mid, si * 2 + 1) + constructSTUtil(arr, mid + 1, se, si * 2 + 2))%1000000007; return st[si]; } public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int q = Integer.parseInt(s[1]); int arr[] = new int[n]; String S[] = br.readLine().split(" "); for(int i=0; i<n; i++){ arr[i] = Integer.parseInt(S[i]); } Main tree = new Main(arr,n); for(int i=0; i<q; i++){ String str[]=br.readLine().split(" "); int qt = Integer.parseInt(str[0]); int val1 = Integer.parseInt(str[1]); int val2 = Integer.parseInt(str[2]); if(qt==1){ tree.updateValue(arr, n, val1-1, val2); } else{ System.out.println(tree.getSum(n, val1-1, val2-1)); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of size N and Q queries of two types: 1 U X - change the value at index U to X 2 L R - print the sum of elements in the range L to R. Print a single integer corresponding to every query of type 2.The first line of input contains two integers N and Q denoting the number of elements in the array and type of queries respectively. The next line contains N integers denoting the elements of the array A. The next Q lines contain three integers T L R denoting the queries. 1 <= N, Q <= 100000 1 <= A[i] <= 100000 1 <= T <= 2 1 <= U, X <= 100000 1 <= L <= R <= 100000Print a single integer corresponding to every query of type 2 in a separate line. Since the answer can be large print ans modulo (10^9 + 7)Sample Input: 5 6 2 1 3 5 4 2 3 5 1 2 7 1 4 2 2 2 4 1 5 3 2 1 5 Sample Output: 12 12 17 Explanation: Array after 2nd query: [2, 7, 3, 5, 4] Array after 3rd query: [2, 7, 3, 2, 4] Array after 5th query: [2, 7, 3, 2, 3], I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N], t[4*N]; void build(int nd, int s, int e){ if(s == e) t[nd] = a[s]; else{ int md = (s + e) >> 1; build(nd << 1, s, md); build(nd << 1 | 1, md+1, e); t[nd] = t[nd << 1] + t[nd << 1 | 1]; } } void upd(int nd, int s, int e, int id, int v){ if(s == e){ t[nd] = v; return; } int md = (s + e) >> 1; if(id <= md) upd(nd << 1, s, md, id, v); else upd(nd << 1 | 1, md+1, e, id, v); t[nd] = t[nd << 1] + t[nd << 1 | 1]; } int query(int nd, int s, int e, int l, int r){ if(s > e || s > r || e < l) return 0; if(s >= l && e <= r) return t[nd]; int md = (s + e) >> 1; return query(nd << 1, s, md, l, r) + query(nd << 1 | 1, md+1, e, l, r); } void solve(){ int n, q; cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); while(q--){ int t, l, r; cin >> t >> l >> r; if(t == 1) upd(1, 1, n, l, r); else cout << query(1, 1, n, l, r) % mod << endl; } } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms:"; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a singly linked list, find out the middle node of the linked list. For example, if given linked list is 1- >2- >3- >4- >5 then middle of the linked list is 3. If there are even nodes, then there would be two middle nodes, then print both the middle elements. For example, if given linked list is 1- >2- >3- >4- >5- >6 then middle elements are 3 and 4. In case of a single node print the value of only node.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>findMiddleElement()</b> that takes head node of the linked list as parameter. Constraints: 1 <=N<= 1000 1 <=value<= 1000find out middle node of the linked list.Sample Input 1: 5 1 2 3 4 5 Sample Output: 3 Sample Input 2: 6 1 2 3 4 5 6 Sample Output:- 3 4, I have written this Solution Code: public static void MiddleElement(Node head) { if(head==null){ //System.out.println("khali"); return; } int cnt=0; Node temp=head; while(temp!=null){ cnt++; temp=temp.next; } if(cnt==1){ System.out.println(head.val); return; } if(cnt==2){ System.out.print(head.val); System.out.print(" "); System.out.println(head.next.val); return; } if(cnt%2!=0){ temp=head; int cnt1=cnt/2; while (temp!=null) { if(cnt1==0){ System.out.println(temp.val); return; } cnt1--; temp=temp.next; } return; } temp=head; int cnt1=cnt/2-1; while (temp!=null) { if(cnt1==0){ System.out.print(temp.val); System.out.print(" "); System.out.println(temp.next.val); return; } cnt1--; temp=temp.next; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An element of the matrix is called strange if its corresponding row and column contains all 1's. Given a boolean matrix of size N*M, your task is to find the number of strange elements.The first line of input contains two space-separated integers N and M. Next N lines of input contain M space-separated integers depicting the values of the matrix. <b>Constraints:-</b> 3 &le; N, M &le; 50 0 &le; Matrix[][] &le; 1Print the number of strange elementsSample Input:- 3 2 1 1 0 1 1 1 Sample Output:- 2 Sample Input:- 4 4 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 Sample Output:- 2 <b>Explanation 1:-</b> (0, 1) and (2, 1), I have written this Solution Code: n = [int(i) for i in input().split()] a = [[int(i) for i in input().split()] for j in range(n[0])] c = 0 for i in range(n[0]): t = True for j in range(n[1]): if a[i][j] == 0: t = False break; if t: c = c+1 r = 0 for j in range(n[1]): t = True for i in range(n[0]): if a[i][j]==0: t = False break; if t: r = r+1 print(r*c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An element of the matrix is called strange if its corresponding row and column contains all 1's. Given a boolean matrix of size N*M, your task is to find the number of strange elements.The first line of input contains two space-separated integers N and M. Next N lines of input contain M space-separated integers depicting the values of the matrix. <b>Constraints:-</b> 3 &le; N, M &le; 50 0 &le; Matrix[][] &le; 1Print the number of strange elementsSample Input:- 3 2 1 1 0 1 1 1 Sample Output:- 2 Sample Input:- 4 4 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 Sample Output:- 2 <b>Explanation 1:-</b> (0, 1) and (2, 1), I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int a[][] = new int[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]= sc.nextInt(); } } int cnt=0; int p=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ p=0; if(a[i][j]==1){ for(int k=0;k<n;k++){ if(a[k][j]==1){p++;} } for(int k=0;k<m;k++){ if(a[i][k]==1){p++;} } if(p==(n+m)){ cnt++;} } } } System.out.print(cnt); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An element of the matrix is called strange if its corresponding row and column contains all 1's. Given a boolean matrix of size N*M, your task is to find the number of strange elements.The first line of input contains two space-separated integers N and M. Next N lines of input contain M space-separated integers depicting the values of the matrix. <b>Constraints:-</b> 3 &le; N, M &le; 50 0 &le; Matrix[][] &le; 1Print the number of strange elementsSample Input:- 3 2 1 1 0 1 1 1 Sample Output:- 2 Sample Input:- 4 4 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 Sample Output:- 2 <b>Explanation 1:-</b> (0, 1) and (2, 1), I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1000001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ int n,m; cin>>n>>m; int a[n][m]; FOR(i,n){ FOR(j,m){ cin>>a[i][j];}} bool b[n]; bool c[m]; FOR(i,n){ b[i]=false;} FOR(i,m){ c[i]=false;} bool win; for(int i=0;i<n;i++){ win=true; for(int j=0;j<m;j++){ if(a[i][j]==0){win=false;} } b[i]=win; } for(int i=0;i<m;i++){ win=true; for(int j=0;j<n;j++){ if(a[j][i]==0){win=false;} } c[i]=win; } int cnt=0; for(int i=0;i<n;i++){ win=true; for(int j=0;j<m;j++){ if(b[i] && c[j]){cnt++;} // if(a[j][i]==0){win=false;} } } out(cnt); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her. In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N. Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries. Then Q lines follow, each line containing a single integer N denoting a query. <b> Constraints: </b> 1 ≤ Q ≤ 1000 1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1: 3 1 6 36 Sample Output 1: 1 0 2 Sample Explanation 1: For the first query, the only possibility is 1. For the third query, the only possibilities are 6 and 12., I have written this Solution Code: import java.io.*; import java.util.*; public class Main { private static final int START_TEST_CASE = 1; public static void solveCase(FastIO io, int testCase) { final long N = io.nextLong(); int count = 0; for (int i = 1; i <= 200; ++i) { if (N % i == 0) { long j = N / i; if (digitSum(j) == i) { ++count; } } } io.println(count); } private static long digitSum(long x) { long s = 0; while (x > 0) { s += x % 10; x /= 10; } return s; } public static void solve(FastIO io) { final int T = io.nextInt(); for (int t = 0; t < T; ++t) { solveCase(io, START_TEST_CASE + t); } } public static class FastIO { private InputStream reader; private PrintWriter writer; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastIO(InputStream r, OutputStream w) { reader = r; writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w))); } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = reader.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printArray(long[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printlnArray(int[] arr) { printArray(arr); writer.println(); } public void printlnArray(long[] arr) { printArray(arr); writer.println(); } public void printf(String format, Object... args) { print(String.format(format, args)); } public void flush() { writer.flush(); } } private static class Solution implements Runnable { @Override public void run() { FastIO io = new FastIO(System.in, System.out); solve(io); io.flush(); } } public static void main(String[] args) throws InterruptedException { Thread t = new Thread(null, new Solution(), "Solution", 1 << 30); t.start(); t.join(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her. In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N. Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries. Then Q lines follow, each line containing a single integer N denoting a query. <b> Constraints: </b> 1 ≤ Q ≤ 1000 1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1: 3 1 6 36 Sample Output 1: 1 0 2 Sample Explanation 1: For the first query, the only possibility is 1. For the third query, the only possibilities are 6 and 12., I have written this Solution Code: q = int(input()) for _ in range(q): n = int(input()) count = 0 for i in range(1,9*len(str(n))): if not n % i: dig = n//i if sum(map(int,str(dig))) == i: count += 1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice has Q queries for you. If you can solve all her queries, she will invite you to participate in a fireworks display with her. In each query, she gives you a positive integer N, and you have to find the number of positive integers M such that M × d(M) = N. Here, d(M) refers to the sum of all digits of M. For example, d(1023) = 6.The first line consists of a single integer Q – the number of queries. Then Q lines follow, each line containing a single integer N denoting a query. <b> Constraints: </b> 1 ≤ Q ≤ 1000 1 ≤ N ≤ 10<sup>18</sup>Print Q lines, the i<sup>th</sup> line containing the answer to the i<sup>th</sup> query.Sample Input 1: 3 1 6 36 Sample Output 1: 1 0 2 Sample Explanation 1: For the first query, the only possibility is 1. For the third query, the only possibilities are 6 and 12., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long // #pragma gcc optimize("ofast") // #pragma gcc target("avx,avx2,fma") #define all(x) (x).begin(), (x).end() #define pb push_back #define endl '\n' #define fi first #define se second // const int mod = 1e9 + 7; const int mod=998'244'353; const long long INF = 2e18 + 10; // const int INF=4e9+10; #define readv(x, n) \ vector<int> x(n); \ for (auto &i : x) \ cin >> i; template <typename t> using v = vector<t>; template <typename t> using vv = vector<vector<t>>; template <typename t> using vvv = vector<vector<vector<t>>>; typedef vector<int> vi; typedef vector<double> vd; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<vector<vector<vector<int>>>> vvvvi; typedef vector<vector<double>> vvd; typedef pair<int, int> pii; int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); } int mult_identity(int a) { return 1; } const double pi = acosl(-1); vector<vector<int> > multiply(vector<vector<int>> a, vector<vector<int>> b, int in_mod) { int n = a.size(); int l = b.size(); int m = b[0].size(); vector<vector<int> > result(n,vector<int>(n)); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { for(int k=0;k<l;k++) { result[i][j] = (result[i][j] + a[i][k]*b[k][j])%in_mod; } } } return result; } vector<vector<int>> operator%(vector<vector<int>> a, int in_mod) { for(auto &i:a) for(auto &j:i) j%=in_mod; return a; } vector<vector<int>> mult_identity(vector<vector<int>> a) { int n=a.size(); vector<vector<int>> output(n, vector<int> (n)); for(int i=0;i<n;i++) output[i][i]=1; return output; } vector<int> mat_vector_product(vector<vector<int>> a, vector<int> b, int in_mod) { int n =a.size(); vector<int> output(n); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { output[i]+=a[i][j]*b[j]; output[i]%=in_mod; } } return output; } auto power(auto a, auto b, const int in_mod) { auto prod = mult_identity(a); auto mult = a % in_mod; while (b != 0) { if (b % 2) { prod = multiply(prod, mult, in_mod); } if(b/2) mult = multiply(mult, mult, in_mod); b /= 2; } return prod; } auto mod_inv(auto q, const int in_mod) { return power(q, in_mod - 2, in_mod); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define stp cout << fixed << setprecision(20); int digit_sum(int x){ int sm = 0; while(x){ sm += x%10; x/= 10; } return sm; } void solv(){ int n; cin>>n; int cnt = 0; for(int sm = 1;sm<= 200;sm++){ if(n %sm == 0){ if( digit_sum(n/sm) == sm){ cnt++; } } } cout<<cnt<<endl; } void solve() { int t = 1; cin>>t; for(int T=1;T<=t;T++) { // cout<<"Case #"<<T<<": "; solv(); } } signed main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL); auto clk = clock(); // -------------------------------------Code starts here--------------------------------------------------------------------- signed t = 1; // cin >> t; for (signed test = 1; test <= t; test++) { // cout<<"Case #"<<test<<": "; solve(); } // -------------------------------------Code ends here------------------------------------------------------------------ clk = clock() - clk; #ifndef ONLINE_JUDGE cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n"; #endif return 0; } /* 000100 1000100 1 0 -1 -2 -1 -2 -3 */ , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { 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]; 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(); } } public static void main (String[] args) throws IOException{ Reader sc = new Reader(); int m = sc.nextInt(); int n = sc.nextInt(); int[][] arr = new int[m][n]; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ arr[i][j] = sc.nextInt(); } } int max_row_index = 0; int j = n - 1; for (int i = 0; i < m; i++) { while (j >= 0 && arr[i][j] == 1) { j = j - 1; max_row_index = i; } } System.out.println(max_row_index); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: r, c = list(map(int, input().split())) max_count = 0 max_r = 0 for i in range(r): count = input().count("1") if count > max_count: max_count = count max_r = i print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int a[max1][max1]; signed main() { int n,m; cin>>n>>m; FOR(i,n){ FOR(j,m){cin>>a[i][j];}} int cnt=0; int ans=0; int res=0; FOR(i,n){ cnt=0; FOR(j,m){ if(a[i][j]==1){ cnt++; }} if(cnt>res){ res=cnt; ans=i; } } out(ans); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix. Constraints:- 1 < = M, N < = 1000 0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:- 3 5 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 Sample Output:- 0 Sample Input:- 4 4 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 Sample Output:- 1, I have written this Solution Code: // mat is the matrix/ 2d array // n,m are dimensions function max1Row(mat, n, m) { // write code here // do not console.log // return the answer as a number let j, max_row_index = 0; j = m - 1; for (let i = 0; i < n; i++) { // Move left until a 0 is found let flag = false; // to check whether a row has more 1's than previous while (j >= 0 && mat[i][j] == 1) { j = j - 1; // Update the index of leftmost 1 // seen so far flag = true;//present row has more 1's than previous } // if the present row has more 1's than previous if (flag) { max_row_index = i; // Update max_row_index } } if (max_row_index == 0 && mat[0][m - 1] == 0) return -1; return max_row_index; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader s=new BufferedReader(new InputStreamReader(System.in)); String []S=s.readLine().split(" "); long A=Long.parseLong(S[0]); long B=Long.parseLong(S[1]); long T=Long.parseLong(S[2]); findmaxsweetness(A,B,T); } public static void findmaxsweetness(long A,long B,long T){ long start=0; long end=1000000001; while(start<end){ long mid=start+(end-start)/2; long amount=findsweetness(A,B,mid); if(amount>T){ end=mid; } else{ start=mid+1; } } if(start==0) System.out.println(start); else System.out.println(start-1); } public static long findsweetness(long A,long B,long mid){ String S=String.valueOf(mid); long len=S.length(); long result= (A*mid)+(B*len); return result; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: a,b,t=map(int,input().split()) if(a+b>t): print(0) exit() i=1 j=1000000000 while i<=j: m=(i+j)//2 v1=str(m) v=(a*m)+(len(v1)*b) if v>t: j=m-1 else: ans=m i=m+1 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif ll A,B,X; cin >> A >> B >> X; ll lb = 0, ub = 1000000001, mid; while (ub - lb > 1) { mid = (ub + lb) / 2; (A*mid+B*to_string(mid).length() <= X ? lb : ub) = mid; } cout << lb << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String str[]=br.readLine().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } long res=0; for (int i=0;i<32;i++){ long cnt=0; for (int j=0;j<n;j++) if ((a[j] & (1 << i)) == 0) cnt++; res=(res+(cnt*(n-cnt)*2))%1000000007; } System.out.println(res%1000000007); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: def suBD(arr, n): ans = 0 # Initialize result for i in range(0, 64): count = 0 for j in range(0, n): if ( (arr[j] & (1 << i)) ): count+= 1 ans += (count * (n - count)) * 2; return (ans)%(10**9+7) n=int(input()) arr = map(int,input().split()) arr=list(arr) print(suBD(arr, n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 101 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }signed main(){ int N; cin>>N; int a[55]; int A[N]; FOR(i,N){ cin>>A[i];} for(int i=0;i<55;i++){ a[i]=0; } int ans=1,p=2; for(int i=0;i<55;i++){ for(int j=0;j<N;j++){ if(ans&A[j]){a[i]++;} } ans*=p; // out(ans); } ans=0; for(int i=0;i<55;i++){ ans+=(a[i]*(N-a[i])*2); ans%=MOD; } out(ans); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean Matrix of size N*M, A cell of the matrix is called "Good" if it is completely surrounded by the cells containing '1' i.e. each adjacent cell (which shares a common edge) contains '1'. Your task is to find the number of such cells. See the below example for a better understandingFirst line of input contains two space- separated integers N and M. Next N lines of input contain M space- separated integers depicting the values of the matrix. Constraints:- 3 <= N, M <= 500 0 <= Matrix[][] <= 1Print the number of good cells.Sample Input:- 3 3 1 1 0 1 1 1 1 1 1 Sample Output:- 1 Explanation:- Only cell at position 1, 1 is good Sample Input:- 5 4 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Sample Output:- 3 Explanation:- (1, 2), (2, 1) and (3, 2) are good cells, I have written this Solution Code: // mat is the matrix/ 2d array // n,m are dimensions function goodCell(mat, n, m) { // write code here // do not console.log // return the answer as a number let cnt = 0; for (let i = 1; i < n - 1; i++) { for (let j = 1; j < m - 1; j++) { if (mat[i - 1][j] == 1 && mat[i + 1][j] == 1 && mat[i][j - 1] == 1 && mat[i][j + 1] == 1) { cnt++; } } } return cnt } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean Matrix of size N*M, A cell of the matrix is called "Good" if it is completely surrounded by the cells containing '1' i.e. each adjacent cell (which shares a common edge) contains '1'. Your task is to find the number of such cells. See the below example for a better understandingFirst line of input contains two space- separated integers N and M. Next N lines of input contain M space- separated integers depicting the values of the matrix. Constraints:- 3 <= N, M <= 500 0 <= Matrix[][] <= 1Print the number of good cells.Sample Input:- 3 3 1 1 0 1 1 1 1 1 1 Sample Output:- 1 Explanation:- Only cell at position 1, 1 is good Sample Input:- 5 4 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Sample Output:- 3 Explanation:- (1, 2), (2, 1) and (3, 2) are good cells, I have written this Solution Code: N, M= list(map(int,input().split())) mat =[] for i in range(N): List =list(map(int,input().split()))[:M] mat.append(List) count =0 for i in range(1,N-1): for j in range(1,M-1): if (mat[i][j-1] == 1 and mat[i][j+1] == 1 and mat[i-1][j] == 1 and mat[i+1][j] == 1): count +=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean Matrix of size N*M, A cell of the matrix is called "Good" if it is completely surrounded by the cells containing '1' i.e. each adjacent cell (which shares a common edge) contains '1'. Your task is to find the number of such cells. See the below example for a better understandingFirst line of input contains two space- separated integers N and M. Next N lines of input contain M space- separated integers depicting the values of the matrix. Constraints:- 3 <= N, M <= 500 0 <= Matrix[][] <= 1Print the number of good cells.Sample Input:- 3 3 1 1 0 1 1 1 1 1 1 Sample Output:- 1 Explanation:- Only cell at position 1, 1 is good Sample Input:- 5 4 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Sample Output:- 3 Explanation:- (1, 2), (2, 1) and (3, 2) are good cells, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1000001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ int n,m; cin>>n>>m; int a[n][m]; FOR(i,n){ FOR(j,m){ cin>>a[i][j];}} int sum=0,sum1=0;; FOR1(i,1,n-1){ FOR1(j,1,m-1){ if(a[i-1][j]==1 && a[i+1][j]==1 && a[i][j-1]==1 && a[i][j+1]==1){ sum++; } } } out1(sum); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a boolean Matrix of size N*M, A cell of the matrix is called "Good" if it is completely surrounded by the cells containing '1' i.e. each adjacent cell (which shares a common edge) contains '1'. Your task is to find the number of such cells. See the below example for a better understandingFirst line of input contains two space- separated integers N and M. Next N lines of input contain M space- separated integers depicting the values of the matrix. Constraints:- 3 <= N, M <= 500 0 <= Matrix[][] <= 1Print the number of good cells.Sample Input:- 3 3 1 1 0 1 1 1 1 1 1 Sample Output:- 1 Explanation:- Only cell at position 1, 1 is good Sample Input:- 5 4 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 Sample Output:- 3 Explanation:- (1, 2), (2, 1) and (3, 2) are good cells, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m= sc.nextInt(); int a[][]= new int[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextInt();}} int cnt=0; for(int i=1;i<n-1;i++){ for(int j=1;j<m-1;j++){ if(a[i-1][j]==1 && a[i+1][j]==1 && a[i][j-1]==1 && a[i][j+1]==1){ cnt++; } } } System.out.print(cnt); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String [] str=br.readLine().trim().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } Arrays.sort(a); int size=a[n-1]+1; int c[]=new int[size]; for(int i=0;i<size;i++) c[i]=0; for(int i=0;i<n;i++) c[a[i]]++; int max=0,freq=c[1]; for(int i=2;i<size;i++){ if(freq<=c[i]){ freq=c[i]; max=i; } } System.out.println(max); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: n = int(input()) a = [int(x) for x in input().split()] freq = {} for x in a: if x not in freq: freq[x] = 1 else: freq[x] += 1 mx = max(freq.values()) rf = sorted(freq) for i in range(len(rf) - 1, -1, -1): if freq[rf[i]] == mx: print(rf[i]) break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } int mx = 0, id = -1; for(int i = 1; i <= 100; i++){ if(a[i] >= mx) mx = a[i], id = i; } cout << id; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); int n=Integer.parseInt(br.readLine().trim()); if(n%3==1) System.out.println("Dead"); else System.out.println("Alive"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: n = int(input().strip()) if n%3 == 1: print("Dead") else: print("Alive"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Joffrey has issued orders for Stark's execution. Now, you are trying to predict if Stark will survive or not. You are confident that Stark's survival depends on the N<sup>th</sup> fibonacci number's parity. If it is odd you will predict that Stark lives but if it is even you will predict that Stark dies. Given N, print your prediction. Fibonacci series is a series where, Fibonacci(1) = 0 Fibonacci(2) = 1 Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2); for i > 2Input Contains a single integer N. Constraints: 1 <= N <= 1000000Print "Alive" if Nth Fibonacci number is odd and print "Dead" if Nth Fibonacci number is even.Sample Input 1 3 Sample Output 1 Alive Explanation: Fibonacci(3) = 1 which is odd. Sample Input 2 4 Sample Output 1 Dead Explanation: Fibonacci(4) = 2 which is even., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; if(n%3==1) cout<<"Dead"; else cout<<"Alive"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a <b>BST</b> and some keys, the task is to insert the keys in the given BST. Duplicates are not inserted. (If a test case contains duplicate keys, you need to consider the first occurrence and ignore duplicates).<b>User Task:</b> Since this will be a functional problem. You don't have to take input. You just have to complete the function <b>insertInBST()</b> that takes "root" node and value to be inserted as parameter. The printing is done by the driver code. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^3 1 <= node values <= 10^4 <b>Sum of "N" over all testcases does not exceed 10^5</b>Return the node of BST after insertion.Input: 2 3 2 1 3 4 8 2 1 3 N N N 6 4 1 Output: 1 2 3 4 1 2 3 4 6 Explanation: Testcase 1: After inserting the node 4 the tree will be 2 / \ 1 3 \ 4 Inorder traversal will be 1 2 3 4. Testcase 2: After inserting the node 1 the tree will be 2 / \ 1 3 / \ / \ N N N 6 / 4 Inorder traversal of the above tree will be 1 2 3 4 6., I have written this Solution Code: static Node insertInBST(Node root,int key) { if(root == null) return new Node(key); if(key < root.data) root.left = insertInBST(root.left,key); else if(key > root.data) root.right = insertInBST(root.right,key); return root; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal. If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100). Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26). It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input: 2 2 3 3 2 Sample Output: -1 aba, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bo=new BufferedWriter(new OutputStreamWriter(System.out)); int t; try{ t=Integer.parseInt(br.readLine()); } catch(Exception e) { return; } while(t-->0) { String[] g=br.readLine().split(" "); int n=Integer.parseInt(g[0]); int k=Integer.parseInt(g[1]); if(k>n || (k==1) || (k>26)) { if(n==1 && k==1) bo.write("a\n"); else bo.write(-1+"\n"); } else { int extra=k-2; boolean check=true; while(n>extra) { if(check==true) bo.write("a"); else bo.write("b"); if(check==true) check=false; else check=true; n--; } for(int i=0;i<extra;i++) bo.write((char)(i+99)); bo.write("\n"); } } bo.close(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal. If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100). Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26). It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input: 2 2 3 3 2 Sample Output: -1 aba, I have written this Solution Code: t=int(input()) for tt in range(t): n,k=map(int,input().split()) if (k==1 and n>1) or (k>n): print(-1) continue s="abcdefghijklmnopqrstuvwxyz" ss="ab" if (n-k)%2==0: a=ss*((n-k)//2)+s[:k] else: a=ss*((n-k)//2)+s[:2]+"a"+s[2:k] print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N and K, find the lexicographically smallest string of length N using only the first K lowercase letters of the alphabet such that each letter is used at least once and no two adjacent characters are equal. If such a string doesn't exist, print -1.The first line of input contains a single integer, T (1 <= T <= 100). Then T lines follow, each containing two space-separated integers, N (1 <= N <= 10<sup>5</sup>) and K (1 <= K <= 26). It is guaranteed that sum of N over all test cases does not exceed 10<sup>6</sup>For each test case, output its answer in a new line.Sample Input: 2 2 3 3 2 Sample Output: -1 aba, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef long long int ll; typedef unsigned long long int ull; const long double PI = acos(-1); const ll mod=1e9+7; const ll mod1=998244353; const int inf = 1e9; const ll INF=1e18; void precompute(){ } void TEST_CASE(){ int n,k; cin >> n >> k; if(k==1){ if(n>1){ cout << -1 << endl; }else{ cout << 'a' << endl; } }else if(n<k){ cout << -1 << endl; }else if(n==k){ string s=""; for(int i=0 ; i<k ; i++){ s+=('a'+i); } cout << s << endl; }else{ string s=""; for(int i=0 ; i<(n-k+2) ; i++){ if(i%2){ s+="b"; }else{ s+="a"; } } for(int i=2 ; i<k ; i++){ s+=('a'+i); } cout << s << endl; } } signed main(){ fast; //freopen ("INPUT.txt","r",stdin); //freopen ("OUTPUT.txt","w",stdout); int test=1,TEST=1; precompute(); cin >> test; while(test--){ TEST_CASE(); } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int k = Integer.parseInt(s[1]); String str[] = br.readLine().split(" "); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(str[i]); } System.out.print(minDivisor(arr,n,k)); } static int minDivisor(int arr[],int N, int limit) { int low = 0, high = 1000000000; while (low < high) { int mid = (low + high) / 2; int sum = 0; for(int i = 0; i < N; i++) { sum += Math.ceil((double) arr[i] / (double) mid); } if(sum <= limit){ high = mid; } else{ low = mid + 1; } } return low; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil def kSum(arr, n, k): low = 0 high = 10 ** 9 while (low < high): mid = (low + high) // 2 sum = 0 for i in range(int(n)): sum += ceil( int(arr[i]) / mid) if (sum <= int(k)): high = mid else: low = mid + 1 return low n, k =input().split() arr = input().split() print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define ll long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N], n, k; bool f(int x){ int sum = 0; for(int i = 1; i <= n; i++) sum += (a[i]-1)/x + 1; return (sum <= k); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = N; while(l+1 < h){ int m = (l + h) >> 1; if(f(m)) h = m; else l = m; } cout << h; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a stack of integers and N queries. Your task is to perform these operations:- <b>push:-</b>this operation will add an element to your current stack. <b>pop:-</b>remove the element that is on top <b>top:-</b>print the element which is currently on top of stack <b>Note:-</b>if the stack is already empty then the pop operation will do nothing and 0 will be printed as a top element of the stack if it is empty.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>push()</b>:- that takes the stack and the integer to be added as a parameter. <b>pop()</b>:- that takes the stack as parameter. <b>top()</b> :- that takes the stack as parameter. <b>Constraints:</b> 1 &le; N &le; 10<sup>3</sup>You don't need to print anything else other than in <b>top</b> function in which you require to print the topmost element of your stack in a new line, if the stack is empty you just need to print 0.Input: 7 push 1 push 2 top pop top pop top Output: 2 1 0 , I have written this Solution Code: public static void push (Stack < Integer > st, int x) { st.push (x); } // Function to pop element from stack public static void pop (Stack < Integer > st) { if (st.isEmpty () == false) { int x = st.pop (); } } // Function to return top of stack public static void top(Stack < Integer > st) { int x = 0; if (st.isEmpty () == false) { x = st.peek (); } System.out.println (x); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int k = Integer.parseInt(s[1]); String str[] = br.readLine().split(" "); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(str[i]); } System.out.print(minDivisor(arr,n,k)); } static int minDivisor(int arr[],int N, int limit) { int low = 0, high = 1000000000; while (low < high) { int mid = (low + high) / 2; int sum = 0; for(int i = 0; i < N; i++) { sum += Math.ceil((double) arr[i] / (double) mid); } if(sum <= limit){ high = mid; } else{ low = mid + 1; } } return low; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil def kSum(arr, n, k): low = 0 high = 10 ** 9 while (low < high): mid = (low + high) // 2 sum = 0 for i in range(int(n)): sum += ceil( int(arr[i]) / mid) if (sum <= int(k)): high = mid else: low = mid + 1 return low n, k =input().split() arr = input().split() print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define ll long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N], n, k; bool f(int x){ int sum = 0; for(int i = 1; i <= n; i++) sum += (a[i]-1)/x + 1; return (sum <= k); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = N; while(l+1 < h){ int m = (l + h) >> 1; if(f(m)) h = m; else l = m; } cout << h; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; cin >> n; int sum = 0; for(int i = 1; i <= n; i++){ int p; cin >> p; if(p > 0) sum += p; } cout << sum; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: n=int(input()) li = list(map(int,input().strip().split())) sum=0 for i in li: if i>0: sum+=i print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); int n = Integer.parseInt(br.readLine()); String str[] = br.readLine().split(" "); long arr[] = new long[n]; long sum=0; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(str[i]); if(arr[i]>0){ sum+=arr[i]; } } System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of N integers and another integer D, your task is to perform D right circular rotations on the array and print the modified array.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>circularRotate() </b> which takes the deque, number of rotation and the number of elements in deque as parameters. Constraint: 1 <= T <= 100 1 <= N <= 100000 1 <= elements <= 10000 1 <= D <= 100000You don't need to print anything you just need to complete the function.Input: 2 5 1 2 3 4 5 6 4 1 2 3 4 7 Output: 5 1 2 3 4 2 3 4 1, I have written this Solution Code: static void circularRotate(Deque<Integer> deq, int d, int n) { // Push first d elements // from last to the beginning for (int i = 0; i < d%n; i++) { int val = deq.peekLast(); deq.pollLast(); deq.addFirst(val); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(read.readLine()); StringTokenizer st = new StringTokenizer(read.readLine()); int[] arr = new int[N]; for(int i=0; i<N; i++) { arr[i] = Integer.parseInt(st.nextToken()); } int[] prefixArr = new int[200010]; int minIndex = 0; for(int i=0; i<N; i++) { prefixArr[i] = -1; } for(int i=0; i < N; i++) { prefixArr[arr[i]] = arr[i]; while(minIndex < N && prefixArr[minIndex] != -1) { minIndex++; } System.out.println(minIndex); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, I have written this Solution Code: def mis(arr, N): m = 0 c = [0] * (N + 1) for i in range(N): if (arr[i] >= 0 and arr[i] < N): c[arr[i]] = True while (c[m]): m += 1 print(m) if __name__ == '__main__': N = int(input()) arr = list(map(int,input().split())) mis(arr, N), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define ld long double #define int long long #define double long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 const int MOD = 1e9+7; const int INF = 1LL<<60; const int N = 2e5+5; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif void solve(){ int cur = 0; set<int> s; int n; cin>>n; For(i, 0, n){ int a; cin>>a; s.insert(a); while(s.find(cur)!=s.end()) cur++; cout<<cur<<"\n"; } } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--){ solve(); // cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader read=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(read.readLine()); int count=0; int cnt[]=new int[n+2]; for(int i=0;i<n;i++){ StringTokenizer st=new StringTokenizer(read.readLine()," "); int ai=Integer.parseInt(st.nextToken()); int bi=Integer.parseInt(st.nextToken()); for(int j=ai;j<=bi;j++) { cnt[j]++; } } int ans=-1; for(int i=0;i<=n;i++){ if(cnt[i]==i) { ans=i; } } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: n=int(input()) a=[0]*(n+1) m=0 for i in range(n): b=[int(k) for k in input().split()] for j in range(b[0],b[1]+1): a[j]+=1; for i in range(n,0,-1): if a[i]==i: print(i) exit() print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: #include<stdio.h> #define maxn 1100 struct node{ int l,r; }a[maxn]; int main(){ int n,i,cnt,j,ans=-1; scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r); for (i=n;i>=0;i--) { cnt=0; for (j=1;j<=n;j++) if(a[j].l<=i&&i<=a[j].r) cnt++; if (cnt==i) {ans=i;break;} } printf("%d\n",ans); return 0; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 // Function to rotate the matrix 90 degree clockwise void rotate90Clockwise(int a[][N],int n) { // Traverse each cycle for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { // Swap elements of each cycle // in clockwise direction int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } } // Function for print matrix void printMatrix(int arr[][N],int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << arr[i][j] << " "; cout << '\n'; } } // Driver code int main() { int n; cin>>n; int arr[n][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>arr[i][j]; }} rotate90Clockwise(arr,n); printMatrix(arr,n); cout<<endl; rotate90Clockwise(arr,n); printMatrix(arr,n); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[][] = new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]= sc.nextInt(); } } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } System.out.println(); for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: x=int(input()) l1=[] for i in range(x): a1=list(map(int,input().split())) l1.append(a1) for j in range(x): for i in range(1,x+1): print(l1[-i][j], end=" ") print() print() for i in range(1,x+1): for j in range(1,x+1): print(l1[-i][-j], end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to represent the given integer as a binary number.Input contains a single integer containing the value of N. Constraints:- 0 <= N <= 1000000000Print a string containing the binary representation of the given integer.Sample Input:- 9 Sample Output:- 1001 Sample input:- 3 Sample Output:- 11, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); System.out.println(Integer.toBinaryString(N)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to represent the given integer as a binary number.Input contains a single integer containing the value of N. Constraints:- 0 <= N <= 1000000000Print a string containing the binary representation of the given integer.Sample Input:- 9 Sample Output:- 1001 Sample input:- 3 Sample Output:- 11, I have written this Solution Code: a=int(input()) print(bin(a)[2:]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to represent the given integer as a binary number.Input contains a single integer containing the value of N. Constraints:- 0 <= N <= 1000000000Print a string containing the binary representation of the given integer.Sample Input:- 9 Sample Output:- 1001 Sample input:- 3 Sample Output:- 11, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 101 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }signed main(){ int t; t=1; while(t--){ int n; cin>>n; string s; if(n==0){ s+='0'; } while(n>0){ if(n&1){ s+='1'; } else{ s+='0'; } n/=2; } reverse(s.begin(),s.end()); out(s); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: static void verticalFive(){ System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); } static void horizontalFive(){ System.out.print("* * * * *"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: def vertical5(): for i in range(0,5): print("*",end="\n") #print() def horizontal5(): for i in range(0,5): print("*",end=" ") vertical5() print(end="\n") horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: static int LikesBoth(int N, int A, int B){ return (A+B-N); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: def LikesBoth(N,A,B): return (A+B-N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: int LikesBoth(int N,int A, int B){ return (A+B-N); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges. <b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LikesBoth()</b> that takes integers N, A, and B as arguments. Constraints:- 1 <= N <= 10000 1 <= A <= N 1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:- 5 3 4 Sample Output:- 2 Sample Input:- 5 5 5 Sample Output:- 5, I have written this Solution Code: int LikesBoth(int N,int A, int B){ return (A+B-N); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String a[]=br.readLine().split(" "); int n=Integer.parseInt(a[0]); int k=Integer.parseInt(a[1]); String s[]=br.readLine().split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=Integer.parseInt(s[i]); int min=100000,max=-100000; long sum=0; for(int i=0;i<n-k+1;i++){ min=100000; max=-100000; for(int j=i;j<k+i;j++){ min=Math.min(arr[j],min); max=Math.max(arr[j],max); } sum=sum+max+min; } System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, I have written this Solution Code: from collections import deque def solve(arr,n,k): Sum = 0 S = deque() G = deque() for i in range(k): while ( len(S) > 0 and arr[S[-1]] >= arr[i]): S.pop() while ( len(G) > 0 and arr[G[-1]] <= arr[i]): G.pop() G.append(i) S.append(i) for i in range(k, n): Sum += arr[S[0]] + arr[G[0]] while ( len(S) > 0 and S[0] <= i - k): S.popleft() while ( len(G) > 0 and G[0] <= i - k): G.popleft() while ( len(S) > 0 and arr[S[-1]] >= arr[i]): S.pop() while ( len(G) > 0 and arr[G[-1]] <= arr[i]): G.pop() G.append(i) S.append(i) Sum += arr[S[0]] + arr[G[0]] return Sum n,k=map(int,input().split()) l=list(map(int,input().split())) print(solve(l,n,k)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size N, your task is to calculate the total sum of maximum and minimum elements in each subarray of size K. See example for better understanding.First line of input contains an two space separated integers depicting values of N and K, next line contains N space separated integers depicting values of Arr[i]. Constraints:- 1 < = k < = N < = 100000 -100000 < = Arr[i] < = 100000Print the required sumSample Input:- 5 3 1 2 3 4 5 Sample Output:- 18 Explanation:- For subarray 1 2 3 :- 1 + 3 = 4 For subarray 2 3 4 :- 2 + 4 = 6 For subarray 3 4 5 :- 3 + 5 = 8 total sum = 4+6+8 = 18 Sample Input:- 7 4 2 5 -1 7 -3 -1 -2 Sample Output:- 18, I have written this Solution Code: // C++ program to find sum of all minimum and maximum // elements Of Sub-array Size k. #include<bits/stdc++.h> using namespace std; #define int long long int int SumOfKsubArray(int arr[] , int n , int k) { int sum = 0; // Initialize result // The queue will store indexes of useful elements // in every window // In deque 'G' we maintain decreasing order of // values from front to rear // In deque 'S' we maintain increasing order of // values from front to rear deque< int > S(k), G(k); // Process first window of size K int i = 0; for (i = 0; i < k; i++) { // Remove all previous greater elements // that are useless. while ( (!S.empty()) && arr[S.back()] >= arr[i]) S.pop_back(); // Remove from rear // Remove all previous smaller that are elements // are useless. while ( (!G.empty()) && arr[G.back()] <= arr[i]) G.pop_back(); // Remove from rear // Add current element at rear of both deque G.push_back(i); S.push_back(i); } // Process rest of the Array elements for ( ; i < n; i++ ) { // Element at the front of the deque 'G' & 'S' // is the largest and smallest // element of previous window respectively sum += arr[S.front()] + arr[G.front()]; // Remove all elements which are out of this // window while ( !S.empty() && S.front() <= i - k) S.pop_front(); while ( !G.empty() && G.front() <= i - k) G.pop_front(); // remove all previous greater element that are // useless while ( (!S.empty()) && arr[S.back()] >= arr[i]) S.pop_back(); // Remove from rear // remove all previous smaller that are elements // are useless while ( (!G.empty()) && arr[G.back()] <= arr[i]) G.pop_back(); // Remove from rear // Add current element at rear of both deque G.push_back(i); S.push_back(i); } // Sum of minimum and maximum element of last window sum += arr[S.front()] + arr[G.front()]; return sum; } // Driver program to test above functions signed main() { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout << SumOfKsubArray(a, n, k) ; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Bob has N integers. He will divide these integers into three <b>non- empty</b> sets S1, S2 and S3. After that bob will take one integer from each set X1, X2 and X3. It can be any integer of the set. Variation of the distribution of integer is defined as V = | X1 - X2 | + | X2 - X3 | What is the best way to distribute integers in three sets so that variation is minimum? Print the minimum variation of any Integer distribution.First line contains N. Next line contains N space separated integers. <b>Constraints</b> 3 &le; N &le; 10<sup>5</sup> 1 &le; arr[i] &le; 10<sup>9</sup>Output a single integer denoting the minimum possible variation of an integer distribution.Input: 5 3 1 5 2 3 Output: 1 Explanation: S1 => 2 5 => say X1 = 2 S2 => 1 3 => say X2 = 3 S3 => 3 => say X3 = 3 V = |X1 - X2| + |X2 - X3| = |2 - 3| + |3-3| = 1, I have written this Solution Code: import java.io.*; 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); OutputWriter out = new OutputWriter(outputStream); int n=Integer.parseInt(in.next()); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(in.next()); } Arrays.sort(a); int ans=(a[1]-a[0]) + (a[2]-a[1]); for(int i=2;i+1<n;i++){ ans=Math.min(ans ,(a[i] - a[i-1]) + (a[i+1]-a[i])); } out.print(ans); out.close(); } 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 println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable