Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; long long b[n],a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=1;i<n-1;i++){ b[i]=a[i-1]*a[i+1]; } b[0]=a[0]*a[1]; b[n-1]=a[n-1]*a[n-2]; for(int i=0;i<n;i++){ cout<<b[i]<<" ";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, 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]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } System.out.print(a[0]*a[1]+" "); for(int i=1;i<n-1;i++){ System.out.print(a[i-1]*a[i+1]+" "); } System.out.print(a[n-1]*a[n-2]); } }, 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 containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 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 br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); String array[] = br.readLine().trim().split(" "); boolean decreasingOrder = false; int[] arr = new int[n]; int totalZeroCount = 0, totalOneCount = 0; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(array[i]); if(i != 0 && arr[i] < arr[i - 1]) decreasingOrder = true; if(arr[i] % 2 == 0) ++totalZeroCount; else ++totalOneCount; } if(!decreasingOrder) { System.out.println("0"); } else { int oneCount = 0; for(int i = 0; i < totalZeroCount; i++) { if(arr[i] == 1) ++oneCount; } System.out.println(oneCount); } } }, 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 containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 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(); ////////////// 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; cin>>n; int a[n]; for(int i=0;i<n;++i){ cin>>a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i]==0) cnt++; } int ans = 0; for (int i = 0; i < cnt; i++) if (a[i] == 1) ans++; cout<<ans; #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 an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: n=int(input()) l=list(map(int,input().split())) x=l.count(0) c=0 for i in range(0,x): if(l[i]==1): c+=1 print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A and an integer K. Find the maximum for each and every contiguous subarray of size K. Problem asked in Amazon, Flipkart.The first line of each test case contains a single integer N denoting the size of array and the size of subarray K. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. Constraints: 1 ≤ N ≤ 10^5 1 ≤ K ≤ N 0 ≤ A[i] <= 10^5Print the maximum for every subarray of size K.Sample Input: 9 3 1 2 3 1 4 5 2 3 6 Sample Output: 3 3 4 5 5 5 6 Explanation: Starting from the first subarray of size k = 3, we have 3 as maximum. Moving the window forward, maximum element are as 3, 4, 5, 5, 5 and 6., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void printMax(int arr[], int n, int k) { int j, max; for(int i = 0; i <= n - k; i++) { max = arr[i]; for(j = 1; j < k; j++) { if(arr[i + j] > max) { max = arr[i + j]; } } System.out.print(max + " "); } } public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1[] = br.readLine().trim().split(" "); int n = Integer.parseInt(str1[0]); int k = Integer.parseInt(str1[1]); String str2[] = br.readLine().trim().split(" "); int arr[] = new int[n]; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(str2[i]); } printMax(arr, n ,k); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A and an integer K. Find the maximum for each and every contiguous subarray of size K. Problem asked in Amazon, Flipkart.The first line of each test case contains a single integer N denoting the size of array and the size of subarray K. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. Constraints: 1 ≤ N ≤ 10^5 1 ≤ K ≤ N 0 ≤ A[i] <= 10^5Print the maximum for every subarray of size K.Sample Input: 9 3 1 2 3 1 4 5 2 3 6 Sample Output: 3 3 4 5 5 5 6 Explanation: Starting from the first subarray of size k = 3, we have 3 as maximum. Moving the window forward, maximum element are as 3, 4, 5, 5, 5 and 6., I have written this Solution Code: n,k=input().split() n=int(n) k=int(k) arr=input().split() for i in range(0,n): arr[i]=int(arr[i]) m=max(arr[0:k]) for i in range(k-1,n): if(arr[i] > m): m=arr[i] if(arr[i-k]==m): m=max(arr[i-k+1:i+1]) print (m, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A and an integer K. Find the maximum for each and every contiguous subarray of size K. Problem asked in Amazon, Flipkart.The first line of each test case contains a single integer N denoting the size of array and the size of subarray K. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. Constraints: 1 ≤ N ≤ 10^5 1 ≤ K ≤ N 0 ≤ A[i] <= 10^5Print the maximum for every subarray of size K.Sample Input: 9 3 1 2 3 1 4 5 2 3 6 Sample Output: 3 3 4 5 5 5 6 Explanation: Starting from the first subarray of size k = 3, we have 3 as maximum. Moving the window forward, maximum element are as 3, 4, 5, 5, 5 and 6., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; // A Dequeue (Double ended queue) based method for printing maximum element of // all subarrays of size k void printKMax(int arr[], int n, int k) { // Create a Double Ended Queue, Qi that will store indexes of array elements // The queue will store indexes of useful elements in every window and it will // maintain decreasing order of values from front to rear in Qi, i.e., // arr[Qi.front[]] to arr[Qi.rear()] are sorted in decreasing order std::deque<int> Qi(k); /* Process first k (or first window) elements of array */ int i; for (i = 0; i < k; ++i) { // For every element, the previous smaller elements are useless so // remove them from Qi while ((!Qi.empty()) && arr[i] >= arr[Qi.back()]) Qi.pop_back(); // Remove from rear // Add new element at rear of queue Qi.push_back(i); } // Process rest of the elements, i.e., from arr[k] to arr[n-1] for (; i < n; ++i) { // The element at the front of the queue is the largest element of // previous window, so print it cout << arr[Qi.front()] << " "; // Remove the elements which are out of this window while ((!Qi.empty()) && Qi.front() <= i - k) Qi.pop_front(); // Remove from front of queue // Remove all elements smaller than the currently // being added element (remove useless elements) while ((!Qi.empty()) && arr[i] >= arr[Qi.back()]) Qi.pop_back(); // Add current element at the rear of Qi Qi.push_back(i); } // Print the maximum element of last window cout << arr[Qi.front()]; } // Driver program to test above functions int main() { int n,k; cin>>n>>k; int arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } printKMax(arr, n, k); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: static boolean isPalindrome(int N) { int sum = 0; int rev = N; while(N > 0) { int digit = N%10; sum = sum*10+digit; N = N/10; } if(rev == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: def isPalindrome(N): sum1 = 0 rev = N while(N > 0): digit = N%10 sum1 = sum1*10+digit N = N//10 if(rev == sum1): return True return False, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } long x=1,y=0; if(n&1){ for(int i=0;i<n;i++){ if(i%2==0){ x*=a[i]; } else{ y+=a[i]; } } } else{ for(int i=0;i<n;i++){ if(i%2==0){ y+=a[i]; } else{ x*=a[i]; } } } cout<<y<<" "<<x; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , I have written this Solution Code: n = int(input()) lst = list(map(int, input().strip().split()))[:n] lst.reverse() lst_1 = 0 for i in range(1, n, 2): lst_1 += lst[i] lst_2 = 1 for i in range(0, n, 2): lst_2 *= lst[i] print(lst_1,lst_2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , 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 Arr[] = new int[n]; for(int i=0;i<n;i++){ Arr[i] = sc.nextInt(); } if(n%2==1){ long sum=0; long product=1; for(int i=0;i<n;i++){ if(i%2==0){ product*=Arr[i]; } else{ sum+=Arr[i]; } } System.out.print(sum+" "+product); } else{ long sum=0; long product=1; for(int i=0;i<n;i++){ if(i%2==1){ product*=Arr[i]; } else{ sum+=Arr[i]; } } System.out.print(sum+" "+product); } } } , 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: 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: Bodega is trying to go from point (0, 0) to (X, Y). In one move, Bodega can perform one of the following operations: 1. Go from (x, y) &rarr; (x', y), if x | x' = x' and x ≠ x'. 2. Go from (x, y) &rarr; (x, y'), if y | y' = y' and y ≠ y'. where "|" denotes the bitwise OR operator. However, a total of N points in the plane are blocked, so Bodega cannot go to those points. You are given the positions of these N blocked points. Find the number of different paths that Bodega can take modulo 998244353.The first line consists of a single integer T – the number of test cases. Then T test cases follow: The first line of each test case contains two integers X and Y, where (X, Y) denotes Bodega's destination. The second line contains a single integer N. Then N lines follow, the i<sup>th</sup> line containing two integers X<sub>i</sub> and Y<sub>i</sub>, where (X<sub>i</sub>, Y<sub>i</sub>) denotes a blocked point. <b>Constraints:</b> 1 &le; T &le; 1000 0 &le; X, Y &le; 10<sup>16</sup> 0 &le; N &le; 1000 0 &le; X<sub>i</sub> &le; X 0 &le; Y<sub>i</sub> &le; Y The sum of N across all test cases does not exceed 1000. Print T lines, the i<sup>th</sup> line containing the answer for the i<sup>th</sup> test case.Sample input 1: 1 2 2 1 2 0 Sample output 1: 1 Explanation: There are only two possible paths if not considering the blocked points, (0,0) &rarr; (2,0) &rarr; (2,2) and (0,0) &rarr; (0,2) &rarr; (2,2). As the point (2, 0) is blocked, this leaves only one possible path. Sample Input 2: 1 3 3 2 1 2 2 3 Sample Output 2: 26, I have written this Solution Code: #include <bits/stdc++.h> #define int long long using namespace std; bool Begin; const int max_n = 68, max_m = 10004, mod = 998244353; inline int read() { int x = 0; bool w = 0; char c = getchar(); while (c < '0' || c > '9') w |= c == '-', c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return w ? -x : x; } inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 ^ 48); } inline int mi(int a, int p = mod - 2) { int res = 1; while (p) { if (p & 1) res *= a, res %= mod; a *= a, a %= mod, p >>= 1; } return res; } int n, cnt, X, Y; const int N = 66; int fac[max_m], inv[max_m]; inline int C(int n, int m) { if (n < 0 || m < 0 || n < m) return 0; return fac[n] * inv[m] % mod * inv[n - m] % mod; } inline int calc(int x) { int res = 0; while (x) ++res, x -= x & -x; return res; } struct dot { int x, y, cx, cy; dot(int X = 0, int Y = 0): x(X), y(Y) { cx = calc(X), cy = calc(Y); } bool operator < (const dot &b) const { dot a = *this; if (a.x == b.x) return ( a.y < b.y); return a.x < b.x; } } a[max_m]; inline bool check(dot A, dot B) { return ((A.x & B.x) == A.x && (A.y & B.y) == A.y); } int f[max_n][max_n], g[max_m]; bool End; #define File "" signed main() { // #ifndef ONLINE_JUDGE // freopen(File ".in","r",stdin); // freopen(File ".out","w",stdout); // #endif // cerr<<"Memory : "<<(&Begin-&End)/1024.0/1024<<"\n"; f[0][0] = fac[0] = inv[0] = 1; for (register int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * i % mod; inv[N] = mi(fac[N]); for (register int i = N - 1; i; --i) inv[i] = inv[i + 1] * (i + 1) % mod; for (register int i = 0; i <= N; ++i) for (register int j = 0; j <= N; ++j) { if(i + j) f[i][j] = 0; for (register int p = 1; p <= i; ++p) f[i][j] = (f[i][j] + f[i - p][j] * C(i, p)) % mod; for (register int p = 1; p <= j; ++p) f[i][j] = (f[i][j] + f[i][j - p] * C(j, p)) % mod; } int t = read(); while(t -- ) { X = read(), Y = read(), n = cnt = read(); for (register int i = 1; i <= n; ++i) { int x = read(), y = read(); a[i] = dot(x, y); } sort(a + 1, a + 1 + n); a[++cnt] = dot(X, Y); for (register int i = 1; i <= cnt; ++i) { int sm = 0; for (register int j = 1; j < i; ++j) if (check(a[j], a[i])) sm = (sm + g[j] * f[a[i].cx - a[j].cx][a[i].cy - a[j].cy]) % mod; g[i] = (f[a[i].cx][a[i].cy] - sm + mod) % mod; } write(g[cnt]); putchar('\n'); } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a circular linked list consisting of N nodes and an integer K, your task is to add the integer K at the end of the list. <b>Note: Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><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>Insertion()</b> that takes head node of circular linked list and the integer K as parameter. Constraints: 1 <=N <= 1000 1 <= Node.data, K<= 1000Return the head node of the modified circular linked list.Sample Input 1:- 3 1- >2- >3 4 Sample Output 1:- 1- >2- >3- >4 Sample Input 2:- 3 1- >3- >2 1 Sample Output 2:- 1- >3- >2- >1, I have written this Solution Code: public static Node Insertion(Node head, int K){ Node node=head; while ( node.next != head) {node = node.next; } Node temp = new Node(K); node.next=temp; temp.next=head; return head;} , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram has a military dog who has the special ability of hearing, He can hear frequencies starting from 70Hz to 44000Hz (both inclusive). Now Ram wants to detect some unusual sounds across him. Tell "Yes" or "No" whether his dog can detect the sound or not.First line of the input contains the value of Test cases T. Each test case consists of a single integer X - the frequency of unusual sound in Hertz. <b>Constraints</b> 1 ≤ T ≤ 10<sup>4</sup> 1 ≤ X ≤ 10<sup>5</sup>Print Yes or No wether his dog can detect them or not for each test case.Sample Input 3 21 453 45000 Sample Output No Yes No, I have written this Solution Code: /** * author: tourist1256 * created: 2022-09-20 14:02:39 **/ #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 #define yn(ans) printf("%s\n", (ans) ? "Yes" : "No"); mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(int l = LLONG_MIN, int r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start = std::chrono::high_resolution_clock::now(); int tt; cin >> tt; while (tt--) { int N; cin >> N; yn(N >= 70 && N <= 44000); } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; return 0; }; , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram has a military dog who has the special ability of hearing, He can hear frequencies starting from 70Hz to 44000Hz (both inclusive). Now Ram wants to detect some unusual sounds across him. Tell "Yes" or "No" whether his dog can detect the sound or not.First line of the input contains the value of Test cases T. Each test case consists of a single integer X - the frequency of unusual sound in Hertz. <b>Constraints</b> 1 ≤ T ≤ 10<sup>4</sup> 1 ≤ X ≤ 10<sup>5</sup>Print Yes or No wether his dog can detect them or not for each test case.Sample Input 3 21 453 45000 Sample Output No Yes No, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0){ int x=s.nextInt(); boolean flag=false; for(int i=70;i<=44000;i++){ if(x==i){ flag=true; } } if(flag){ System.out.println("Yes"); } else{ System.out.println("No"); } t--; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram has a military dog who has the special ability of hearing, He can hear frequencies starting from 70Hz to 44000Hz (both inclusive). Now Ram wants to detect some unusual sounds across him. Tell "Yes" or "No" whether his dog can detect the sound or not.First line of the input contains the value of Test cases T. Each test case consists of a single integer X - the frequency of unusual sound in Hertz. <b>Constraints</b> 1 ≤ T ≤ 10<sup>4</sup> 1 ≤ X ≤ 10<sup>5</sup>Print Yes or No wether his dog can detect them or not for each test case.Sample Input 3 21 453 45000 Sample Output No Yes No, I have written this Solution Code: T = int(input()) for i in range(T): X = int(input()) if X>=70 and X<=44000: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Saurabh has a paper of size N*M and some horizontal and vertical lines in the form of arrays. Saurabh wants to know the maximum area which is trapped inside the lines. Note:- Consider the boundary of the paper to be vertical and horizontal lines. Also consider 0 indexingThe first line of input contains 4 space separated integers depicting N, M, size of array contains horizontal lines(H), size of array containing vertical lines(V). The second line contains H space separated integers depicting horizontal lines. Last lines contains V space separated integers depicting vertical lines. Constraints:- 1 <= N, M <= 10<sup>9</sup> 1 <= H, V <= 100000 0 <= horizontal lines <= N 0 <= vertical lines <= MPrint the maximum area trapped between the lines. <b>Note:</b>Area to be printed might be large print area as (area%(10<sup>9</sup> +7)).Sample Input:- 5 4 3 2 1 2 4 1 3 Sample Output:- 4 Explanation:- The area is- (2,1), (2,3) (4,1) (4,3) Sample Input:- 5 4 2 1 3 1 1 Sample Output:- 6, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int m = scn.nextInt(); int h = scn.nextInt(); int w = scn.nextInt(); int harr[] = new int[h]; int warr[] = new int[w]; for(int i=0; i<h; i++) { harr[i] = scn.nextInt(); } for(int i=0; i<w; i++) { warr[i] = scn.nextInt(); } System.out.println(maxArea( n, m, harr, warr)); } public static int maxArea(int n, int m, int[] hc, int[] vc) { Arrays.sort(hc); Arrays.sort(vc); int maxh = Math.max(hc[0], n - hc[hc.length-1]), maxv = Math.max(vc[0], m - vc[vc.length-1]); for (int i = 1; i < hc.length; i++) maxh = Math.max(maxh, hc[i] - hc[i-1]); for (int i = 1; i < vc.length; i++) maxv = Math.max(maxv, vc[i] - vc[i-1]); return (int)((long)maxh * maxv % 1000000007); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Saurabh has a paper of size N*M and some horizontal and vertical lines in the form of arrays. Saurabh wants to know the maximum area which is trapped inside the lines. Note:- Consider the boundary of the paper to be vertical and horizontal lines. Also consider 0 indexingThe first line of input contains 4 space separated integers depicting N, M, size of array contains horizontal lines(H), size of array containing vertical lines(V). The second line contains H space separated integers depicting horizontal lines. Last lines contains V space separated integers depicting vertical lines. Constraints:- 1 <= N, M <= 10<sup>9</sup> 1 <= H, V <= 100000 0 <= horizontal lines <= N 0 <= vertical lines <= MPrint the maximum area trapped between the lines. <b>Note:</b>Area to be printed might be large print area as (area%(10<sup>9</sup> +7)).Sample Input:- 5 4 3 2 1 2 4 1 3 Sample Output:- 4 Explanation:- The area is- (2,1), (2,3) (4,1) (4,3) Sample Input:- 5 4 2 1 3 1 1 Sample Output:- 6, 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); } int solve(int ha, int w, vector<int>h, vector<int> v){ sort(h.begin(),h.end()); sort(v.begin(),v.end()); h.push_back(ha); v.push_back(w); long long hh=h[0],vv=v[0];; for(int i=1;i<h.size();i++){ hh=max(hh,(1LL)*(h[i]-h[i-1])); } for(int i=1;i<v.size();i++){ vv=max(vv,(1LL)*(v[i]-v[i-1])); } return (hh*vv*1LL)%(1000000007); } signed main(){ fast(); int n; cin>>n; int m; cin>>m; int x,y; cin>>x>>y; vector<int> h(x),v(y); FOR(i,x){ cin>>h[i];} FOR(i,y){ cin>>v[i];} cout<<solve(n,m,h,v); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not. <b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements. <b>Constraints:</b> 1 &le; T &le; 10 1 &le; N &le; 10<sup>5</sup> 1 &le; K &le; 10<sup>9</sup> 1 &le; arr[i] &le; 10<sup>9</sup> <b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input: 2 5 6 1 2 3 4 6 5 2 1 3 4 5 6 Sample Output: 1 -1, I have written this Solution Code: static int isPresent(long arr[], int n, long k) { int left = 0; int right = n-1; int res = -1; while(left<=right){ int mid = (left+right)/2; if(arr[mid] == k){ res = 1; break; }else if(arr[mid] < k){ left = mid + 1; }else{ right = mid - 1; } } return res; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not. <b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements. <b>Constraints:</b> 1 &le; T &le; 10 1 &le; N &le; 10<sup>5</sup> 1 &le; K &le; 10<sup>9</sup> 1 &le; arr[i] &le; 10<sup>9</sup> <b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input: 2 5 6 1 2 3 4 6 5 2 1 3 4 5 6 Sample Output: 1 -1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; unordered_map<long long,int> m; long k; cin>>k; long long a; for(int i=0;i<n;i++){ cin>>a; m[a]++; } if(m.find(k)!=m.end()){ cout<<1<<endl; } else{ cout<<-1<<endl; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not. <b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements. <b>Constraints:</b> 1 &le; T &le; 10 1 &le; N &le; 10<sup>5</sup> 1 &le; K &le; 10<sup>9</sup> 1 &le; arr[i] &le; 10<sup>9</sup> <b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input: 2 5 6 1 2 3 4 6 5 2 1 3 4 5 6 Sample Output: 1 -1, I have written this Solution Code: def binary_search(arr, low, high, x): if high >= low: mid = (high + low) // 2 if arr[mid] == x: return 1 elif arr[mid] > x: return binary_search(arr, low, mid - 1, x) else: return binary_search(arr, mid + 1, high, x) else: return -1 def position(n,arr,x): return binary_search(arr,0,n-1,x) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not. <b>Note:</b> Use binary search to solve the problemThe first line of input contains a number of test cases T. For each test case, the first line of input contains a number of elements in the array, and the number K is separated by space. The next line contains N elements. <b>Constraints:</b> 1 &le; T &le; 10 1 &le; N &le; 10<sup>5</sup> 1 &le; K &le; 10<sup>9</sup> 1 &le; arr[i] &le; 10<sup>9</sup> <b>Sum of N over all test cases doesn't exceed 10<sup>6</sup></b>If the element is present in the array print "1" else print "-1".Sample Input: 2 5 6 1 2 3 4 6 5 2 1 3 4 5 6 Sample Output: 1 -1, I have written this Solution Code: // arr is they array to search from // x is target function binSearch(arr, x) { // write code here // do not console.log // return the 1 or -1 let l = 0; let r = arr.length - 1; let mid; while (r >= l) { mid = l + Math.floor((r - l) / 2); // If the element is present at the middle // itself if (arr[mid] == x) return 1; // If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) r = mid - 1; // Else the element can only be present // in right subarray else l = mid + 1; } // We reach here when element is not // present in array return -1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; bool EqualOrNot(int h1, int h2, int v1,int v2){ if (v2>v1&&(h1-h2)%(v2-v1)==0){ return true; } return false; } int main(){ int n1,n2,v1,v2; cin>>n1>>n2>>v1>>v2; if(EqualOrNot(n1,n2,v1,v2)){ cout<<"Yes";} else{ cout<<"No"; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2): if (v2>v1 and (h1-h2)%(v2-v1)==0): return True else: return False , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s. At the end of each second Doraemon check if their heights are equal or not. Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter. <b>Constraints:-</b> 1 <b>&le;</b> h2 < h1<b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v1 <b>&le;</b> 10<sup>4</sup> 1 <b>&le;</b> v2 <b>&le;</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False Sample input:- 4 2 2 4 Sample output:- Yes Explanation:- height of Gian goes as- 4 6 8 10. . height of Suneo goes as:- 2 6 10.. at the end of 1 second their height will become equal. Sample Input:- 5 4 1 6 Sample Output: No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){ if (v2>v1&&(h1-h2)%(v2-v1)==0){ return true; } return false; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube. <b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter. <b>Constraints:</b> 1 <= N <= 6Return the number on the opposite side.Sample Input:- 2 Sample Output:- 5 Sample Input:- 1 Sample Output:- 6, I have written this Solution Code: def DiceProblem(N): return (7-N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube. <b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter. <b>Constraints:</b> 1 <= N <= 6Return the number on the opposite side.Sample Input:- 2 Sample Output:- 5 Sample Input:- 1 Sample Output:- 6, I have written this Solution Code: int diceProblem(int N){ return (7-N); } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube. <b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter. <b>Constraints:</b> 1 <= N <= 6Return the number on the opposite side.Sample Input:- 2 Sample Output:- 5 Sample Input:- 1 Sample Output:- 6, I have written this Solution Code: static int diceProblem(int N){ return (7-N); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube. <b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter. <b>Constraints:</b> 1 <= N <= 6Return the number on the opposite side.Sample Input:- 2 Sample Output:- 5 Sample Input:- 1 Sample Output:- 6, I have written this Solution Code: int diceProblem(int N){ return (7-N); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Olivia likes triangles. Hence, John decided to give her three integers and ask whether a triangle with edge length as given three integers is possible. Help Olivia in answering it.The input consists of a single line containing three space-separated integers A, B, and C. <b>Constraints </b> 1 <= A, B, C <= 100Output "Yes" if the triangle is possible otherwise, "No" (without quotes).Sample Input 1: 5 3 4 Sample Output 1: Yes Sample Explanation 1: The possible triangle is a right-angled triangle with a hypotenuse of 5., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if(a<(b+c) && b<(c+a) && c<(a+b)){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A binary heap is a Binary Tree with following properties: 1) It’s a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Max Heap. In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The same property must be recursively true for all nodes in Binary Tree. Max Binary Heap is similar to MinHeap. Given some queries and your task is to implement the three methods insertKey, deleteKey, and extractMin on a Binary Min Heap and call them as per the query given below: 1) 1 x (a query of this type means to insert an element in the min heap with value x ) 2) 2 x (a query of this type means to remove an element at position x from the min heap) 3) 3 (a query like this removes the min element from the min heap and prints it ).The first line of the input contains an integer 'T' denoting the number of test cases. Then T test cases follow. First line of each test case contains an integer Q denoting the number of queries. The second line of each test case contains Q queries separated by space. Constraints: 1 <= T <= 100 1 <= Q <= 100 1 <= x <= 100The output for each test case of query 3 will be space separated integers having -1 if the heap is empty else the min element of the heap. Sample Input: 2 7 1 4 1 2 3 1 6 2 0 3 3 5 1 8 1 9 2 1 3 3 Sample Output: 2 6 -1 8 -1 Explanation: Testcase 1: In the first test case for query 1 4 the heap will have {4} 1 2 the heap will be {2 4} 3 removes min element from heap ie 2 and prints it now heap is {4} 1 6 inserts 6 to heap now heap is {4 6} 2 0 delete element at position 0 of heap now heap is {6} 3 remove min element from heap ie 6 and prints it now the heap is empty {} 3 since heap is empty thus no min element exist so -1 is printed ., I have written this Solution Code: // Initial Template for C++ #include <bits/stdc++.h> using namespace std; typedef long long int ll; // Structure for Min Heap struct MinHeap { int *harr; int capacity; int heap_size; // Constructor for Min Heap MinHeap(int c) { heap_size = 0; capacity = c; harr = new int[c]; } ~MinHeap() { delete[] harr; } int parent(int i) { return (i - 1) / 2; } int left(int i) { return (2 * i + 1); } int right(int i) { return (2 * i + 2); } void MinHeapify(int); // Implemented in user editor int extractMin(); void decreaseKey(int i, int new_val); void deleteKey(int i); void insertKey(int k); }; // Position this line where user code will be pasted. // Driver code int main() { int t; cin >> t; while (t--) { ll a; cin >> a; MinHeap h(a); for (ll i = 0; i < a; i++) { int c; int n; cin >> c; if (c == 1) { cin >> n; h.insertKey(n); } if (c == 2) { cin >> n; h.deleteKey(n); } if (c == 3) { cout << h.extractMin() << " "; } } cout << endl; // delete h.harr; h.harr = NULL; } return 0; } // } Driver Code Ends /*The structure of the class is struct MinHeap { int *harr; int capacity, heap_size; MinHeap(int cap) {heap_size = 0; capacity = cap; harr = new int[cap];} int extractMin(); void deleteKey(int i); void insertKey(int k); };*/ // You need to write code for below three functions /* Removes min element from min heap and returns it */ int MinHeap::extractMin() { if(heap_size==0) return -1; if(heap_size==1) { int x=harr[0]; heap_size=0; return x; } else { int x=harr[0]; swap(harr[heap_size-1],harr[0]); heap_size=heap_size-1; MinHeapify(0); return x; } } /* Removes element from position x in the min heap */ void MinHeap::deleteKey(int i) { if(i>heap_size-1) return ; decreaseKey(i,INT_MIN); extractMin(); } /* Inserts an element at position x into the min heap*/ void MinHeap::insertKey(int k) { if(heap_size==capacity) return; heap_size=heap_size+1; harr[heap_size-1]=k; int i=heap_size-1; while(i!=0 && harr[parent(i)]> harr[i]) { swap(harr[i],harr[parent(i)]); i=parent(i); } } // Decrease Key operation, helps in deleting key from heap void MinHeap::decreaseKey(int i, int new_val) { harr[i] = new_val; while (i != 0 && harr[parent(i)] > harr[i]) { swap(harr[i], harr[parent(i)]); i = parent(i); } } /* You may call below MinHeapify function in above codes. Please do not delete this code if you are not writing your own MinHeapify */ void MinHeap::MinHeapify(int i) { int l = left(i); int r = right(i); int smallest = i; if (l < heap_size && harr[l] < harr[i]) smallest = l; if (r < heap_size && harr[r] < harr[smallest]) smallest = r; if (smallest != i) { swap(harr[i], harr[smallest]); MinHeapify(smallest); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: nan, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: inp = eval(input("")) new_set = [] for i in inp: if(str(i) not in new_set): new_set.append(str(i)) print(" ".join(new_set)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: L,B,H=input().split() a=4*(int(L)+int(B)+int(H)) print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: static int Perimeter(int L, int B, int H){ return 4*(L+B+H); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, 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)); br.readLine(); String[] line = br.readLine().split(" "); int happyBalloons = 0; for(int i=1;i<=line.length;++i){ int num = Integer.parseInt(line[i-1]); if(num%2 == i%2 ){ happyBalloons++; } } System.out.println(happyBalloons); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, I have written this Solution Code: x=int(input()) arr=input().split() for i in range(0,x): arr[i]=int(arr[i]) count=0 for i in range(0,x): if(arr[i]%2==0 and (i+1)%2==0): count+=1 elif (arr[i]%2!=0 and (i+1)%2!=0): count+=1 print (count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, 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 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 n; cin>>n; int ans = 0; For(i, 1, n+1){ int a; cin>>a; if(i%2 == a%2) ans++; } cout<<ans; } 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: An array of numbers is given. It has all unique elements except one. Find the only duplicate element in that array having all other unique elements.The first line contains an integer N, the number of elements in the array. The second line contains N integers. Constraints: 1 <= N <= 10^5 1 <= Elements of Array <= 10^5Print the single duplicate number in the arrayInput 6 1 2 3 4 4 5 Output 4 Explanation: 4 is repeated in this array Input: 3 2 1 2 Output: 2, I have written this Solution Code: n = int(input()) arr = list(map(int, input().split())) l = [0] * (max(arr) + 1) for i in arr: l[i] += 1 for i in range(len(l)): if l[i] > 1: print(i), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array of numbers is given. It has all unique elements except one. Find the only duplicate element in that array having all other unique elements.The first line contains an integer N, the number of elements in the array. The second line contains N integers. Constraints: 1 <= N <= 10^5 1 <= Elements of Array <= 10^5Print the single duplicate number in the arrayInput 6 1 2 3 4 4 5 Output 4 Explanation: 4 is repeated in this array Input: 3 2 1 2 Output: 2, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int m = 100001; int main(){ int n,k; cin>>n; long long a[n],sum=0; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]<0){ a[i]=-a[i]; } } sort(a,a+n); for(int i=0;i<n-1;i++){ if(a[i]==a[i+1]){cout<<a[i];return 0;} } cout<<sum; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i=0;i<t;i++){ int n = Integer.parseInt(br.readLine()); System.out.println(Ways(n,1)); } } static int Ways(int x, int num) { int val =(x - num); if (val == 0) return 1; if (val < 0) return 0; return Ways(val, num + 1) + Ways(x, num + 1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long cnt=0; int j; void sum(int X,int j) { if(X==0){cnt++;} if(X<0) {return;} else { for(int i=j;i<=(X);i++){ X=X-i; sum(X,i+1); X=X+i; } } } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; if(n<1){cout<<0<<endl;continue;} sum(n,1); cout<<cnt<<endl; cnt=0; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: // ignore number of testcases // n is the number as provided in input function numberOfWays(n) { // write code here // do not console.log the answer // return answer as a number if(n < 1) return 0; let cnt = 0; let j; function sum(X, j) { if (X == 0) { cnt++; } if (X < 0) { return; } else { for (let i = j; i <= X; i++) { X = X - i; sum(X, i + 1); X = X + i; } } } sum(n,1); return cnt } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: for _ in range(int(input())): x = int(input()) n = 1 dp = [1] + [0] * x for i in range(1, x + 1): u = i ** n for j in range(x, u - 1, -1): dp[j] += dp[j - u] if x==0: print(0) else: print(dp[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given n and m and a matrix of size n x m. print sum of XOR of all SEPERATED ELEMENT. A element a is said to be SEPERATED element from an element B if a will not share any side with b or vice versa.first line contain two element n and m. next n line contains m space separated integer i. e. element of matrix. Constraints: 1<=n,m<=100print sum of XOR.Sample input 1: 3 4 1 2 3 4 2 3 4 5 3 4 5 6 Sample Output 1: 4 Explanation: XOR of first part of SEPERATED ELEMENTS is 2. XOR of second part of SEPERATED ELEMENTS is 2. sum of both part equal to 4., I have written this Solution Code: import java.util.*; class Main { private static int Max_Xor(int[][] mat,int n, int m) { int sum1=0,sum2=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if((i+j)%2==1) sum1^=mat[i][j]; else sum2^=mat[i][j]; } } return sum1+sum2; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n,m; n=sc.nextInt(); m=sc.nextInt(); int [][]arr=new int[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) arr[i][j]=sc.nextInt(); System.out.print(Max_Xor(arr, n, m)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: static boolean isPalindrome(int N) { int sum = 0; int rev = N; while(N > 0) { int digit = N%10; sum = sum*10+digit; N = N/10; } if(rev == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: def isPalindrome(N): sum1 = 0 rev = N while(N > 0): digit = N%10 sum1 = sum1*10+digit N = N//10 if(rev == sum1): return True return False, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to delete every kth Node from the circular linked list until only one node is left. Also, print the intermediate lists <b>Note: Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><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>deleteK()</b> that takes head node of circular linked list and the integer K as parameter. Constraints: 1 <= K <= N <= 500 1 <= Node. data<= 1000Print the intermediate nodes until one node is left as shown in example.Sample Input:- 4 2 1 2 3 4 Sample Output:- 1->2->3->4->1 1->2->4->1 2->4->2 2->2 Sample Input:- 9 4 1 2 3 4 5 6 7 8 9 Sample Output:- 1->2->3->4->5->6->7->8->9->1 1->2->3->4->6->7->8->9->1 1->2->3->4->6->7->8->1 1->2->3->6->7->8->1 2->3->6->7->8->2 2->3->6->8->2 2->3->8->2 2->3->2 2->2, I have written this Solution Code: static void printList(Node head) { if (head == null) return; Node temp = head; do { System.out.print( temp.data + "->"); temp = temp.next; } while (temp != head); System.out.println(head.data ); } /*Function to delete every kth Node*/ static Node deleteK(Node head_ref, int k) { Node head = head_ref; // If list is empty, simply return. if (head == null) return null; // take two pointers - current and previous Node curr = head, prev=null; while (true) { // Check if Node is the only Node\ // If yes, we reached the goal, therefore // return. if (curr.next == head && curr == head) break; // Print intermediate list. printList(head); // If more than one Node present in the list, // Make previous pointer point to current // Iterate current pointer k times, // i.e. current Node is to be deleted. for (int i = 0; i < k; i++) { prev = curr; curr = curr.next; } // If Node to be deleted is head if (curr == head) { prev = head; while (prev.next != head) prev = prev.next; head = curr.next; prev.next = head; head_ref = head; } // If Node to be deleted is last Node. else if (curr.next == head) { prev.next = head; } else { prev.next = curr.next; } } return head; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: def ncr(n, r): ans = 1 for i in range(1,r+1): ans *= (n - r + i) ans //= i return ans def NoOfDistributions(N, R): return ncr(N - 1, R - 1) N = int(input()) print(NoOfDistributions(N, 12)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, 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; cin>>n; int ans=1; for(int i=1;i<12;i++){ ans=ans*(n-i); ans=ans/i; } cout<<ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int rope = sc.nextInt(); System.out.println(possibleValues(rope)); } static long possibleValues(int rope) { long ans = 1; for(int i = 1; i < 12; i++) { ans *= (rope-i); ans /= i; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: static int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: def forgottenNumbers(N): ans = 0 for i in range (1,51): for j in range (1,51): if i != j and i+j==N: ans=ans+1 return ans//2 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] and a number K where K is not greater than the size of array, the task is to find the Kth smallest element in the given array. It is given that all array elements are distinct. <b>Note:</b> Do Not Use sort() STL function, Use heap data structure.The input line contains T, denoting the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers N and K. Second-line contains N space-separated integer denoting elements of the array. <b>Constraints:</b> 1 <= T <= 50 1 <= N <= 10000 1 <= K <= N 1 <= arr[i] <= 10<sup>6</sup>Corresponding to each test case, print the kth smallest element in a new line.Sample Input 1 6 3 7 10 4 3 20 15 Sample Output 7 <b>Explanation:</b> Sorted array: 3 4 7 10 15 20, 7 is the third element, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void sort(int arr[]) { int n = arr.length; for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); for (int i = n - 1; i > 0; i--) { int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; heapify(arr, i, 0); } } static void heapify(int arr[], int n, int i) { int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < n && arr[l] > arr[largest]) largest = l; if (r < n && arr[r] > arr[largest]) largest = r; if (largest != i) { int swap = arr[i]; arr[i] = arr[largest]; arr[largest] = swap; heapify(arr, n, largest); } } public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } sort(arr); System.out.println(arr[k-1]); arr=null; System.gc(); } sc.close(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] and a number K where K is not greater than the size of array, the task is to find the Kth smallest element in the given array. It is given that all array elements are distinct. <b>Note:</b> Do Not Use sort() STL function, Use heap data structure.The input line contains T, denoting the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers N and K. Second-line contains N space-separated integer denoting elements of the array. <b>Constraints:</b> 1 <= T <= 50 1 <= N <= 10000 1 <= K <= N 1 <= arr[i] <= 10<sup>6</sup>Corresponding to each test case, print the kth smallest element in a new line.Sample Input 1 6 3 7 10 4 3 20 15 Sample Output 7 <b>Explanation:</b> Sorted array: 3 4 7 10 15 20, 7 is the third element, I have written this Solution Code: for _ in range(int(input())): s,k = map(int,input().split()) lis=list(map(int,input().split())) lis.sort() print(lis[k-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] and a number K where K is not greater than the size of array, the task is to find the Kth smallest element in the given array. It is given that all array elements are distinct. <b>Note:</b> Do Not Use sort() STL function, Use heap data structure.The input line contains T, denoting the number of test cases. Each test case consists of two lines. The first line of each test case contains two integers N and K. Second-line contains N space-separated integer denoting elements of the array. <b>Constraints:</b> 1 <= T <= 50 1 <= N <= 10000 1 <= K <= N 1 <= arr[i] <= 10<sup>6</sup>Corresponding to each test case, print the kth smallest element in a new line.Sample Input 1 6 3 7 10 4 3 20 15 Sample Output 7 <b>Explanation:</b> Sorted array: 3 4 7 10 15 20, 7 is the third element, 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--){ int n, k; cin >> n >> k; priority_queue<int> s; for(int i = 1; i <= n; i++){ int p; cin >> p; s.push(-p); } int ans = 0; while(k--){ ans = -s.top(); s.pop(); } cout << ans << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of n numbers, sorted in non-decreasing order, and k queries. For each query, print the minimum index of an array element not less than the given one. Note: if the query value is greater than all the elements in the array return n+1.The first line of the input contains n and k. The second line contains n elements of the array, sorted in non- decreasing order. The third line contains k queries. All array elements and queries are integers, each of which does not exceed 2.10<sup>9</sup>. <b>Constraints</b> 0 &le; n, k &le; 10<sup>5</sup>For each of the k queries, print the minimum index of an array element not less than the given one. If there are none, print n+1.Sample Input 5 5 3 3 5 8 9 2 4 8 1 10 Sample Output 1 3 4 1 6, I have written this Solution Code: #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(int l = LLONG_MIN, int r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } double Solve() { int n, k; cin >> n >> k; vector<double> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } double l = 0, r = 1e9; auto check = [&](double x) -> bool { int piece = 0; for (int i = 0; i < n; i++) { piece += a[i] / x; } if (piece >= k) { return true; } return false; }; while (r - l > 0.000001) { double mid = l + (r - l) / 2; if (check(mid)) l = mid; else r = mid; } return l; } double Actual() { int n, k; cin >> n >> k; vector<double> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } double l = 0, r = 1e9; auto check = [&](double x) -> bool { int piece = 0; for (int i = 0; i < n; i++) { piece += a[i] / x; } if (piece >= k) { return true; } return false; }; while (r - l > 0.000001) { double mid = l + (r - l) / 2; if (check(mid)) l = mid; else r = mid; } return l; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start = std::chrono::high_resolution_clock::now(); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } while (q--) { int x; cin >> x; int l = 0, r = n - 1; while (l <= r) { int mid = l + (r - l) / 2; if (a[mid] <= x) { l = mid + 1; } else { r = mid - 1; } } cout << l << "\n"; } return 0; }; , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to traverse the list and print its elements.<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>printList()</b> that takes head node of the linked list as parameter. <b>Constraints:</b> 1 <=N <= 1000 1 <=Node.data<= 1000For each testcase you need to print the elements of the linked list separated by space. The driver code will take care of printing new line.Sample input 5 2 4 5 6 7 Sample output 2 4 5 6 7 Sample Input 4 1 2 3 5 Sample output 1 2 3 5, I have written this Solution Code: public static void printList(Node head) { while(head!=null) { System.out.print(head.val + " "); head=head.next; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Akash is hosting a farewell party and wants to serve the most delicious pizzas to his K friends. There are N restaurants in the city, numbered from 1 to N, and each restaurant has a rating between 1 and 100. Akash wants to select K different restaurants such that the minimum rating of any selected restaurant is maximized. Help Akash find the maximum possible minimum rating of the K-selected restaurants for his farewell party.The first line of the input contains 2 space-separated integers N and K. The second line of the input contains N space-separated integers denoting the rating of restaurants. <b>Constraints</b> 1 &le; K &le; N &le; 10<sup>5</sup>Print the maximum possible minimum rating of the K selected restaurants for Akash's farewell party.<b>Sample Input</b> 5 3 10 20 30 40 50 <b>Sample output</b> 30 <b>Explanation</b> Akash can select restaurants with ratings 30, 40, and 50 for his friends. The minimum rating among these restaurants is 30, which is the maximum possible minimum rating of the selected restaurants., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); cout << a[n - k] << "\n"; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an integer A and a floating point number B, upto exactly two decimal places. Compute their product, truncate its fractional part, and print the result as an integer.Since this will be a functional problem, you don't have to take input. You just have to complete the function solve() that takes an integer and a float as arguments. <b>Constraints</b> 0<=A<=2 x 10<sup>15</sup> 0<=B<sub>i</sub><=10Return the product after truncating the fractional part.Sample Input: 155 2.41 Sample Output: 373 The result is 373.55, after truncating the fractional part, we get 373., I have written this Solution Code: class Solution { long solve(long a, double b) { b = b*100 ; return (a*(long)b)/100 ; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: def ncr(n, r): ans = 1 for i in range(1,r+1): ans *= (n - r + i) ans //= i return ans def NoOfDistributions(N, R): return ncr(N - 1, R - 1) N = int(input()) print(NoOfDistributions(N, 12)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, 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; cin>>n; int ans=1; for(int i=1;i<12;i++){ ans=ans*(n-i); ans=ans/i; } cout<<ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a rope of length L which you have to cut at 11 positions to divide it into 12 ropes. Here, each of the 12 resulting ropes must have a positive integer length. Find the number of ways to do this division. Note: Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.Input contains a single integer L. Constraints: 12 <= L <= 200Print the number of ways to do the division.Sample Input 1 12 Sample Output 1 1 Sample Input 2 13 Sample Output 2 12, I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int rope = sc.nextInt(); System.out.println(possibleValues(rope)); } static long possibleValues(int rope) { long ans = 1; for(int i = 1; i < 12; i++) { ans *= (rope-i); ans /= i; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, I have written this Solution Code: n=1 index=0 li=[] while n!=0: n=int(input()) li.append(n) index=index+1 #li = list(map(int,input().strip().split())) for i in range(0,len(li)-1): print(li[i],end=" ") print(li[len(li)-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, 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=100001; int a; for(int i=0;i<n;i++){ a=sc.nextInt(); System.out.print(a+" "); if(a==0){break;} } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take input from standard input while you do not get 0 as an input. Print all the inputs separated by space. It is guaranteed that the number of integers are less than 100000.The input will contain a series of integers in one line each. Input should be taken while you have not get a 0 as an input. 0 <= input <= 10Print the input integers seperated by space.Sample Input 6 5 5 0 Sample Output 6 5 5 0 Sample Input 9 3 5 7 6 9 8 3 2 7 7 3 5 0 Sample Output 9 3 5 7 6 9 8 3 2 7 7 3 5 0, 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; while(cin >> n){ cout << n << " "; if(n == 0) break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: import java.util.*; import java.io.*; 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) { int n = Integer.parseInt(read.readLine()); int[] arr = new int[n]; String str[] = read.readLine().trim().split(" "); for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); arr = sortedSquares(arr); for(int i = 0; i < n; i++) System.out.print(arr[i] + " "); System.out.println(); } } public static int[] sortedSquares(int[] A) { int[] nums = new int[A.length]; int k=A.length-1; int i=0, j=A.length-1; while(i<=j){ if(Math.abs(A[i]) <= Math.abs(A[j])){ nums[k--] = A[j]*A[j]; j--; } else{ nums[k--] = A[i]*A[i]; i++; } } return nums; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output. <b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space. Constraints: 1 &le; T &le; 100 1 &le; N &le; 10000 -10000 &le; A[i] &le; 10000 The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput: 1 5 -7 -2 3 4 6 Output: 4 9 16 36 49, I have written this Solution Code: t = int(input()) for i in range(t): n = int(input()) for i in sorted(map(lambda j:int(j)**2,input().split())): print(i,end=' ') print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b> You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array A. The third line of the input contains an integer Q. The next Q lines contain two integers L and R. Constraints 1 <= N <= 200000 1 <= A[i] <= 1000000000 1 <= Q <= 100000 1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input 4 5 3 3 1 2 2 3 4 4 Sample Output 6 11 Explanation: The array A = [5, 3, 3, 1]. First Query: Sum = 5 + 1 = 6. Second Query: Sum = 5 + 3 + 3 = 11, 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') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main (String[] args) throws IOException { Reader sc = new Reader(); int arrSize = sc.nextInt(); long[] arr = new long[arrSize]; for(int i = 0; i < arrSize; i++) { arr[i] = sc.nextLong(); } long[] prefix = new long[arrSize]; prefix[0] = arr[0]; for(int i = 1; i < arrSize; i++) { long val = 1000000007; prefix[i - 1] %= val; long prefixSum = prefix[i - 1] + arr[i]; prefixSum %= val; prefix[i] = prefixSum; } long[] suffix = new long[arrSize]; suffix[arrSize - 1] = arr[arrSize - 1]; for(int i = arrSize - 2; i >= 0; i--) { long val = 1000000007; suffix[i + 1] %= val; long suffixSum = suffix[i + 1] + arr[i]; suffixSum %= val; suffix[i] = suffixSum; } int query = sc.nextInt(); for(int x = 1; x <= query; x++) { int l = sc.nextInt(); int r = sc.nextInt(); long val = 1000000007; long ans = 0; ans += (l != 1 ? prefix[l-2] : 0); ans %= val; ans += (r != arrSize ? suffix[r] : 0); ans %= val; System.out.println(ans); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b> You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array A. The third line of the input contains an integer Q. The next Q lines contain two integers L and R. Constraints 1 <= N <= 200000 1 <= A[i] <= 1000000000 1 <= Q <= 100000 1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input 4 5 3 3 1 2 2 3 4 4 Sample Output 6 11 Explanation: The array A = [5, 3, 3, 1]. First Query: Sum = 5 + 1 = 6. Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: n = int(input()) arr = list(map(int ,input().rstrip().split(" "))) temp = 0 modified = [] for i in range(n): temp = temp + arr[i] modified.append(temp) q = int(input()) for i in range(q): s = list(map(int ,input().rstrip().split(" "))) l = s[0] r = s[1] sum = 0 sum = ((modified[l-1]-arr[l-1])+(modified[n-1]-modified[r-1]))%1000000007 print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b> You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array A. The third line of the input contains an integer Q. The next Q lines contain two integers L and R. Constraints 1 <= N <= 200000 1 <= A[i] <= 1000000000 1 <= Q <= 100000 1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input 4 5 3 3 1 2 2 3 4 4 Sample Output 6 11 Explanation: The array A = [5, 3, 3, 1]. First Query: Sum = 5 + 1 = 6. Second Query: Sum = 5 + 3 + 3 = 11, 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 n; cin>>n; vector<int> a(n+1); vector<int> pre(n+1, 0); int tot = 0; For(i, 1, n+1){ cin>>a[i]; assert(a[i]>0LL && a[i]<=1000000000LL); tot += a[i]; pre[i]=pre[i-1]+a[i]; } int q; cin>>q; while(q--){ int l, r; cin>>l>>r; int s = tot - (pre[r]-pre[l-1]); s %= MOD; cout<<s<<"\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(); } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Check if given two number are in golden ratio. Two numbers are said to be in the golden ratio if their ratio is the same as the ratio of the sum of the two numbers to the larger number . If A>B>0 then A and B are in golden ratio if <b> A+B / A = A/B = 1.618 </b> <b>Note</b> : precision is important here .The first line of the input contains a single floating number (A). The second line of the input contains a single floating number (B). <b>Constraints</b> 1 &le; A, B &le; 500Print Yes if two numbers form a golden ratio, otherwise No.Sample Input 1 0.618 Sample Output Yes Sample Input 61.77 38.22 Sample Output No, 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); double A = sc.nextDouble(); double B = sc.nextDouble(); double f1 = 1.00d; double f2 = 2.00d; if(A > B) { f1 = A / B; f2 = (A + B) / A; } else { f1 = B / A; f2 = (A + B) / B; } f1 = Math.round(f1 * 100.0) / 100.0; f2 = Math.round(f2 * 100.0) / 100.0; if (f1 == f2) { System.out.println("Yes"); } else { System.out.println("No"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Check if given two number are in golden ratio. Two numbers are said to be in the golden ratio if their ratio is the same as the ratio of the sum of the two numbers to the larger number . If A>B>0 then A and B are in golden ratio if <b> A+B / A = A/B = 1.618 </b> <b>Note</b> : precision is important here .The first line of the input contains a single floating number (A). The second line of the input contains a single floating number (B). <b>Constraints</b> 1 &le; A, B &le; 500Print Yes if two numbers form a golden ratio, otherwise No.Sample Input 1 0.618 Sample Output Yes Sample Input 61.77 38.22 Sample Output No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; bool checkGoldenRatio(float a, float b) { if (a <= b) { float temp = a; a = b; b = temp; } std::stringstream ratio1; ratio1 << std ::fixed << std ::setprecision(3) << (a / b); std::stringstream ratio2; ratio2 << std ::fixed << std ::setprecision(3) << (a + b) / a; if ((ratio1.str() == ratio2.str()) && ratio1.str() == "1.618") { cout << "Yes" << endl; return true; } else { cout << "No" << endl; return false; } } int main() { float a,b; cin>>a>>b; checkGoldenRatio(a, b); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter. Constraints: 1 <= T <= 100 1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input: 3 3 5 6 Sample Output: 0 5 9 Explanation: For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: static int numberOfDiagonal(int N){ if(N<=3){return 0;} return (N*(N-3))/2; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter. Constraints: 1 <= T <= 100 1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input: 3 3 5 6 Sample Output: 0 5 9 Explanation: For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: int numberOfDiagonals(int n){ if(n<=3){return 0;} return (n*(n-3))/2; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter. Constraints: 1 <= T <= 100 1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input: 3 3 5 6 Sample Output: 0 5 9 Explanation: For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: def numberOfDiagonals(n): if n <=3: return 0 return (n*(n-3))//2 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Write a program to the find number of diagonals possible in N sided convex polygon.<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>numberOfDiagonal()</b> that takes the integer N parameter. Constraints: 1 <= T <= 100 1 <= N <= 10^3Return number of diagonals possible in N sided convex polygon.Sample Input: 3 3 5 6 Sample Output: 0 5 9 Explanation: For test case 2: The number of diagonals of 5 sided polygon: 5., I have written this Solution Code: int numberOfDiagonals(int n){ if(n<=3){return 0;} return (n*(n-3))/2; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a number N. You need to Fix the middle bit of N in binary form and print the result in decimal form. If number of bits in binary form of N are odd then Fix the middle bit (Like 111 to 101). If number of bits in binary form of N are even then Fix both the middle bits (Like 1111 to 1001) Note: Fixing a bit means converting a 0 to 1 and vice versa.The first line of input contains T denoting the number of test cases. T test cases follow. Each test case contains a single number N. Constraints: 1 <= T <= 100 1 <= N <= 1000000For each test case, in a new line, print the decimal form after toggling the middle bit of N.Input: 5 1 2 3 4 5 Output: 0 1 0 6 7 Examples: Test case 3: N = 3. Binary is 11. Toggle the middle bits: 00. 00 in decimal is 0 Test case 5: N = 5. Binary is 101. Toggle the middle bit: 111. 111 in decimal is 7, I have written this Solution Code: t=int(input()) while t>0: n=int(input()) count=len(bin(n))-2 if count%2!=0: print(n^(1<<(count//2))) else: n=n^(1<<(count//2)) print(n^(1<<(count//2-1))) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a number N. You need to Fix the middle bit of N in binary form and print the result in decimal form. If number of bits in binary form of N are odd then Fix the middle bit (Like 111 to 101). If number of bits in binary form of N are even then Fix both the middle bits (Like 1111 to 1001) Note: Fixing a bit means converting a 0 to 1 and vice versa.The first line of input contains T denoting the number of test cases. T test cases follow. Each test case contains a single number N. Constraints: 1 <= T <= 100 1 <= N <= 1000000For each test case, in a new line, print the decimal form after toggling the middle bit of N.Input: 5 1 2 3 4 5 Output: 0 1 0 6 7 Examples: Test case 3: N = 3. Binary is 11. Toggle the middle bits: 00. 00 in decimal is 0 Test case 5: N = 5. Binary is 101. Toggle the middle bit: 111. 111 in decimal is 7, 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 int C[sz]; signed main() { int t; cin>>t; while(t>0) { t--; int n; vector<int> A; cin>>n; while(n>0) { int p=n%2; n/=2; A.pu(p); } int x=A.size(); if(x%2==1) { A[x/2]=1-A[x/2]; }else { A[x/2]=1-A[x/2]; A[(x-1)/2]=1-A[(x-1)/2]; } int ans=0; int y=1; for(int i=0;i<A.size();i++) { ans+=y*A[i]; y*=2; } cout<<ans<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a number N. You need to Fix the middle bit of N in binary form and print the result in decimal form. If number of bits in binary form of N are odd then Fix the middle bit (Like 111 to 101). If number of bits in binary form of N are even then Fix both the middle bits (Like 1111 to 1001) Note: Fixing a bit means converting a 0 to 1 and vice versa.The first line of input contains T denoting the number of test cases. T test cases follow. Each test case contains a single number N. Constraints: 1 <= T <= 100 1 <= N <= 1000000For each test case, in a new line, print the decimal form after toggling the middle bit of N.Input: 5 1 2 3 4 5 Output: 0 1 0 6 7 Examples: Test case 3: N = 3. Binary is 11. Toggle the middle bits: 00. 00 in decimal is 0 Test case 5: N = 5. Binary is 101. Toggle the middle bit: 111. 111 in decimal is 7, I have written this Solution Code: import java.io.*; import java.util.*; 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().trim()); while(t-- > 0) { long n= Long.parseLong(read.readLine().trim()); int numberOfBits=1+(int)Math.floor(Math.log(n)/Math.log(2)); //finding number of bits if(numberOfBits%2!=0) //if bits are odd { n=n^(1<<(numberOfBits/2)); } else //else if bits are even { n=n^(1<<(numberOfBits/2)); n=n^(1<<((numberOfBits/2)-1)); } System.out.println(n); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input()) bSum=0 wSum=0 for i in range(n): c=(input().split()) for j in range(len(c)): if(i%2==0): if(j%2==0): bSum+=int(c[j]) else: wSum+=int(c[j]) else: if(j%2==0): wSum+=int(c[j]) else: bSum+=int(c[j]) print(bSum) print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, 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 { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int mat[][] = new int[N][N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) mat[i][j] = sc.nextInt(); } alternate_Matrix_Sum(mat,N); } static void alternate_Matrix_Sum(int mat[][], int N) { long sum =0, sum1 = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if((i+j)%2 == 0) sum += mat[i][j]; else sum1 += mat[i][j]; } } System.out.println(sum); System.out.print(sum1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a double linked list consisting of N nodes, your task is to reverse the linked list and return the head of the modified list.<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>Reverse()</b> that takes head node of the linked list as a parameter. Constraints: 1 <= N <= 10^3 1<=value<=100Return the head of the modified linked list.Input: 6 1 2 3 4 5 6 Output: 6 5 4 3 2 1 Explanation: After reversing the list, elements are as 6 <-> 5 <-> 4 <-> 3 <-> 2 <-> 1., I have written this Solution Code: public static Node Reverse(Node head) { Node temp = null; Node current = head; while (current != null) { temp = current.prev; current.prev = current.next; current.next = temp; current = current.prev; } if (temp != null) { head = temp.prev; } return head; }, 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. Your task is to check whether you can divide the array into two subsets of equal sum.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the values of the Arr. Constraints:- 1 <= N <= 100 1 <= Arr[i] <= 100 Note:- The sum of all elements in the array does not exceed 2000Print "YES" if the array can be divided into two subsets of equal sum else print "NO".Sample Input:- 5 1 2 3 4 6 Sample Output:- YES Explanation:- (1, 3, 4) and (2, 6) Sample Input:- 6 1 2 4 6 7 9 Sample Output:- NO, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static boolean subsetsum(int [] arr, int s, int n){ boolean [][] dp = new boolean [n+1][s+1]; for(int i=0;i<=n;i++){ dp[i][0] = true; } for(int i=1;i<=s;i++){ dp[0][i] = false; } for(int i=1;i<=n;i++){ for(int j=1;j<=s;j++){ if(j < arr[i-1]){ dp[i][j] = dp[i-1][j]; } if(j >= arr[i-1]){ dp[i][j] = dp[i-1][j] || dp[i-1][j-arr[i-1]]; } } } return dp[n][s]; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String [] s = br.readLine().split(" "); int sum = 0; int [] arr = new int [n]; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(s[i]); sum += arr[i]; } if(sum%2 == 0){ boolean flag = subsetsum(arr, sum/2, n); if(flag){ System.out.println("YES"); } else{ System.out.println("NO"); } } else{ System.out.println("NO"); } } }, 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. Your task is to check whether you can divide the array into two subsets of equal sum.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the values of the Arr. Constraints:- 1 <= N <= 100 1 <= Arr[i] <= 100 Note:- The sum of all elements in the array does not exceed 2000Print "YES" if the array can be divided into two subsets of equal sum else print "NO".Sample Input:- 5 1 2 3 4 6 Sample Output:- YES Explanation:- (1, 3, 4) and (2, 6) Sample Input:- 6 1 2 4 6 7 9 Sample Output:- NO, I have written this Solution Code: def subsets(arr, n): arr.sort() set1 = 0 set2 = 0 for i in range(n-1, -1, -1): if(set1 < set2): set1 += arr[i] else: set2 += arr[i] if(set1 == set2): print('YES') else: print('NO') n=int(input()) arr = list(map(int, input().split())) subsets(arr, n), 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. Your task is to check whether you can divide the array into two subsets of equal sum.The first line of input contains a single integer N. The next line of input contains N space separated integers depicting the values of the Arr. Constraints:- 1 <= N <= 100 1 <= Arr[i] <= 100 Note:- The sum of all elements in the array does not exceed 2000Print "YES" if the array can be divided into two subsets of equal sum else print "NO".Sample Input:- 5 1 2 3 4 6 Sample Output:- YES Explanation:- (1, 3, 4) and (2, 6) Sample Input:- 6 1 2 4 6 7 9 Sample Output:- NO, 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' #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); } int solve(int n){ int cnt=0; int p=sqrt(n); for(int i=1;i<=p;i++){ if(n%i==0){ cnt++; if(i*i!=n){cnt++;} } } return cnt; } bool dp[max1][max1]; vector<int> v; signed main(){ int n; cin>>n; int sum=0; int a[n]; FOR(i,n){ cin>>a[i]; sum+=a[i];} //out(sum); if(sum&1){out("NO");return 0;} sum/=2; for (int i = 0; i <= n; i++) {dp[i][0] = true;} for (int i = 1; i <= sum; i++) { dp[0][i] = false;} for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j < a[i - 1]){ dp[i][j] = dp[i - 1][j];} if (j >=a[i - 1]){ dp[i][j] = dp[i - 1][j] || dp[i - 1][j - a[i - 1]];} } } if(dp[n][sum]){out("YES");} else{ out("NO"); } } , 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 ArrayList of N lowercase characters. The task is to insert given elements in the list and count frequency of elements present in the list. You can use some inbuilt functions as:- add() to append element in the list contains() to check an element is present or not in the list collections.frequency() to find the frequency of the element in the list.<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>insert()</b> and <b>freq()</b> that takes the array list and the character c as parameters. Constraints: 1 <= T <= 100 1 <= N <= 1000 c will be a lowercase english character You need to print the count of the character c if it is present else you need to print "Not Present" all in a separate line in function freq().Sample Input: 2 6 i n i e i w i t i n f n 4 i c i p i p f f Sample Output: 2 Not Present Explanation: Testcase 1: Inserting n, e, w, t, n into the list. Frequency of n is 2 in the list. Testcase 2: Inserting c, p, p into the list. Frequency of f is 0 in the list., I have written this Solution Code: // Function to insert element public static void insert(ArrayList<Character> clist, char c) { clist.add(c); } // Function to count frequency of element public static void freq(ArrayList<Character> clist, char c) { if(clist.contains(c) == true) System.out.println(Collections.frequency(clist, c)); else System.out.println("Not Present"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array A of N integers. You can perform the following operation as many times as you like:- Choose two indices i and j (1 <= i < j <= N), replace A[i] by A[i] OR A[j] and replace A[j] by A[i] AND A[j]. (where OR and AND are logical operators). All you need to do is find the maximum value of sum of squares of all integers in array A.The first line of the input contains an integer N, the number of integers in the array. The second line of the input contains N non- negative integers of the array A. Constraints 1 <= N <= 100000 0 <= A[i] <= 1000000Output a single integer, the maximum value for the sum of squares after performing the above defined operation.Sample Input 3 1 3 5 Sample Output 51 Explanation Choose indices i = 2 and j = 3. A[2] = 3 OR 5 = 7, A[3] = 3 AND 5 = 1. Sum of squares of final array 1<sup>2</sup>+ 1<sup>2</sup>+7<sup>2</sup> = 51. Sample Input 1 45 Sample Output 2025, I have written this Solution Code: import java.io.*; import java.util.*; class Main{ static long ans = 0; static int []binary = new int[31]; static void findMaximumSum(long []arr, int n) { for(long x : arr) { int idx = 0; while (x > 0) { if ((x & 1) > 0) binary[idx]++; x >>= 1; idx++; } } for(int i = 0; i < n; ++i) { long total = 0; for(int j = 0; j < 21; ++j) { if (binary[j] > 0) { total += Math.pow(2, j); binary[j]--; } } ans += total * total; } System.out.print(ans + " "); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); long arr[] = new long[N]; String str1 = br.readLine(); StringTokenizer st1 = new StringTokenizer(str1, " "); int j=0; while(st1.hasMoreTokens() && j<N) { arr[j] = Long.parseLong(st1.nextToken()); j++; } findMaximumSum(arr, N); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array A of N integers. You can perform the following operation as many times as you like:- Choose two indices i and j (1 <= i < j <= N), replace A[i] by A[i] OR A[j] and replace A[j] by A[i] AND A[j]. (where OR and AND are logical operators). All you need to do is find the maximum value of sum of squares of all integers in array A.The first line of the input contains an integer N, the number of integers in the array. The second line of the input contains N non- negative integers of the array A. Constraints 1 <= N <= 100000 0 <= A[i] <= 1000000Output a single integer, the maximum value for the sum of squares after performing the above defined operation.Sample Input 3 1 3 5 Sample Output 51 Explanation Choose indices i = 2 and j = 3. A[2] = 3 OR 5 = 7, A[3] = 3 AND 5 = 1. Sum of squares of final array 1<sup>2</sup>+ 1<sup>2</sup>+7<sup>2</sup> = 51. Sample Input 1 45 Sample Output 2025, 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 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 n; cin>>n; vector<int> ct(21, 0); For(i, 0, n){ int a; cin>>a; For(j, 0, 21){ if(a%2){ ct[j]++; } a/=2; } } int ans = 0; For(i, 0, n){ int val = 0; For(j, 0, 21){ if(ct[j]){ val += (1LL<<j); ct[j]--; } } ans += (val*val); } cout<<ans; } 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 is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. You have given a string of moves that represents the move sequence of the robot where moves[i] represent its ith move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down). Return true if the robot returns to the origin after it finishes all of its moves, or false otherwise. <b>Note:</b> The way that the robot is "facing" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.There is a single line containing a string as input. <b>Constraints:</b> 1 &le; s. length &le; 10<sup>5</sup> s contains only characters 'L', 'R', 'U', 'D'Print True if the robot returns to the origin after it finishes all of its moves, or False otherwise.Sample Input: UD Sample Output: True, I have written this Solution Code: def main(): moves = input() left = 0 up = 0 for c in moves: if(c == 'U'): up += 1 if(c == 'D'): up -= 1 if(c == 'L'): left += 1 if(c == 'R'): left -= 1 print(left == 0 and up == 0) main(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. You have given a string of moves that represents the move sequence of the robot where moves[i] represent its ith move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down). Return true if the robot returns to the origin after it finishes all of its moves, or false otherwise. <b>Note:</b> The way that the robot is "facing" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.There is a single line containing a string as input. <b>Constraints:</b> 1 &le; s. length &le; 10<sup>5</sup> s contains only characters 'L', 'R', 'U', 'D'Print True if the robot returns to the origin after it finishes all of its moves, or False otherwise.Sample Input: UD Sample Output: True, I have written this Solution Code: #include <iostream> #include <unordered_set> #include <algorithm> #include <bits/stdc++.h> using namespace std; // Function to find a pair with the given difference in an array. // This method handles duplicates in the array bool Journey(string &s){ int n=s.size(); int curr_x=0,curr_y=0; for(int i=0;i<n;i++){ if(s[i]=='L')curr_x--; else if(s[i]=='R')curr_x++; else if(s[i]=='U')curr_y++; else curr_y--; } //cout<<curr_x<<" "<<curr_y<<endl; if(curr_x==0&&curr_y==0)return true; return false; } int main() { string s; cin>>s; bool ans=Journey(s); if(ans) cout<<"True"<<endl; else cout<<"False"<<endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable