Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: For a given positive integer N, determine if there exist three <b>positive</b> integers a, b and c such that the following two conditions hold: 1. a + b + c = N 2. a ^ b ^ c = 0 where ^ denotes the bitwise XOR operation. If there exist such a triple (a, b, c), print the lexicographically smallest one. Else, print -1.The first line of input contains a single integer, T. T lines follow, each containing a single integer, N. <b>Constraints:</b> 1 <= T <= 10<sup>3</sup> 3 <= N <= 10<sup>18</sup>For each test, in a new line, print the lexicographically smallest triple (a, b, c) if it exists, else print -1.Sample Input: 3 3 6 12 Sample Output: -1 1 2 3 2 4 6, I have written this Solution Code: import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; import static java.lang.Math.*; import static java.lang.System.out; public class Main { void solve(){ long n= in.nextLong(); if(n%2==1){ sb.append(-1).append("\n"); } else{ long cnt=0; n=n/2; while(n%2==0){ cnt++; n=n>>1; } long x=(1L<<cnt); long y=(1L<<cnt); long z=0; while(n!=0){ n=n>>1; cnt++; if((n&1)==1){ y+=(1L<<cnt); z+=(1L<<cnt); } } long[] a= new long[3]; a[0]=x; a[1]=y; a[2]=z; sort(a); if(a[0]!=0){ sb.append(a[0]).append(" "); sb.append(a[1]).append(" "); sb.append(a[2]).append("\n"); } else{ sb.append(-1).append("\n"); } } } FastReader in; StringBuffer sb; public static void main(String[] args) { new Main().run(); } void run(){ in= new FastReader(); start(); } void start(){ sb= new StringBuffer(); for(int t=in.nextInt();t>0;t--) { solve(); } out.print(sb); } void swap( int i , int j) { int tmp = i; i = j; j = tmp; } long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int lower_bound(long[] a, long x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } int upper_bound(long[] arr, int key) { int i=0, j=arr.length-1; if (arr[j]<=key) return j+1; if(arr[i]>key) return i; while (i<j){ int mid= (i+j)/2; if(arr[mid]<=key){ i= mid+1; }else{ j=mid; } } return i; } void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } int[] intArr(int n){ int[] res= new int[n]; for(int i=0;i<n;i++){ res[i]= in.nextInt(); } return res; } long[] longArr(int n){ long[] res= new long[n]; for(int i=0;i<n;i++){ res[i]= in.nextLong(); } return res; } boolean isDigitSumPalindrome(long N) { long sum= sumOfDigits(String.valueOf(N)); long rev=0; long org= sum; while (sum!=0){ long d= sum%10; rev = rev*10 +d; sum /= 10; } return org == rev; } long sumOfDigits(String n){ long sum= 0; for (char c: n.toCharArray()){ sum += Integer.parseInt(String.valueOf(c)); } return sum; } long[] revArray(long[] arr) { int n= arr.length; int i=0, j=n-1; while (i<j){ long temp= arr[i]; arr[i]= arr[j]; arr[j]= temp; i++; j--; } return arr; } long gcd(long a, long b){ if (b==0) return a; return gcd(b, a%b); } long lcm(long a,long b){ return (a*b)/gcd(a,b); } static class Pair implements Comparable<Pair>{ long first; long second; Pair(long x, long y){ this.first=x; this.second=y; } @Override public int compareTo(Pair o) { return 0; } } public static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st==null || !st.hasMoreElements()){ try{ st=new StringTokenizer(br.readLine()); }catch (Exception e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ String str=""; try{ str=br.readLine(); }catch (Exception e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree containing with N nodes and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to a value X. Example: A tree given below<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>countSubtreesWithSumX()</b> that takes "root" node and the integer x as parameter. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^3 1 <= node values <= 10^4 <b>Sum of "N" over all testcases does not exceed 10^5</b>Return the number of subtrees with sum X. The driver code will take care of printing it.Sample Input: 1 3 5 1 2 3 Sum=5 Tree:- 1 / \ 2 3 Sample Output: 0 Explanation: No subtree has a sum equal to 5. Sample Input:- 1 5 5 2 1 3 4 5 Sum=5 Tree:- 2 / \ 1 3 / \ 4 5 Sample Output:- 1, I have written this Solution Code: static int c = 0; static int countSubtreesWithSumXUtil(Node root,int x) { // if tree is empty if (root==null)return 0; // sum of nodes in the left subtree int ls = countSubtreesWithSumXUtil(root.left,x); // sum of nodes in the right subtree int rs = countSubtreesWithSumXUtil(root.right, x); int sum = ls + rs + root.data; // if tree's nodes sum == x if (sum == x)c++; return sum; } static int countSubtreesWithSumX(Node root, int x) { c = 0; // if tree is empty if (root==null)return 0; // sum of nodes in the left subtree int ls = countSubtreesWithSumXUtil(root.left, x); // sum of nodes in the right subtree int rs = countSubtreesWithSumXUtil(root.right, x); // check if above sum is equal to x if ((ls + rs + root.data) == x)c++; return c; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings A and B, check if the string A is a sub-string of string B or not.First line of input contains a string A, the second line of the input contains the string B. Constraints:- 1 < = |A| < = |B| < = 1000 Note:- String will only contain lowercase english letters.Print "Yes" if the string A is the substring of string B, else print "No".Sample Input:- ewt newton Sample Output:- Yes Sample Input:- erf sdafa Sample Output:- No, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String A=br.readLine(); String B=br.readLine(); int j=0; boolean flag=false; for(int i=0;i<B.length();i++) { if(A.charAt(j)==B.charAt(i)) { j+=1; } else j=0; if(j==A.length()) { System.out.println("Yes"); flag=true; break; } } if(!flag) System.out.println("No"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings A and B, check if the string A is a sub-string of string B or not.First line of input contains a string A, the second line of the input contains the string B. Constraints:- 1 < = |A| < = |B| < = 1000 Note:- String will only contain lowercase english letters.Print "Yes" if the string A is the substring of string B, else print "No".Sample Input:- ewt newton Sample Output:- Yes Sample Input:- erf sdafa Sample Output:- No, I have written this Solution Code: # Take input from users MyString1 = input() MyString2 = input() if MyString1 in MyString2: print("Yes") else: print("No") , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings A and B, check if the string A is a sub-string of string B or not.First line of input contains a string A, the second line of the input contains the string B. Constraints:- 1 < = |A| < = |B| < = 1000 Note:- String will only contain lowercase english letters.Print "Yes" if the string A is the substring of string B, else print "No".Sample Input:- ewt newton Sample Output:- Yes Sample Input:- erf sdafa Sample Output:- No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; // Returns true if s1 is substring of s2 int isSubstring(string s1, string s2) { int M = s1.length(); int N = s2.length(); /* A loop to slide pat[] one by one */ for (int i = 0; i <= N - M; i++) { int j; /* For current index i, check for pattern match */ for (j = 0; j < M; j++) if (s2[i + j] != s1[j]) break; if (j == M) return i; } return -1; } /* Driver program to test above function */ int main() { string s1; string s2 ; cin>>s1>>s2; int res = isSubstring(s1, s2); if (res == -1) cout << "No"; else cout <<"Yes"; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's call a positive integer powerful if it has only one non- zero digits. For example, 5000, 4, 1, 10, and 200 are powerful integers whereas 42, 13, 666, 77, and 101 are not. You are given an integer n. You have to calculate the number of powerful integers x such that 1 &le; x &le; n.The input consists of an integer n. <b>Constraints</b> 1 &le; n &le; 999999Print one integer denoting the number of extremely round integers x such that 1 &le; x &le; n.<b>Sample Input 1</b> 9 <b>Sample Output 1</b> 9 <b>Sample Input 2</b> 42 <b>Sample Output 2</b> 13, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t=1; // cin >> t; for (int i = 0; i < t; i++){ int n; cin >> n; int ans = 0; for (int j = 1; j <= 9; j++){ int x = j; while (x <= n){ ans++; x *= 10; } } cout << ans << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have to complete a function that takes two parameters <b> First parameter:</b> an array which contains sub array in it at multi level <b>Second parameter: </b>an integer [depth] Now your task is to return a new array that have its sub array concatenated into it upto the given specified depth given in the parameter. Note:- Ignore "Generate Expected Output" for this one, since its not a DSA question the function <code>findTheString(array, depth)</code> take two parameters <b> First Parameter: </b> array which contains sub arrays <b> Second parameter: </b> <code>depth</code> which is an integer specifying till which depth we want to concatenate sub array elementsthe output will be an array with all sub array elements concatenated into it recursively up to the specified depthconst array=[2,[3,[4]]] let depth=1 const answer= findTheString(array,depth) //returns an array with 1 nested subarray concatenated console.log(answer) //[2,3,[4]] depth = 2 const answer2 = findTheString(array,depth) // returns an array with 2 nested array concatenated console.log(answer2) // [2,3,4], I have written this Solution Code: function findTheString(array,depth) { let flatArray = array.flat(depth); return flatArray; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: def OccurenceOfX(N,X): cnt=0 for i in range(1, N+1): if(X%i==0 and X/i<=N): cnt=cnt+1 return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: int OccurenceOfX(int N,long X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: int OccurenceOfX(int N,long X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; } int main() { , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; } , In this Programming Language: Java, 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: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){ int x=N; while(D-->0){ x-=x/2; x*=3; } System.out.println(x); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } cout << x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } printf("%d", x); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D): ans = N while D > 0: ans = ans - ans//2 ans = ans*3 D = D-1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: // n is the input number function recSum(n) { // write code here // do not console.log // return the answer as a number if (n < 10) return n; return n % 10 + recSum(Math.floor(n / 10)) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: static long Sum(long n) { if(n==0){return 0;} return n%10+Sum(n/10); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd. Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow. <b>Constraints:</b> 1 <= N <=10<sup>5</sup> 1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input : 5 1 1 2 2 3 Output: 3, 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 noofterm=Integer.parseInt(br.readLine()); int arr[] = new int[noofterm]; String s[] = br.readLine().split(" "); for(int i=0; i<noofterm;i++){ arr[i]= Integer.parseInt(s[i]); } System.out.println(unique(arr)); } public static int unique(int[] inputArray) { int result = 0; for(int i=0;i<inputArray.length;i++) { result ^= inputArray[i]; } return (result>0 ? result : -1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd. Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow. <b>Constraints:</b> 1 <= N <=10<sup>5</sup> 1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input : 5 1 1 2 2 3 Output: 3, I have written this Solution Code: n = int(input()) a = [int (x) for x in input().split()] mapp={} for index,val in enumerate(a): if val in mapp: del mapp[val] else: mapp[val]=1 for key, value in mapp.items(): print(key), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd. Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow. <b>Constraints:</b> 1 <= N <=10<sup>5</sup> 1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input : 5 1 1 2 2 3 Output: 3, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; signed main() { int n; cin>>n; int p=0; for(int i=0;i<n;i++) { int a; cin>>a; p^=a; } cout<<p<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise. A substring is a contiguous sequence of characters within a string.<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>queryString()</b> that takes string "s" and Integer "n" as parameters. <b>Constraints:</b> 1 &le; s.length &le; 1000 s[i] is either '0' or '1'. 1 &le; n &le; 10<sup>9</sup>Return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.Sample 1: Input: s = "0110", n = 3 Output: true Sample 2: Input: s = "0110", n = 4 Output: false, I have written this Solution Code: class Solution { public boolean queryString(String S, int N) { for (int i = 1; i <= N; ++i) if (!S.contains(Integer.toBinaryString(i))) return false; return true; } } , 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: We define a number <b>A</b> as a good integer if: the number of divisors (excluding 1 and the number itself) of A is greater than 0 and the divisors would be in consecutive sequence when arranged in sorted order Given a number N, calculate the number of <b>good integers</b> less than or equal to N.The input contains a single integer N. <b>Constraints:</b> 1 <= N <= 10<sup>9</sup>Print the number of good integers less than or equal to N.Sample Input:- 4 Sample Output:- 1 Sample Input:- 9 Sample Output:- 3 Explanation:- 4 6 9 are the only good integers, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static int a[]=new int[100001]; static void seive(int a[]) { a[0]=1;a[1]=1; for(int i=2;i*i<=100001;i++) { if(a[i]==0) { for(int j=i*i;j<100001;j+=i) { a[j]=1; } } } } public static void main (String[] args) throws IOException{ BufferedReader scan=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(scan.readLine()); seive(a); if(n<4) { System.out.println(0); } else if(n<6) { System.out.println(1); } else if(n<9) { System.out.println(2); } else { int ans=2; for(int i=3;i*i<=n;i+=2) { if(a[i]==0) { ans++; } } System.out.println(ans); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We define a number <b>A</b> as a good integer if: the number of divisors (excluding 1 and the number itself) of A is greater than 0 and the divisors would be in consecutive sequence when arranged in sorted order Given a number N, calculate the number of <b>good integers</b> less than or equal to N.The input contains a single integer N. <b>Constraints:</b> 1 <= N <= 10<sup>9</sup>Print the number of good integers less than or equal to N.Sample Input:- 4 Sample Output:- 1 Sample Input:- 9 Sample Output:- 3 Explanation:- 4 6 9 are the only good integers, I have written this Solution Code: // author-Shivam gupta #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 MOD 1000000007 #define read(type) readInt<type>() #define max1 100001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' const double pi=acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<string> VS; typedef vector<PII> VII; typedef vector<VI> VVI; typedef map<int,int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; typedef long int li; typedef unsigned long int uli; typedef long long int ll; typedef unsigned long long int ull; bool isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main(){ ll n; cin>>n; ll x=100001; bool a[x]; FOR(i,x){ a[i]=false; } for(int i=2;i<=x;i++){ if(a[i]==false){ for(int j=i+i;j<=x;j+=i){ a[j]=true; } } } ll ans=(sqrt(n)); ll cnt=0; for(int i=2;i<=ans;i++){ if(a[i]==false){ cnt++; } } if(n>5){cnt++;} out(cnt); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){ int x=N; while(D-->0){ x-=x/2; x*=3; } System.out.println(x); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } cout << x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } printf("%d", x); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D): ans = N while D > 0: ans = ans - ans//2 ans = ans*3 D = D-1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: def factorial(n): if(n == 1): return 1 return n * factorial(n-1) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: static int Factorial(int N) { if(N==0){ return 1;} return N*Factorial(N-1); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: // n is the input number function factorial(n) { // write code here // do not console.log // return the answer as a number if (n == 1 ) return 1; return n * factorial(n-1) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: def factorial(n): if(n == 1): return 1 return n * factorial(n-1) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: static int Factorial(int N) { if(N==0){ return 1;} return N*Factorial(N-1); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find factorial of a given number N. <b>Note: </b> The Factorial of a number is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24 (4*3*2*1).<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Factorial()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 15 Return the factorial of the given number.Sample Input:- 5 Sample Output:- 120 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: // n is the input number function factorial(n) { // write code here // do not console.log // return the answer as a number if (n == 1 ) return 1; return n * factorial(n-1) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N. Constraints: 1 < = T < = 100 1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input: 2 5 10 Sample Output: 15 55, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); System.out.println(n*(n+1)/2); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N. Constraints: 1 < = T < = 100 1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input: 2 5 10 Sample Output: 15 55, I have written this Solution Code: for t in range(int(input())): n = int(input()) print(n*(n+1)//2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N. Constraints: 1 < = T < = 100 1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input: 2 5 10 Sample Output: 15 55, 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; cout<<(n*(n+1))/2<<endl; } }, In this Programming Language: C++, 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: You are given an undirected tree with N vertices and our task is to colour the vertices of the tree. For simplicity, the colours are represented by integers from 1 to N. Some of the vertices have already been assigned a colour, and the remaining are uncoloured. Let's represent the colour of vertex k by A<sub>k</sub>. If A<sub>k</sub> is -1, this means that the vertex k is initially uncoloured. Otherwise, the vertex k is initially coloured with colour A<sub>k</sub>. We call a colouring to be valid if no two adjacent vertices have the same colour, i.e, if two vertices have an edge in between them, then the colours assigned to them must be different. You are not allowed to change the colour of vertices whose colour is given in the input. But you must colour the initially uncoloured vertices using any of the N colours, so that all the vertices get coloured. There could be multiple ways to do so, hence to simplify our task, we define the cost of the colouring as the sum of A<sub>k</sub> for all k from 1 to N after all the vertices have been coloured (you need to consider all i's even if it's coloured initially). Find the minimum cost for a valid colouring of the tree. It is guaranteed that the test cases are designed in such a way that at least one valid colouring exists.The first line has a single integer N — the number of vertices of the tree. The next N-1 lines contain two integers each, u and v (u ≠ v and 1 ≤ u, v ≤ N), denoting an edge between vertices u and v. The last line contains N integers A<sub>1</sub>, A<sub>2</sub>,... A<sub>N</sub>, denoting the colours of the vertices. If A<sub>k</sub> = -1, the k<sup>th</sup> vertex is uncoloured. Furthermore, it is guaranteed that there exists a colouring such that no two adjacent vertices have the same colour. <b>Constraints:</b> 1 ≤ N ≤ 10<sup>5</sup> 1 ≤ A<sub>k</sub> ≤ N or A<sub>k</sub> = -1 Output a single integer — the minimum cost to colour the tree.Sample Input 1: 3 3 2 3 1 2 2 -1 Sample Output 1: 5 Sample Explanation 1: 3 is the only uncoloured vertex. Since vertex 3 is connected to vertex 1 and vertex 2, both of them having colour 2, we cannot colour vertex 3 with colour 2. The optimal way will be to colour vertex 3 with colour 1. Hence, our total cost becomes 2 + 2 + 1 = 5. Sample Input 2: 4 2 1 3 4 4 1 1 -1 2 -1 Sample Output 2: 8 Sample Explanation 2: An optimal solution is to colour vertex 2 with colour 2, and vertex 4 with colour 3. Thus, total cost is 1 + 2 + 2 + 3 = 8., I have written this Solution Code: //#define ASC //#define DBG_LOCAL #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 <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #define int long long // #define int __int128 #define all(X) (X).begin(), (X).end() #define pb push_back #define endl '\n' #define fi first #define se second // const int mod = 1e9 + 7; const int mod=998'244'353; const long long INF = 2e18 + 10; // const int INF=1e9+10; #define readv(x, n) \ vector<int> x(n); \ for (auto &i : x) \ cin >> i; template <typename T> using v = vector<T>; template <typename T> using vv = vector<vector<T>>; template <typename T> using vvv = vector<vector<vector<T>>>; typedef vector<int> vi; typedef vector<double> vd; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<vector<vector<vector<int>>>> vvvvi; typedef vector<vector<double>> vvd; typedef pair<int, int> pii; int multiply(int a, int b, int in_mod) { return (int)(1LL * a * b % in_mod); } int mult_identity(int a) { return 1; } const double PI = acosl(-1); auto power(auto a, auto b, const int in_mod) { auto prod = mult_identity(a); auto mult = a % 2; while (b != 0) { if (b % 2) { prod = multiply(prod, mult, in_mod); } if(b/2) mult = multiply(mult, mult, in_mod); b /= 2; } return prod; } auto mod_inv(auto q, const int in_mod) { return power(q, in_mod - 2, in_mod); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define stp cout << fixed << setprecision(20); vvi adj; void solv() { int n; cin>>n; adj.resize(n); for(int i = 0;i<n-1;i++) { int a, b; cin>>a>>b; a--; b--; adj[a].pb(b); adj[b].pb(a); } readv(a,n); const int mx_used = 25; v<vector<int>> sm(n, vector<int>(mx_used)); vector<int> b(n); function<void(int, int)> mn_cost = [&](int root, int parent) { if(a[root] == -1) { for(int i = 1;i<mx_used;i++) sm[root][i] = i; for(auto child :adj[root]) { if(child == parent) continue; mn_cost(child, root); if(a[child] == -1) { for(int i = 1;i<mx_used;i++) { int mn = INF; for(int j = 1;j<mx_used;j++) { if(i == j) continue; mn = min(mn, sm[child][j]); } if(sm[root][i] != INF && mn != INF) sm[root][i] += mn; else sm[root][i] = INF; } } else{ for(int i = 1;i<mx_used;i++) { int mn = INF; if(i != a[child]) mn = min(mn, b[child]); if(sm[root][i] != INF && mn != INF) sm[root][i] += mn; else sm[root][i] = INF; } } } } else{ b[root] = a[root]; for(auto child:adj[root]) { if(child == parent) continue; mn_cost(child, root); int mn = INF; if(a[child] != -1) { assert(a[child] != a[root]); b[root] += b[child]; assert(b[child] != INF); } else{ int mn = INF; for(int i = 1;i<mx_used;i++) { if(i != a[root]) { mn = min(mn, sm[child][i]); } } if(b[root] != INF && mn != INF) b[root] += mn; else b[root] = INF; } } } }; mn_cost(0,0); int mn = INF; if(a[0] == -1) mn = *min_element(1 + all(sm[0])); else mn = b[0]; cout<<mn<<endl; } void solve() { int t = 1; // cin>>t; for(int i = 1;i<=t;i++) { // cout<<"Case #"<<i<<": "; solv(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL); #ifndef ONLINE_JUDGE freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); #else #ifdef ASC namespace fs = std::filesystem; std::string path = "./"; string filename; for (const auto & entry : fs::directory_iterator(path)){ if( entry.path().extension().string() == ".in"){ filename = entry.path().filename().stem().string(); } } if(filename != ""){ string input_file = filename +".in"; string output_file = filename +".out"; if (fopen(input_file.c_str(), "r")) { freopen(input_file.c_str(), "r", stdin); freopen(output_file.c_str(), "w", stdout); } } #endif #endif // auto clk = clock(); // -------------------------------------Code starts here--------------------------------------------------------------------- signed t = 1; // cin >> t; for (signed test = 1; test <= t; test++) { // cout<<"Case #"<<test<<": "; // cout<<endl; solve(); } // -------------------------------------Code ends here------------------------------------------------------------------ // clk = clock() - clk; #ifndef ONLINE_JUDGE // cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n"; #endif return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, I have written this Solution Code: n = int(input()) all_no = input().split(' ') i = 0 joined_str = '' while(i < n-1): if(i == 0): joined_str = str(int(all_no[i]) + int(all_no[i+1])) else: joined_str = joined_str + ' ' + str(int(all_no[i]) + int(all_no[i+1])) i = i + 2 print(joined_str), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, 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(); } int t; for(int i=0;i<n;i+=2){ System.out.print(a[i]+a[i+1]+" "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A. In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 100 1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1 4 1 2 6 4 output-1 3 10 input-2 10 1 2 3 4 5 6 0 7 8 9 output-2 3 7 11 7 17 Explanation(might now be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [1 2 6 4] Step 2: (1 2) and (6 4) Step 3: 3 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i+=2){ cout<<a[i]+a[i+1]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader read=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(read.readLine()); int count=0; int cnt[]=new int[n+2]; for(int i=0;i<n;i++){ StringTokenizer st=new StringTokenizer(read.readLine()," "); int ai=Integer.parseInt(st.nextToken()); int bi=Integer.parseInt(st.nextToken()); for(int j=ai;j<=bi;j++) { cnt[j]++; } } int ans=-1; for(int i=0;i<=n;i++){ if(cnt[i]==i) { ans=i; } } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: n=int(input()) a=[0]*(n+1) m=0 for i in range(n): b=[int(k) for k in input().split()] for j in range(b[0],b[1]+1): a[j]+=1; for i in range(n,0,-1): if a[i]==i: print(i) exit() print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies. Each person i makes a claim of the form: “the number of truth-tellers in this circle is between a<sub>i</sub> and b<sub>i</sub>, inclusive.” Compute the maximum number of people who could be telling the truth.The first line contains a single integer n (1 ≤ n ≤ 10^3). Each of the next n lines contains two space-separated integers a<sub>i</sub> and b<sub>i</sub> (0 ≤ a<sub>i</sub> ≤ b<sub>i</sub> ≤ n).Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements are inconsistent, print -1 instead.Sample input 3 1 1 2 3 2 2 Sample output 2 Sample input 8 0 1 1 7 4 8 3 7 1 2 4 5 3 7 1 8 Sample output -1, I have written this Solution Code: #include<stdio.h> #define maxn 1100 struct node{ int l,r; }a[maxn]; int main(){ int n,i,cnt,j,ans=-1; scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r); for (i=n;i>=0;i--) { cnt=0; for (j=1;j<=n;j++) if(a[j].l<=i&&i<=a[j].r) cnt++; if (cnt==i) {ans=i;break;} } printf("%d\n",ans); return 0; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String [] str=br.readLine().trim().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } Arrays.sort(a); int size=a[n-1]+1; int c[]=new int[size]; for(int i=0;i<size;i++) c[i]=0; for(int i=0;i<n;i++) c[a[i]]++; int max=0,freq=c[1]; for(int i=2;i<size;i++){ if(freq<=c[i]){ freq=c[i]; max=i; } } System.out.println(max); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: n = int(input()) a = [int(x) for x in input().split()] freq = {} for x in a: if x not in freq: freq[x] = 1 else: freq[x] += 1 mx = max(freq.values()) rf = sorted(freq) for i in range(len(rf) - 1, -1, -1): if freq[rf[i]] == mx: print(rf[i]) break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } int mx = 0, id = -1; for(int i = 1; i <= 100; i++){ if(a[i] >= mx) mx = a[i], id = i; } cout << id; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number (n) is represented in Linked List such that each digit corresponds to a node in linked list. Add 1 to it. <b>Note:-</b> Linked list representation of a number is from left to right i.e if the number is 123 than in linked list it is represented as 3->2->1<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>addOne()</b> that takes head node of the linked list as parameter. Constraints: 1 <=length of n<= 1000Return the head of the modified linked list.Input 1: 456 Output 1: 457 Input 2: 999 Output 2: 1000, I have written this Solution Code: static Node addOne(Node head) { Node res = head; Node temp = null, prev = null; int carry = 1, sum; while (head != null) //while both lists exist { sum = carry + head.data; carry = (sum >= 10)? 1 : 0; sum = sum % 10; head.data = sum; temp = head; head = head.next; } if (carry > 0) { Node x=new Node(carry); temp.next=x;} return res; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of several arrays that each contain integers and your goal is to write a function that will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:- [[3, 2], [1], [4, 12]] Sample output:- 22 Explanation:- 3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) { // store our final answer var sum = 0; // loop through entire array for (var i = 0; i < arr.length; i++) { // loop through each inner array for (var j = 0; j < arr[i].length; j++) { // add this number to the current final sum sum += arr[i][j]; } } console.log(sum); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N numbers, and each number is present thrice in the array except for one element which is present only once. Find that element. Note: Used extra space must be less than O(N). Use bit manipulation.First line contains a single integer N, denoting the number of elements. Next line contains N integers A[i], denoting the elements of the array. It is guaranteed that all numbers appear thrice except one. Constraints : 1 <= N <= 1e6 1 <= A[i] <= 1e8The element with frequency 1.Input: 10 1 1 1 2 3 3 3 4 4 4 Output: 2, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 #define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int getSingle(int arr[], int n) { // Initialize result int result = 0; int x, sum; // Iterate through every bit for (int i = 0; i < 32; i++) { // Find sum of set bits at ith position in all // array elements sum = 0; x = (1 << i); for (int j = 0; j < n; j++ ) { if (arr[j] & x) sum++; } // The bits with sum not multiple of 3, are the // bits of element with single occurrence. if (sum % 3) result |= x; } return result; } signed main() { int n; cin>>n; int A[n]; for(int i=0;i<n;i++) { cin>>A[i]; } cout<<getSingle(A,n); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a Doubly linked list and an integer K . Your task is to insert the integer K at the head of the given linked 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>insertnew()</b> that takes the head node and the integer K as a parameter. <b>Constraints:</b> 1 <=N<= 1000 1 <=K, value<= 1000Return the head of the modified linked listSample Input:- 5 2 1 2 3 4 5 Sample Output: 2 1 2 3 4 5 , I have written this Solution Code: public static Node insertnew(Node head, int k) { Node temp = new Node(k); temp.next = head; head.prev=temp; return temp; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: void magicTrick(int a, int b){ cout<<a+b/2; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: static void magicTrick(int a, int b){ System.out.println(a + b/2); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: A,B = map(int,input().split(' ')) C = A+B//2 print(C) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: char Race(int A, int B, int C){ if(abs(C-A)==abs(C-B)){return 'D';} if(abs(C-A)>abs(C-B)){return 'S';} else{ return 'N';} } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: def Race(A,B,C): if abs(C-A) ==abs(C-B): return 'D' if abs(C-A)>abs(C-B): return 'S' return 'N' , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: char Race(int A, int B, int C){ if(abs(C-A)==abs(C-B)){return 'D';} if(abs(C-A)>abs(C-B)){return 'S';} else{ return 'N';} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed. Given initial positions of Naruto and Sasuke as A and B recpectively. you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ). if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter. Constraints 1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input 1 2 3 Sample Output S Sample Input 1 3 2 Sample Output D, I have written this Solution Code: static char Race(int A,int B,int C){ if(Math.abs(C-A)==Math.abs(C-B)){return 'D';} if(Math.abs(C-A)>Math.abs(C-B)){return 'S';} else{ return 'N';} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the given <code>printMultiplesOfThree</code> function. You will be given two arguments <code>beginNum</code>, and <code>endNum</code>. Your task is to loop from <code>beginNum</code> to <code>endNum</code>, and if a number is a multiple of 3, print that number to the console. Note: While looping through the numbers, <code>beginNum</code> and <code>endNum</code> must not be excluded.The <code>printMultiplesOfThree</code> function takes in two arguments, both numberThe <code>printMultiplesOfThree</code> function should print numbers to the console that lie in the range and is also a multiple of 3.<strong>Example 1:</strong> let beginNum = 3; let endNum = 12; printMultiplesOfThree(beginNum, endNum); // prints 3 6 9 12 <strong>Example 2:</strong> let beginNum = 2; let endNum = 7; printMultiplesOfThree(beginNum, endNum); // prints 3 6, I have written this Solution Code: function printMultiplesOfThree(beginNum, endNum) { // write your code here for (let i = beginNum; i <= endNum; i++) { if (i % 3 === 0) { console.log(i); } } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine().trim(); char[] express = s.toCharArray(); StringBuilder ans = new StringBuilder(""); Stack<Character> stack = new Stack<>(); for(int i=0; i<express.length; i++){ if(express[i]>=65 && express[i]<=90){ ans.append(express[i]); }else if(express[i]==')'){ while(stack.peek()!='('){ ans.append(stack.peek()); stack.pop(); } stack.pop(); }else if(stack.empty() || express[i]=='(' || precedence(express[i])>=precedence(stack.peek())){ stack.push(express[i]); }else{ while(!stack.empty() && stack.peek()!='(' && precedence(stack.peek())<=express[i]){ ans.append(stack.peek()); stack.pop(); } stack.push(express[i]); } } while(!stack.empty()){ ans.append(stack.peek()); stack.pop(); } System.out.println(ans); } static int precedence(char operator){ int precedenceValue; if(operator=='+' || operator=='-') precedenceValue = 1; else if(operator=='*' || operator=='/') precedenceValue = 2; else if(operator == '^') precedenceValue = 3; else precedenceValue = -1; return precedenceValue; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: string=input() stack=list() preced={'+':1,'-':1,'*':2,'/':2,'^':3} for i in string: if i!=')': if i=='(': stack.append(i) elif i in ['*','+','/','-','^']: while(stack and stack[-1]!='(' and preced[i]<=preced[stack[-1]]): print(stack.pop(),end="") stack.append(i) else: print(i,end="") else: while(stack and stack[-1]!='('): print(stack.pop(),end="") stack.pop() while(stack): print(stack.pop(),end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; //Function to return precedence of operators int prec(char c) { if(c == '^') return 3; else if(c == '*' || c == '/') return 2; else if(c == '+' || c == '-') return 1; else return -1; } // The main function to convert infix expression //to postfix expression void infixToPostfix(string s) { std::stack<char> st; st.push('N'); int l = s.length(); string ns; for(int i = 0; i < l; i++) { // If the scanned character is an operand, add it to output string. if((s[i] >= 'a' && s[i] <= 'z')||(s[i] >= 'A' && s[i] <= 'Z')) ns+=s[i]; // If the scanned character is an ‘(‘, push it to the stack. else if(s[i] == '(') st.push('('); // If the scanned character is an ‘)’, pop and to output string from the stack // until an ‘(‘ is encountered. else if(s[i] == ')') { while(st.top() != 'N' && st.top() != '(') { char c = st.top(); st.pop(); ns += c; } if(st.top() == '(') { char c = st.top(); st.pop(); } } //If an operator is scanned else{ while(st.top() != 'N' && prec(s[i]) <= prec(st.top())) { char c = st.top(); st.pop(); ns += c; } st.push(s[i]); } } //Pop all the remaining elements from the stack while(st.top() != 'N') { char c = st.top(); st.pop(); ns += c; } cout << ns << endl; } //Driver program to test above functions int main() { string exp; cin>>exp; infixToPostfix(exp); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N. Constraints: 1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1 3 Sample Output 1 even Explanation: Xor of 1, 2 and 3 is 0 which is even. Sample Input 2 5 Sample Output 2 odd Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { try{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int input= Integer.parseInt(reader.readLine()); int result=1; for(int i=2;i<=input;i++) { result = result^i; } if(result%2 == 0) System.out.println("even"); else System.out.println("odd"); } catch(Exception e){ System.out.println("Something went wrong"+e); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N. Constraints: 1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1 3 Sample Output 1 even Explanation: Xor of 1, 2 and 3 is 0 which is even. Sample Input 2 5 Sample Output 2 odd Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., I have written this Solution Code: n=int(input()) odds = n//2 if n%2==0 else (n+1)//2 if(odds % 2 == 0 ): print("even") else: print("odd"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N. Constraints: 1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1 3 Sample Output 1 even Explanation: Xor of 1, 2 and 3 is 0 which is even. Sample Input 2 5 Sample Output 2 odd Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., 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; if(n%4==1||n%4==2) cout<<"odd"; else cout<<"even"; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: // n is the input number function recSum(n) { // write code here // do not console.log // return the answer as a number if (n < 10) return n; return n % 10 + recSum(Math.floor(n / 10)) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the sum of all the digits of the number Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter. Constraints: 1 ≤ T ≤ 100 0 ≤ N ≤ 1000000000Return sum of digits.Sample Input 2 25 28 Sample Output 7 10, I have written this Solution Code: static long Sum(long n) { if(n==0){return 0;} return n%10+Sum(n/10); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: static void verticalFive(){ System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); } static void horizontalFive(){ System.out.print("* * * * *"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: def vertical5(): for i in range(0,5): print("*",end="\n") #print() def horizontal5(): for i in range(0,5): print("*",end=" ") vertical5() print(end="\n") horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a Doubly linked list and an integer K . Your task is to insert the integer K at the head of the given linked 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>insertnew()</b> that takes the head node and the integer K as a parameter. <b>Constraints:</b> 1 <=N<= 1000 1 <=K, value<= 1000Return the head of the modified linked listSample Input:- 5 2 1 2 3 4 5 Sample Output: 2 1 2 3 4 5 , I have written this Solution Code: public static Node insertnew(Node head, int k) { Node temp = new Node(k); temp.next = head; head.prev=temp; return temp; } , In this Programming Language: Java, 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: // arr is the array of numbers, n is the number fo elements function replaceArray(arr, n) { // write code here // do not console.log // return the new array const newArr = [] newArr[0] = arr[0] * arr[1] newArr[n-1] = arr[n-1] * arr[n-2] for(let i= 1;i<n-1;i++){ newArr[i] = arr[i-1] * arr[i+1] } return newArr } , In this Programming Language: JavaScript, 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: n = int(input()) X = [int(x) for x in input().split()] lst = [] for i in range(len(X)): if i == 0: lst.append(X[i]*X[i+1]) elif i == (len(X) - 1): lst.append(X[i-1]*X[i]) else: lst.append(X[i-1]*X[i+1]) for i in lst: print(i,end=" "), In this Programming Language: Python, 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: #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, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String [] str=br.readLine().trim().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } Arrays.sort(a); int size=a[n-1]+1; int c[]=new int[size]; for(int i=0;i<size;i++) c[i]=0; for(int i=0;i<n;i++) c[a[i]]++; int max=0,freq=c[1]; for(int i=2;i<size;i++){ if(freq<=c[i]){ freq=c[i]; max=i; } } System.out.println(max); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: n = int(input()) a = [int(x) for x in input().split()] freq = {} for x in a: if x not in freq: freq[x] = 1 else: freq[x] += 1 mx = max(freq.values()) rf = sorted(freq) for i in range(len(rf) - 1, -1, -1): if freq[rf[i]] == mx: print(rf[i]) break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array. <b>Constraints:</b> 3 <= N <= 1000 1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input 5 1 4 2 4 5 Sample Output 4 <b>Explanation:-</b> 4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; for(int i = 1; i <= n; i++){ int p; cin >> p; a[p]++; } int mx = 0, id = -1; for(int i = 1; i <= 100; i++){ if(a[i] >= mx) mx = a[i], id = i; } cout << id; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces. Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input 4 5 2 3 Sample Output 2 Sample Input 2 10 10 40 Sample Output -20, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int[][]arr=new int[2][2]; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ arr[i][j]=sc.nextInt(); } } int determinent=(arr[0][0]*arr[1][1])-(arr[1][0]*arr[0][1]); System.out.print(determinent); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces. Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input 4 5 2 3 Sample Output 2 Sample Input 2 10 10 40 Sample Output -20, I have written this Solution Code: arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) lis=[] a11=arr1[0] a12=arr1[1] a21=arr2[0] a22=arr2[1] det=(a11*a22)-(a12*a21) print(det), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a 2X2 square matrix. You need to find the determinant of the matrix.The input contains two-line, each line contain two integers separated by spaces. Each element of the matrix is from 1 to 100.Output a single integer, the determinant of the matrix.Sample Input 4 5 2 3 Sample Output 2 Sample Input 2 10 10 40 Sample Output -20, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<a*d-b*c; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Peter Parker is taking part in a competition where Mr Tony Stark has come to see Peter lift the cup. But Tony can't tell what position Peter is on since the school authorities didn't display a leaderboard. Help Tony Identify which rank is Peter on by seeing his victory status in different rounds. Points are awarded on solving every question based on the difficulty level of the question which are divided into subcategories. The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.The first line contains an integer n, the number of participants on the leaderboard. The next line contains n space- separated integers containing the leaderboard points in decreasing order in the competition. The next line contains an integer m, denoting the number of times Peter is attempting the question. The last line contains m space- separated integers containing Peter's score in each attempt in the competition. <b>Constraints:-</b> 1 <= n <= 10<sup>5</sup> 1 <= m <= 10<sup>3</sup> 1 <= points, score <= 10<sup>7</sup> Note:- In the existing leaderboard, points are in descending order. Peter's points are in ascending order.Print m integers indicating Peter's rank in each competition.Sample Input:- 7 100 100 50 40 40 20 10 4 5 25 50 120 Sample Output:- 6 4 2 1, 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 n = Integer.parseInt(br.readLine()); String line1 = br.readLine(); String[] num1 = line1.trim().split("\\s+"); int[] arr1 = new int[n]; for(int i = 0; i < n; i++) { arr1[i] = Integer.parseInt(num1[i]); } int m = Integer.parseInt(br.readLine()); int[] arr2 = new int[m]; String line2 = br.readLine(); String[] num2 = line2.trim().split("\\s+"); for(int i = 0; i < m; i++) { arr2[i] = Integer.parseInt(num2[i]); } Stack<Integer> st = new Stack<>(); for(int i = 0; i < n; i++) { while(!st.isEmpty() && st.peek() == arr1[i]) st.pop(); st.push(arr1[i]); } for(int i = 0; i < m; i++) { while(!st.isEmpty() && st.peek() <= arr2[i]) st.pop(); System.out.println(st.size() + 1); st.push(arr2[i]); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Peter Parker is taking part in a competition where Mr Tony Stark has come to see Peter lift the cup. But Tony can't tell what position Peter is on since the school authorities didn't display a leaderboard. Help Tony Identify which rank is Peter on by seeing his victory status in different rounds. Points are awarded on solving every question based on the difficulty level of the question which are divided into subcategories. The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.The first line contains an integer n, the number of participants on the leaderboard. The next line contains n space- separated integers containing the leaderboard points in decreasing order in the competition. The next line contains an integer m, denoting the number of times Peter is attempting the question. The last line contains m space- separated integers containing Peter's score in each attempt in the competition. <b>Constraints:-</b> 1 <= n <= 10<sup>5</sup> 1 <= m <= 10<sup>3</sup> 1 <= points, score <= 10<sup>7</sup> Note:- In the existing leaderboard, points are in descending order. Peter's points are in ascending order.Print m integers indicating Peter's rank in each competition.Sample Input:- 7 100 100 50 40 40 20 10 4 5 25 50 120 Sample Output:- 6 4 2 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ // freopen("ou.txt", "r", stdin); // freopen("output.txt", "w", stdout); unsigned long n, m, i, tmp; cin>> n; stack<unsigned long> scores; for (i = 0; i< n; ++i) { cin>>tmp; if (scores.empty() || scores.top() != tmp) scores.push(tmp); } cin>> m; for (i = 0; i< m; ++i) { cin>>tmp; while (!scores.empty() &&tmp>= scores.top()) scores.pop(); cout<< (scores.size() + 1) <<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 positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String input[]=br.readLine().split("\\s"); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(input[i]); } System.out.print(implementMergeSort(a,0,n-1)); } public static long implementMergeSort(int arr[], int start, int end) { long count=0; if(start<end) { int mid=start+(end-start)/2; count +=implementMergeSort(arr,start,mid); count +=implementMergeSort(arr,mid+1,end); count +=merge(arr,start,end,mid); } return count; } public static long merge(int []a,int start,int end,int mid) { int i=start; int j=mid+1; int k=0; int len=end-start+1; int c[]=new int[len]; long inv_count=0; while(i<=mid && j<=end) { if(a[i]<=a[j]) { c[k++]=a[i]; i++; } else { c[k++]=a[j]; j++; inv_count +=(mid-i)+1; } } while(i<=mid) { c[k++]=a[i++]; } while(j<=end) { c[k++]=a[j++]; } for(int l=0;l<len;l++) a[start+l]=c[l]; return inv_count; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long long long _mergeSort(int arr[], int temp[], int left, int right); long long merge(int arr[], int temp[], int left, int mid, int right); /* This function sorts the input array and returns the number of inversions in the array */ long long mergeSort(int arr[], int array_size) { int temp[array_size]; return _mergeSort(arr, temp, 0, array_size - 1); } /* An auxiliary recursive function that sorts the input array and returns the number of inversions in the array. */ long long _mergeSort(int arr[], int temp[], int left, int right) { int mid, inv_count = 0; if (right > left) { /* Divide the array into two parts and call _mergeSortAndCountInv() for each of the parts */ mid = (right + left) / 2; /* Inversion count will be sum of inversions in left-part, right-part and number of inversions in merging */ inv_count += _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid + 1, right); /*Merge the two parts*/ inv_count += merge(arr, temp, left, mid + 1, right); } return inv_count; } /* This funt merges two sorted arrays and returns inversion count in the arrays.*/ long long merge(int arr[], int temp[], int left, int mid, int right) { int i, j, k; long long inv_count = 0; i = left; /* i is index for left subarray*/ j = mid; /* j is index for right subarray*/ k = left; /* k is index for resultant merged subarray*/ while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; /* this is tricky -- see above explanation/diagram for merge()*/ inv_count = inv_count + (mid - i); } } /* Copy the remaining elements of left subarray (if there are any) to temp*/ while (i <= mid - 1) temp[k++] = arr[i++]; /* Copy the remaining elements of right subarray (if there are any) to temp*/ while (j <= right) temp[k++] = arr[j++]; /*Copy back the merged elements to original array*/ for (i = left; i <= right; i++) arr[i] = temp[i]; return inv_count; } signed main() { int n; cin>>n; int a[n]; unordered_map<int,int> m; for(int i=0;i<n;i++){ cin>>a[i]; if(m.find(a[i])==m.end()){ m[a[i]]=i; } } cout<<mergeSort(a,n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pairs and vectors can be used together to achieve some amazing results. Here we will learn to use a vector that holds pairs. You are given a vector V of size N. The vector hold pair of integers. Example V={(1,2),(3,4)...}. Now, you need to sum the second elements.First line contains N denoting the size of the array. The second line contains 2*N elements where the (2i - 1)'th and (2i)'th element represent the i'th pair. Constraints: 1 <= N <= 10^5 0 <= Vi <= 10^5For each testcase, in a new line, print the required output.Input: 5 1 2 3 4 5 6 7 8 9 10 Output: 30 Explanation: Sum = 10+8+6+4+2 = 30, I have written this Solution Code: input() print(sum([int(i) for (j, i) in enumerate(input().split()) if j % 2 == 1])), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pairs and vectors can be used together to achieve some amazing results. Here we will learn to use a vector that holds pairs. You are given a vector V of size N. The vector hold pair of integers. Example V={(1,2),(3,4)...}. Now, you need to sum the second elements.First line contains N denoting the size of the array. The second line contains 2*N elements where the (2i - 1)'th and (2i)'th element represent the i'th pair. Constraints: 1 <= N <= 10^5 0 <= Vi <= 10^5For each testcase, in a new line, print the required output.Input: 5 1 2 3 4 5 6 7 8 9 10 Output: 30 Explanation: Sum = 10+8+6+4+2 = 30, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader reader =new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(reader.readLine())*2; long sum=0; String arr[]=reader.readLine().split(" "); reader.close(); for(int i=0;i<a;i++){ if(i%2==1) { sum=sum+Integer.parseInt(arr[i]); } } System.out.println(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pairs and vectors can be used together to achieve some amazing results. Here we will learn to use a vector that holds pairs. You are given a vector V of size N. The vector hold pair of integers. Example V={(1,2),(3,4)...}. Now, you need to sum the second elements.First line contains N denoting the size of the array. The second line contains 2*N elements where the (2i - 1)'th and (2i)'th element represent the i'th pair. Constraints: 1 <= N <= 10^5 0 <= Vi <= 10^5For each testcase, in a new line, print the required output.Input: 5 1 2 3 4 5 6 7 8 9 10 Output: 30 Explanation: Sum = 10+8+6+4+2 = 30, 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 = 1e3 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n, ans = 0; cin >> n; for(int i = 1; i <= 2*n; i++){ int p; cin >> p; if(i%2 == 0) ans += p; } cout << ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: def OccurenceOfX(N,X): cnt=0 for i in range(1, N+1): if(X%i==0 and X/i<=N): cnt=cnt+1 return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: int OccurenceOfX(int N,long X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: int OccurenceOfX(int N,long X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; } int main() { , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j. Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter. Constraints:- 1 <= N <= 10^5 1 <= X <= 10^9Return the count of X.Sample Input:- 5 5 Sample Output:- 2 Explanation:- table :- 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Count of occurrence of X is :- 2 Sample Input:- 10 13 Sample Output:- 0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){ int cnt=0,i; for( i=1;i<=N;i++){ if(X%i==0 && X/i<=N){cnt++;}} return cnt; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <em>The JS Date object has many useful properties. </em> Implement the function <code>whichDay</code>, which takes a Date object and returns a string like this "It is the first day of the week" depending on that object it will show the return string, which day of the week it is. (Use JS built-in functions) Note:- Sunday is the "last" day of the week while rest all days are the first, second, third, fourth, fifth, and sixth dayThe function takes an argument <code>date</code> which is a Date object.The function returns a stringconst date = new Date("2022", "1", "2") // Wed Feb 02 2022 // In the above line we create a Date object using Date Class which is used to create arbitrary dates console.log(whichDay(date)) // prints "It is the third day of the week", I have written this Solution Code: function whichDay(date) { // write code here // return the output , do not use console.log here let str = "" switch (date.getDay()) { case 0: str = 'last' break; case 1: str = 'first' break; case 2: str = 'second' break; case 3: str = 'third' break; case 4: str = 'fourth' break; case 5: str = 'fifth' break; case 6: str = 'sixth' break; default: break; } return `Today is the ${str} day of the week` }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, 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()); double arr[] = new double[N]; String str[] = br.readLine().trim().split(" "); for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); double resistance=0; int equResistance=0; for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); for(int i=0;i<N;i++) { resistance=resistance+(1/arr[i]); } equResistance = (int)Math.floor((1/resistance)); System.out.println(equResistance); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("") r = int(r) n = input("").split() resistance=0.0 for i in range(0,r): resistor = float(n[i]) resistance = resistance + (1/resistor) print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; cin >> n; double s = 0; for(int i = 1; i <= n; i++){ double p; cin >> p; s = s + (1/p); } s = 1/s; cout << floor(s); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a N x M integer matrix A and Q queries of form X1 Y1 X2 Y2. Print the sum of A[i][j], for X1 <= i <= X2 and Y1 <= j <= Y2.The first line contains two integer N and M, denoting the size of the matrix. Next N line contains M integers denoting elements of the matrix. Next line contains a single integer Q, denoting the number of queries. Next Q lines lines four integers X1 Y1 X2 Y2, denoting the query as mentioned in problem statement 1 <= N, M <= 100 1 <= A[i][j] <= 100 1 <= Q <= 100000 1 <= X1 <= X2 <= N 1 <= Y1 <= Y2 <= MPrint Q lines containing the answer to each query.Sample Input: 2 2 1 5 2 3 3 1 1 1 1 1 1 1 2 1 1 2 2 Sample Output: 1 6 11 Explanation: Q1: 1 Q2: 1 + 5 = 6 Q3: 1 + 5 + 2 + 3 = 11, 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) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[][] a = new int[n + 1][m + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { a[i][j] = 0; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[i][j] = sc.nextInt(); a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]; } } int q = sc.nextInt(); while (q-- > 0) { int x1 = sc.nextInt(); int y1 = sc.nextInt(); int x2 = sc.nextInt(); int y2 = sc.nextInt(); int sum = 0; sum = a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1]; System.out.println(sum); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable