Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b> <b>Constraints:-</b> 1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:- 3 5 Sample Output:- 2 Sample Input:- 9 16 Sample Output:- 7, I have written this Solution Code: def profit(C, S): print(S - C), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to become rich so he came up with an idea, So, he buys some gadgets from the future at a price of C and sells them at a price of S to his friends. Now Nobita wants to know how much he gains by selling all gadget. As we all know Nobita is weak in maths help him to find the profit he getsYou don't have to worry about the input, you just have to complete the function <b>Profit()</b> <b>Constraints:-</b> 1 <= C <= S <= 1000Print the profit Nobita gets from selling one gadget.Sample Input:- 3 5 Sample Output:- 2 Sample Input:- 9 16 Sample Output:- 7, I have written this Solution Code: static void Profit(int C, int S){ System.out.println(S-C); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied: 1) S is a palindrome. 2) Let N be the length of S. The string formed by the 1- st through ((N−1)/2)<sub>th</sub> characters of S is a palindrome. 3) The string consisting of the (N+3)/2- st through N<sub>th</sub> characters of S is a palindrome. Determine whether S is a strong palindrome.The first and the only line of the input contains a single string S. <b>Constraints:</b> 3 &le; |S| &le; 99If S is a strong palindrome, print "Yes"; otherwise, print "No".<b>Sample Input 1:</b> akasaka <b>Sample Output 1:</b> Yes <b>Sample Explanation 1:</b> 1) S is Akasaka. 2) The string formed by the 1<sub>st</sub> through the 3<sub>rd</sub> characters is aka. 3) The string formed by the 5<sub>th</sub> through the 7<sub>th</sub> characters is aka. All of these are palindromes, so S is a strong palindrome., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define mod 1000000007 #define endl '\n' #define ha cout<<"YES"<<endl #define na cout<<"NO"<<endl #define mod 1000000007 #define ll long long int main() { string s; cin >> s; int f=0,fl=0,flag=0; int l=s.length();//7 for(int i=0,j=l-1;i<l/2;i++,j--) { if(s[i]!=s[j]) { f=1; break; } } for(int i=0,j=l/2-1;i<l/2;i++,j--) { if(s[i]!=s[j]) { fl=1; break; } } for(int i=l/2+1,j=l-1;i<j;i++,j--) { if(s[i]!=s[j]) { flag=1; break; } } //cout<<f<<fl<<flag<<endl; if (f == 0 && fl==0 && flag==0) cout<<"Yes"; else cout<<"No"; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem. Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d. <b>Constraints</b> 1<= a, b, c, d <= 100 Print single line containing the percentage.Sample Input 1: 25 25 25 25 Sample Output 1: 25 Sample Input 2: 75 25 75 25 Sample Output 2: 50, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str[]=br.readLine().split(" "); int a[]=new int[str.length]; int sum=0; for(int i=0;i<str.length;i++) { a[i]=Integer.parseInt(str[i]); sum=sum+a[i]; } System.out.println(sum/4); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem. Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d. <b>Constraints</b> 1<= a, b, c, d <= 100 Print single line containing the percentage.Sample Input 1: 25 25 25 25 Sample Output 1: 25 Sample Input 2: 75 25 75 25 Sample Output 2: 50, I have written this Solution Code: a,b,c,d = map(int,input().split()) print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M. Constraints: 1 <= N <= 10^18 1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input 10 5 Sample Output Yes Explanation: Give 2 candies to all. Sample Input: 4 3 Sample Output: No, I have written this Solution Code: m,n = map(int , input().split()) if (m%n==0): print("Yes") else: print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M. Constraints: 1 <= N <= 10^18 1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input 10 5 Sample Output Yes Explanation: Give 2 candies to all. Sample Input: 4 3 Sample Output: No, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n,m; cin>>n>>m; if(n%m==0) cout<<"Yes"; else cout<<"No"; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M. Constraints: 1 <= N <= 10^18 1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input 10 5 Sample Output Yes Explanation: Give 2 candies to all. Sample Input: 4 3 Sample Output: No, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); Long m = sc.nextLong(); if(n%m==0){ System.out.print("Yes"); } else{ System.out.print("No"); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Fashionable Integers are defined as those integers whose sum of digits is divisible by 2 and all of whose digits are odd. Given an integer N, find whether the given integer is fashionable or not.The first line of the input contains the length of the integer. The second line contains the integer. Constraints: 1 <= Length of Integer <= 10<sup>5</sup>Print "YES" if the given integer is fashionable, else print "NO".Sample Input: 2 73 Sample Output: YES, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin >> n; string s; cin >> s; assert(n == s.size()); int sum = 0; for(auto i : s){ sum += (i - '0'); if((i - '0') % 2 == 0){ cout << "NO"; return 0; } } if(sum % 2 == 0){ cout << "YES"; } else cout << "NO"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: n=int(input()) for i in range(1,n+1): if i%3==0 and i%5==0: print("NewtonSchool",end=" ") elif i%3==0: print("Newton",end=" ") elif i%5==0: print("School",end=" ") else: print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static void NewtonSchool(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");} else if(i%5==0){System.out.print("School ");} else if(i%3==0){System.out.print("Newton ");} else{System.out.print(i+" ");} } } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int x= sc.nextInt(); NewtonSchool(x); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array Arr. <b>Constraints:</b> 1 <= N <= 100000 1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1 4 5 3 3 1 Sample Output 1 24 Sample Input 2 2 1 10 Sample Output 2 10 <b>Explanation 1</b> max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(read.readLine()); long[] arr = new long[N]; StringTokenizer st = new StringTokenizer(read.readLine()); for(int i=0; i<N; i++) { arr[i] = Long.parseLong(st.nextToken()); } Arrays.sort(arr); long res = 0; for(int i=N-1;i >-1; i--) { res += arr[i]*i; } System.out.println(res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array Arr. <b>Constraints:</b> 1 <= N <= 100000 1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1 4 5 3 3 1 Sample Output 1 24 Sample Input 2 2 1 10 Sample Output 2 10 <b>Explanation 1</b> max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24 , I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) arr.sort(reverse=True) l=[] for i in range(n-1): l.append(arr[i]*((n-1)-i)) print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array Arr. <b>Constraints:</b> 1 <= N <= 100000 1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1 4 5 3 3 1 Sample Output 1 24 Sample Input 2 2 1 10 Sample Output 2 10 <b>Explanation 1</b> max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24 , 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+1]; for(int i=1;i<=n;++i){ cin>>a[i]; } sort(a+1,a+n+1); int ans=0; for(int i=1;i<=n;++i) ans+=(a[i]*(i-1)); 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: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: def compound_interest(principle, rate, time): Amount = principle * (pow((1 + rate / 100), time)) CI = Amount - principle print( '%.2f'%CI) principle,rate,time=map(int, input().split()) compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: function calculateCI(P, R, T) { let interest = P * (Math.pow(1.0 + R/100.0, T) - 1); return interest.toFixed(2); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int p,r,t; cin>>p>>r>>t; double rate= (float)r/100; double amt = (float)p*(pow(1+rate,t)); cout << fixed << setprecision(2) << (amt - p); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s= br.readLine().split(" "); double[] darr = new double[s.length]; for(int i=0;i<s.length;i++){ darr[i] = Double.parseDouble(s[i]); } double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0]; System.out.printf("%.2f",ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a singly linked list consisting of N Nodes, your task is to convert it into a circular linked list. Note:- For custom input you will get 1 if your code is correct else you get a 0. <b>Note:</b>Examples in Sample Input and Output just shows how a linked list will look like depending on the questions. Do not copy-paste as it is in <b>custom input</b><b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeCircular()</b> that takes head node of singly linked list as parameter. Constraints: 1 <=N <= 1000 1 <= Node. data<= 1000Return the head node of the circular linked list.Sample Input 1:- 1- >2- >3 Sample Output 1:- 1- >2- >3- >1 Sample Input 2:- 1- >3- >2 Sample Output 2:- 1- >3- >2- >1, I have written this Solution Code: public static Node MakeCircular(Node head) { Node temp=head; while(temp.next!=null){ temp=temp.next;} temp.next=head; return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N. Second line of input contains N space separated elements of the array. Constraints: 1 <= N <= 100000 0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1 4 1 0 1 0 Sample output 1 2 Sample input 2 4 1 1 0 0 Sample output 2 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); StringTokenizer tokens = new StringTokenizer(reader.readLine()); int partitions = 0; int c0 = 0, c1 = 0; for(int i = 0; i < N; i++) { int x = Integer.parseInt(tokens.nextToken()); if(x == 0) { c0++; } else { c1++; } if(c0 > 0 || c1 > 0) { if(c0 == c1) { partitions++; c0 = c1 = 0; } } } if(c1 > 0 || c0 > 0) { partitions = -1; } System.out.println(partitions); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N. Second line of input contains N space separated elements of the array. Constraints: 1 <= N <= 100000 0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1 4 1 0 1 0 Sample output 1 2 Sample input 2 4 1 1 0 0 Sample output 2 1, I have written this Solution Code: n = int(input()) a = input().split() o,z = 0,0 cnt = 0 for i in a: if i == '1': o += 1 else: z +=1 if o == z: cnt += 1 if o == z: print(cnt) else: print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N. Second line of input contains N space separated elements of the array. Constraints: 1 <= N <= 100000 0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1 4 1 0 1 0 Sample output 1 2 Sample input 2 4 1 1 0 0 Sample output 2 1, I have written this Solution Code: #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 c=0; int ans=0; for(int i=0;i<n;++i){ int x; cin>>x; if(x==0) ++c; else --c; if(c==0) ++ans; } if(c==0){ cout<<ans; }else { cout<<"-1"; } #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 integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testcase = Integer.parseInt(br.readLine()); for(int t=0;t<testcase;t++){ int num = Integer.parseInt(br.readLine().trim()); if(num==1) System.out.println("No"); else if(num<=3) System.out.println("Yes"); else{ if((num%2==0)||(num%3==0)) System.out.println("No"); else{ int flag=0; for(int i=5;i*i<=num;i+=6){ if(((num%i)==0)||(num%(i+2)==0)){ System.out.println("No"); flag=1; break; } } if(flag==0) System.out.println("Yes"); } } } }catch (Exception e) { System.out.println("I caught: " + e); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: t=int(input()) for i in range(t): number = int(input()) if number > 1: i=2 while i*i<=number: if (number % i) == 0: print("No") break i+=1 else: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A. Constraints 1 <= T <= 100 1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input 3 5 9 13 Output Yes No Yes, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n,k; cin>>n; long x=sqrt(n); int cnt=0; vector<int> v; for(long long i=2;i<=x;i++){ if(n%i==0){ cout<<"No"<<endl; goto f; }} cout<<"Yes"<<endl; f:; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of N integers. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 5000 1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input: 5 1 5 2 2 1 Sample Output: YES Explanation: We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: def sunpal(n,a): ok=False for i in range(n): for j in range(i+2,n): if a[i]==a[j]: ok=True return("YES" if ok else "NO") if __name__=="__main__": n=int(input()) a=input().split() res=sunpal(n,a) print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of N integers. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 5000 1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input: 5 1 5 2 2 1 Sample Output: YES Explanation: We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long #define pb push_back #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using T = pair<int, int>; typedef long double ld; const int mod = 1e9 + 7; const int INF = 1e18; void solve(){ int N; cin >> N; map<int, int> mp; string ans = "NO"; for(int i = 1; i <= N; i++) { int a; cin >> a; if(mp[a] != 0 and mp[a] <= i - 2) { ans = "YES"; } if(mp[a] == 0) mp[a] = i; } cout << ans; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int X = scan.nextInt(); int Y = scan.nextInt(); if((X == 1) && (Y == 1)){ System.out.println(0); } else if((X == 1) || (Y == 1)){ System.out.println(1); } else{ System.out.println(2); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: X, Y = [int(x) for x in input().split()] if X == 1 and Y == 1: print(0) elif X == 1 or Y == 1: print(1) else: print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a rook is placed at a position (X, Y). Your task is to find the minimum steps Rook will take to go to the position (1, 1).The input contains two integer X and Y. Constraints:- 1 <= X <= 8 1 <= Y <= 8Print the number of steps rook will take to go to the position (X, Y).Sample Input:- 2 4 Sample Output:- 2 Explanation:- one of the possible paths is:- (2, 4) - > (2, 1) - > (1, 1) Sample Input:- 1 2 Sample Output:- 1, I have written this Solution Code: #include <iostream> using namespace std; int Rook(int X, int Y){ //Enter your code here if(X==1 && Y==1){return 0;} if(X==1 || Y==1){return 1;} return 2; } int main(){ int x,y; scanf("%d%d",&x,&y); printf("%d",Rook(x,y)); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a marathon to be run on a circular track. There are N checkpoints on the track where energy drinks are placed. Checkpoints are numbered from 1 to N (both inclusive). For each checkpoint, you know the distance to the next checkpoint and also the energy replenished by the drink at this checkpoint. Toros is going to take part in the marathon. For every 1 unit distance covered by him, his energy decreases by 1. He can't run further if he has 0 energy. Find the minimum index of the point where he should start so that he can visit every checkpoint at least once. Initially, he has 0 energy.The first line contains a single integer N, denoting the number of checkpoints. The next N lines contain two space-separated integers, E[i] and D[i], denoting the energy replenished by the energy drink kept at the ith checkpoint and the distance to the next checkpoint. <b>Constraints</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; E[i], D[i] &le; 10<sup>9</sup> Print a single integer containing the minimum index of the checkpoint where Toros should start so that he can complete the race. If no such point exists, print -1Sample Input 1: 3 1 5 10 3 3 4 Sample Output 1: 2 Sample Input 2:- 3 2 4 5 4 2 7 Sample Output 2:- -1 Sample Input 3:- 5 1 4 5 6 3 1 7 2 5 8 Sample Output 3:- 3 <b>Explanation 1:</b> Toros starts at index 2 and drinks energy drinks. So, current energy = 10. At index 3, energy = 10 - 3 + 3 = 10. At index 1 energy = 10 - 4 + 1 = 7., I have written this Solution Code: #include<bits/stdc++.h> //#define int long long #define ll long long #define pb push_back #define endl '\n' #define pii pair<int,int> #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define sz(x) (int)x.size() #define hell 1000000007 #define rep(i,a,b) for(int i=a;i<b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N], b[N]; void solve(){ int n; cin >> n; bool flag = 0; for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; } int l = 0, r = 0; int sum = 0, d, c = 0; while((l + 1)%n != r && c < 2){ d = a[l] - b[l]; if(sum + d >= 0) l++, sum += d; else sum = 0, l++, r = l; if(l == n) c++; l %= n; } if(c == 2) cout << -1 << endl; else cout << r+1 << endl; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: "; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There is a marathon to be run on a circular track. There are N checkpoints on the track where energy drinks are placed. Checkpoints are numbered from 1 to N (both inclusive). For each checkpoint, you know the distance to the next checkpoint and also the energy replenished by the drink at this checkpoint. Toros is going to take part in the marathon. For every 1 unit distance covered by him, his energy decreases by 1. He can't run further if he has 0 energy. Find the minimum index of the point where he should start so that he can visit every checkpoint at least once. Initially, he has 0 energy.The first line contains a single integer N, denoting the number of checkpoints. The next N lines contain two space-separated integers, E[i] and D[i], denoting the energy replenished by the energy drink kept at the ith checkpoint and the distance to the next checkpoint. <b>Constraints</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; E[i], D[i] &le; 10<sup>9</sup> Print a single integer containing the minimum index of the checkpoint where Toros should start so that he can complete the race. If no such point exists, print -1Sample Input 1: 3 1 5 10 3 3 4 Sample Output 1: 2 Sample Input 2:- 3 2 4 5 4 2 7 Sample Output 2:- -1 Sample Input 3:- 5 1 4 5 6 3 1 7 2 5 8 Sample Output 3:- 3 <b>Explanation 1:</b> Toros starts at index 2 and drinks energy drinks. So, current energy = 10. At index 3, energy = 10 - 3 + 3 = 10. At index 1 energy = 10 - 4 + 1 = 7., 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(); if(n>10000){ System.out.print(-1); return; } int[] remEnrgy = new int[n]; for(int i=0;i<n;i++) { int e = sc.nextInt(); int d = sc.nextInt(); remEnrgy[i] = e-d; } for(int i=0;i<n;i++) { if(remEnrgy[i] >= 0){ if(run(remEnrgy,i)) { System.out.print(i+1); return; } } } System.out.print(-1); } private static boolean run(int[]arr,int idx) { long enrgy = 0; if(idx==0){ for(int i=0;i<arr.length-1;i++) { enrgy += arr[i]; if(enrgy<0){ return false; } } return true; } for(int i=idx;i<arr.length;i++) { enrgy += arr[i]; if(enrgy<0){ return false; } } for(int i=0;i<idx-1;i++) { enrgy += arr[i]; if(enrgy<0){ return false; } } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba 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 Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char str[] = br.readLine().toCharArray(); int ans = 0; char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; Set<String> set = new HashSet<>(); for(int i=0;i<str.length;i++){ char p = str[i]; for(char ch:arr){ if(ch==p) continue; str[i] = ch; if(isPallindrome(str)){ if(set.contains(String.valueOf(str))==false){ set.add(String.valueOf(str)); ans++; } } str[i] = p; } } System.out.println(ans); } static boolean isPallindrome(char[] str){ int i = 0; int j = str.length-1; while(i<j){ if(str[i]!=str[j]) return false; i++; j--; } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: n=input() n=list(n) ln=len(n) cnt=0 for i in range(ln//2): if not(n[i]==n[ln-i-1]): cnt+=1 if(cnt==1): print(2) elif(cnt==0 and ln%2==1): print(25) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n' #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define sz(x) ((ll)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x = min(x,y) #define maxi(x,y) x = max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(0, 1e9); // DEBUG FUNCTIONS START void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void deb() {cerr << "\n";} template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);} // DEBUG FUNCTIONS END const int N = 2e5 + 5; void solve(){ string s; cin >> s; int n = sz(s); int x = 0; rep(i, 0, n / 2){ x += s[i] != s[n - 1 - i]; } if(x == 1){ cout << 2 << endl; } else if(x > 1){ cout << 0 << endl; } else{ if(n & 1){ cout << 25 << endl; } else{ cout << 0 << endl; } } } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } , 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, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers. Constraints:- 1 < = N < = 1000 -10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:- 4 1 2 3 -3 Sample Output:- Yes Sample Input:- 3 1 2 3 Sample Output:- No, I have written this Solution Code: N = int(input()) Nums = list(map(int,input().split())) f = False for n in Nums: if n < 0: f = True break if (f): print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers. Constraints:- 1 < = N < = 1000 -10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:- 4 1 2 3 -3 Sample Output:- Yes Sample Input:- 3 1 2 3 Sample Output:- No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a; bool win=false; for(int i=0;i<n;i++){ cin>>a; if(a<0){win=true;}} if(win){ cout<<"Yes"; } else{ cout<<"No"; } } , 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, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers. Constraints:- 1 < = N < = 1000 -10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:- 4 1 2 3 -3 Sample Output:- Yes Sample Input:- 3 1 2 3 Sample Output:- No, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i] = sc.nextInt(); } for(int i=0;i<n;i++){ if(a[i]<0){System.out.print("Yes");return;} } System.out.print("No"); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e) { System.out.println(a); System.out.println(b); System.out.printf("%.2f",c); System.out.println(); System.out.printf("%.4f",d); System.out.println(); System.out.println(e); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){ cout<<a<<endl; cout<<b<<endl; cout <<fixed<< std::setprecision(2) << c << '\n'; cout <<fixed<< std::setprecision(4) << d << '\n'; cout<<e<<endl; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: a=int(input()) b=int(input()) x=float(input()) g = "{:.2f}".format(x) d=float(input()) e = "{:.4f}".format(d) u=input() print(a) print(b) print(g) print(e) print(u), 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, 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 T= sc.nextInt(); for(int i=0;i<T;i++){ int arrsize=sc.nextInt(); int max=0,secmax=0,thirdmax=0,j; for(int k=0;k<arrsize;k++){ j=sc.nextInt(); if(j>max){ thirdmax=secmax; secmax=max; max=j; } else if(j>secmax){ thirdmax=secmax; secmax=j; } else if(j>thirdmax){ thirdmax=j; } if(k%10000==0){ System.gc(); } } System.out.println(max+" "+secmax+" "+thirdmax+" "); } } }, 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: t=int(input()) while t>0: t-=1 n=int(input()) l=list(map(int,input().strip().split())) li=[0,0,0] for i in l: x=i for j in range(0,3): y=min(x,li[j]) li[j]=max(x,li[j]) x=y print(li[0],end=" ") print(li[1],end=" ") print(li[2]), 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ long long n; cin>>n; vector<long> a(n); long ans[3]={0}; long x,y; for(int i=0;i<n;i++){ cin>>a[i]; x=a[i]; for(int j=0;j<3;j++){ y=min(x,ans[j]); ans[j]=max(x,ans[j]); // cout<<ans[j]<<" "; x=y; } } if(ans[1]<ans[0]){ swap(ans[1],ans[0]); } if(ans[2]<ans[1]){ swap(ans[1],ans[2]); } if(ans[1]<ans[0]){ swap(ans[1],ans[0]); } cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element. Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T. For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A. <b>Constraints:</b> 1 <= T <= 100 3 <= N <= 10<sup>6</sup> 1 <= A[i] <= 10<sup>9</sup> <b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input: 3 5 1 4 2 4 5 6 1 3 5 7 9 8 7 11 22 33 44 55 66 77 Sample Output: 5 4 4 9 8 7 77 66 55 <b>Explanation:</b> Testcase 1: [1 4 2 4 5] First max = 5 Second max = 4 Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) { // write code here // do not console.log the answer // return the answer as an array of 3 numbers return arr.sort((a,b)=>b-a).slice(0,3) }; , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples. <b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. 1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT: 1 2 3 4 OUTPUT: 14 Explanation: Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int m1,a1,m2,a2; cin >> m1 >> a1 >> m2 >> a2; cout << (m1*a1)+(m2*a2) << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way. There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised. Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons. The second line of the input contains N integers, the strengths of the dragons. Constraints 1 <= N <= 200000 (so many dragons, huh) 1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i N is divisible by 2Output a single integer, the answer to the problem.Sample Input 4 1 2 1 2 Sample Output 0 Explanation Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together Sample Input 6 2 3 2 4 5 1 Sample Output 1, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.StringTokenizer; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (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; } }; public static void main(String[] args) { FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int n=sc.nextInt(); long arr[]=new long[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextLong(); } Arrays.sort(arr); long min=Long.MAX_VALUE; long max=Long.MIN_VALUE; for(int i=0;i<n/2;i++) { min=Math.min(min,arr[n-i-1]+arr[i]); max=Math.max(max,arr[n-i-1]+arr[i]); } System.out.println(max-min); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way. There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised. Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons. The second line of the input contains N integers, the strengths of the dragons. Constraints 1 <= N <= 200000 (so many dragons, huh) 1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i N is divisible by 2Output a single integer, the answer to the problem.Sample Input 4 1 2 1 2 Sample Output 0 Explanation Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together Sample Input 6 2 3 2 4 5 1 Sample Output 1, I have written this Solution Code: n = int(input()) bruh = input().strip().split(" ") for i in range(len(bruh)): bruh[i] = int(bruh[i]) bruh.sort() maxSum = 0 minSum = 100000000000000000000 for i in range(len(bruh)//2): add = bruh[i] + bruh[-(i+1)] if add > maxSum: maxSum = add if add < minSum: minSum = add print(maxSum - minSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Pree says he stole Daenerys' dragons, and would return them to Daenerys only if she can pair the dragons in a peculiar way. There are N (N is even) dragons, the strength of i<sup>th</sup> dragon is A<sub>i</sub>. She needs to create N/2 pairs of the dragons. The strength of the dragon pair is the sum of the strengths of dragons in the pair. She needs to pair them in such a way that the difference between the strength of dragon pair with maximum strength and the strength of the dragon pair with minimum strength is minimised. Now, you need to find the minimum difference in strengths if she has paired them correctly.The first line of the input contains an integer N, the number of dragons. The second line of the input contains N integers, the strengths of the dragons. Constraints 1 <= N <= 200000 (so many dragons, huh) 1 <= A<sub>i</sub> <= 10<sup>9</sup> for all values of i N is divisible by 2Output a single integer, the answer to the problem.Sample Input 4 1 2 1 2 Sample Output 0 Explanation Daenerys pairs 1st and the 2nd dragons together; the 3rd and the 4th dragon together Sample Input 6 2 3 2 4 5 1 Sample Output 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define ld long double #define int long long #define double long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 const int MOD = 1e9+7; const int INF = 1LL<<60; const int N = 2e5+5; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif void solve(){ int n; cin>>n; vector<int> v(n); For(i, 0, n){ cin>>v[i]; } sort(all(v)); vector<int> cur; For(i, 0, n/2){ cur.pb(v[i]+v[n-i-1]); } sort(all(cur)); cout<<cur[n/2-1]-cur[0]; } 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: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: static int LastDigit(int N){ return N%10; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: def LastDigit(N): return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: def lenOfLongSubarr(arr, N, K): mydict = dict() sum = 0 maxLen = 0 for i in range(N): sum += arr[i] if (sum == K): maxLen = i + 1 elif (sum - K) in mydict: maxLen = max(maxLen, i - mydict[sum - K]) if sum not in mydict: mydict[sum] = i return maxLen if __name__ == '__main__': T = int(input()) #N,K=list(map(int,input().split())) for i in range(T): N,k= [int(N)for N in input("").split()] arr=list(map(int,input().split())) N = len(arr) print(lenOfLongSubarr(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 containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ unordered_map<long long,int> um; int n,k; cin>>n>>k; long arr[n]; int maxLen=0; for(int i=0;i<n;i++){cin>>arr[i];} long long sum=0; for(int i=0;i<n;i++){ sum += arr[i]; // when subarray starts from index '0' if (sum == k) maxLen = i + 1; // make an entry for 'sum' if it is // not present in 'um' if (um.find(sum) == um.end()) um[sum] = i; // check if 'sum-k' is present in 'um' // or not if (um.find(sum - k) != um.end()) { // update maxLength if (maxLen < (i - um[sum - k])) maxLen = i - um[sum - k]; } } cout<<maxLen<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, 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 t=sc.nextInt(); while(t-->0){ if(t%10==0){ System.gc(); } int arrsize=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[arrsize]; for(int i=0;i<arrsize;i++){ arr[i]=sc.nextInt(); } int subsize=0; int sum=0; HashMap<Integer, Integer> hash=new HashMap<>(); for(int i=0;i<arrsize;i++){ sum+=arr[i]; if(sum==k){ subsize=i+1; } if(!hash.containsKey(sum)){ hash.put(sum,i); } if(hash.containsKey(sum-k)){ if(subsize<(i-hash.get(sum-k))){ subsize=i-hash.get(sum-k); } } } System.out.println(subsize); } } }, 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 print all the even integer from 1 to N.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 <= n <= 100 <b>Note:</b> <i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:- 5 Sample Output:- 2 4 Sample Input:- 6 Sample Output:- 2 4 6, I have written this Solution Code: def For_Loop(n): string = "" for i in range(1, n+1): if i % 2 == 0: string += "%s " % i return string , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 <= n <= 100 <b>Note:</b> <i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:- 5 Sample Output:- 2 4 Sample Input:- 6 Sample Output:- 2 4 6, I have written this Solution Code: public static void For_Loop(int n){ for(int i=2;i<=n;i+=2){ System.out.print(i+" "); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<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>PerfectNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:- 122 Sample Output:- 1 Explanation:- 1 + 2 + 2 = 5 which is divisible by 5 Sample Input:- 123 Sample Output:- 0, I have written this Solution Code: int PerfectNumber(int N){ int ans=0; while(N>0){ ans+=N%10; N/=10; } if(ans%5==0){return 1;} return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<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>PerfectNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:- 122 Sample Output:- 1 Explanation:- 1 + 2 + 2 = 5 which is divisible by 5 Sample Input:- 123 Sample Output:- 0, I have written this Solution Code: int PerfectNumber(int N){ int ans=0; while(N>0){ ans+=N%10; N/=10; } if(ans%5==0){return 1;} return 0; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<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>PerfectNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:- 122 Sample Output:- 1 Explanation:- 1 + 2 + 2 = 5 which is divisible by 5 Sample Input:- 123 Sample Output:- 0, I have written this Solution Code: static int PerfectNumber(int N){ int ans=0; while(N>0){ ans+=N%10; N/=10; } if(ans%5==0){return 1;} return 0; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<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>PerfectNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:- 122 Sample Output:- 1 Explanation:- 1 + 2 + 2 = 5 which is divisible by 5 Sample Input:- 123 Sample Output:- 0, I have written this Solution Code: def PerfectNumber(N): cnt=0 while N>0: cnt=cnt+int(N%10) N=int(N/10) if (cnt%5==0): return 1 return 0 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<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>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ System.out.print(x+4*j+" "); } System.out.println(); x+=6; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<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>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: def Pattern(N): x=0 for i in range (0,N): for j in range (0,N): print(x+4*j,end=' ') print() x = x+6 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<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>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ printf("%d ",x+4*j); } printf("\n"); x+=6; } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it. The pattern for height 6:- 0 4 8 12 16 20 6 10 14 18 22 26 12 16 20 24 28 32 18 22 26 30 34 38 24 28 32 36 40 44 30 34 38 42 46 50<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>Pattern()</b> that takes integer N as an argument. Constraints:- 1 <= N <= 100Print the given pattern.Sample Input:- 3 Sample Output:- 0 4 8 6 10 14 12 16 20 Sample Input:- 5 Sample Output:- 0 4 8 12 16 6 10 14 18 22 12 16 20 24 28 18 22 26 30 34 24 28 32 36 40, I have written this Solution Code: void Pattern(int N){ int x=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ printf("%d ",x+4*j); } printf("\n"); x+=6; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: t=int(input()) while t!=0: m,n=input().split() m,n=int(m),int(n) for i in range(m): arr=input().strip() if '1' in arr: arr='1 '*n else: arr='0 '*n print(arr) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 int a[N][N]; // Driver code int main() { int t; cin>>t; while(t--){ int n,m; cin>>n>>m; bool b[n]; for(int i=0;i<n;i++){ b[i]=false; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; if(a[i][j]==1){ b[i]=true; } } } for(int i=0;i<n;i++){ if(b[i]){ for(int j=0;j<m;j++){ cout<<1<<" "; }} else{ for(int j=0;j<m;j++){ cout<<0<<" "; } } cout<<endl; } }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String[] args) throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader bf = new BufferedReader(isr); int t = Integer.parseInt(bf.readLine()); while (t-- > 0){ String inputs[] = bf.readLine().split(" "); int m = Integer.parseInt(inputs[0]); int n = Integer.parseInt(inputs[1]); String[] matrix = new String[m]; for(int i=0; i<m; i++){ matrix[i] = bf.readLine(); } StringBuffer ones = new StringBuffer(""); StringBuffer zeros = new StringBuffer(""); for(int i=0; i<n; i++){ ones.append("1 "); zeros.append("0 "); } for(int i=0; i<m; i++){ if(matrix[i].contains("1")){ System.out.println(ones); }else{ System.out.println(zeros); } } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: a="Hello World" print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation: Hello World is printed., I have written this Solution Code: import java.util.*; import java.io.*; class Main{ public static void main(String args[]){ System.out.println("Hello World"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i> Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers: Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself. For example: A = 9, B = 14 can follow the given steps during conversion A = 9 A = 9 + 3 = 12 (3 is a factor of 9) A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B. Constraints 1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input 9 14 Sample Output Yes Explanation: In the problem statement Sample Input 33 35 Sample Output No Explanation The minimum factor of 33 is 3, so we cannot transform 33 to 35., I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.StringTokenizer; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (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; } }; public static void main(String[] args) { FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); long a=sc.nextLong(); long b=sc.nextLong(); long tmp=a; res=new ArrayList<>(); factorize(a); if(res.size()==1&&res.get(0)==a) { System.out.println("No"); return; } if(a==b) { System.out.println("Yes"); return; } for(long i=2;i <= (long) Math.sqrt(b);i++) { if(b%i==0&&(b-i)>=a) { for(long j:res) { if((b-i)%j==0) { System.out.println("Yes"); return; } } } } System.out.println("No"); } static ArrayList<Long> res; static void factorize(long n) { int count = 0; while (!(n % 2 > 0)) { n >>= 1; count++; } if (count > 0) { res.add(2l); } for (long i = 3; i <= (long) Math.sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count > 0) { res.add(i); } } if (n > 2) { res.add(n); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i> Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers: Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself. For example: A = 9, B = 14 can follow the given steps during conversion A = 9 A = 9 + 3 = 12 (3 is a factor of 9) A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B. Constraints 1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input 9 14 Sample Output Yes Explanation: In the problem statement Sample Input 33 35 Sample Output No Explanation The minimum factor of 33 is 3, so we cannot transform 33 to 35., I have written this Solution Code: import math arr=[int (x) for x in input().split()] a,b=arr[0],arr[1] if a>=b: print("No") else: m=-1 i=2 while i**2<=a: if a%i==0: m=i break i+=1 if m==-1: print("No") elif math.gcd(a,b)!=1: print("Yes") else: a=a+m if a<b and math.gcd(a,b)!=1: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: <i>Your Grace, I feel I've been remiss in my duties. I've given you meat and wine and music, but I haven’t shown you the hospitality you deserve. My King has married and I owe my new Queen a wedding gift. </i> Roose Bolton thinks of attacking Robb Stark, but since Catelyn has realised his traumatising idea, she signals Robb by shouting two numbers A and B. For Robb to understand the signal, he needs to solve the following problem with the two numbers: Given A and B, find whether A can be transformed to B if A can be converted to A + fact(A) any number of times, where fact(A) is any factor of A other than 1 and A itself. For example: A = 9, B = 14 can follow the given steps during conversion A = 9 A = 9 + 3 = 12 (3 is a factor of 9) A = 12 + 2 = 14 = B (2 is a factor of 12)The first and the only line of input contains two numbers A and B. Constraints 1 <= A, B <= 10<sup>12</sup>Output "Yes" (without quotes) if we can transform A to B, else output "No" (without quotes)Sample Input 9 14 Sample Output Yes Explanation: In the problem statement Sample Input 33 35 Sample Output No Explanation The minimum factor of 33 is 3, so we cannot transform 33 to 35., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define sz(v) (int) v.size() #define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl; #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long #define ld long double #define int long long #define double long double #define mp make_pair #define F first #define S second typedef pair<int, int> pii; typedef vector<int> vi; #define pi 3.141592653589793238 const int MOD = 1e9+7; const int INF = 1LL<<60; const int N = 2e5+5; // it's swapnil07 ;) #ifdef SWAPNIL07 #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define endl '\n' #define trace(...) #define end_routine() #endif int small_prime(int x) { for(int i=2; i*i<=x; i++){ if(x%i==0){ return i; } } return -1; } void solve(){ int a, b; cin>>a>>b; int aa = a, bb = b; int d1 = small_prime(a); int d2 = small_prime(b); if (d1 == -1 || d2 == -1) { cout<<"No"; return; } if ((a % 2) == 1) { a += d1; } if ((b % 2) == 1) { b -= d2; } if (a > b) { cout<<"No"; return; } cout<<"Yes"; } 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: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, 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 1073741824 #define read(type) readInt<type>() #define max1 1000001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' const double pi=acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<string> VS; typedef vector<PII> VII; typedef vector<VI> VVI; typedef map<int,int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; typedef long int li; typedef unsigned long int uli; typedef long long int ll; typedef unsigned long long int ull; bool isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll power(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to 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; } // Returns n^(-1) mod p ll modInverse(ll n, ll p) { return power(n, p-2, p); } // Returns nCr % p using Fermat's little // theorem. ll ncr(ll n, ll r,ll p) { // Base case if (r==0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r ll fac[n+1]; fac[0] = 1; for (ll i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p; return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; } ll fastexp (ll a, ll b, ll n) { ll res = 1; while (b) { if (b & 1) res = res*a%n; a = a*a%n; b >>= 1; } return res; } bool a[max1]; int main() { FOR(i,max1){ a[i]=false;} for(int i=2;i<max1;i++){ if(a[i]==false){ for(int j=i+i;j<max1;j+=i){ a[j]=true; } }} vector<int> v; map<int,int> m; for(int i=2;i<max1;i++){ if(a[i]==false){ v.EB(i); m[i]++; } } int t; cin>>t; while(t--){ int n; cin>>n; bool win=false; for(int i=0;i<v.size();i++){ if(m.find(n-v[i])!=m.end()){ if(v[i]>n){break;} cout<<v[i]<<" "<<n-v[i]<<endl;win=true;break; } } if(win==false){out(-1);} } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static boolean isPrime(int n) { boolean ans=true; if(n<=1) { ans=false; } else if(n==2 || 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)); int t=Integer.parseInt(scan.readLine()); while(t-->0) { int n=Integer.parseInt(scan.readLine()); int a=0,b=0; if(n%2==1) { if(isPrime(n-2)) { a=2;b=n-2; } } else { for(int i=2;i<=n/2;i++) { if(isPrime(i)) { if(isPrime(n-i)) { a=i;b=n-i; break; } } } } if(a!=0 && b!=0) { System.out.println(a+" "+b); } else { System.out.println(-1); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N. Constraints: 1 ≤ T ≤ 100 2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input: 2 8 3 Sample Output: 3 5 -1, I have written this Solution Code: def isprime(num): if(num==1 or num==0): return False for i in range(2,int(num**0.5)+1): if(num%i==0): return False return True T = int(input()) for test in range(T): N = int(input()) value = -1 if(N%2==0): for i in range(2,int(N/2)+1): if(isprime(i)): if(isprime(N-i)): value = i break else: if(isprime(N-2)): value = 2 if(value==-1): print(value) else: print(str(value)+" "+str(N-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a letter of lowercase English alphabet, your task is to determine whether it is a vowel or a consonant.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>VowelorConsonant()</b> which contains M as a parameter. Constraints:- 'a' <= alpha <= 'z'Print C if the given alphabet is Consonant else Print V.Sample Input:- a Sample Output:- V Sample Input:- b Sample Output:- C, I have written this Solution Code: ch = input() if(ch=='a' or ch =='e' or ch=='i' or ch=='o' or ch=='u'): print("V") else: print("C"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a letter of lowercase English alphabet, your task is to determine whether it is a vowel or a consonant.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>VowelorConsonant()</b> which contains M as a parameter. Constraints:- 'a' <= alpha <= 'z'Print C if the given alphabet is Consonant else Print V.Sample Input:- a Sample Output:- V Sample Input:- b Sample Output:- C, I have written this Solution Code: static void VowelorConsonant(char C){ if(C=='a' || C=='e' || C=='i' || C=='o' || C=='u'){System.out.print("V");} else{ System.out.print("C"); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Complete the function <code>repeatWithDelay</code>. You will be given a single argument, <code>count</code>, a number. This <code>count</code> argument should control the number of times the function should be executed with a 1-second delay. <strong>Use the JS inbuilt function, which repeatedly calls a function after a specific interval of time, to call the function after a 1-second delay </strong>. The function within the inbuilt function (i.e passed as callback) should print <code>"Interval has been executed " + executionCount + " time(s)"</code> to the console. The <code>executionCount</code> should increment as the function is called after every second. When the executionCount is equal to the count argument, clear the interval. After executing the above function, use another <strong> JS inbuilt function that calls a function after a specific time</strong>. This callback function, within the inbuilt function, should print <code>"Interval execution stopped"</code> to the console. Use the built-in method, to clear the interval after the count+1 delay. <strong>Note: </strong>You may see <code>"setTimeout was not called"</code> printed on the console. This is because you may have solved the question using loops.The function takes in a number.The function prints a string on the console.let count = 3; repeatWithDelay(count); // prints Interval has been executed 1 time(s) Interval has been executed 2 time(s) Interval has been executed 3 time(s) Interval execution stopped, I have written this Solution Code: function repeatWithDelay(count) { let executionCount = 0; let intervalId = setInterval(function() { executionCount++; console.log("Interval has been executed " + executionCount + " time(s)"); if (executionCount === count) { clearInterval(intervalId); } }, 1000); setTimeout(function() { console.log("Interval execution stopped"); clearInterval(intervalId); }, (count + 1) * 1000); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid. <b>Constraints:-</b> 1 <= n <= 100000 0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:- 10 1 2 3 2 4 3 6 6 7 6 Sample Output 1:- 0 0 0 1 0 1 0 0 0 1 43 Sample Input 2:- 7 10 20 30 40 30 20 10 Sample Output 2:- 0 0 0 0 10 20 30 220, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); int n = Integer.parseInt(in.readLine()); int []donationList = new int[n]; int[] defaulterList = new int[n]; long totalDonations = 0L; StringTokenizer st = new StringTokenizer(in.readLine()); for(int i=0 ; i<n ; i++){ donationList[i] = Integer.parseInt(st.nextToken()); } int max = Integer.MIN_VALUE; for(int i=0; i<n; i++){ totalDonations += donationList[i]; max = Math.max(max,donationList[i]); if(i>0){ if(donationList[i] >= max) defaulterList[i] = 0; else defaulterList[i] = max - donationList[i]; } totalDonations += defaulterList[i]; } for(int i=0; i<n ;i++){ System.out.print(defaulterList[i]+" "); } System.out.println(); System.out.print(totalDonations); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid. <b>Constraints:-</b> 1 <= n <= 100000 0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:- 10 1 2 3 2 4 3 6 6 7 6 Sample Output 1:- 0 0 0 1 0 1 0 0 0 1 43 Sample Input 2:- 7 10 20 30 40 30 20 10 Sample Output 2:- 0 0 0 0 10 20 30 220, I have written this Solution Code: n = int(input()) a = input().split() b = int(a[0]) sum = 0 for i in a: if int(i)<b: print(b-int(i),end=' ') else: b = int(i) print(0,end=' ') sum = sum+b print() print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid. <b>Constraints:-</b> 1 <= n <= 100000 0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:- 10 1 2 3 2 4 3 6 6 7 6 Sample Output 1:- 0 0 0 1 0 1 0 0 0 1 43 Sample Input 2:- 7 10 20 30 40 30 20 10 Sample Output 2:- 0 0 0 0 10 20 30 220, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int n; cin>>n; int a[n]; int ma=0; int cnt=0; //map<int,int> m; for(int i=0;i<n;i++){ cin>>a[i]; ma=max(ma,a[i]); cout<<ma-a[i]<<" "; cnt+=ma-a[i]; cnt+=a[i]; //m[a[i]]++; } cout<<endl; cout<<cnt<<endl; } signed main(){ int t; t=1; while(t--){ solve();} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main (String[] args)throws IOException { Reader sc = new Reader(); int N = sc.nextInt(); int[] arr = new int[N]; for(int i=0;i<N;i++){ arr[i] = sc.nextInt(); } int max=0; if(arr[0]<arr[N-1]) System.out.print(N-1); else{ for(int i=0;i<N-1;i++){ int j = N-1; while(j>i){ if(arr[i]<arr[j]){ if(max<j-i){ max = j-i; } break; } j--; } if(i==j) break; if(j==N-1) break; } if(max==0) System.out.print("-1"); else System.out.print(max); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long /* For a given array arr[], returns the maximum j – i such that arr[j] > arr[i] */ int maxIndexDiff(int arr[], int n) { int maxDiff; int i, j; int *LMin = new int[(sizeof(int) * n)]; int *RMax = new int[(sizeof(int) * n)]; /* Construct LMin[] such that LMin[i] stores the minimum value from (arr[0], arr[1], ... arr[i]) */ LMin[0] = arr[0]; for (i = 1; i < n; ++i) LMin[i] = min(arr[i], LMin[i - 1]); /* Construct RMax[] such that RMax[j] stores the maximum value from (arr[j], arr[j+1], ..arr[n-1]) */ RMax[n - 1] = arr[n - 1]; for (j = n - 2; j >= 0; --j) RMax[j] = max(arr[j], RMax[j + 1]); /* Traverse both arrays from left to right to find optimum j - i. This process is similar to merge() of MergeSort */ i = 0, j = 0, maxDiff = -1; while (j < n && i < n) { if (LMin[i] < RMax[j]) { maxDiff = max(maxDiff, j - i); j = j + 1; } else i = i + 1; } return maxDiff; } // Driver Code signed main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int maxDiff = maxIndexDiff(a, n); cout << maxDiff; 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 integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) rightMax = [0] * n rightMax[n - 1] = arr[n - 1] for i in range(n - 2, -1, -1): rightMax[i] = max(rightMax[i + 1], arr[i]) maxDist = -2**31 i = 0 j = 0 while (i < n and j < n): if (rightMax[j] >= arr[i]): maxDist = max(maxDist, j - i) j += 1 else: i += 1 if maxDist==0: maxDist=-1 print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: t=int(input()) while t!=0: m,n=input().split() m,n=int(m),int(n) for i in range(m): arr=input().strip() if '1' in arr: arr='1 '*n else: arr='0 '*n print(arr) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 int a[N][N]; // Driver code int main() { int t; cin>>t; while(t--){ int n,m; cin>>n>>m; bool b[n]; for(int i=0;i<n;i++){ b[i]=false; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; if(a[i][j]==1){ b[i]=true; } } } for(int i=0;i<n;i++){ if(b[i]){ for(int j=0;j<m;j++){ cout<<1<<" "; }} else{ for(int j=0;j<m;j++){ cout<<0<<" "; } } cout<<endl; } }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String[] args) throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader bf = new BufferedReader(isr); int t = Integer.parseInt(bf.readLine()); while (t-- > 0){ String inputs[] = bf.readLine().split(" "); int m = Integer.parseInt(inputs[0]); int n = Integer.parseInt(inputs[1]); String[] matrix = new String[m]; for(int i=0; i<m; i++){ matrix[i] = bf.readLine(); } StringBuffer ones = new StringBuffer(""); StringBuffer zeros = new StringBuffer(""); for(int i=0; i<n; i++){ ones.append("1 "); zeros.append("0 "); } for(int i=0; i<m; i++){ if(matrix[i].contains("1")){ System.out.println(ones); }else{ System.out.println(zeros); } } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<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>implementMergeSort()</b> that takes 3 arguments. arr: input array start: starting index which is 0 end: ending index of array Constraints 1 <= T <= 100 1 <= N <= 10<sup>6</sup> 0 <= Arr[i] <= 10<sup>9</sup> Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: public static int[] implementMergeSort(int arr[], int start, int end) { if (start < end) { // Find the middle point int mid = (start+end)/2; // Sort first and second halves implementMergeSort(arr, start, mid); implementMergeSort(arr , mid+1, end); // Merge the sorted halves merge(arr, start, mid, end); } return arr; } public static void merge(int arr[], int start, int mid, int end) { // Find sizes of two subarrays to be merged int n1 = mid - start + 1; int n2 = end - mid; /* Create temp arrays */ int L[] = new int [n1]; int R[] = new int [n2]; /*Copy data to temp arrays*/ for (int i=0; i<n1; ++i) L[i] = arr[start + i]; for (int j=0; j<n2; ++j) R[j] = arr[mid + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = start; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an unsorted array, your task is to sort the array using merge sort.<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>implementMergeSort()</b> that takes 3 arguments. arr: input array start: starting index which is 0 end: ending index of array Constraints 1 <= T <= 100 1 <= N <= 10<sup>6</sup> 0 <= Arr[i] <= 10<sup>9</sup> Sum of 'N' over all test cases does not exceed 10<sup>6</sup>You need to return the sorted array. The driver code will print the array in sorted form.Sample Input: 2 3 3 1 2 3 4 5 6 Sample Output: 1 2 3 4 5 6, I have written this Solution Code: for _ in range(int(input())): n = int(input()) print(*sorted(list(map(int,input().split())))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable