Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: public static long SumOfDivisors(long N){ long sum=0; long c=(long)Math.sqrt(N); for(long i=1;i<=c;i++){ if(N%i==0){ sum+=i; if(i*i!=N){sum+=N/i;} } } return sum; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: long long SumOfDivisors(long long N){ long long sum=0; long sq=sqrt(N); for(long i=1;i<=sq;i++){ if(N%i==0){ sum+=i; if(i*i!=N){ sum+=N/i; } } } return sum; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: long long SumOfDivisors(long long N){ long long sum=0; long sq=sqrt(N); for(long i=1;i<=sq;i++){ if(N%i==0){ sum+=i; if(i*i!=N){ sum+=N/i; } } } return sum; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SumOfDivisors()</b> that takes the integer N as parameter. Constraints:- 1<=N<=10^9Return the sum of all of the divisors.Sample Input:- 4 Sample Output:- 7 Sample Input:- 13 Sample Output:- 14, I have written this Solution Code: def SumOfDivisors(num) : # Final result of summation of divisors result = 0 # find all divisors which divides 'num' i = 1 while i<= (math.sqrt(num)) : # if 'i' is divisor of 'num' if (num % i == 0) : # if both divisors are same then # add it only once else add both if (i == (num / i)) : result = result + i; else : result = result + (i + num/i); i = i + 1 # Add 1 to the result as 1 is also # a divisor return (result); , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom is a teacher responsible for a class of N students. The students are given distinct student numbers from 1 to N. Today, all the students entered the classroom at different times. According to Tom's record, there were Ai students in the classroom when student number i entered the classroom (including student number i). From these records, reconstruct the order in which the students entered the classroom.Input is given from Standard Input in the following format: First line contains a single integer N the array length and the second line contains elements of the array Constraints 1 ≤ N ≤ 10000 1 ≤ Ai ≤ N Ai ≠ Aj if (i≠j)Print the student numbers of the students in the order the students entered the classroom.Sample Input 3 2 3 1 Sample Output 3 1 2 Explanation:- First, student number 3 entered the classroom. Then, student number 1 entered the classroom. Finally, student number 2 entered the classroom. Sample Input: 5 5 4 3 2 1 Sample Output: 5 4 3 2 1 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String s[]=br.readLine().split(" "); int arr1[]=new int[n]; int arr2[]=new int[n]; for(int i=0;i<n;i++) { arr1[i]=Integer.parseInt(s[i]); arr2[arr1[i]-1]=i+1; } for(int i=0;i<n;i++) { System.out.print(arr2[i]+" "); } System.out.println(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom is a teacher responsible for a class of N students. The students are given distinct student numbers from 1 to N. Today, all the students entered the classroom at different times. According to Tom's record, there were Ai students in the classroom when student number i entered the classroom (including student number i). From these records, reconstruct the order in which the students entered the classroom.Input is given from Standard Input in the following format: First line contains a single integer N the array length and the second line contains elements of the array Constraints 1 ≤ N ≤ 10000 1 ≤ Ai ≤ N Ai ≠ Aj if (i≠j)Print the student numbers of the students in the order the students entered the classroom.Sample Input 3 2 3 1 Sample Output 3 1 2 Explanation:- First, student number 3 entered the classroom. Then, student number 1 entered the classroom. Finally, student number 2 entered the classroom. Sample Input: 5 5 4 3 2 1 Sample Output: 5 4 3 2 1 , I have written this Solution Code: t=int(input()) li=[int(i) for i in input().split()] ans=[0]*t for i in range(t): ans[li[i]-1] = i+1 for i in ans: print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom is a teacher responsible for a class of N students. The students are given distinct student numbers from 1 to N. Today, all the students entered the classroom at different times. According to Tom's record, there were Ai students in the classroom when student number i entered the classroom (including student number i). From these records, reconstruct the order in which the students entered the classroom.Input is given from Standard Input in the following format: First line contains a single integer N the array length and the second line contains elements of the array Constraints 1 ≤ N ≤ 10000 1 ≤ Ai ≤ N Ai ≠ Aj if (i≠j)Print the student numbers of the students in the order the students entered the classroom.Sample Input 3 2 3 1 Sample Output 3 1 2 Explanation:- First, student number 3 entered the classroom. Then, student number 1 entered the classroom. Finally, student number 2 entered the classroom. Sample Input: 5 5 4 3 2 1 Sample Output: 5 4 3 2 1 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n],b; for(int i=0;i<n;i++){ cin>>b; b--; a[b]=i; } for(int i=0;i<n;i++){ cout<<a[i]+1<<" "; }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader s=new BufferedReader(new InputStreamReader(System.in)); String []S=s.readLine().split(" "); long A=Long.parseLong(S[0]); long B=Long.parseLong(S[1]); long T=Long.parseLong(S[2]); findmaxsweetness(A,B,T); } public static void findmaxsweetness(long A,long B,long T){ long start=0; long end=1000000001; while(start<end){ long mid=start+(end-start)/2; long amount=findsweetness(A,B,mid); if(amount>T){ end=mid; } else{ start=mid+1; } } if(start==0) System.out.println(start); else System.out.println(start-1); } public static long findsweetness(long A,long B,long mid){ String S=String.valueOf(mid); long len=S.length(); long result= (A*mid)+(B*len); return result; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: a,b,t=map(int,input().split()) if(a+b>t): print(0) exit() i=1 j=1000000000 while i<=j: m=(i+j)//2 v1=str(m) v=(a*m)+(len(v1)*b) if v>t: j=m-1 else: ans=m i=m+1 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A shop sells candies of sweetness ranging from 1 to 1000000000. Price of a candy with sweetness X is <b>A*X + B*f(X)</b> units, where f(X) returns number of digits in the decimal notation of X. Given A, B, and T, find the candy with maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.The first and the only line of input contains three integers A, B and T. Constraints: 1 <= A, B <= 10^9 1 <= T <= 10^18Print the maximum sweetness that Andy can buy if he has T units of money. If he cannot buy any candy, print 0.Sample Input 1 10 7 100 Sample Output 1 9 Explanation: Cost of 9 level candy = 9*10 + 7*f(9) = 9*10 + 7*1 = 97. Sample Input 2 1000000000 1000000000 100 Sample Output 2 0, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// typedef unsigned long long ull; auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif ll A,B,X; cin >> A >> B >> X; ll lb = 0, ub = 1000000001, mid; while (ub - lb > 1) { mid = (ub + lb) / 2; (A*mid+B*to_string(mid).length() <= X ? lb : ub) = mid; } cout << lb << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: <em>Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970</em> Implement the function <code>msSinceEpoch</code>, which returns milliseconds since the Unix epoch. (Use JS built-in functions)The function takes no argumentThe function returns a numberconsole. log(msSinceEpoch()) // prints 1642595040109, I have written this Solution Code: function msSinceEpoch() { // write code here // return the output , do not use console.log here return Date.now() }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: #include <iostream> using namespace std; int Dishes(int N, int T){ return T-N; } int main(){ int n,k; scanf("%d%d",&n,&k); printf("%d",Dishes(n,k)); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i=0;i<t;i++){ int n = Integer.parseInt(br.readLine()); System.out.println(Ways(n,1)); } } static int Ways(int x, int num) { int val =(x - num); if (val == 0) return 1; if (val < 0) return 0; return Ways(val, num + 1) + Ways(x, num + 1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long cnt=0; int j; void sum(int X,int j) { if(X==0){cnt++;} if(X<0) {return;} else { for(int i=j;i<=(X);i++){ X=X-i; sum(X,i+1); X=X+i; } } } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; if(n<1){cout<<0<<endl;continue;} sum(n,1); cout<<cnt<<endl; cnt=0; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: // ignore number of testcases // n is the number as provided in input function numberOfWays(n) { // write code here // do not console.log the answer // return answer as a number if(n < 1) return 0; let cnt = 0; let j; function sum(X, j) { if (X == 0) { cnt++; } if (X < 0) { return; } else { for (let i = j; i <= X; i++) { X = X - i; sum(X, i + 1); X = X + i; } } } sum(n,1); return cnt } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N. Constraint:- 1 <= T <= 100 0 <= N <= 120Print a single integer containing number of ways.Sample input 4 6 1 4 2 Sample output:- 4 1 2 1 Explanation:- TestCase1:- 6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: for _ in range(int(input())): x = int(input()) n = 1 dp = [1] + [0] * x for i in range(1, x + 1): u = i ** n for j in range(x, u - 1, -1): dp[j] += dp[j - u] if x==0: print(0) else: print(dp[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K Constraints : 0 <= L <= R <= 1000000000000000000(10^18) 1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1 1 10 2 Sample output 1 5 Sample intput 2 4 5 3 Sample output 2 0 Explanation:- Required divisors = 2 4 6 8 10, 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 str[]=br.readLine().split(" "); long l=Long.parseLong(str[0]); long r=Long.parseLong(str[1]); long k=Long.parseLong(str[2]); long count=(r/k)-((l-1)/k); System.out.print(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K Constraints : 0 <= L <= R <= 1000000000000000000(10^18) 1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1 1 10 2 Sample output 1 5 Sample intput 2 4 5 3 Sample output 2 0 Explanation:- Required divisors = 2 4 6 8 10, I have written this Solution Code: l,r,k=[int(x)for x in input().split()] print(r//k - (l-1)//k), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You think that integers divisible by K are nice. Given L and R (L<=R), find the number of nice integers from L to R (both inclusive).First Line of input contains three integers L R K Constraints : 0 <= L <= R <= 1000000000000000000(10^18) 1 <= K <= 1000000000000000000(10^18)Output a single integer which is the number of nice integers from L to R (both inclusive).Sample input 1 1 10 2 Sample output 1 5 Sample intput 2 4 5 3 Sample output 2 0 Explanation:- Required divisors = 2 4 6 8 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ unsigned long long x,l,r,k; cin>>l>>r>>k; x=l/k; if(l%k==0){x--;} cout<<r/k-x; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alex always skips math class. As a punishment, his teacher has given him an array of size n where every number except one is the power of x. Being poor in mathematics, Alex has asked for your help to solve the problem. Can you help him to find the bad number which is not a power of x? <b>NOTE:</b> It is guaranteed that there always exists an answer.The first line of the input contains the integers n and x The following line contains n integers describing the array a <b>Constraints</b> 2 &le; n &le; 1000 1 &le; x &le; 20 1 &le a<sub>i</sub> &le; 10<sup>8</sup>For each test case, output a single line containing the bad number.input 6 7 16807 343 50 823543 2401 5764801 output 50, I have written this Solution Code: y=input().split() n=int(y[0]) x=int(y[1]) a=input().split() a=list(map(int,a)) k=0 for i in a: r=i while r!=1: r/=x if int(r)!=r: print(i) k=1 break if k==1: break, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alex always skips math class. As a punishment, his teacher has given him an array of size n where every number except one is the power of x. Being poor in mathematics, Alex has asked for your help to solve the problem. Can you help him to find the bad number which is not a power of x? <b>NOTE:</b> It is guaranteed that there always exists an answer.The first line of the input contains the integers n and x The following line contains n integers describing the array a <b>Constraints</b> 2 &le; n &le; 1000 1 &le; x &le; 20 1 &le a<sub>i</sub> &le; 10<sup>8</sup>For each test case, output a single line containing the bad number.input 6 7 16807 343 50 823543 2401 5764801 output 50, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n >> x; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<long long> powers; long long MX = 1e8; powers.push_back(1); // to store all the powers of x which are <= 10^8 while (true) { long long curr = powers.back() * x; if (curr <= MX) powers.push_back(curr); else break; } for (int i = 0; i < n; i++) { // checking if a[i] is in the powers array, i.e whether a[i] is a power of x or not bool found = binary_search(powers.begin(), powers.end(), a[i]); if (!found) { cout << a[i]; return 0; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alex always skips math class. As a punishment, his teacher has given him an array of size n where every number except one is the power of x. Being poor in mathematics, Alex has asked for your help to solve the problem. Can you help him to find the bad number which is not a power of x? <b>NOTE:</b> It is guaranteed that there always exists an answer.The first line of the input contains the integers n and x The following line contains n integers describing the array a <b>Constraints</b> 2 &le; n &le; 1000 1 &le; x &le; 20 1 &le a<sub>i</sub> &le; 10<sup>8</sup>For each test case, output a single line containing the bad number.input 6 7 16807 343 50 823543 2401 5764801 output 50, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int ans = 0; for(int i=0; i<n; i++){ int a = sc.nextInt(); if(!solve(a,x)){ System.out.print(a); break; } } } static boolean solve(int a, int b){ while(a>1){ if(a%b!=0) return false; a = a/b; } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N integers written on a black board. You can perform the following operation if and only if all the integers on the board are even. Choose any one of the integers from the board. Let it be x. Replace x by x/2. Find the maximum number of operations you can perform.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub> <= 10<sup>9</sup>Find the maximum number of operations you can perform.Sample Input: 3 8 12 40 Sample Output: 5, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int count = 0; int[] arr = new int[n]; String[] str = br.readLine().split(" "); for(int i = 0; i < n; ++i) { arr[i] = Integer.parseInt(str[i]); if(arr[i]%2 == 1) { System.out.println(0); return; } } for(int i = 0; i < n; ++i) { while((arr[i]/2)%2 != 1) { count++; arr[i] /= 2; } } System.out.print(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N integers written on a black board. You can perform the following operation if and only if all the integers on the board are even. Choose any one of the integers from the board. Let it be x. Replace x by x/2. Find the maximum number of operations you can perform.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub> <= 10<sup>9</sup>Find the maximum number of operations you can perform.Sample Input: 3 8 12 40 Sample Output: 5, I have written this Solution Code: def evenpow(n): power = 0 while(n%2 == 0): power += 1 n = n//2 if power == 0: return power else : return power-1 n = int(input()) A = list(map(int,input().split())) maxop = 0 for i in range(n): if A[i] % 2 == 0: maxop += evenpow(A[i]) else: maxop = 0 break print(maxop), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N integers written on a black board. You can perform the following operation if and only if all the integers on the board are even. Choose any one of the integers from the board. Let it be x. Replace x by x/2. Find the maximum number of operations you can perform.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub> <= 10<sup>9</sup>Find the maximum number of operations you can perform.Sample Input: 3 8 12 40 Sample Output: 5, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin >> n; vector<int> a(n); for(auto &i : a) cin >> i; int ans = 0; for(int i = 0; i < n; i++){ if(a[i] % 2){ ans = 0; break; } a[i] /= 2; while(a[i] % 2 == 0){ ans++; a[i] /= 2; } } cout << ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: import java.io.*; import java.io.IOException; import java.util.*; class Main { public static long mod = (long)Math.pow(10,9)+7 ; public static double epsilon=0.00000000008854; public static InputReader sc = new InputReader(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { String s=sc.nextLine(); int n=s.length(); int hnum[]=new int[26]; int hpast[]=new int[26]; Arrays.fill(hpast,-1); long hsum[]=new long[26]; long ans=0; for(int i=0;i<n;i++){ int k=s.charAt(i)-'a'; if(hpast[k]!=-1) hsum[k]=hsum[k]+(i-hpast[k])*hnum[k]; ans+=hsum[k]; hnum[k]++; hpast[k]=i; } pw.println(ans); pw.flush(); pw.close(); } public static Comparator<Long[]> column(int i){ return new Comparator<Long[]>() { @Override public int compare(Long[] o1, Long[] o2) { return o1[i].compareTo(o2[i]); } }; } public static Comparator<Integer[]> col(int i){ return new Comparator<Integer[]>() { @Override public int compare(Integer[] o1, Integer[] o2) { return o1[i].compareTo(o2[i]); } }; } public static String reverseString(String s){ StringBuilder input1 = new StringBuilder(); input1.append(s); input1 = input1.reverse(); return input1.toString(); } public static int[] scanArray(int n){ int a[]=new int [n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); return a; } public static long[] scanLongArray(int n){ long a[]=new long [n]; for(int i=0;i<n;i++) a[i]=sc.nextLong(); return a; } public static String [] scanStrings(int n){ String a[]=new String [n]; for(int i=0;i<n;i++) a[i]=sc.nextLine(); return a; } public static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: def findS(s): visited= [ 0 for i in range(256)]; distance =[0 for i in range (256)]; for i in range(256): visited[i]=0; distance[i]=0; sum=0; for i in range(len(s)): sum+=visited[ord(s[i])] * i - distance[ord(s[i])]; visited[ord(s[i])] +=1; distance[ord(s[i])] +=i; return sum; if __name__ == '__main__': s=input(""); print(findS(s));, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: #pragma GCC optimize ("O3") #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; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // 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 string s; cin>>s; int c[26]={}; int f[26]={}; int ans=0; int n=s.length(); for(int i=0;i<n;++i){ ans+=f[s[i]-'a']*i-c[s[i]-'a']; f[s[i]-'a']++; c[s[i]-'a']+=i; } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a square matrix of size N*N. Initially all elements of this matrix are equal to 0. You are given Q queries. Each query consists of two integers, i and j (1 <= i, j <= N) wherein you increase the value of all elements in the i<sup>th</sup> row and j<sup>th</sup> column by 1. After doing this, for each query print the number of zeroes left in the matrix.The first line of the input consists of two integers N and Q. The next Q lines each contains two integers i and j. Constraints: 1 <= N, Q <= 10<sup>5</sup> 1 <= i, j <= NFor each query print the number of zeroes left in the matrix.Sample Input: 3 3 1 1 1 2 3 2 Sample Output: 4 2 1 Explaination: Initially, the matrix will look like: 0 0 0 0 0 0 0 0 0 After the first query, the matrix will look something like this: 1 1 1 1 0 0 1 0 0 <b>Number of zeroes = 4</b> After the second query, the matrix will look something like this: 1 1 1 1 1 0 1 1 0 <b>Number of zeroes = 2</b> After the third query, the matrix will look something like this: 1 1 1 1 1 0 1 1 1 <b>Number of zeroes = 1</b> , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main() { int n, r = 0, c = 0; cin >> n; int k; cin >> k; int ans = n*n; vector<int> row(n + 1), col(n + 1); while(k--){ int i, j; cin >> i >> j; if(row[i] == 0) ans -= n - c, row[i] = 1, r++; if(col[j] == 0) ans -= n - r, col[j] = 1, c++; cout << ans << ' '; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>floor</code>, which should take a number which can be a float(decimal) and return its result as an integer with floor function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(floor(1.99)) // prints 1 console.log(floor(2.1)) // prints 2 console.log(floor(-0.8)) // prints -1, I have written this Solution Code: function floor(num){ // write code here // return the output , do not use console.log here return Math.floor(num) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>floor</code>, which should take a number which can be a float(decimal) and return its result as an integer with floor function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(floor(1.99)) // prints 1 console.log(floor(2.1)) // prints 2 console.log(floor(-0.8)) // prints -1, 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); float a = sc.nextFloat(); System.out.print((int)Math.floor(a)); } }, 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: 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 string S and a char X, your task is to print the number of times the character X occurred in the string S.The input contains the string S and the character X separated by a space. Constraints:- 1 <= |S| <= 100000 'a' <= S[i] <= 'z' 'a' <= X <= 'z'Print the number of times the character X occurred in the string S.Sample Input:- newtonschool o Sample 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) ); String[] st1=(br.readLine()).split(" "); String s=st1[0]; String s_char=st1[1]; char X=s_char.charAt(0); int cnt=0; for(int i=0;i<s.length();i++){ char ch=s.charAt(i); if(ch == X){ cnt++; } } System.out.print(cnt); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S and a char X, your task is to print the number of times the character X occurred in the string S.The input contains the string S and the character X separated by a space. Constraints:- 1 <= |S| <= 100000 'a' <= S[i] <= 'z' 'a' <= X <= 'z'Print the number of times the character X occurred in the string S.Sample Input:- newtonschool o Sample Output:- 3, I have written this Solution Code: input_string, char = input().split(' ') print(input_string.count(char)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S and a char X, your task is to print the number of times the character X occurred in the string S.The input contains the string S and the character X separated by a space. Constraints:- 1 <= |S| <= 100000 'a' <= S[i] <= 'z' 'a' <= X <= 'z'Print the number of times the character X occurred in the string S.Sample Input:- newtonschool o Sample Output:- 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long signed main(){ string s; cin>>s; char c; cin>>c; int cnt=0; for(int i=0;i<s.length();i++){ if(s[i]==c){ cnt++; } } cout<<cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to find the maximum value of X such that sum of some X consecutive natural numbers is N.Input contains a single integer N. Constraints:- 1 <= N <= 1000000000Print the maximum value of X such that sum of some X consecutive natural numbers is N.Sample Input:- 5 Sample Output:- 2 Explanation:- 2 + 3 = 5 Sample Input:- 50 Sample Output:- 5 Explanation:- 8 + 9 + 10 + 11 + 12 = 50, 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 sumOfCon = 0; for(int i=1; i<=N; i++) { for(int j=i; j<=N; j++) { sumOfCon += j; if(sumOfCon > N) { break; } if(sumOfCon == N) { System.out.print(j-i+1); break; } } if(sumOfCon == N) { break; } sumOfCon = 0; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to find the maximum value of X such that sum of some X consecutive natural numbers is N.Input contains a single integer N. Constraints:- 1 <= N <= 1000000000Print the maximum value of X such that sum of some X consecutive natural numbers is N.Sample Input:- 5 Sample Output:- 2 Explanation:- 2 + 3 = 5 Sample Input:- 50 Sample Output:- 5 Explanation:- 8 + 9 + 10 + 11 + 12 = 50, I have written this Solution Code: n = int(input()) i = 1 j = 1 s = 0 while(True): if(s == n): print(j-i) break s += j j += 1 while(s > n): s -= i i += 1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to find the maximum value of X such that sum of some X consecutive natural numbers is N.Input contains a single integer N. Constraints:- 1 <= N <= 1000000000Print the maximum value of X such that sum of some X consecutive natural numbers is N.Sample Input:- 5 Sample Output:- 2 Explanation:- 2 + 3 = 5 Sample Input:- 50 Sample Output:- 5 Explanation:- 8 + 9 + 10 + 11 + 12 = 50, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1000001 #define MOD 1000000000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int cnt[max1]; signed main(){ int t; t=1; while(t--){ int n; cin>>n; int x=1; int p=2*sqrt(n); int ans=1,t=1; while(t<=n){ if((n-t)%x==0){ans=x;} x++; t=x*(x+1); t=t/2; } out(ans); } } , 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: 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: You are given a string S consisting of lowercase English letters. Determine whether adding some number of a's (possibly zero) at the beginning of S can make it a palindrome.The input consists of a single string S. Constraints 1 &le; ∣S∣ &le; 10^6 S consists of lowercase English letters.If adding some number of a's (possibly zero) at the beginning of S can make it a palindrome, print Yes; otherwise, print No.<b>Sample Input 1</b> kasaka <b>Sample Output 1</b> Yes <b>Sample Input 2</b> reveh <b>Sample Output 2</b> No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(void) { int n, x, y; string a; cin >> a; n = a.size(); x = 0; for (int i = 0; i < n; i++) { if (a[i] == 'a')x++; else break; } y = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] == 'a')y++; else break; } if (x == n) { cout << "Yes" << endl; return 0; } if (x > y) { cout << "No" << endl; return 0; } for (int i = x; i < (n - y); i++) { if (a[i] != a[x + n - y - i - 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; 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: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 // Function to rotate the matrix 90 degree clockwise void rotate90Clockwise(int a[][N],int n) { // Traverse each cycle for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { // Swap elements of each cycle // in clockwise direction int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } } // Function for print matrix void printMatrix(int arr[][N],int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << arr[i][j] << " "; cout << '\n'; } } // Driver code int main() { int n; cin>>n; int arr[n][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>arr[i][j]; }} rotate90Clockwise(arr,n); printMatrix(arr,n); cout<<endl; rotate90Clockwise(arr,n); printMatrix(arr,n); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[][] = new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]= sc.nextInt(); } } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } System.out.println(); for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: x=int(input()) l1=[] for i in range(x): a1=list(map(int,input().split())) l1.append(a1) for j in range(x): for i in range(1,x+1): print(l1[-i][j], end=" ") print() print() for i in range(1,x+1): for j in range(1,x+1): print(l1[-i][-j], end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b> <b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments. <b>Custom Input</b> The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K. Constraints:- 1 <= N <= 100000 1 <= K, Arr[i] <= 1000000000000 1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:- 5 2 5 6 11 15 5 2 4 8 1 16 Sample Output:- 2 2 2 5 6 11 -1 2 15 -1, I have written this Solution Code: n = int(input()) arr = list(map(int,input().split())) t = int(input()) def findFloor(arr, l, h, x, res): if(l<=h): m = l+(h-l)//2 if(arr[m] == x): return m if(arr[m] > x): return findFloor(arr, l, m-1, x, res) if(arr[m] < x): res = m return findFloor(arr, m+1, h, x, res) else: return res def findCeil(arr, l, h, x, res): if(l<=h): m = l+(h-l)//2 if(arr[m] == x): return m if(arr[m] < x): return findCeil(arr, m+1, h, x, res) res = m return findCeil(arr, l, m-1, x, res) else: return res for _ in range(t): x = int(input()) f = findFloor(arr, 0, n-1, x, -1) c = findCeil(arr, 0, n-1, x, -1) floor = -1 ceil = -1 if(f!=-1): floor = arr[f] if(c!=-1): ceil = arr[c] print(floor,ceil), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b> <b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments. <b>Custom Input</b> The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K. Constraints:- 1 <= N <= 100000 1 <= K, Arr[i] <= 1000000000000 1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:- 5 2 5 6 11 15 5 2 4 8 1 16 Sample Output:- 2 2 2 5 6 11 -1 2 15 -1, I have written this Solution Code: static void floorAndCeil(int a[], int n, int x){ int it = lower(a,n,x); if(it==0){ if(a[it]==x){ System.out.println(x+" "+x); } else{ System.out.println("-1 "+a[it]); } } else if (it==n){ it--; System.out.println(a[it]+" -1"); } else{ if(a[it]==x){ System.out.println(x+" "+x); } else{ it--; System.out.println(a[it]+" "+a[it+1]); } } } static int lower(int a[], int n,int k){ int l=0; int h=n-1; int m; int ans=n; while(l<=h){ m=l+h; m/=2; if(a[m]<k){ l=m+1; } else{ h=m-1; ans=m; } } return ans; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given one element K your task is to print the maximum element from the array which is less than or equal to the given element(Floor), and the minimum element from the array which is greater than or equal to the given element(Ceil).<b>In case of Java only</b> <b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>floorAndCeil()</b> that takes the array a[], integer N and integer k as arguments. <b>Custom Input</b> The first line of input contains a single integer N. The Second line of input contains N space-separated integers depicting the values of the array. The third line of input contains a single integer Q. The next Q line of input contains a single integer the value of K. Constraints:- 1 <= N <= 100000 1 <= K, Arr[i] <= 1000000000000 1 <= Q <= 10000In a new line Print two space-separated integers depicting the values of Floor and Ceil of the given number. If the floor or ceil of the element does not exist print -1.Sample Input:- 5 2 5 6 11 15 5 2 4 8 1 16 Sample Output:- 2 2 2 5 6 11 -1 2 15 -1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ int n; cin>>n; vector<int> v; int x; FOR(i,n){ cin>>x; v.EB(x);} int q; cin>>q; while(q--){ cin>>x; auto it = lower_bound(v.begin(),v.end(),x); if(it==v.begin()){ if(*it==x){ cout<<x<<" "<<x; } else{ cout<<-1<<" "<<*it; } } else if (it==v.end()){ it--; cout<<*it<<" -1"; } else{ if(*it==x){ cout<<x<<" "<<x; } else{ it--; cout<<*it<<" "; it++; cout<<*it;} } END; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted doubly linked list containing n nodes. Your task is to remove duplicate nodes from the given list. Example 1: Input 1<->2<->2-<->3<->3<->4 Output: 1<->2<->3<->4 Example 2: Input 1<->1<->1<->1 Output 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>deleteDuplicates()</b> that takes head node as parameter. Constraints: 1 <=N <= 10000 1 <= Node. data<= 2*10000Return the head of the modified list.Sample Input:- 6 1 2 2 3 3 4 Sample Output:- 1 2 3 4 Sample Input:- 4 1 1 1 1 Sample Output:- 1, I have written this Solution Code: public static Node deleteDuplicates(Node head) { /* if list is empty */ if (head== null) return head; Node current = head; while (current.next != null) { /* Compare current node with next node */ if (current.val == current.next.val) /* delete the node pointed to by ' current->next' */ deleteNode(head, current.next); /* else simply move to the next node */ else current = current.next; } return head; } /* Function to delete a node in a Doubly Linked List. head_ref --> pointer to head node pointer. del --> pointer to node to be deleted. */ public static void deleteNode(Node head, Node del) { /* base case */ if(head==null || del==null) { return ; } /* If node to be deleted is head node */ if(head==del) { head=del.next; } /* Change next only if node to be deleted is NOT the last node */ if(del.next!=null) { del.next.prev=del.prev; } /* Change prev only if node to be deleted is NOT the first node */ if (del.prev != null) del.prev.next = del.next; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: def Marks(P,Q,R): return 4*P-2*Q-R , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: static int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void compress(String str, int l){ for (int i = 0; i < l; i++) { int count = 1; while (i < l - 1 && str.charAt(i) == str.charAt(i + 1)) { count++; i++; } System.out.print(str.charAt(i)); System.out.print(count); } System.out.println(); } public static void main (String[] args) throws IOException{ BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(rd.readLine()); while(test-->0){ String s = rd.readLine(); int len = s.length(); compress(s,len); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: def compress(st): n = len(st) i = 0 while i < n: count = 1 while (i < n-1 and st[i] == st[i + 1]): count += 1 i += 1 i += 1 print(st[i-1] +str(count),end="") t=int(input()) for i in range(t): s=input() compress(s) print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: We are given a string. Your task is to compress the consecutive letters of the string For example, given string is "AAACCCBBD", thus here A's occurrence 3 times C's occurrence 3 times B's occurrence 2 times D's occurrence 1 time So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line. Constraints: 1 <= T <= 10 1 <= sizeof(String) <= 10^6 All characters of String are upper case letters. (A-Z) Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input: 2 AAACCCBBD ABCD Output: A3C3B2D1 A1B1C1D1, I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; void solve(){ string s; cin >> s; int c = 1; char p = 0; int n = s.length(); for(int i = 1; i < n; i++){ if(s[i] != s[i-1]){ cout << s[i-1] << c; c = 1; } else c++; } cout << s[n-1] << c << endl; } void testcases(){ int tt = 1; cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara has N <b>even</b> numbers with her in which all even numbers from <i>2</i> to<i> N</i> appear exactly <b>once</b> except for one number which appears exactly K times. Given the sum of all the numbers S, N, and K, your task is to find the repeated number.The input contains two space-separated integers N, K, and S. Constraints:- 1 <= N, S <= 1000000 2 <= K <= 100000Print the repeated number, it is guaranteed that for the given test case there exists a set of numbers that fulfill the given conditions.Sample Input:- 5 3 14 Sample Output:- 4 Explanation:- numbers:- {2, 4, 4, 4} Sample Input:- 10 5 38 Sample Output:- 2, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int S=sc.nextInt(); int s=0; int i=2; while(i<=n){ s=s+i; i=i+2; } int val=(S-s)/(k-1); System.out.println(val); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara has N <b>even</b> numbers with her in which all even numbers from <i>2</i> to<i> N</i> appear exactly <b>once</b> except for one number which appears exactly K times. Given the sum of all the numbers S, N, and K, your task is to find the repeated number.The input contains two space-separated integers N, K, and S. Constraints:- 1 <= N, S <= 1000000 2 <= K <= 100000Print the repeated number, it is guaranteed that for the given test case there exists a set of numbers that fulfill the given conditions.Sample Input:- 5 3 14 Sample Output:- 4 Explanation:- numbers:- {2, 4, 4, 4} Sample Input:- 10 5 38 Sample Output:- 2, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int n,k,x; cin>>n>>k>>x; n/=2; int res=n*(n+1); x-=res; x/=(k-1); cout<<x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The students of Newton School threw a grand party to celebrate their hard work and achievements. They danced and sang the night away, enjoying delicious food and creating memories that would last a lifetime. There are N guests in the party and N-1 relationships are given. The guests are numbered 1, 2, N. The i<sub>th</sub> relationship depicts that guest a<sub>i</sub> and guest b<sub>i</sub> are friends. Determine whether a guest exists or not who is a friend of all other guests. Here, we only consider direct friendship.Input is given from Standard Input in the following format: N a1 b1 a2 b2 a3 b3 . . an-1 bn-1 <b>Constraints</b> 3 &le; N &le; 10<sup>5</sup> 1 &le; ai, bi &le; N i&le;NIf a guest exists or who is a friend of all other guests, print "Yes" else print "No".<b>Sample Input 1</b> 5 1 4 2 4 3 4 4 5 <b>Sample Output 1</b> Yes <b>Sample Input 2</b> 4 2 4 1 4 2 3 <b>Sample Output 2</b> No <b>Sample Input 3</b> 10 3 10 4 10 9 10 1 10 7 10 5 10 2 10 8 10 6 10 <b>Sample Output 3</b> Yes <b>Explanation</b> In the first case,4 is a friend of everyone else's, while in the third case, 10 is a friend to all, while there is no such number in the second case., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { ll n; cin >> n; vector<ll> guests(n + 1, 0); // Counts the number of friends of each guest for (ll i = 1; i <= n - 1; i++) { ll a, b; cin >> a >> b; guests[a]++; guests[b]++; } for (ll i = 1; i <= n; i++) { if (guests[i] == n - 1) // If any guest is friend with all other guests than we have to return YES { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Newton wants to study for an exam and he wants H more hours, He knows a planet where time passes S times faster than earth. Which means that <em>t</em> hours on earth is equal to S x <em>t</em> hours on that planet. Now Newton travels to that planet and studies for H hours, Find out how many how many hours passed on earth.The first and only line of the input contains two integers H and S <b>Constraints:</b> 1 &le; H &le; 100 1 &le; S &le; 100Output the time passed on earth and print the answer upto 5 decimal places.<b>Sample Input 1:</b> 8 3 <b>Sample Output 1:</b> 2.66667 <b>Sample Input 2:</b> 1 10 <b>Sample Output 2:</b> 0.10000, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int solve() { int x,t; cin>>x>>t; float ans=0; ans = abs((float) x / (float) t); cout<<fixed<<setprecision(5)<<ans<<endl; return 0; } int main() { int t=1; while(t--) { solve(); } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an equation: T<sub>n</sub> = 2*n + (n + 1)<sup>2</sup> - (n<sup>2</sup> + 4) Your task is to find S<sub>n</sub>: S<sub>n</sub> = T<sub>1</sub> + T<sub>2</sub> + T<sub>3</sub> +. .. . + T<sub>n</sub>User task: Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get n as a parameter. <b>Constraints:</b> 1 <= n <= 10^4You need to return the sum.Sample Input:- 2 Sample Output:- 6 Explanation:- T1 = 2*1 + (1+1)^2 - (1^2+4) = 2 + 4 - 5 = 1 T2 = 2*2 + (2 + 1)^2 - (2^2 + 4) = 4 + 9 - 8 = 5 S2 = T1 + T2 S2 = 6 Sample Input:- 3 Sample Output:- 15, I have written this Solution Code: def equationSum(N) : re=2*N*(N+1) re=re-3*N return re, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an equation: T<sub>n</sub> = 2*n + (n + 1)<sup>2</sup> - (n<sup>2</sup> + 4) Your task is to find S<sub>n</sub>: S<sub>n</sub> = T<sub>1</sub> + T<sub>2</sub> + T<sub>3</sub> +. .. . + T<sub>n</sub>User task: Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get n as a parameter. <b>Constraints:</b> 1 <= n <= 10^4You need to return the sum.Sample Input:- 2 Sample Output:- 6 Explanation:- T1 = 2*1 + (1+1)^2 - (1^2+4) = 2 + 4 - 5 = 1 T2 = 2*2 + (2 + 1)^2 - (2^2 + 4) = 4 + 9 - 8 = 5 S2 = T1 + T2 S2 = 6 Sample Input:- 3 Sample Output:- 15, I have written this Solution Code: static long equationSum(long N) { return 2*N*(N+1) - 3*N; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an equation: T<sub>n</sub> = 2*n + (n + 1)<sup>2</sup> - (n<sup>2</sup> + 4) Your task is to find S<sub>n</sub>: S<sub>n</sub> = T<sub>1</sub> + T<sub>2</sub> + T<sub>3</sub> +. .. . + T<sub>n</sub>User task: Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get n as a parameter. <b>Constraints:</b> 1 <= n <= 10^4You need to return the sum.Sample Input:- 2 Sample Output:- 6 Explanation:- T1 = 2*1 + (1+1)^2 - (1^2+4) = 2 + 4 - 5 = 1 T2 = 2*2 + (2 + 1)^2 - (2^2 + 4) = 4 + 9 - 8 = 5 S2 = T1 + T2 S2 = 6 Sample Input:- 3 Sample Output:- 15, I have written this Solution Code: long int equationSum( long N){ long ans = (2*N*(N+1)) - 3*N; return ans; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an equation: T<sub>n</sub> = 2*n + (n + 1)<sup>2</sup> - (n<sup>2</sup> + 4) Your task is to find S<sub>n</sub>: S<sub>n</sub> = T<sub>1</sub> + T<sub>2</sub> + T<sub>3</sub> +. .. . + T<sub>n</sub>User task: Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>equationSum()</b>, where you will get n as a parameter. <b>Constraints:</b> 1 <= n <= 10^4You need to return the sum.Sample Input:- 2 Sample Output:- 6 Explanation:- T1 = 2*1 + (1+1)^2 - (1^2+4) = 2 + 4 - 5 = 1 T2 = 2*2 + (2 + 1)^2 - (2^2 + 4) = 4 + 9 - 8 = 5 S2 = T1 + T2 S2 = 6 Sample Input:- 3 Sample Output:- 15, I have written this Solution Code: long int equationSum( long N){ long ans = (2*N*(N+1)) - 3*N; return ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Everyone loves having chocolates. Saloni loves having chocolates more than anyone. She has n bags having a[1], a[2], ..., a[n] number of chocolates. In one unit time, she can choose any bag a[i], eat all a[i] chocolates and then fill the bag with floor(a[i]/2) chocolates. Find the maximum number of chocolates she can eat in k units of time.The first line of the input contains an integer n and k, the number of bags Saloni has and the units of time she will eat. The second line of input contains n integers, the number of chocolates in ith bag. Constraints 1 <= n, k <= 100000 1 <= a[i] <= 1000000000Output a single integer, the maximum number of chocolates she can have in k units of time.Sample Input 3 3 7 5 1 Sample Output 15 Explanation In 1st unit time, she will eat from 1st bag (7 chocolates) In 2nd unit time, she will eat from 2nd bag (5 chocolates) In 3rd unit time, she will eat from 1st bag (3 chocolates), 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[] s=br.readLine().split(" "); PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder()); int n=Integer.parseInt(s[0]); int k=Integer.parseInt(s[1]); long max=0; String[] str=br.readLine().split(" "); for(int i=0;i<n;i++){ int cur=Integer.parseInt(str[i]); pq.add(cur); } for(int i=0;i<k;i++){ int cur=pq.poll(); max+=cur; pq.add(cur/2); } System.out.println(max); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Everyone loves having chocolates. Saloni loves having chocolates more than anyone. She has n bags having a[1], a[2], ..., a[n] number of chocolates. In one unit time, she can choose any bag a[i], eat all a[i] chocolates and then fill the bag with floor(a[i]/2) chocolates. Find the maximum number of chocolates she can eat in k units of time.The first line of the input contains an integer n and k, the number of bags Saloni has and the units of time she will eat. The second line of input contains n integers, the number of chocolates in ith bag. Constraints 1 <= n, k <= 100000 1 <= a[i] <= 1000000000Output a single integer, the maximum number of chocolates she can have in k units of time.Sample Input 3 3 7 5 1 Sample Output 15 Explanation In 1st unit time, she will eat from 1st bag (7 chocolates) In 2nd unit time, she will eat from 2nd bag (5 chocolates) In 3rd unit time, she will eat from 1st bag (3 chocolates), 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, k; cin >> n >> k; priority_queue<int> s; for(int i = 1; i <= n; i++){ int p; cin >> p; s.push(p); } int ans = 0; while(k--){ int x = s.top(); s.pop(); ans += x; s.push(x/2); } cout << ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Swastik initially has rupees 1000 with him, he goes to a candy shop to buy some candies. There are only two types of candies available which costs 3 and 7 rupees. Swastik can buy any number of candies he wants, possibly 0, with the money he have. Given the remaining amount of money he had left with him, your task to check whether the amount he have is possible or not.First line of input contains the number of test cases T, next T lines contains a single integer M(remaining amount). Constraints :- 1 < = T < = 100 1 < = M < = 1000For each test case, in a new line print "Yes" if possible or "No" if not.Sample Input:- 3 995 997 994 Sample Output:- No Yes Yes, 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 str[] = br.readLine().trim().split(" "); int t = Integer.parseInt(str[0]); while(t-->0) { String strg[] = br.readLine().trim().split(" "); int n = Integer.parseInt(strg[0]); int diff = 1000 - n; if(diff%7 == 0 || diff%3 == 0) System.out.println("Yes"); else { if(diff == 1 || diff == 2 || diff == 4 || diff == 5 || diff == 8 || diff == 11) System.out.println("No"); else System.out.println("Yes"); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Swastik initially has rupees 1000 with him, he goes to a candy shop to buy some candies. There are only two types of candies available which costs 3 and 7 rupees. Swastik can buy any number of candies he wants, possibly 0, with the money he have. Given the remaining amount of money he had left with him, your task to check whether the amount he have is possible or not.First line of input contains the number of test cases T, next T lines contains a single integer M(remaining amount). Constraints :- 1 < = T < = 100 1 < = M < = 1000For each test case, in a new line print "Yes" if possible or "No" if not.Sample Input:- 3 995 997 994 Sample Output:- No Yes Yes, I have written this Solution Code: def check(v): if(v==0): return True if(v<3): return False if(v%3==0 or v%7==0): return True return check(v-3) or check(v-7) t=int(input()) for i in range(0,t): value=int(input()) value=1000-value if(check(value)): print ("Yes") else: print ("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Swastik initially has rupees 1000 with him, he goes to a candy shop to buy some candies. There are only two types of candies available which costs 3 and 7 rupees. Swastik can buy any number of candies he wants, possibly 0, with the money he have. Given the remaining amount of money he had left with him, your task to check whether the amount he have is possible or not.First line of input contains the number of test cases T, next T lines contains a single integer M(remaining amount). Constraints :- 1 < = T < = 100 1 < = M < = 1000For each test case, in a new line print "Yes" if possible or "No" if not.Sample Input:- 3 995 997 994 Sample Output:- No Yes Yes, 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' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } // Returns true if d is present as digit // in number x. bool isDigitPresent(int x, int d) { // Breal loop if d is present as digit while (x > 0) { if (x % 10 == d) break; x = x / 10; } // If loop broke return (x > 0); } // function to display the values void printNumbers(int n, int d) { // Check all numbers one by one for (int i = 0; i <= n; i++) // checking for digit if (i == d || isDigitPresent(i, d)) cout << i << " "; } signed main() { bool sieve[1001] = {0}; sieve[1000] = true; for (int i = 999; i >= 0; i--) { if (i+3 <= 1000 && sieve[i+3]) { sieve[i] = true; } else if (i+7 <= 1000 && sieve[i+7]) { sieve[i] = true; } } int t; cin >> t; while (t-- > 0) { int n; cin >> n; if(sieve[n]){ out("Yes"); } else{out("No");} } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A binary heap is a Binary Tree with following properties: 1) It’s a complete tree (All levels are completely filled except possibly the last level and the last level has all keys as left as possible). This property of Binary Heap makes them suitable to be stored in an array. 2) A Binary Heap is either Min Heap or Max Heap. In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The same property must be recursively true for all nodes in Binary Tree. Max Binary Heap is similar to MinHeap. Given some queries and your task is to implement the three methods insertKey, deleteKey, and extractMin on a Binary Min Heap and call them as per the query given below: 1) 1 x (a query of this type means to insert an element in the min heap with value x ) 2) 2 x (a query of this type means to remove an element at position x from the min heap) 3) 3 (a query like this removes the min element from the min heap and prints it ).The first line of the input contains an integer 'T' denoting the number of test cases. Then T test cases follow. First line of each test case contains an integer Q denoting the number of queries. The second line of each test case contains Q queries separated by space. Constraints: 1 <= T <= 100 1 <= Q <= 100 1 <= x <= 100The output for each test case of query 3 will be space separated integers having -1 if the heap is empty else the min element of the heap. Sample Input: 2 7 1 4 1 2 3 1 6 2 0 3 3 5 1 8 1 9 2 1 3 3 Sample Output: 2 6 -1 8 -1 Explanation: Testcase 1: In the first test case for query 1 4 the heap will have {4} 1 2 the heap will be {2 4} 3 removes min element from heap ie 2 and prints it now heap is {4} 1 6 inserts 6 to heap now heap is {4 6} 2 0 delete element at position 0 of heap now heap is {6} 3 remove min element from heap ie 6 and prints it now the heap is empty {} 3 since heap is empty thus no min element exist so -1 is printed ., I have written this Solution Code: // Initial Template for C++ #include <bits/stdc++.h> using namespace std; typedef long long int ll; // Structure for Min Heap struct MinHeap { int *harr; int capacity; int heap_size; // Constructor for Min Heap MinHeap(int c) { heap_size = 0; capacity = c; harr = new int[c]; } ~MinHeap() { delete[] harr; } int parent(int i) { return (i - 1) / 2; } int left(int i) { return (2 * i + 1); } int right(int i) { return (2 * i + 2); } void MinHeapify(int); // Implemented in user editor int extractMin(); void decreaseKey(int i, int new_val); void deleteKey(int i); void insertKey(int k); }; // Position this line where user code will be pasted. // Driver code int main() { int t; cin >> t; while (t--) { ll a; cin >> a; MinHeap h(a); for (ll i = 0; i < a; i++) { int c; int n; cin >> c; if (c == 1) { cin >> n; h.insertKey(n); } if (c == 2) { cin >> n; h.deleteKey(n); } if (c == 3) { cout << h.extractMin() << " "; } } cout << endl; // delete h.harr; h.harr = NULL; } return 0; } // } Driver Code Ends /*The structure of the class is struct MinHeap { int *harr; int capacity, heap_size; MinHeap(int cap) {heap_size = 0; capacity = cap; harr = new int[cap];} int extractMin(); void deleteKey(int i); void insertKey(int k); };*/ // You need to write code for below three functions /* Removes min element from min heap and returns it */ int MinHeap::extractMin() { if(heap_size==0) return -1; if(heap_size==1) { int x=harr[0]; heap_size=0; return x; } else { int x=harr[0]; swap(harr[heap_size-1],harr[0]); heap_size=heap_size-1; MinHeapify(0); return x; } } /* Removes element from position x in the min heap */ void MinHeap::deleteKey(int i) { if(i>heap_size-1) return ; decreaseKey(i,INT_MIN); extractMin(); } /* Inserts an element at position x into the min heap*/ void MinHeap::insertKey(int k) { if(heap_size==capacity) return; heap_size=heap_size+1; harr[heap_size-1]=k; int i=heap_size-1; while(i!=0 && harr[parent(i)]> harr[i]) { swap(harr[i],harr[parent(i)]); i=parent(i); } } // Decrease Key operation, helps in deleting key from heap void MinHeap::decreaseKey(int i, int new_val) { harr[i] = new_val; while (i != 0 && harr[parent(i)] > harr[i]) { swap(harr[i], harr[parent(i)]); i = parent(i); } } /* You may call below MinHeapify function in above codes. Please do not delete this code if you are not writing your own MinHeapify */ void MinHeap::MinHeapify(int i) { int l = left(i); int r = right(i); int smallest = i; if (l < heap_size && harr[l] < harr[i]) smallest = l; if (r < heap_size && harr[r] < harr[smallest]) smallest = r; if (smallest != i) { swap(harr[i], harr[smallest]); MinHeapify(smallest); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String str[]=br.readLine().split(" "); int a[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(str[i]); } long res=0; for (int i=0;i<32;i++){ long cnt=0; for (int j=0;j<n;j++) if ((a[j] & (1 << i)) == 0) cnt++; res=(res+(cnt*(n-cnt)*2))%1000000007; } System.out.println(res%1000000007); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: def suBD(arr, n): ans = 0 # Initialize result for i in range(0, 64): count = 0 for j in range(0, n): if ( (arr[j] & (1 << i)) ): count+= 1 ans += (count * (n - count)) * 2; return (ans)%(10**9+7) n=int(input()) arr = map(int,input().split()) arr=list(arr) print(suBD(arr, n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the sum of bit difference in all pairs which can be formed.The first line of input contains a single integer N, the second line of input contains N space separated integers depicting values of the array. Constraints:- 1 <= N <= 100000 0 <= Arr[i] <= 1000000000Print the sum of bit difference of all possible pairs. Note:- Since the answer can be quite large print your answer modulo 10<sup>9</sup> + 7Sample Input:- 2 1 3 Sample Output:- 2 Explanation:- (1, 1) = 0 (1, 3) = 1 (3, 1) = 1 (3, 3) = 0 Sample Input:- 2 1 2 Sample Output:- 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 101 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }signed main(){ int N; cin>>N; int a[55]; int A[N]; FOR(i,N){ cin>>A[i];} for(int i=0;i<55;i++){ a[i]=0; } int ans=1,p=2; for(int i=0;i<55;i++){ for(int j=0;j<N;j++){ if(ans&A[j]){a[i]++;} } ans*=p; // out(ans); } ans=0; for(int i=0;i<55;i++){ ans+=(a[i]*(N-a[i])*2); ans%=MOD; } out(ans); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 // Function to rotate the matrix 90 degree clockwise void rotate90Clockwise(int a[][N],int n) { // Traverse each cycle for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { // Swap elements of each cycle // in clockwise direction int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } } // Function for print matrix void printMatrix(int arr[][N],int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << arr[i][j] << " "; cout << '\n'; } } // Driver code int main() { int n; cin>>n; int arr[n][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>arr[i][j]; }} rotate90Clockwise(arr,n); printMatrix(arr,n); cout<<endl; rotate90Clockwise(arr,n); printMatrix(arr,n); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[][] = new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]= sc.nextInt(); } } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } //rotating by 90 degree for (int i = 0; i < n / 2; i++) { for (int j = i; j < n - i - 1; j++) { int temp = a[i][j]; a[i][j] = a[n - 1 - j][i]; a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j]; a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i]; a[j][n - 1 - i] = temp; } } System.out.println(); for(int i =0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N. N lines follow each containing N space-separated integers. <b>Constraints</b> 2 <= N <= 100 1 <= Mat[i][j] <= 10000Output 2*N+1 lines. First N lines should contain the Matrix rotated by 90 degrees. Then print a blank line. Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1: 2 3 4 7 6 Sample Output 1: 7 3 6 4 6 7 4 3 Sample Input 2: 2 1 2 3 4 Sample Output 2: 3 1 4 2 4 3 2 1, I have written this Solution Code: x=int(input()) l1=[] for i in range(x): a1=list(map(int,input().split())) l1.append(a1) for j in range(x): for i in range(1,x+1): print(l1[-i][j], end=" ") print() print() for i in range(1,x+1): for j in range(1,x+1): print(l1[-i][-j], end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given N intervals, the i<sup>th</sup> of them being [A<sub>i</sub>, B<sub>i</sub>], where A<sub>i</sub> and B<sub>i</sub> are positive integers. Let the union of all these intervals be S. It is easy to see that S can be uniquely represented as an union of disjoint closed intervals. Your task is to find the sum of the lengths of the disjoint closed intervals that comprises S. For example, if you are given the intervals: [1, 3], [2, 4], [5, 7] and [7, 8], then S can be uniquely represented as the union of disjoint intervals [1, 4] and [5, 8]. In this case, the answer will be 6, as (4 - 1) + (8 - 5) = 6.The first line of the input consists of a single integer N – the number of intervals. Then N lines follow, the i<sup>th</sup> line containing two space-separated integers A<sub>i</sub> and B<sub>i</sub>. <b> Constraints: </b> 1 ≤ N ≤ 10<sup>4</sup> 1 ≤ A<sub>i</sub> < B<sub>i</sub> ≤ 2×10<sup>5</sup>Print a single integer, the sum of the lengths of the disjoint intervals of S.Sample Input 1: 3 1 3 3 4 6 7 Sample Output 1: 4 Sample Explanation 1: Here, S can be uniquely written as union of disjoint intervals [1, 4] and [6, 7]. Thus, answer is (4 - 1) + (7 - 6) = 4. Sample Input 2: 4 9 12 8 10 5 6 13 15 Sample Output 2: 7 Sample Explanation 2: Here, S can be uniquely written as union of disjoint intervals [5, 6], [8, 12] and [13, 15]. Thus, answer is (6 - 5) + (12 - 8) + (15 - 13) = 7. , I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << (a) << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (auto i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 998244353; // 1e9 + 7; const ll N = 4e5 + 100; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int arr[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); read(n); FOR (i, 1, n) { readb(a, b); a *= 2, b *= 2; arr[a]++; arr[b + 1]--; } int ans = 0, sum = 0, cur = 0; FOR (i, 0, N - 2) { sum += arr[i]; if (sum) cur++; else ans += cur/2, cur = 0; } print(ans); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N find number of positive integers with N digits with all digits in non-decreasing order. As this can be large find ans modulo 1000000007. For example 111227 is valid whereas 1112231 is not.Input contains one line of input containing a single integer N. 1 <= N <= 1000000000000Print a single integer containing the number of positive integers with N digits with all digits in non-decreasing order modulo 1000000007.Sample Input 1 Sample output 9 Sample Input 2 Sample Input 45, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static long modulo = 1000000007; public static long power(long a, long b, long m) { long ans=1; while(b>0){ if(b%2!=0){ ans = ((ans%m)*(a%m))%m; } b=b/2; a = ((a%m)*(a%m))%m; } return ans; } public static void main (String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long result = 1; if(N == (long)Math.pow(10,12)){ System.out.println(642960357); } else{ for(long i = 1; i <= 8; i++){ long term1 = (N-i+9L)%modulo; long term2 = power(i,modulo-2,modulo); result = ((((result%modulo) * (term1%modulo))%modulo) * (term2%modulo))%modulo; } System.out.println(result); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N find number of positive integers with N digits with all digits in non-decreasing order. As this can be large find ans modulo 1000000007. For example 111227 is valid whereas 1112231 is not.Input contains one line of input containing a single integer N. 1 <= N <= 1000000000000Print a single integer containing the number of positive integers with N digits with all digits in non-decreasing order modulo 1000000007.Sample Input 1 Sample output 9 Sample Input 2 Sample Input 45, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define ll long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int sz; const int NN = 9; class matrix{ public: ll mat[NN][NN]; matrix(){ for(int i = 0; i < NN; i++) for(int j = 0; j < NN; j++) mat[i][j] = 0; sz = NN; } inline matrix operator * (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ for(int k = 0; k < sz; k++){ temp.mat[i][j] += (mat[i][k] * a.mat[k][j]) % mod; if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod; } } return temp; } inline matrix operator + (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ temp.mat[i][j] = mat[i][j] + a.mat[i][j] ; if(temp.mat[i][j] >= mod) temp.mat[i][j] -= mod; } return temp; } inline matrix operator - (const matrix &a){ matrix temp; for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++){ temp.mat[i][j] = mat[i][j] - a.mat[i][j] ; if(temp.mat[i][j] < mod) temp.mat[i][j] += mod; } return temp; } inline void operator = (const matrix &b){ for(int i = 0; i < sz; i++) for(int j = 0; j < sz; j++) mat[i][j] = b.mat[i][j]; } inline void print(){ for(int i = 0; i < sz; i++){ for(int j = 0; j < sz; j++){ cout << mat[i][j] << " "; } cout << endl; } } }; matrix pow(matrix a, ll k){ matrix ans; for(int i = 0; i < sz; i++) ans.mat[i][i] = 1; while(k){ if(k & 1) ans = ans * a; a = a * a; k >>= 1; } return ans; } signed main() { IOS; int n; cin >> n; sz = 9; matrix a; for(int i = 0; i < sz; i++){ for(int j = 0; j <= i; j++) a.mat[i][j] = 1; } a = pow(a, n); int ans = 0; for(int i = 0; i < sz; i++){ ans += a.mat[i][0]; ans %= mod; } cout << ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively. Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v. Constraints: 1 <= N, M <= 1000 0 <= u, v <= N-1, u != v There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1: 4 5 0 1 1 2 2 3 3 0 0 2 Sample Output 1: Yes Explanation: There is a cycle with nodes 0, 1, 2, 3 Sample Input 2: 4 4 0 1 1 2 2 3 0 3 Sample Output 2: No Explanation: There is no cycle in this graph, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static ArrayList<ArrayList<Integer>> adj; static void graph(int v){ adj =new ArrayList<>(); for(int i=0;i<=v;i++) adj.add(new ArrayList<Integer>()); } static void addedge(int u, int v){ adj.get(u).add(v); } static boolean dfs(int i, boolean [] vis, int parent[]){ vis[i] = true; parent[i] = 1; for(Integer it: adj.get(i)){ if(vis[it]==false) { if(dfs(it, vis, parent)==true) return true; } else if(parent[it]==1) return true; } parent[i] = 0; return false; } static boolean helper(int n){ boolean vis[] = new boolean [n+1]; int parent[] = new int[n+1]; for(int i=0;i<=n;i++){ if(vis[i]==false){ if(dfs(i, vis, parent)) return true; } } return false; } public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String t[] = br.readLine().split(" "); int n = Integer.parseInt(t[0]); graph(n); int e = Integer.parseInt(t[1]); for(int i=0;i<e;i++) { String num[] = br.readLine().split(" "); int u = Integer.parseInt(num[0]); int v = Integer.parseInt(num[1]); addedge(u, v); } if(helper(n)) System.out.println("Yes"); else System.out.println("No"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively. Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v. Constraints: 1 <= N, M <= 1000 0 <= u, v <= N-1, u != v There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1: 4 5 0 1 1 2 2 3 3 0 0 2 Sample Output 1: Yes Explanation: There is a cycle with nodes 0, 1, 2, 3 Sample Input 2: 4 4 0 1 1 2 2 3 0 3 Sample Output 2: No Explanation: There is no cycle in this graph, I have written this Solution Code: from collections import defaultdict class Graph(): def __init__(self,vertices): self.graph = defaultdict(list) self.V = vertices def addEdge(self,u,v): self.graph[u].append(v) def isCyclicUtil(self, v, visited, recStack): visited[v] = True recStack[v] = True for neighbour in self.graph[v]: if visited[neighbour] == False: if self.isCyclicUtil(neighbour, visited, recStack) == True: return True elif recStack[neighbour] == True: return True recStack[v] = False return False def isCyclic(self): visited = [False] * (self.V + 1) recStack = [False] * (self.V + 1) for node in range(self.V): if visited[node] == False: if self.isCyclicUtil(node,visited,recStack) == True: return True return False V,edges=map(int,input().split()) g = Graph(V) for i in range(edges): u,v=map(int,input().split()) g.addEdge(u,v) if g.isCyclic() == 1: 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 a directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively. Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v. Constraints: 1 <= N, M <= 1000 0 <= u, v <= N-1, u != v There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1: 4 5 0 1 1 2 2 3 3 0 0 2 Sample Output 1: Yes Explanation: There is a cycle with nodes 0, 1, 2, 3 Sample Input 2: 4 4 0 1 1 2 2 3 0 3 Sample Output 2: No Explanation: There is no cycle in this graph, 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; vector<int> g[N]; int vis[N]; bool flag = 0; void dfs(int u){ vis[u] = 1; for(auto i: g[u]){ if(vis[i] == 1) flag = 1; if(vis[i] == 0) dfs(i); } vis[u] = 2; } signed main() { IOS; int n, m; cin >> n >> m; for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[u].push_back(v); } for(int i = 0; i < n; i++){ if(vis[i]) continue; dfs(i); } if(flag) cout << "Yes"; else cout << "No"; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an integer A and a floating point number B, upto exactly two decimal places. Compute their product, truncate its fractional part, and print the result as an integer.Since this will be a functional problem, you don't have to take input. You just have to complete the function solve() that takes an integer and a float as arguments. <b>Constraints</b> 0<=A<=2 x 10<sup>15</sup> 0<=B<sub>i</sub><=10Return the product after truncating the fractional part.Sample Input: 155 2.41 Sample Output: 373 The result is 373.55, after truncating the fractional part, we get 373., I have written this Solution Code: class Solution { long solve(long a, double b) { b = b*100 ; return (a*(long)b)/100 ; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N. Constraints:- 1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:- 2 Sample Output:- YES Sample Input:- 4 Sample Output:- NO, 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); long n = sc.nextLong(); int p=(int)Math.sqrt(n); for(int i=2;i<=p;i++){ if(n%i==0){System.out.print("NO");return;} } System.out.print("YES"); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N. Constraints:- 1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:- 2 Sample Output:- YES Sample Input:- 4 Sample Output:- NO, I have written this Solution Code: import math def isprime(A): if A == 1: return False sqrt = int(math.sqrt(A)) for i in range(2,sqrt+1): if A%i == 0: return False return True inp = int(input()) if isprime(inp): 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 an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N. Constraints:- 1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:- 2 Sample Output:- YES Sample Input:- 4 Sample Output:- NO, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ long n; cin>>n; long x = sqrt(n); for(int i=2;i<=x;i++){ if(n%i==0){cout<<"NO";return 0;} } cout<<"YES"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int size = Integer.parseInt(line); String str = br.readLine(); String[] strArray = str.split(" "); int[] array = new int[size]; for (int i = -0; i < size; i++) { array[i] = Integer.parseInt(strArray[i]); } int count = largestSubarray(array,size); System.out.println(count); } static int largestSubarray(int[] array,int size){ int count = -1; int sum = 0; Map<Integer,Integer> mymap = new HashMap<>(); mymap.put(0,-1); for(int i=0; i<array.length; i++){ sum += array[i]; if(mymap.containsKey(sum)){ count = Math.max(count, i-mymap.get(sum)); } else{ mymap.put(sum,i); } } if(count > 0){ return count; } else{ return -1; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: def maxLen(arr,n,k): mydict = dict() sum = 0 maxLen = 0 for i in range(n): sum += arr[i] if (sum == k): maxLen = i + 1 elif (sum - k) in mydict: maxLen = max(maxLen, i - mydict[sum - k]) if sum not in mydict: mydict[sum] = i return maxLen n=int(input()) arr=input().split() for i in range(0,n): arr[i]=int(arr[i]) max_len=maxLen(arr,n,0) if(max_len==0): print ("-1") else: print (max_len), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b>, of length <b>N</b> containing zero , positive and negative integers. You need to find the length of the largest subarray whose sum of elements is <b>0</b>.The first line contains N denoting the size of the array A. Then in the next line contains N space-separated values of the array A. <b>Constraints:-</b> 1 <= N <= 1e5 -1e6 <= A[i] <= 1e6Print the length of the largest subarray which has sum 0, If no subarray exist print -1.Sample Input:- 8 15 -2 2 -8 1 7 10 23 Sample Output:- 5 Explanation:- -2 2 -8 1 7 is the required subarray Sample Input:- 5 1 2 1 2 3 Sample Output:- -1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ unordered_map<long long,int> m; int n,k; cin>>n; long a[n]; int ans=-1; for(int i=0;i<n;i++){cin>>a[i];if(a[i]==0){ans=1;}} long long sum=0; for(int i=0;i<n;i++){ sum+=a[i]; if(sum==0){ans=max(i+1,ans);} if(m.find(sum)==m.end()){m[sum]=i;} else{ ans=max(i-m[sum],ans); } } cout<<ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable