Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){ int x=N; while(D-->0){ x-=x/2; x*=3; } System.out.println(x); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } cout << x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){ int x=N; while(D--){ x-=x/2; x*=3; } printf("%d", x); }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days? <b>Note:- </b> Take the floor value while dividing by 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters. <b>Constraints:-</b> 1 <= N <= 100 1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:- 5 1 Sample Output 1:- 9 </b>Explanation:-</b> Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9. Sample Input 2:- 5 3 Sample Output 2:- 24 <b>Explanation:-</b> Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9 Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15 Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D): ans = N while D > 0: ans = ans - ans//2 ans = ans*3 D = D-1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement <code>getObjKeys</code> which only takes one argument which will be a object. The function should return all they keys present in object as a string where elements are seperated by a ', '. (No nested objects)(Use JS Built in function)Function will take one argument which will be an objectFunction will is string which contain all the keys from the input object seperated by a ', 'const obj = {email:"akshat. sethi@newtonschool. co", password:"123456"} const keyString = getObjKeys(obj) console. log(keyString) // prints email, password, I have written this Solution Code: function getObjKeys(obj){ return Object.keys(obj).join(",") }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader r = new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); String num = br.readLine(); int N = Integer.parseInt(num); String result = ""; if(N < 1000 && N > 0 && N == 1){ result = "AC"; } else { result = "WA"; } System.out.println(result); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: N=int(input()) if N==1: print("AC") else: print("WA"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: //Author: Xzirium //Time and Date: 03:04:29 27 December 2021 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll b, ll e) { ll r = 1ll; for(; e > 0; e /= 2, (b *= b) %= MOD) if(e % 2) (r *= b) %= MOD; return r; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk; clk = clock(); //-----------------------------------------------------------------------------------------------------------// READV(N); if(N==1) { cout<<"AC"<<endl; } else { cout<<"WA"<<endl; } //-----------------------------------------------------------------------------------------------------------// clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, 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(); if(s==null){ System.exit(0); } StringTokenizer st = new StringTokenizer(s, " "); int power = Integer.parseInt(st.nextToken()); int multiple = Integer.parseInt(st.nextToken()); int res = power; for(int i = 1;i<=multiple;i++){ res = res*2; } System.out.println(res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: #include <iostream> using namespace std; int main() { int x, n; cin >> x >> n; cout << x*(1 << n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: x,n = map(int,input().split()) print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); double arr[] = new double[N]; String str[] = br.readLine().trim().split(" "); for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); double resistance=0; int equResistance=0; for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); for(int i=0;i<N;i++) { resistance=resistance+(1/arr[i]); } equResistance = (int)Math.floor((1/resistance)); System.out.println(equResistance); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("") r = int(r) n = input("").split() resistance=0.0 for i in range(0,r): resistor = float(n[i]) resistance = resistance + (1/resistor) print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; cin >> n; double s = 0; for(int i = 1; i <= n; i++){ double p; cin >> p; s = s + (1/p); } s = 1/s; cout << floor(s); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Piyush has N chocolates in his extremely huge bag. He wants to buy some chocolates (maybe 0) so that the total number of chocolates he has in his bag can never be fairly divided into piles. A division is considered fair if there are at least 2 piles and each pile has more than 1 chocolate. Moreover, each pile should contain an equal number of chocolates. You need to help Piyush find the minimum number of chocolates he needs to buy.The first and the only line of input contains N, the total number of chocolates Piyush has in his bag currently. Constraints 2 ≤ N ≤ 1000000000The output should contain only one integer, the minimum number of chocolates Piyush needs to buy so that the total number of chocolates can never be fairly divided.Sample Input 1 8 Sample Output 1 3 Sample Input 2 17 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static boolean isPrime(long n) { boolean ans=true; if(n<=3) { ans=true; } else if(n%2==0 || n%3==0) { ans=false; } else { for(int i=5;i*i<=n;i+=6) { if(n%i==0 || n%(i+2)==0) { ans=false; break; } } } return ans; } public static void main (String[] args) throws IOException{ BufferedReader scan=new BufferedReader(new InputStreamReader(System.in)); long n=Long.parseLong(scan.readLine()); long ans=0; while(true) { if(isPrime(n+ans)) { break; } ans++; } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Piyush has N chocolates in his extremely huge bag. He wants to buy some chocolates (maybe 0) so that the total number of chocolates he has in his bag can never be fairly divided into piles. A division is considered fair if there are at least 2 piles and each pile has more than 1 chocolate. Moreover, each pile should contain an equal number of chocolates. You need to help Piyush find the minimum number of chocolates he needs to buy.The first and the only line of input contains N, the total number of chocolates Piyush has in his bag currently. Constraints 2 ≤ N ≤ 1000000000The output should contain only one integer, the minimum number of chocolates Piyush needs to buy so that the total number of chocolates can never be fairly divided.Sample Input 1 8 Sample Output 1 3 Sample Input 2 17 Sample Output 2 0, I have written this Solution Code: def prime(n): for i in range(2,int(n**.5)+1): if(n%i==0): return False return True def check(n): if(n%2==0): n +=1 while(True): if(prime(n)==True): return n n +=2; return n n=int(input()) x=check(n) print(x-n), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Piyush has N chocolates in his extremely huge bag. He wants to buy some chocolates (maybe 0) so that the total number of chocolates he has in his bag can never be fairly divided into piles. A division is considered fair if there are at least 2 piles and each pile has more than 1 chocolate. Moreover, each pile should contain an equal number of chocolates. You need to help Piyush find the minimum number of chocolates he needs to buy.The first and the only line of input contains N, the total number of chocolates Piyush has in his bag currently. Constraints 2 ≤ N ≤ 1000000000The output should contain only one integer, the minimum number of chocolates Piyush needs to buy so that the total number of chocolates can never be fairly divided.Sample Input 1 8 Sample Output 1 3 Sample Input 2 17 Sample Output 2 0, I have written this Solution Code: #include <bits/stdc++.h> // #define ll long long using namespace std; int main(){ long long x,n; cin>>n; for(int i=n;i<n+500;i++){ x=i; long long p=sqrt(x); for(int j=2;j<=p;j++){ if(x%j==0){goto f;} } cout<<i-n; return 0; f:; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br.readLine(); String[] line = br.readLine().split(" "); int happyBalloons = 0; for(int i=1;i<=line.length;++i){ int num = Integer.parseInt(line[i-1]); if(num%2 == i%2 ){ happyBalloons++; } } System.out.println(happyBalloons); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, I have written this Solution Code: x=int(input()) arr=input().split() for i in range(0,x): arr[i]=int(arr[i]) count=0 for i in range(0,x): if(arr[i]%2==0 and (i+1)%2==0): count+=1 elif (arr[i]%2!=0 and (i+1)%2!=0): count+=1 print (count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N balloons numbered from 1 to N. Every balloon has an another integer value Arr[i] assigned to it where i varies from 1 to N, and i represents the number of balloon. A balloon at an odd position (i = 1, 3, 5. ) is happy if Arr[i] is odd. A balloon at an even position (i = 2, 4, 6. ) is happy if Arr[i] is even. Find the number of happy balloons.The first line of the input contains a single integer N. The second line of the input contains N singly spaced integers, Arr[1], Arr[2], Arr[3],. , Arr[N]. Constrains 1 <= N <= 200000 1 <= Arr[i] <= 1000000Output a single integer, the number of happy balloons.Sample Input 5 1 3 4 6 7 Sample Output 3 Explanation Happy balloons are balloons numbered 1, 4, 5. Sample Input 5 1 2 3 4 5 Sample Output 5, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(ll i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define ld long double #define int long long #define double long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 const int MOD = 1e9+7; const int INF = 1LL<<60; const int N = 2e5+5; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif void solve(){ int n; cin>>n; int ans = 0; For(i, 1, n+1){ int a; cin>>a; if(i%2 == a%2) ans++; } cout<<ans; } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--){ solve(); cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Create a new class VipCustomer it should have 3 fields name, creditLimit(double), and email address, there default value is as {name:"XYZ", creditLimit:"10", email:"xyz@abc. com"} respectively means ordering of parameter should be same. E.g constructor(name,creditLimit,email); create 3 constructor 1st constructor empty should call the constructor with 3 parameters with default values 2nd constructor should pass on the 2 values it receives as name and creditLimit respectively and, add a default value for the 3rd 3rd constructor should save all fields. create getters only for this name getName, getCreditLimit and getEmail and confirm it works. Note: each methods and variables should of public typeYou don't have to take any input, You only have to write class <b>VipCustomer</b>.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Input: class VipCustomer{ // if your code works fine for the tester } Sample Output: Correct, I have written this Solution Code: class VipCustomer{ public double creditLimit; public String name; public String email; VipCustomer(){ this("XYZ",10.0,"[email protected]"); } VipCustomer(String name,double creditLimit){ this(name,creditLimit,"[email protected]"); } VipCustomer(String _name,double _creditLimit,String _email){ email=_email; name=_name; creditLimit=_creditLimit; } public String getName(){ return this.name; } public String getEmail(){ return this.email; } public double getCreditLimit(){ return this.creditLimit; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the value of the below Equation for the given number. Equation: - N ∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2} X = 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 <b>equationSum()</b>, where you will get N as a parameter. <b>Constraints:</b> 1 <= N <= 100Return the sum of equation.Sample Input:- 1 Sample Output:- 14 Sample Input:- 2 Sample Output:- 44, I have written this Solution Code: static int equationSum(int n) { int sum=n*(n+1); sum=sum/2; sum=sum*sum; sum+=9*((n*(n+1))/2); sum+=4*(n); return sum; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the value of the below Equation for the given number. Equation: - N ∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2} X = 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 <b>equationSum()</b>, where you will get N as a parameter. <b>Constraints:</b> 1 <= N <= 100Return the sum of equation.Sample Input:- 1 Sample Output:- 14 Sample Input:- 2 Sample Output:- 44, I have written this Solution Code: def equationSum(N) : re=(N*(N+1))//2 re=re*re re=re+9*((N*(N+1))//2) re=re+4*N return re , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the value of the below Equation for the given number. Equation: - N ∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2} X = 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 <b>equationSum()</b>, where you will get N as a parameter. <b>Constraints:</b> 1 <= N <= 100Return the sum of equation.Sample Input:- 1 Sample Output:- 14 Sample Input:- 2 Sample Output:- 44, I have written this Solution Code: int equationSum(int n){ int sum=n*(n+1); sum=sum/2; sum=sum*sum; sum+=9*((n*(n+1))/2); sum+=4*(n); return sum; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, find the value of the below Equation for the given number. Equation: - N ∑ {(X - 1)<sup>3</sup> + 3(X + 1)<sup>2</sup> + 2} X = 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 <b>equationSum()</b>, where you will get N as a parameter. <b>Constraints:</b> 1 <= N <= 100Return the sum of equation.Sample Input:- 1 Sample Output:- 14 Sample Input:- 2 Sample Output:- 44, I have written this Solution Code: int equationSum(int n){ int sum=n*(n+1); sum=sum/2; sum=sum*sum; sum+=9*((n*(n+1))/2); sum+=4*(n); return sum; } , 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: Given a number N and a number P, your task is to calculate N<sup>P</sup>. Since the ans can be very long calculate your ans as N<sup>P</sup>%M where M = 10<sup>9</sup>+7Input contains only two integers N and P separated by spaces. Constraints:- 1 < = N, P <= 1000000000Print N<sup>P</sup>%M.Sample Input:- 2 5 Sample Output:- 32 Sample Input:- 2 100 Sample Output:- 976371285, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException{ BufferedReader rd=new BufferedReader(new InputStreamReader(System.in)); String y[]=rd.readLine().split(" "); long n=Long.parseLong(y[0]); long p=Long.parseLong(y[1]); long v=1; while(p>0){ if((p&1L)==1L) v=(v*n)%1000000007; p/=2; n=(n*n)%1000000007; } System.out.print(v); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N and a number P, your task is to calculate N<sup>P</sup>. Since the ans can be very long calculate your ans as N<sup>P</sup>%M where M = 10<sup>9</sup>+7Input contains only two integers N and P separated by spaces. Constraints:- 1 < = N, P <= 1000000000Print N<sup>P</sup>%M.Sample Input:- 2 5 Sample Output:- 32 Sample Input:- 2 100 Sample Output:- 976371285, I have written this Solution Code: n, p =input().split() n, p =int(n), int(p) def FastModularExponentiation(b, k, m): res = 1 b = b % m while (k > 0): if ((k & 1) == 1): res = (res * b) % m k = k >> 1 b = (b * b) % m return res m=pow(10,9)+7 print(FastModularExponentiation(n, p, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N and a number P, your task is to calculate N<sup>P</sup>. Since the ans can be very long calculate your ans as N<sup>P</sup>%M where M = 10<sup>9</sup>+7Input contains only two integers N and P separated by spaces. Constraints:- 1 < = N, P <= 1000000000Print N<sup>P</sup>%M.Sample Input:- 2 5 Sample Output:- 32 Sample Input:- 2 100 Sample Output:- 976371285, 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); } int power(int x, unsigned int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } // Driver code signed main() { int x ; int y; cin>>x>>y; int p = 1e9+7; cout<< power(x, y, p); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); String s[] = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int k = Integer.parseInt(s[1]); String str[] = br.readLine().split(" "); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(str[i]); } System.out.print(minDivisor(arr,n,k)); } static int minDivisor(int arr[],int N, int limit) { int low = 0, high = 1000000000; while (low < high) { int mid = (low + high) / 2; int sum = 0; for(int i = 0; i < N; i++) { sum += Math.ceil((double) arr[i] / (double) mid); } if(sum <= limit){ high = mid; } else{ low = mid + 1; } } return low; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: from math import ceil def kSum(arr, n, k): low = 0 high = 10 ** 9 while (low < high): mid = (low + high) // 2 sum = 0 for i in range(int(n)): sum += ceil( int(arr[i]) / mid) if (sum <= int(k)): high = mid else: low = mid + 1 return low n, k =input().split() arr = input().split() print( kSum(arr, n, k) ), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of size N and a number K, the task is to find the smallest number M such that the sum of the array becomes lesser than or equal to the number K when every element of that array is divided by the number M. Note: Each result of the division is rounded to the nearest integer greater than or equal to that element. For example: 10/3 = 4 and 6/2 = 3The first line contains two integers N and K. Next line contains N integers denoting the elements of arr[] <b>Constraints:</b> 1 <= N <= 100000 1 <= arr[i] <= 100000 1 <= K <= 100000000Print a single integer the value of smallest number MSample Input: 4 6 2 3 4 9 Sample Output: 4 Explanation: When every element is divided by 4 - 2/4 + 3/4 + 4/4 + 9/4 = 1 + 1 + 1 + 3 = 6 When every element is divided by 3 - 2/3 + 3/3 + 4/3 + 9/3 = 1 + 1 + 2 + 3 = 7 which is greater than K. Hence the smallest integer which makes the sum less than or equal to K = 6 is 4., I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define ll long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N], n, k; bool f(int x){ int sum = 0; for(int i = 1; i <= n; i++) sum += (a[i]-1)/x + 1; return (sum <= k); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = N; while(l+1 < h){ int m = (l + h) >> 1; if(f(m)) h = m; else l = m; } cout << h; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { IOS; clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., I have written this Solution Code: a=int(input()) b=input().split(" ") p=0 if b[0]=="1" and b[1]=="1" and b[2]=="1" and b[3]=="1" and b[4]=="1" and b[5]=="1": print(1) p=1 exit(0) bb="" for i in b: bb=bb+i b=bb while len(b)!=1 and p==0: if "101" in b: b=b.replace("101","1") elif "110" in b: b=b.replace("110","1") elif "011" in b: b=b.replace("011","1") elif "010" in b: b=b.replace("010","0") elif "001" in b: b=b.replace("001","0") elif "100" in b: b=b.replace("100","0") else: break if len(b)==1 and p==0: print("1") elif p==0 and len(b)!=1: print("0"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., 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 int n; cin>>n; int v=0; for(int i=0;i<n;++i){ int d; cin>>d; if(d==0) ++v; else --v; } if(abs(v)==1){ cout<<1; } else{ cout<<0; } #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary array (a binary array is an array consisting only of zeroes and ones) of size N. You can do following operation on the array any number of times. In an operation you can select any subarray of size 3 of the array such that all three elements of that subarray are not same and replace that subarray with a single element which is the element with frequency 2 in that subarray. For example if we are given array [0, 1, 0, 1, 1, 0] if we select subarray (0-2) then we will replace [0, 1, 0] with [0] so the array finally becomes [0, 1, 1, 0]. You have to find if it is possible to apply this operation some number of times to finally reduce the array to size 1.First line of input contains a single integer N, size of the array. Second line contains N integers denoting the binary array. Constraints: 3 <= N <= 100000 0 <= Arr[i] <= 1Print 1 if it is possible to finally reduce the array to size 1 else print 0.Sample Input 1 5 0 1 0 1 0 Sample Output 1 1 Explanation: First we select subarray (0-2) array gets changed to 0 1 0 Second we select subarray (0-2) array gets changed to 0 As the size became 1 therefore it is possible. Sample Input 2 5 1 1 1 1 0 Sample Output 2 0 Explanation - First we select subarray (2-4) array gets changed to 1 1 1 1 Now we cannot do the operation anymore., 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 zero = 0,one = 0; String[] s = br.readLine().trim().split(" "); for(int i=0;i<n;i++){ int x = Integer.parseInt(s[i]); if(x%2==0) zero++; else one++; } if(zero-one==1 || zero-one==-1 ) System.out.print(1); else System.out.print(0); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Abhas likes to play with numbers. He is given integers N and K. Find the number of triples (a, b, c) of positive integers not greater than N such that a+b, b+c, and c+a are all multiples of K. The order of a, b, and c does matter, and some of them can be the same.The input line contains N and K separated by space. <b>Constraints</b> 1&le;N, K&le;2×10^5 N and K are integers.Print the number of triples (a, b, c) of positive integers not greater than N such that a+b, b+c, and c+a are all multiples of K.<b>Sample Input 1</b> 3 2 <b>Sample Output 1</b> 9 <b>Sample Input 2</b> 5 3 <b>Sample Output 2</b> 1 <b>Sample Input 3</b> 35897 932 <b>Sample Output 3</b> 114191, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; typedef long long ll; ll get(ll x) { return x*x*x; } int main() { ll n,k,ans=0; cin>>n>>k; if (k&1) { cout<<get(n/k); } else { cout<<get(n/k)+get(2*n/k-n/k); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The username field in `PROFILE` must have at least 3 characters. Create a table `PROFILE` having this constraint. Fields are (USERNAME VARCHAR (24), FULL_NAME (72), HEADLINE VARCHAR (72)). ( USE ONLY UPPERCASE LETTERS FOR CODE ) <schema>[{'name': 'PROFILE', 'columns': [{'name': 'USERNAME', 'type': 'VARCHAR (24)'}, {'name': 'FULL_NAME', 'type': 'VARCHAR (72)'}, {'name': 'HEADLINE', 'type': 'VARCHAR (72)'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE PROFILE( USERNAME VARCHAR(24) CHECK (LENGTH(USERNAME) >= 3) , FULL_NAME VARCHAR(72), HEADLINE VARCHAR(72) );, In this Programming Language: SQL, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, find all combination of four elements in the array whose sum is equal to a given value K. For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and K = 23, one of the quadruple is “3 5 7 8” (3 + 5 + 7 + 8 = 23). The output should contain only unique quadruple For example, if the input array is {1, 1, 1, 1, 1, 1} and K = 4, then the output should be only one quadruple {1, 1, 1, 1}The first line of input contains two integers N and K. Then in the next line there are N space-separated values of the array. Constraints: 1 <= N <= 1000 -20000 <= K <= 20000 -50000 <= A[i] <= 50000 All elements are pairwise distinctPrint all the quadruples present in the array separated by space which sums up to the value of K. Each quadruple is unique which are separated by a new line and are in increasing order. NOTE The order of printing each quadruple should be from lowest lexicographical quadruple to the highest and each quadruple must be printed in sorted order and only once. It is guaranteed that at least one solution will always exist.Sample Input 5 3 0 0 2 1 1 Sample Output 0 0 1 2 Sample Input 7 23 10 2 3 4 5 7 8 Sample Output 2 3 8 10 2 4 7 10 3 5 7 8 , 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[]arr = new int[n]; for(int i=0; i<n; i++){ arr[i] = sc.nextInt(); } List<List<Integer>> result = fourSum(arr, k); for(List<Integer>list : result){ for(Integer x : list){ System.out.print(x + " "); } System.out.println(); } } public static List<List<Integer>> fourSum(int[] nums, int target) { List<List<Integer>>quadruplets = new ArrayList<>(); if(nums.length < 4){ return quadruplets; } Arrays.sort(nums); for(int a=0; a<nums.length; a++){ if(a!=0 && nums[a]==nums[a-1]){ continue; } for(int b=a+1; b<nums.length; b++){ if(b!=a+1 && nums[b]==nums[b-1]){ continue; } int c = b+1; int d = nums.length-1; while(c < d){ if(c!=b+1 && nums[c] == nums[c-1]){ c++; continue; } if(d!=nums.length-1 && nums[d] == nums[d+1]){ d--; continue; } int sum = nums[b] + nums[c] + nums[d] + nums[a]; if(sum == target){ quadruplets.add(Arrays.asList(nums[a], nums[b], nums[c], nums[d])); d--; } else if(sum < target){ c++; } else{ d--; } } } } return quadruplets; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, find all combination of four elements in the array whose sum is equal to a given value K. For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and K = 23, one of the quadruple is “3 5 7 8” (3 + 5 + 7 + 8 = 23). The output should contain only unique quadruple For example, if the input array is {1, 1, 1, 1, 1, 1} and K = 4, then the output should be only one quadruple {1, 1, 1, 1}The first line of input contains two integers N and K. Then in the next line there are N space-separated values of the array. Constraints: 1 <= N <= 1000 -20000 <= K <= 20000 -50000 <= A[i] <= 50000 All elements are pairwise distinctPrint all the quadruples present in the array separated by space which sums up to the value of K. Each quadruple is unique which are separated by a new line and are in increasing order. NOTE The order of printing each quadruple should be from lowest lexicographical quadruple to the highest and each quadruple must be printed in sorted order and only once. It is guaranteed that at least one solution will always exist.Sample Input 5 3 0 0 2 1 1 Sample Output 0 0 1 2 Sample Input 7 23 10 2 3 4 5 7 8 Sample Output 2 3 8 10 2 4 7 10 3 5 7 8 , I have written this Solution Code: from collections import defaultdict n,total=list(map(int,input().split())) arr=list(map(int,input().split())) mp = defaultdict(list) for i in range(n - 1): for j in range(i + 1, n): mp[arr[i] + arr[j]].append([i, j]) answer=set() for i in range(n - 1): for j in range(i + 1, n): summ = arr[i] + arr[j] if (total - summ) in mp: probable=mp[total-summ] for p in probable: if (p[0] != i and p[0] != j and p[1] != i and p[1] != j): x=sorted([arr[i], arr[j],arr[p[0]],arr[p[1]]]) x=tuple(x) if x not in answer: answer.add(x) answer=sorted(answer) for i in answer: print(i[0],i[1],i[2],i[3]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, find all combination of four elements in the array whose sum is equal to a given value K. For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and K = 23, one of the quadruple is “3 5 7 8” (3 + 5 + 7 + 8 = 23). The output should contain only unique quadruple For example, if the input array is {1, 1, 1, 1, 1, 1} and K = 4, then the output should be only one quadruple {1, 1, 1, 1}The first line of input contains two integers N and K. Then in the next line there are N space-separated values of the array. Constraints: 1 <= N <= 1000 -20000 <= K <= 20000 -50000 <= A[i] <= 50000 All elements are pairwise distinctPrint all the quadruples present in the array separated by space which sums up to the value of K. Each quadruple is unique which are separated by a new line and are in increasing order. NOTE The order of printing each quadruple should be from lowest lexicographical quadruple to the highest and each quadruple must be printed in sorted order and only once. It is guaranteed that at least one solution will always exist.Sample Input 5 3 0 0 2 1 1 Sample Output 0 0 1 2 Sample Input 7 23 10 2 3 4 5 7 8 Sample Output 2 3 8 10 2 4 7 10 3 5 7 8 , 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; map<int, vector<pi> > m; map<pair<pi, pi>, int> m1; int a[N]; signed main() { IOS; int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) for(int j = i+1; j <= n; j++) m[a[i]+a[j]].push_back({i, j}); for(int i = 1; i <= n; i++){ for(int j = i+1; j <= n; j++){ int cur = a[i] + a[j]; int rem = k - cur; if(m.find(rem) != m.end()){ for(auto p: m[rem]){ if(p.fi != i && p.fi != j && p.se != i && p.se != j && j <= p.fi) m1[{{a[i], a[j]}, {a[p.fi], a[p.se]}}]++; } } } } for(auto i: m1){ cout << i.fi.fi.fi << " " << i.fi.fi.se << " " << i.fi.se.fi << " " << i.fi.se.se << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); String array[] = br.readLine().trim().split(" "); boolean decreasingOrder = false; int[] arr = new int[n]; int totalZeroCount = 0, totalOneCount = 0; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(array[i]); if(i != 0 && arr[i] < arr[i - 1]) decreasingOrder = true; if(arr[i] % 2 == 0) ++totalZeroCount; else ++totalOneCount; } if(!decreasingOrder) { System.out.println("0"); } else { int oneCount = 0; for(int i = 0; i < totalZeroCount; i++) { if(arr[i] == 1) ++oneCount; } System.out.println(oneCount); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int a[n]; for(int i=0;i<n;++i){ cin>>a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i]==0) cnt++; } int ans = 0; for (int i = 0; i < cnt; i++) if (a[i] == 1) ans++; cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: n=int(input()) l=list(map(int,input().split())) x=l.count(0) c=0 for i in range(0,x): if(l[i]==1): c+=1 print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine().trim(); char[] express = s.toCharArray(); StringBuilder ans = new StringBuilder(""); Stack<Character> stack = new Stack<>(); for(int i=0; i<express.length; i++){ if(express[i]>=65 && express[i]<=90){ ans.append(express[i]); }else if(express[i]==')'){ while(stack.peek()!='('){ ans.append(stack.peek()); stack.pop(); } stack.pop(); }else if(stack.empty() || express[i]=='(' || precedence(express[i])>=precedence(stack.peek())){ stack.push(express[i]); }else{ while(!stack.empty() && stack.peek()!='(' && precedence(stack.peek())<=express[i]){ ans.append(stack.peek()); stack.pop(); } stack.push(express[i]); } } while(!stack.empty()){ ans.append(stack.peek()); stack.pop(); } System.out.println(ans); } static int precedence(char operator){ int precedenceValue; if(operator=='+' || operator=='-') precedenceValue = 1; else if(operator=='*' || operator=='/') precedenceValue = 2; else if(operator == '^') precedenceValue = 3; else precedenceValue = -1; return precedenceValue; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: string=input() stack=list() preced={'+':1,'-':1,'*':2,'/':2,'^':3} for i in string: if i!=')': if i=='(': stack.append(i) elif i in ['*','+','/','-','^']: while(stack and stack[-1]!='(' and preced[i]<=preced[stack[-1]]): print(stack.pop(),end="") stack.append(i) else: print(i,end="") else: while(stack and stack[-1]!='('): print(stack.pop(),end="") stack.pop() while(stack): print(stack.pop(),end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an infix expression, your task is to convert it into postfix. <b>Infix expression</b>: The expression of the form a operator b. When an operator is in- between every pair of operands. <b>Postfix expression</b>: The expression of the form a b operator. When an operator is followed for every pair of operands. Valid operators are +, - , *, /, ^. Each operand is an uppercase english alphabet. Infix expression may contains parenthesis as '(' and ')'. See example for better understanding.The input contains a single string of infix expression. <b>Constraints:-</b> 1 <= |String| <= 40Output the Postfix expression.Sample Input:- ((A-(B/C))*((A/K)-L)) Sample Output:- ABC/-AK/L-* Sample Input:- A+B Sample Output:- AB+, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; //Function to return precedence of operators int prec(char c) { if(c == '^') return 3; else if(c == '*' || c == '/') return 2; else if(c == '+' || c == '-') return 1; else return -1; } // The main function to convert infix expression //to postfix expression void infixToPostfix(string s) { std::stack<char> st; st.push('N'); int l = s.length(); string ns; for(int i = 0; i < l; i++) { // If the scanned character is an operand, add it to output string. if((s[i] >= 'a' && s[i] <= 'z')||(s[i] >= 'A' && s[i] <= 'Z')) ns+=s[i]; // If the scanned character is an ‘(‘, push it to the stack. else if(s[i] == '(') st.push('('); // If the scanned character is an ‘)’, pop and to output string from the stack // until an ‘(‘ is encountered. else if(s[i] == ')') { while(st.top() != 'N' && st.top() != '(') { char c = st.top(); st.pop(); ns += c; } if(st.top() == '(') { char c = st.top(); st.pop(); } } //If an operator is scanned else{ while(st.top() != 'N' && prec(s[i]) <= prec(st.top())) { char c = st.top(); st.pop(); ns += c; } st.push(s[i]); } } //Pop all the remaining elements from the stack while(st.top() != 'N') { char c = st.top(); st.pop(); ns += c; } cout << ns << endl; } //Driver program to test above functions int main() { string exp; cin>>exp; infixToPostfix(exp); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); String array[] = br.readLine().trim().split(" "); boolean decreasingOrder = false; int[] arr = new int[n]; int totalZeroCount = 0, totalOneCount = 0; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(array[i]); if(i != 0 && arr[i] < arr[i - 1]) decreasingOrder = true; if(arr[i] % 2 == 0) ++totalZeroCount; else ++totalOneCount; } if(!decreasingOrder) { System.out.println("0"); } else { int oneCount = 0; for(int i = 0; i < totalZeroCount; i++) { if(arr[i] == 1) ++oneCount; } System.out.println(oneCount); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int a[n]; for(int i=0;i<n;++i){ cin>>a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i]==0) cnt++; } int ans = 0; for (int i = 0; i < cnt; i++) if (a[i] == 1) ans++; cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers containing only 0 or 1. You can do the following operations on the array: <ul><li>swap elements at two indices</li><li>choose one index and change its value from 0 to 1 or vice-versa.</li></ul> You have to do the minimum number of the above operations such that the final array is non-decreasing. <b>Note</b> Consider 1 based Array-indexingThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 &le; N &le; 100000 elements of the array are 0 or 1.Minimum number of moves required such that the final array is non- decreasing.Sample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0, I have written this Solution Code: n=int(input()) l=list(map(int,input().split())) x=l.count(0) c=0 for i in range(0,x): if(l[i]==1): c+=1 print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: How would you add your own method to the Array object so the following code would work? const arr = [1, 2, 3] console. log(arr.average()) // 2input will be an array, run like this const anyArray = [5,6...] anyArray.average should return average of the arraysAverage of the given arrayconst myArray = [1,2,3,4,5] console.log(myArray.average()) // 3, I have written this Solution Code: Array.prototype.average = function() { // calculate sum var sum = this.reduce(function(prev, cur) { return prev + cur; }); // return sum divided by number of elements return sum / this.length; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, I have written this Solution Code: m,n=map(int ,input().split()) matrix=[] for i in range(m): l1=[eval(x) for x in input().split()] matrix.append(l1) l2=[] for coloumn in range(n): sum1=0 for row in range(m): sum1+= matrix[row][coloumn] l2.append(sum1) print(max(l2)) '''for row in range(n): sum2=0 for col in range(m): sum2 += matrix[row][col] print(sum2)''', In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, I have written this Solution Code: // mat is the matrix/ 2d array // the dimensions of array are:- a rows, b columns function colMaxSum(mat,a,b) { // write code here // do not console.log // return the answer as a number let idx = -1; // Variable to store max sum let maxSum = Number.MIN_VALUE; // Traverse matrix column wise for (let i = 0; i < b; i++) { let sum = 0; // calculate sum of column for (let j = 0; j < a; j++) { sum += mat[j][i]; } // Update maxSum if it is // less than current sum if (sum > maxSum) { maxSum = sum; // store index idx = i; } } let res; res = [idx, maxSum]; // return result return maxSum; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, 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,m; cin>>n>>m; int a[m]; for(int i=0;i<m;i++){ a[i]=0; } int x; int sum=0; FOR(i,n){ FOR(j,m){ cin>>x; a[j]+=x; sum=max(sum,a[j]); } } out(sum); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix. Constraints:- 1 <= M, N <= 100 1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:- 3 3 1 2 3 4 5 6 7 8 9 Sample Output:- 18 Explanation:- 1 + 4 + 7 = 12 2 + 5 + 8 = 15 3 + 6 + 9 = 18 maximum = 18 Sample Input:- 3 2 1 4 9 6 9 1 Sample Output:- 19, 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 m = sc.nextInt(); int n = sc.nextInt(); int a[][] = new int[m][n]; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ a[i][j]=sc.nextInt(); } } int sum=0; int ans=0; for(int i=0;i<n;i++){ sum=0; for(int j=0;j<m;j++){ sum+=a[j][i]; } if(sum>ans){ans=sum;} } System.out.print(ans); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A movie theater gave you two tables: Seats that are available for an upcoming screening and neighboring seats for each seat listed. You are asked to find all seats that are adjacent and available for a fixed price. Output only distinct pairs of seats in two columns such that the seat with the lower number is always in the first column and the one with the higher number is in the second column.DataFrame/SQL Table with the following schema - <schema>[{'name': 'theater_availability', 'columns': [{'name': 'seat_number', 'type': 'int64'}, {'name': 'is_available', 'type': 'bool'}]}, {'name': 'theater_seatmap', 'columns': [{'name': 'seat_number', 'type': 'int64'}, {'name': 'seat_left', 'type': 'float64'}, {'name': 'seat_right', 'type': 'float64'}]}]</schema>Each row in a new line and each value of a row separated by a |, i.e., 0|1|2 1|2|3 2|3|4-, I have written this Solution Code: available_seats = theater_availability[theater_availability['is_available']==True]['seat_number'].unique() pair = set() for i, row in theater_seatmap.iterrows(): seat = row['seat_number'] left = row['seat_left'] right = row['seat_right'] if left in available_seats and seat in available_seats: pair.add((left, seat)) if seat in available_seats and right in available_seats: pair.add((seat, right)) pair = list(pair) pair.sort(key = lambda x : x[0]) for i in pair: print(f'{i[0]}|{i[1]}'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A movie theater gave you two tables: Seats that are available for an upcoming screening and neighboring seats for each seat listed. You are asked to find all seats that are adjacent and available for a fixed price. Output only distinct pairs of seats in two columns such that the seat with the lower number is always in the first column and the one with the higher number is in the second column.DataFrame/SQL Table with the following schema - <schema>[{'name': 'theater_availability', 'columns': [{'name': 'seat_number', 'type': 'int64'}, {'name': 'is_available', 'type': 'bool'}]}, {'name': 'theater_seatmap', 'columns': [{'name': 'seat_number', 'type': 'int64'}, {'name': 'seat_left', 'type': 'float64'}, {'name': 'seat_right', 'type': 'float64'}]}]</schema>Each row in a new line and each value of a row separated by a |, i.e., 0|1|2 1|2|3 2|3|4-, I have written this Solution Code: WITH adjacent_seats AS (SELECT seat_number AS seat, seat_left AS adj_seat FROM theater_seatmap UNION SELECT seat_number AS seat, seat_right AS adj_seat FROM theater_seatmap) SELECT seat AS available_seat1, adj_seat AS available_seat2 FROM adjacent_seats s JOIN theater_availability a1 ON s.seat = a1.seat_number JOIN theater_availability a2 ON s.adj_seat = a2.seat_number WHERE a1.is_available AND a2.is_available AND seat < adj_seat, In this Programming Language: SQL, 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: Harry saved money to have a dinner at a five star restaurant. He want to have a complete meal. The restaurant has N items on it's menu. The menu's i<sup>th</sup> item belongs to the category A<sub>i</sub> and takes B<sub>i</sub> time to prepare. His dinner meal should include at least K different categories of food. The sum of the cooking times for each item in Harry's order is the total time needed to prepare everything he orders. Find the minimum time Harry needs to have a complete meal for himself or or let him know if it is not possible to do so.First line will contain T, the number of test cases. Then the test cases follow. Each test case contains three lines:<ul><li>The first line of each test case contains two space- separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal. </li><li>The second line contains N space- separated integers where the i<sup>th</sup> integer is A<sub>i</sub>, denoting the category of the i<sup>th</sup>dish in the menu. </li><li>The third line contains N space- separated integers where the i<sup>th</sup>integer is B<sub>i</sub>, denoting the time required to cook the i<sup>th</sup> dish in the menu. </li></ul> <b>Constraints</b> 1 &le; T &le; 100 1 &le; N, K &le; 10<sup>5</sup> 1 &le; A<sub>i</sub> &le; 10<sup>5</sup> 0 &le; B<sub>i</sub> &le; 10<sup>5</sup> The sum of N over all test cases won't exceed 10<sup>5</sup>.For each test case, output in a single line, the minimum time required to have a complete meal. If it is impossible to have a complete meal, print -1 instead.Sample Input : 4 3 1 1 2 3 2 1 3 8 3 1 3 2 2 4 1 3 5 3 3 0 1 2 4 1 4 1 1 5 1 5 3 1 1 2 2 1 1 1 0 3 5 Sample Output : 1 3 1 -1 Explanation : <ul><li>Harry can choose dish with index 2 having category 2. The total time required to get the complete meal is 1. </li><li>Harry can choose dishes with index 3, 5, and 7 from the menu. <ul><li>Dish 3: The dish has category 2 and requires time 0. </li><li>Dish 5: The dish has category 4 and requires time 2. </li><li>Dish 7: The dish has category 3 and requires time 1. </li></ul>Thus, there are 3 distinct categories and the total time to get the meal is 0 + 2 + 1 = 3. It can be shown that this is the minimum time to get the complete meal. </li><li>Harry can choose the only available dish having category 5. The total time required to get the complete meal is 1. </li><li>The total number of distinct categories available is 2, which is less than K. Thus, it is impossible to have a complete meal. </li></ul>, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void solve(){ int n = sc.nextInt(), k = sc.nextInt(); int [] cat = sc.nextIntArray(n); int [] time = sc.nextIntArray(n); HashMap<Integer, Integer> hash = new HashMap<>(); HashSet<Integer> set = new HashSet<>(); for(int i=0; i<n; i++){ if(!hash.containsKey(cat[i])){ hash.put(cat[i], Integer.MAX_VALUE); } set.add(cat[i]); int max = hash.get(cat[i]); hash.put(cat[i], Math.min(max, time[i])); } if(set.size() < k){ out.println(-1); return; } PriorityQueue<Integer> pq = new PriorityQueue<>(); for(Map.Entry<Integer, Integer> en : hash.entrySet()){ pq.add(en.getValue()); } long ans= 0; while (k>0){ ans += pq.poll(); k--; } out.println(ans); } static PrintWriter out; static Scanner sc; public static void main (String[] args) throws java.lang.Exception { sc = new Scanner(); out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0){ solve(); } out.close(); } private static long power(long a, long b) { long res = 1; while (b > 0) { if ((b & 1)==1) res = res * a; a = a * a; b >>= 1; } return res; } private static long power(long a, long b, long m) { a %= m; long res = 1; while (b > 0) { if ((b & 1)==1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } private static long lcm(long a, long b) { return a * b / gcd(a, b); } private static long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); /* try { br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt")))); } catch (FileNotFoundException e) { e.printStackTrace(); } */ } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } Integer[] nextIntegerArray(int n) { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } String[] nextStringArray() { return nextLine().split(" "); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Harry saved money to have a dinner at a five star restaurant. He want to have a complete meal. The restaurant has N items on it's menu. The menu's i<sup>th</sup> item belongs to the category A<sub>i</sub> and takes B<sub>i</sub> time to prepare. His dinner meal should include at least K different categories of food. The sum of the cooking times for each item in Harry's order is the total time needed to prepare everything he orders. Find the minimum time Harry needs to have a complete meal for himself or or let him know if it is not possible to do so.First line will contain T, the number of test cases. Then the test cases follow. Each test case contains three lines:<ul><li>The first line of each test case contains two space- separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal. </li><li>The second line contains N space- separated integers where the i<sup>th</sup> integer is A<sub>i</sub>, denoting the category of the i<sup>th</sup>dish in the menu. </li><li>The third line contains N space- separated integers where the i<sup>th</sup>integer is B<sub>i</sub>, denoting the time required to cook the i<sup>th</sup> dish in the menu. </li></ul> <b>Constraints</b> 1 &le; T &le; 100 1 &le; N, K &le; 10<sup>5</sup> 1 &le; A<sub>i</sub> &le; 10<sup>5</sup> 0 &le; B<sub>i</sub> &le; 10<sup>5</sup> The sum of N over all test cases won't exceed 10<sup>5</sup>.For each test case, output in a single line, the minimum time required to have a complete meal. If it is impossible to have a complete meal, print -1 instead.Sample Input : 4 3 1 1 2 3 2 1 3 8 3 1 3 2 2 4 1 3 5 3 3 0 1 2 4 1 4 1 1 5 1 5 3 1 1 2 2 1 1 1 0 3 5 Sample Output : 1 3 1 -1 Explanation : <ul><li>Harry can choose dish with index 2 having category 2. The total time required to get the complete meal is 1. </li><li>Harry can choose dishes with index 3, 5, and 7 from the menu. <ul><li>Dish 3: The dish has category 2 and requires time 0. </li><li>Dish 5: The dish has category 4 and requires time 2. </li><li>Dish 7: The dish has category 3 and requires time 1. </li></ul>Thus, there are 3 distinct categories and the total time to get the meal is 0 + 2 + 1 = 3. It can be shown that this is the minimum time to get the complete meal. </li><li>Harry can choose the only available dish having category 5. The total time required to get the complete meal is 1. </li><li>The total number of distinct categories available is 2, which is less than K. Thus, it is impossible to have a complete meal. </li></ul>, I have written this Solution Code: #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <unordered_set> #define ax long long using namespace std; void solve(){ ax cv,q; cin>>cv>>q; vector<ax>a(cv),b(cv); set<ax>unq; ax e = 0; while (e < cv) { cin>>a[e]; unq.insert(a[e]); e++; } e = 0; while (e < cv) { cin>>b[e]; e++; } if (unq.size()<q) { cout<<-1<<endl; return; } map<ax, ax>re; e = 0; while (e < cv) { if (re.find(a[e])==re.end()) { re[a[e]]=b[e]; } else { re[a[e]]=min(re[a[e]],b[e]); } e++; } vector<ax>oi; for(auto&x:re)oi.push_back(x.second); sort(oi.begin(), oi.end()); ax ans=accumulate(oi.begin(),oi.begin()+q,0LL); cout<<ans<<endl; } int main(){ ax t=1; cin>>t; while(t--){ solve(); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a function called lucky_sevens which takes an array of integers and returns true if any three consecutive elements sum to 7An array containing numbers.Print true if such triplet exists summing to 7 else print falseSample input:- [2, 1, 5, 1, 0] [1, 6] Sample output:- true false Explanation:- 1+5+1 = 7 no 3 consecutive numbers so false, I have written this Solution Code: function lucky_sevens(arr) { // if less than 3 elements then this challenge is not possible if (arr.length < 3) { console.log(false) return; } // because we know there are at least 3 elements we can // start the loop at the 3rd element in the array (i=2) // and check it along with the two previous elements (i-1) and (i-2) for (let i = 2; i < arr.length; i++) { if (arr[i] + arr[i-1] + arr[i-2] === 7) { console.log(true) return; } } // if loop is finished and no elements summed to 7 console.log(false) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, 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(); if(s==null){ System.exit(0); } StringTokenizer st = new StringTokenizer(s, " "); int power = Integer.parseInt(st.nextToken()); int multiple = Integer.parseInt(st.nextToken()); int res = power; for(int i = 1;i<=multiple;i++){ res = res*2; } System.out.println(res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: #include <iostream> using namespace std; int main() { int x, n; cin >> x >> n; cout << x*(1 << n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≤ X ≤ 1000 1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: x,n = map(int,input().split()) print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: static void verticalFive(){ System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); System.out.println("*"); } static void horizontalFive(){ System.out.print("* * * * *"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b> There will be two functions: <ul> <li>verticalFive(): Print stars in vertical order</li> <li>horizontalFive(): Print stars in horizontal order</l> </ul><b>User Task:</b> Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>. Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function. <b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input: Sample Output: * * * * * * * * * *, I have written this Solution Code: def vertical5(): for i in range(0,5): print("*",end="\n") #print() def horizontal5(): for i in range(0,5): print("*",end=" ") vertical5() print(end="\n") horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[] of size N containing non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements. Note: You must do this in-place without making a copy of the array. Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^5 <b>Sum of N over all testcases does not exceed 10^6</b> For each testcase you need to print the updated array.Sample Input: 2 5 0 1 0 3 12 8 0 0 0 0 1 2 3 4 Sample Output: 1 3 12 0 0 1 2 3 4 0 0 0 0, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t; t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int j=-1; for(int i=0;i<n;i++){ if(a[i]==0 && j==-1){ j=i; } if(j!=-1 && a[i]!=0){ a[j]=a[i]; a[i]=0; j++; } } for(int i=0;i<n;i++){ System.out.print(a[i]+" "); } System.out.println(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[] of size N containing non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements. Note: You must do this in-place without making a copy of the array. Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^5 <b>Sum of N over all testcases does not exceed 10^6</b> For each testcase you need to print the updated array.Sample Input: 2 5 0 1 0 3 12 8 0 0 0 0 1 2 3 4 Sample Output: 1 3 12 0 0 1 2 3 4 0 0 0 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n,k; cin>>n; int a[n]; int cnt=0; for(int i=0;i<n;i++){ cin>>a[i];\ if(a[i]==0){cnt++;} } for(int i=0;i<n;i++){ if(a[i]!=0){ cout<<a[i]<<" "; } } while(cnt--){ cout<<0<<" "; } cout<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; cin >> n; int sum = 0; for(int i = 1; i <= n; i++){ int p; cin >> p; if(p > 0) sum += p; } cout << sum; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: n=int(input()) li = list(map(int,input().strip().split())) sum=0 for i in li: if i>0: sum+=i print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Numbers are awesome, larger numbers are more awesome! Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array. The next line contains N (white-space separated) integers denoting the elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>4</sup> -10<sup>7</sup> &le; A[i] &le;10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1: 5 1 2 1 -1 1 output 1: 5 input 2: 5 0 0 -1 0 0 output 2: 0 <b>Explanation 1:</b> In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); int n = Integer.parseInt(br.readLine()); String str[] = br.readLine().split(" "); long arr[] = new long[n]; long sum=0; for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(str[i]); if(arr[i]>0){ sum+=arr[i]; } } System.out.print(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 2 numbers a, b. You can perform at most b steps In one step : 1- increase a by 3 2- decrease a by 3 3- multiply a by 2 Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T. For each test case: Input two integers a and b. 0 < T <= 100 1 <= a <= 100000 1 <= b <= 9Print answer on a separate line for each test caseSample Input 2 5 1 30 2 Sample Output 4 11 For test 1:- In 0 steps, 5 can be formed In 1 steps 2, 8, 10 can be formed For test 2:- in 0 step :- 30 in 1 step- 27 33 60 in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120 total unique number = 11, I have written this Solution Code: import java.util.*; class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int a=sc.nextInt(); int b=sc.nextInt(); ArrayList<Integer> arr=new ArrayList(); arr.add(a); for(int j=1;j<b+1;j++) { int decrease=0; int increse=0; int mul=0; int len=arr.size(); for(int e=0;e<len;e++) { decrease=arr.get(e)-3; if(!arr.contains(decrease)) { arr.add(decrease); } increse=arr.get(e)+3; if(!arr.contains(increse)) { arr.add(increse); } mul=arr.get(e)*2; if(!arr.contains(mul)) { arr.add(mul); } } } System.out.println(arr.size()); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 2 numbers a, b. You can perform at most b steps In one step : 1- increase a by 3 2- decrease a by 3 3- multiply a by 2 Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T. For each test case: Input two integers a and b. 0 < T <= 100 1 <= a <= 100000 1 <= b <= 9Print answer on a separate line for each test caseSample Input 2 5 1 30 2 Sample Output 4 11 For test 1:- In 0 steps, 5 can be formed In 1 steps 2, 8, 10 can be formed For test 2:- in 0 step :- 30 in 1 step- 27 33 60 in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120 total unique number = 11, I have written this Solution Code: T = int(input()) for t in range(T): n, k = map(int, input().strip().split()) s = set() s.add(n) l = list(s) while(k): for i in range(len(l)): s.add(l[i]-3) s.add(l[i]+3) s.add(l[i]*2) l = list(s) k -= 1 print(len(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 2 numbers a, b. You can perform at most b steps In one step : 1- increase a by 3 2- decrease a by 3 3- multiply a by 2 Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T. For each test case: Input two integers a and b. 0 < T <= 100 1 <= a <= 100000 1 <= b <= 9Print answer on a separate line for each test caseSample Input 2 5 1 30 2 Sample Output 4 11 For test 1:- In 0 steps, 5 can be formed In 1 steps 2, 8, 10 can be formed For test 2:- in 0 step :- 30 in 1 step- 27 33 60 in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120 total unique number = 11, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 set<int> ss; int yy; void solve(int a,int x) { ss.insert(a); if(yy<=x) return; solve((a+3LL),x+1); solve((a-3LL),x+1); solve((a*2LL),x+1); } signed main() { int t; cin>>t; while(t>0) { t--; int a,b; cin>>a>>b; ss.clear(); yy=b+1; ss.insert(a); solve(a,1); cout<<ss.size()<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the function <code>checkCanIVote</code> <ol> <li>Takes 2 arguments</li> <li>1st argument <code>time</code>, which is the number of milliseconds after the function will resolve or reject</li> <li>Second argument is the <code>age</code> upon (also a number) which you will use to return the string based on logic mentioned below</li> <li>The function returns a promise, which will have 2 functions as arguments <code>resolve</code> and <code>reject</code> like any other promise.</li> <li>The <code>resolve</code> function should be called with the argument <code>"You can vote"</code> after x milliseconds if <code>age</code> is greater than or equal to 18</li> <li>The <code>reject</code> function should be called with the argument with "You can not vote" after x milliseconds if <code>age</code> less than 18</li> </ol> Note:- You only have to implement the function, in the example it shows how your implemented question will be ran.Function will take two arguments 1) 1st argument will be a number which tells after how much milliseconds promise will be resolved or rejected. 2) 2nd argument will be a number (age)Function returns a promise which resolves to "You can vote" or rejects to "You can not vote". If age >= 18 resolves to "You can vote" else rejects to "You can not vote".checkCanIVote(200, 70). then(data=>{ console. log(data) // prints 'You can vote' }).catch((err)=>{ console.log(err) // does not do anything }) checkCanIVote(200, 16). then(data=>{ console. log(data) // does not do anything }).catch((err)=>{ console.log(err) // prints 'You can not vote' }), I have written this Solution Code: function checkCanIVote(number, dat) { return new Promise((res,rej)=>{ if(dat >= 18){ setTimeout(()=>{ res('You can vote') },number) }else{ setTimeout(()=>{ rej('You can not vote') },number) } }) // return the output using return keyword // do not console.log it }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given of array of N integers, find its number of increasing subsequences modulo (10^9 + 7) A subsequence of the given array is the array formed after removing zero or more elements from it. It is said to be increasing when every element is greater than its previous one.First line of input contains T, the number of test cases. Each test case is of two lines. First line of each test case contains N, the number of elements of the array. Next line contains N integers Ai, denoting elements of the array 1 <= T <= 50 1 <= N <= 2000 1 <= Ai <= 10^9Output T lines denoting the number of increasing subsequence for every test case. Print the answer modulo (10^9 + 7)Sample input 1: 2 5 1 5 2 6 1 3 8 4 2 Sample output 1: 12 3 Explanation: All increasing subsequence for test 1 are: {1} {5} {2} {6} {1} {1, 5} {1, 2} {1. 6} {2, 6} {5, 6} {1, 5, 6} {1, 2, 6}, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)) ; int test = Integer.parseInt(read.readLine()) ; while(test-- > 0) { int n = Integer.parseInt(read.readLine()) ; String[] str = read.readLine().trim().split(" ") ; long[] arr = new long[n] ; for(int i=0; i<n; i++) { arr[i] = Long.parseLong(str[i]) ; } long sum = 0L ; long[] count = new long[n] ; for(int i=0; i<n; i++) { count[i] = 1L ; for(int j=0; j<i; j++) { if(arr[i] > arr[j]) { count[i] = (count[i] + count[j]) % 1000000007 ; } } sum = (sum + count[i]) % 1000000007; } System.out.println(sum); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given of array of N integers, find its number of increasing subsequences modulo (10^9 + 7) A subsequence of the given array is the array formed after removing zero or more elements from it. It is said to be increasing when every element is greater than its previous one.First line of input contains T, the number of test cases. Each test case is of two lines. First line of each test case contains N, the number of elements of the array. Next line contains N integers Ai, denoting elements of the array 1 <= T <= 50 1 <= N <= 2000 1 <= Ai <= 10^9Output T lines denoting the number of increasing subsequence for every test case. Print the answer modulo (10^9 + 7)Sample input 1: 2 5 1 5 2 6 1 3 8 4 2 Sample output 1: 12 3 Explanation: All increasing subsequence for test 1 are: {1} {5} {2} {6} {1} {1, 5} {1, 2} {1. 6} {2, 6} {5, 6} {1, 5, 6} {1, 2, 6}, 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 = 2e3+ 5; const int mod = 1e9 + 7; const int inf = 1e18 + 9; int a[N], dp[N]; void solve(){ int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; dp[i] = 0; } dp[0] = 1; int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j < i; j++){ if(a[i] > a[j]) (dp[i] += dp[j]) %= mod; } (ans += dp[i]) %= mod; } cout << ans << 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: 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: Walter white is considered very intelligent person. He has a problem to solve. As he is suffering from cancer, can you help him solve it? Given two integer arrays C and S of length c and s respectively. Index i of array S can be considered good if a subarray of length c can be formed starting from index i which is complimentary to array C. Two arrays A, B of same length are considered complimentary if any cyclic permutation of A satisfies the property (A[i]- A[i-1]=B[i]-B[i-1]) for all i from 2 to length of A (1 indexing). Calculate number of good positions in S . <a href="https://mathworld.wolfram.com/CyclicPermutation.html">Cyclic Permutation</a> 1 2 3 4 has 4 cyclic permutations 2 3 4 1, 3 4 1 2, 4 1 2 3,1 2 3 4First line contains integer s (length of array S). Second line contains s space separated integers of array S. Third line contain integer c (length of array C). Forth line contains c space separated integers of array C. Constraints: 1 <= s <=1000000 1 <= c <=1000000 1 <= S[i], C[i] <= 10^9 Print the answer. Input : 9 1 2 3 1 2 4 1 2 3 3 1 2 3 Output : 4 Explanation : index 1- 1 2 3 matches with 1 2 3 index 2- 2 3 1 matches with 2 3 1(2 3 1 is cyclic permutation of 1 2 3) index 3- 3 1 2 matches with 3 1 2(3 1 2 is cyclic permutation of 1 2 3) index 7- 1 2 3 matches with 1 2 3 Input : 4 3 4 3 4 2 1 2 Output : 3 , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair // #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 2000015 #define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout); #define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout); #define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout); #define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout); #define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout); #define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int A[sz],B[sz],C[sz],D[sz],E[sz],F[sz],G[sz]; int n,m; signed main() { cin>>n; for(int i=0;i<n;i++) { cin>>A[i]; F[i]=A[i]; } cin>>m; for(int i=0;i<m;i++) { cin>>B[i]; G[i]=B[i]; C[m-i-1]=B[i]; } C[m]=-500000000; for(int i=0;i<n;i++) { C[i+m+1]=A[n-i-1]; } int l=0,r=0; for(int i=1;i<=n+m;i++) { if(i<=r) { E[i]=min(r-i+1,E[i-l]); } while(i+E[i]<=n+m && C[E[i]]-C[0]==C[i+E[i]]-C[i]) E[i]++; if(i+E[i]-1>r) { l=i;r=i+E[i]-1; } } for(int i=0;i<m;i++) { C[i]=B[i]; } for(int i=0;i<n;i++) { C[i+m+1]=A[i]; } for(int i=0;i<n;i++) { A[i]=E[n+m-i]; } l=0; r=0; for(int i=1;i<=n+m;i++) { if(i<=r) { D[i]=min(r-i+1,D[i-l]); } while(i+D[i]<=n+m && C[D[i]]-C[0]==C[i+D[i]]-C[i]) D[i]++; if(i+D[i]-1>r) { l=i;r=i+D[i]-1; } } // cout<<0<<" "; for(int i=0;i<n;i++) { B[i]=D[i+m+1]; // cout<<A[i]<<" "; } // cout<<endl; // for(int i=0;i<n;i++) // { // cout<<B[i]<<" "; // }cout<<endl; // for(int i=0;i<=n;i++) // { // cout<<i<<" "; // } // cout<<endl; int cnt=0; vector<pii> xx,yy; for(int i=0;i<=n;i++){ int a=0; int b=0; if(i>0) a=A[i-1]; if(i<n) b=B[i]; // cout<<i<<" "<<a<<" "<<b<<endl; if(a+b>=m && (a==0 || b==0 ||(F[i]-F[i-1]==G[0]-G[m-1]))) {xx.pu(mp(i-a,i+b-m)); } if(a==m) xx.pu(mp(i-a,i-a)); if(b==m ) xx.pu(mp(i,i)); } sort(xx.begin(),xx.end()); for(int i=0;i<xx.size();i++) { // cout<<xx[i].fi<<" "<<xx[i].se<<endl; if(yy.size()==0) yy.pu(mp(xx[i].fi,xx[i].se)); else{ int p=yy.size()-1; // cout<<i<<" "<<xx[i].fi<<" "<<xx[i].se<<" " <<yy[p].se<<endl; if(yy[p].se>=xx[i].se) continue; if(yy[p].se>=xx[i].fi) yy[p].se=xx[i].se; else yy.pu(mp(xx[i].fi,xx[i].se)); } } for(int i=0;i<yy.size();i++) { // cout<<yy[i].fi<<" "<<yy[i].se<<endl; cnt+=yy[i].se-yy[i].fi+1; } cout<<cnt<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given side A of the equilateral triangle, compute its area. The area of an equilateral triangle is given as. <b>Note:</b> Round off the answer to 2 decimals.The input line contains a single float value. <b>Constraints</b> 1 <= A <= 50Print the output, containing the area of an equilateral triangle.Input: 3 Output: 3.90 <b>Explanation</b> The area of the triangle will be (1.73/4)*3*3 = 3.897, which rounded off to 2 digits gives 3.90 as the answer., I have written this Solution Code: import math A = float(input()) print('%.2f' % ((math.sqrt(3)/4)*A*A)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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 <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: def checkSpecial_M_Visor(N,M) : # Final result of summation of divisors i=2; count=0 while i<=N : if(N%i==0): count=count+1 i=i+2 if(count == M): return "Yes" return "No" , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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 <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: static String checkSpecial_M_Visor(int N, int M) { int temp=0; for(int i = 2; i <=N; i+=2) { if(N%i==0) temp++; } if(temp==M) return "Yes"; else return "No"; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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 <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: string checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } if(count==M){return "Yes";} return "No"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not. <b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<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 <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter. Constraints: 1 <= N <= 10^6 0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:- 4 2 Sample Output:- Yes Explanation:- 2 and 4 are the only even divisors of 4 Sample Input:- 8 5 Sample Output:- No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){ int count=0; for(int i=2;i<=N;i+=2){ if(N%i==0){ count++; } } char* ans; if(count==M){return "Yes";} return "No"; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main (String[] args) throws IOException { Reader sc=new Reader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int count=search(a,0,n-1); System.out.println(count); } } public static int search(int[] a,int l,int h){ while(l<=h){ int mid=l+(h-l)/2; if ((mid==h||a[mid+1]==0)&&(a[mid]==1)) return mid+1; if (a[mid]==1) l=mid+1; else h=mid-1; } return 0; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int l = 0, h = n+1; while(l+1 < h){ int m = (l + h) >> 1; if(a[m] == 1) l = m; else h = m; } cout << l << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary sorted non-increasing array arr of size <b>N</b>. You need to print the count of <b>1's</b> in the binary array. Try to solve the problem using binary searchThe input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1 <b>Sum of N over all testcases does not exceed 10^6</b>For each testcase in new line, print the count 1's in binary array.Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0 Output: 5 2 Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2., I have written this Solution Code: c=int(input()) for x in range(c): size=int(input()) s=input() print(s.count('1')), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 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)); String[] str=br.readLine().split(" "); int t=Integer.parseInt(str[0]); while(t-->0){ str=br.readLine().split(" "); int k=Integer.parseInt(str[0]); int n=Integer.parseInt(str[1]); int[] arr=new int[n]; str=br.readLine().split(" "); for(int i=0;i<n;i++){ arr[i]=Integer.parseInt(str[i]); } String[] st=new String[k]; for(int i=0;i<k;i++){ st[i]=""; } for(int i=0;i<n;i++){ st[arr[i]%k]+="->"+str[i]; } for(int i=0;i<k;i++){ if(st[i]!=""){ System.out.println(i+st[i]); } } System.out.println("~"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 1., I have written this Solution Code: t=int(input()) for i in range(t): rowNcol=input().split() els=input().split() ds=[] for i in range(int(rowNcol[0])): col=[] ds.append(col) for i in range(int(rowNcol[1])): ds[int(int(els[i])%int(rowNcol[0]))].append(els[i]) for i in range(len(ds)): if(len(ds[i])==0): continue else: print(i,end="") for j in range(len(ds[i])): print("->"+ds[i][j],end="") print() print("~"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Separate chaining technique in hashing allows us to use a linked list at each hash slot to handle the problem of collisions. That is, every slot of the hash table is a linked list, so whenever a collision occurs, the element can be appened as a node to the linked list at the slot. In this question, we'll learn how to fill up the hash table using Separate chaining technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr. The size of the array is denoted by sizeOfArray. You need to fill up the hash table using Separate chaining and print the resultant hash table.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains 2 lines of input. The first line contains size of the hashtable and the size of the array. The next line contains elements of the array Constraints: 1 <= T <= 100 2 <= hashSize <= 10^3 1 <= sizeOfArray <= 10^3 0 <= arr[i] <= 10^7For each testcase, in a new line, print the hash table. You need to print the hash table as represented in the example. Note: Please print tilde ( '~') character at the end of every testcase for separation of list from one another. Given below in the example represent to how to separate each testcase by tilde character.Sample Input: 2 10 6 92 4 14 24 44 91 10 5 12 45 36 87 11 Sample Output: 1->91 2->92 4->4->14->24->44 ~ 1->11 2->12 5->45 6->36 7->87 ~ Explanation: Testcase1: 92%10=2 so 92 goes to slot 2. 4%10=4 so 4 goes to slot 4. 14%10=4. But 4 is already occupied so we make a linked list at this position and add 14 after 4 in slot 4 and so on. Testcase2: 12%10=2 so 12 goes to slot 2. 45%10=5 goes to slot 5. 36%10=6 goes to slot 6. 87%10=7 goes to slot 7 and finally 11%10=1 goes to slot 1., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 1000001 int main(){ int t; cin>>t; while(t--){ int n,m,x; cin>>m>>n; vector<int> a[m]; for(int i=0;i<n;i++){ cin>>x; a[x%m].push_back(x); } for(int i=0;i<m;i++){ if(a[i].size()==0){continue;} cout<<i<<"->"; for(int j=0;j<a[i].size()-1;j++){ cout<<a[i][j]<<"->"; } cout<<a[i][a[i].size()-1]<<endl; } cout<<"~"<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andrew is now bored with usual prime numbers and decides to find prime numbers which has exactly three factors. He sits back and keeps on thinking random numbers, and asks you to tell him if the number he has chosen had exactly 3 factors. Now he has given <b>N</b> random numbers, you need to tell him "<b>Yes</b>" if those numbers had exactly 3 factors otherwise "<b>No</b>". <b>Note:</b> You can consider the number to be factor of its own.First-line contains N, the number of random numbers he thinks of. Second-line contains the N numbers separated by space. <b>Constraints:</b> 1 <= N <= 10^5 1 <= numbers <= 10^12Print N lines containing "Yes" or "No".Sample Input 1 3 2 4 6 Sample Output 1 No Yes No Explanation: 2 has 2 factors: 1, 2 4 has 3 factors: 1,2,4 6 has 4 factors: 1,2,3,6 Sample Input 2 3 3 5 7 Sample Output 2 No No No, I have written this Solution Code: from math import sqrt def isPrime(n): if (n <= 1): return False if (n <= 3): return True if (n % 2 == 0 or n % 3 == 0): return False k= int(sqrt(n))+1 for i in range(5,k,6): if (n % i == 0 or n % (i + 2) == 0): return False return True def isThreeDisctFactors(n): sq = int(sqrt(n)) if (1 * sq * sq != n): return False if (isPrime(sq)): return True else: return False N = int(input()) numbers = input().split() for x in numbers: if isThreeDisctFactors(int(x)): print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andrew is now bored with usual prime numbers and decides to find prime numbers which has exactly three factors. He sits back and keeps on thinking random numbers, and asks you to tell him if the number he has chosen had exactly 3 factors. Now he has given <b>N</b> random numbers, you need to tell him "<b>Yes</b>" if those numbers had exactly 3 factors otherwise "<b>No</b>". <b>Note:</b> You can consider the number to be factor of its own.First-line contains N, the number of random numbers he thinks of. Second-line contains the N numbers separated by space. <b>Constraints:</b> 1 <= N <= 10^5 1 <= numbers <= 10^12Print N lines containing "Yes" or "No".Sample Input 1 3 2 4 6 Sample Output 1 No Yes No Explanation: 2 has 2 factors: 1, 2 4 has 3 factors: 1,2,4 6 has 4 factors: 1,2,3,6 Sample Input 2 3 3 5 7 Sample Output 2 No No No, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { static int MAX = 1000005; static long spf[] = new long[MAX+5]; public static void main (String[] args)throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(read.readLine()); SOF(); String str[] = read.readLine().trim().split(" "); for(int i = 0; i < N; i++) { long x = Long.parseLong(str[i]); long g = (long)Math.sqrt(x); if((g*g)!=x) { System.out.println("No"); } else { if(spf[(int)g]==g) { System.out.println("Yes"); } else System.out.println("No"); } } } public static void SOF() { spf[1] = 0; for (int i=2; i<MAX; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i=4; i<MAX; i+=2) spf[i] = 2; for (int i=3; i*i<MAX; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisitedible by i for (int j=i*i; j<MAX; j+=i) // marking spf[j] if it is not // previously marked if (spf[j]==j) spf[j] = i; } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Andrew is now bored with usual prime numbers and decides to find prime numbers which has exactly three factors. He sits back and keeps on thinking random numbers, and asks you to tell him if the number he has chosen had exactly 3 factors. Now he has given <b>N</b> random numbers, you need to tell him "<b>Yes</b>" if those numbers had exactly 3 factors otherwise "<b>No</b>". <b>Note:</b> You can consider the number to be factor of its own.First-line contains N, the number of random numbers he thinks of. Second-line contains the N numbers separated by space. <b>Constraints:</b> 1 <= N <= 10^5 1 <= numbers <= 10^12Print N lines containing "Yes" or "No".Sample Input 1 3 2 4 6 Sample Output 1 No Yes No Explanation: 2 has 2 factors: 1, 2 4 has 3 factors: 1,2,4 6 has 4 factors: 1,2,3,6 Sample Input 2 3 3 5 7 Sample Output 2 No No No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 1000001 bool a[max1]; signed main() { string s="abcdefghijklmnopqrstuvwxyz"; for(int i=0;i<=1000000;i++){ a[i]=false; } for(int i=2;i<1000000;i++){ if(a[i]==false){ for(int j=i+i;j<=1000000;j+=i){ a[j]=true; } } } int n; cin>>n; long long x; long long y; for(int i=0;i<n;i++){ cin>>x; long long y=sqrt(x); if(y*y==x){ if(a[y]==false){cout<<"Yes"<<endl;} else{cout<<"No"<<endl;} } else{ cout<<"No"<<endl; } }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>ceil</code>, which should take a number which can be a float(decimal) and return its result as an integer with ceil function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(ceil(1.99)) // prints 2 console.log(ceil(2.1)) // prints 3 console.log(ceil(-1.1)) // prints -1, I have written this Solution Code: function ceil(num){ // write code here // return the output , do not use console.log here return Math.ceil(num) }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement the function <code>ceil</code>, which should take a number which can be a float(decimal) and return its result as an integer with ceil function applied to it (Use JS In built functions)Function will take a float as inputFunction will return a numberconsole.log(ceil(1.99)) // prints 2 console.log(ceil(2.1)) // prints 3 console.log(ceil(-1.1)) // 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(); int b=(int)(Math.ceil(a)); System.out.println(b); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print a number is positive/negative using if- else.The first line contains the number to be checked. Constraints: -100000<=n<=100000Prints "Positive number" if the number is positive, "Zero" if the number is zero and "Negative number" if the number is negative.Sample input: 33 Sample Output: Positive number, I have written this Solution Code: num = int(input()) if num > 0: print("Positive number") elif num == 0: print("Zero") else: print("Negative number") , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable