Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: You are given the number N. You need to convert it to 1 in the minimum number of operations. The operations allowed are as follows: 1. If N is even then divide the number by 2. 2. If N is odd then you can either add 1 to it or subtract 1 from it. Using the above operations, find the minimum number of operations required to convert N to 1.The first line of input contains an integer T denoting the number of test cases. T test cases follow. Each test case contains 1 line of input containing integer N. <b>Constraints:</b> 1 &le; T &le; 100 1 &le; N &le; 10<sup>7</sup> For each testcase, in a new line, print the minimum number of steps required.Sample Input: 4 1 2 3 4 Sample Output: 0 1 2 2 <b>Explanation:</b> 1 can be converted into 1 in 0 steps. 2 can be converted into 1 in 1 step: 2/2=1 3 can be converted into 1 in 3 steps: 3-1= 2 then 2/2=1 4 can be converted into 1 in 2 steps: 4/2=2 then 2/2=1, I have written this Solution Code: import java.lang.*; import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int testcases=sc.nextInt(); while(testcases-->0) { long n=sc.nextLong(); System.out.println(NS.minOperations(n)); } } } class NS { public static long minOperations(long n) { if(n==1) return 0; //since 1 is already 1 if(n==2) return 1; //convert 2 to 1. 1 step if(n==3) return 2; //convert 3 to 2. Then 2 to 1. 2 steps long total=0; //save total steps if(n%2!=0) //if odd { total=1+Math.min(minOperations(n-1),minOperations(n+1)); //convert n to n-1 or n+1 then minimum of those conversions } else total=1+minOperations(n/2); //convert n to n/2 then count operations required for n/2 to 1 return total; //returning total at the end } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to check if the given number prime or not.<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Ifprime()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 10<sup>9</sup> <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 if it is required</i>Print "Yes" if the given number is prime else print "No"Sample Input:- 6 Sample Output:- No Sample Input:- 3 Sample Output:- Yes, I have written this Solution Code: def IFprime(N): is_prime = 'Yes' if N == 1: is_prime = 'No' else: for i in range(2, N//2+1): if N % i == 0: is_prime = 'No' break print(is_prime) IFprime(int(input())), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer N, your task is to check if the given number prime or not.<b>User Task</b> Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Ifprime()</i> which contains the given number N. <b>Constraints:</b> 1 <= N <= 10<sup>9</sup> <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 if it is required</i>Print "Yes" if the given number is prime else print "No"Sample Input:- 6 Sample Output:- No Sample Input:- 3 Sample Output:- Yes, I have written this Solution Code: static void Ifprime(int N) { if(N==1){ System.out.print("No"); return; } boolean prime = true; for(int i=2; i*i<=N ;i++){ if(N%i==0){prime=false;break;} } if(prime==true){ 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: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); String array[] = br.readLine().trim().split(" "); StringBuilder sb = new StringBuilder(""); int[] arr = new int[n]; int oddCount = 0, evenCount = 0; for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(array[i]); if(arr[i] % 2 == 0) ++evenCount; else ++oddCount; } if(evenCount > 0 && oddCount > 0) Arrays.sort(arr); for(int i = 0; i < n; i++) sb.append(arr[i] + " "); System.out.println(sb.substring(0, sb.length() - 1)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 3, I have written this Solution Code: n=int(input()) p=[int(x) for x in input().split()[:n]] o=0;e=0 for i in range(n): if (p[i] % 2 == 1): o += 1; else: e += 1; if (o > 0 and e > 0): p.sort(); for i in range(n): print(p[i], end = " ");, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements. What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:- 3 4 1 7 Sample Output:- 1 4 7 Explanation:- Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd Sample Input:- 2 2 4 Sample Output:- 2 4 Sample Input:- 2 5 3 Sample Output:- 5 3, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; long long a[n]; bool win=false,win1=false; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]&1){win=true;} if(a[i]%2==0){win1=true;} } if(win==true && win1==true){sort(a,a+n);} for(int i=0;i<n;i++){ cout<<a[i]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, I have written this Solution Code: a,b,c=[int(a) for a in input().split()] print(max(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 your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c <b>Constraint:</b> 1<=integers<=10000Print the maximum integer among the given integers.Sample Input:- 2 6 3 Sample Output:- 6 Sample Input:- 48 100 100 Sample Output: 100, 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 p = scanner.nextInt(); int tm = scanner.nextInt(); int r = scanner.nextInt(); int intrst = MaxInteger(p,tm,r); System.out.println(intrst); } static int MaxInteger(int a ,int b, int c){ if(a>=b && a>=c){return a;} if(b>=a && b>=c){return b;} return c;} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Thomas liked a girl named Grace and he decided to reach out to her. Grace agreed to go on a date with him if he helped her solve a problem. The problem is: You are given an equation a - x = a βŠ• x (a xor x) and an integer parameter a. You have to tell how many non- negative solutions of this equation exist. Thomas is stuck in this problem and is asking you for your help. Help Thomas save his date.The first line of input contains a single integer T. Second line contains an integer a, parameter of the equation. Constraints:- 1 <= T <= 100000 1 <= a <= 2^60 -1For each value of a, print the number of non- negative solutions of the given equation.Sample Input:- 3 0 2 5 Sample Output:- 1 2 4, 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 testCases = Integer.parseInt(read.readLine()); while(testCases-- > 0) { long value = Long.parseLong(read.readLine()); long count = 0; while(value > 0) { if(value%2 == 1) count++; value /= 2; } long ans = 1; long p=2; while(count-- > 0){ ans *= p; } System.out.println(ans); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Thomas liked a girl named Grace and he decided to reach out to her. Grace agreed to go on a date with him if he helped her solve a problem. The problem is: You are given an equation a - x = a βŠ• x (a xor x) and an integer parameter a. You have to tell how many non- negative solutions of this equation exist. Thomas is stuck in this problem and is asking you for your help. Help Thomas save his date.The first line of input contains a single integer T. Second line contains an integer a, parameter of the equation. Constraints:- 1 <= T <= 100000 1 <= a <= 2^60 -1For each value of a, print the number of non- negative solutions of the given equation.Sample Input:- 3 0 2 5 Sample Output:- 1 2 4, I have written this Solution Code: t=int(input()) for i in range(t): a=int(input()) binary=bin(a)[2:] count1=0 for bit in binary: if bit=="1": count1+=1 print(2**count1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Thomas liked a girl named Grace and he decided to reach out to her. Grace agreed to go on a date with him if he helped her solve a problem. The problem is: You are given an equation a - x = a βŠ• x (a xor x) and an integer parameter a. You have to tell how many non- negative solutions of this equation exist. Thomas is stuck in this problem and is asking you for your help. Help Thomas save his date.The first line of input contains a single integer T. Second line contains an integer a, parameter of the equation. Constraints:- 1 <= T <= 100000 1 <= a <= 2^60 -1For each value of a, print the number of non- negative solutions of the given equation.Sample Input:- 3 0 2 5 Sample Output:- 1 2 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int check(int x){ int p = sqrt(x); for(int i=2;i<=p;i++){ if(x%i==0){return 1;} } return 0; } signed main(){ int t; cin>>t; while(t--){ int n; cin>>n; int cnt=0; while(n){ if(n&1){cnt++;} n/=2; } int ans =1; int p=2; while(cnt--){ ans*=p; } out(ans); } } , 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 a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: def countMultiples(N): return int(100/N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: static int countMultiples(int N) { int i = 1, count = 0; while(i < 101){ if(i % N == 0) count++; i++; } return count; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: str1 = input() str2 = '' for i in range(len(str1)): if(i % 2 == 0): str2 = str2 + str1[i]+" " print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., 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); String s = sc.next(); for(int i = 0;i<s.length();i++){ if(i%2==0){ System.out.print(s.charAt(i)+" "); } } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: // str is input function oddChars(str) { // write code here // do not console.log // return the output as a string return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ') }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters. Constraints:- 1 <= |S| <= 100 The output should contain the character's at odd positions seperated by space.Sample Input abcde Sample Output a c e Sample Input abcd Sample Output a c Explanation: index => 1 2 3 4 chars => a b c d a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; for(int i=0;i<s.length();i++){ if(!(i&1)){cout<<s[i]<<" ";} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: static int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: def maximumMarks(X): if X>5: return (X) return (10-X) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible. Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument. Constraints:- 0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:- X = 5 Sample Output:- 5 Explanation:- One of the possible solutions is she can mark all the answers true. Sample Input:- 1 Sample Output:- 9, I have written this Solution Code: int maximumMarks(int X){ if(X>5){ return X; } return 10-X; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Maruti is a software engineer at Newton School. He is very passionate regarding his Job due to that he always remains very conscious regarding his health. So he checks his BMI(Body mask Index) regularly and shows that to the doctor. You are given the weight and height of Maruti in pounds and inches respectively. Calculate Maruti's BMI and return it. <b>Note:</b>Return BMI value of two decimal places. BMI=Weight(in kg)/Height(in meters)<sup>2</sup> 1 Pound = 0.453592 kg 1 Inch = 0.0254 metresThere are two decimal values w, h (weight and height of maruti) are given as input. <b>Constraints</b> 1 <b>&le;</b> w, h <b>&le;</b> 10<sup>2</sup>Return BMI Value of maruti.Sample Input: 72 45 Sample Output: 25.00, I have written this Solution Code: import java.util.Scanner; public class Main { public static void main(String[] Strings) { Scanner input = new Scanner(System.in); double weight = input.nextDouble(); double inches = input.nextDouble(); double BMI = weight * 0.45359237 / (inches * 0.0254 * inches * 0.0254); System.out.printf("%.2f",BMI); } } , 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 Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: import math n= int(input()) for i in range (1,n+1): arm=i summ=0 while(arm!=0): rem=math.pow(arm%10,3) summ=summ+rem arm=math.floor(arm/10) if summ == i : print(i,end=" "), 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 Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; bool checkArmstrong(int n) { int temp = n, sum = 0; while(n > 0) { int d = n%10; sum = sum + d*d*d; n = n/10; } if(sum == temp) return true; return false; } int main() { int n; cin>>n; for(int i = 1; i <= n; i++) { if(checkArmstrong(i) == true) cout << i << " "; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int digitsum,num,digit; for(int i=1;i<=n;i++){ digitsum=0; num=i; while(num>0){ digit=num%10; digitsum+=digit*digit*digit; num/=10; } if(digitsum==i){System.out.print(i+" ");} } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</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 functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 &le; n &le; 100Print even or odd for each i, separated by white spaces.Sample Input: 5 Sample Output: odd even odd even odd Sample Input: 2 Sample Output: odd even, I have written this Solution Code: public static void For_Loop(int n){ for(int i=1;i<=n;i++){ if(i%2==1){System.out.print("odd ");} else{ System.out.print("even "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</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 functions <b>For_Loop()</b> that take the integer n as a parameter. </b>Constraints:</b> 1 &le; n &le; 100Print even or odd for each i, separated by white spaces.Sample Input: 5 Sample Output: odd even odd even odd Sample Input: 2 Sample Output: odd even, I have written this Solution Code: n = int(input()) for i in range(1, n+1): if(i%2)==0: print("even ",end="") else: print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: t=int(input()) while t>0: n=int(input()) a=map(int,input().split()) m=0 c=0 for i in a: c+=i if c>m:m=c elif c<0:c=0 print(m) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static long Sum(int a[], int size) { long max_so_far = -1000000007, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); while(t-->0){ int n = Integer.parseInt(br.readLine().trim()); int arr[] = new int[n]; String inputLine[] = br.readLine().trim().split(" "); for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(inputLine[i]); } System.out.println(Sum(arr,n)); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long long Sum(long long a[], int size) { long long max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout<<Sum(a,n)<<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, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10 Explanation: Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9. Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array // n is the number of elements in the array function insertionSort(arr, n) { // write code here // do not console.log the answer // return sorted array return arr.sort((a, b) => a - b) } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10 Explanation: Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9. Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void insertionSort(int[] arr){ for(int i = 0; i < arr.length-1; i++){ for(int j = i+1; j < arr.length; j++){ if(arr[i] > arr[j]){ int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } } public static void main (String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); while(T > 0){ int n = scan.nextInt(); int arr[] = new int[n]; for(int i = 0; i<n; i++){ arr[i] = scan.nextInt(); } insertionSort(arr); for(int i = 0; i<n; i++){ System.out.print(arr[i] + " "); } System.out.println(); T--; System.gc(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10 Explanation: Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9. Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10 Explanation: Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9. Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr): arr.sort() return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A. In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]). (Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 10^2 1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1 10 2 1 4 1 6 2 2 6 4 1 Output-1 2 4 12 12 4 Input-2 8 1 23 54 2 3 6 43 2 Output-2 23 108 18 86 Explanation(might not be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [2 1 4 1 6 2 2 6 4 1] Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1) Step 3: 2 4 12 12 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); String n1 = br.readLine(); int n = Integer.parseInt(n1); long arr[] = new long[n]; String data = br.readLine(); String s[] = data.split(" "); long mul = 1; for(int i = 0; i < arr.length; i++){ arr[i] = Integer.parseInt(s[i]); } for(int i = 0; i < arr.length; i+=2){ mul = arr[i]*arr[i+1]; System.out.print(mul+" "); mul = 1; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A. In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]). (Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 10^2 1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1 10 2 1 4 1 6 2 2 6 4 1 Output-1 2 4 12 12 4 Input-2 8 1 23 54 2 3 6 43 2 Output-2 23 108 18 86 Explanation(might not be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [2 1 4 1 6 2 2 6 4 1] Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1) Step 3: 2 4 12 12 4, I have written this Solution Code: a=int(input()) b=list(map(int,input().split())) for i in range(0,a-1,2): print(b[i]*b[i+1],end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A. In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]). (Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers. Constraints 1 <= N <= 10^2 1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1 10 2 1 4 1 6 2 2 6 4 1 Output-1 2 4 12 12 4 Input-2 8 1 23 54 2 3 6 43 2 Output-2 23 108 18 86 Explanation(might not be the optimal solution): Testcase 1: Follow the below steps:- Step 1: [2 1 4 1 6 2 2 6 4 1] Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1) Step 3: 2 4 12 12 4, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i+=2){ cout<<a[i]*a[i+1]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); int n; while(t>0) { n = Integer.parseInt(br.readLine()); int a[] = new int[n]; String s = br.readLine(); String arr[] = s.split(" "); for(int i=0;i<n;i++) { a[i] = Integer.parseInt(arr[i]); } int b[] = sort(a); for(int i=0;i<n;i++) { System.out.print(b[i] + " "); } System.out.println(); t--; } } static int[] sort(int[] a) { int temp, index; for(int i=0;i<a.length-1;i++) { index = i; for(int j=i+1;j<a.length;j++) { if(a[j]<a[index]) { index = j; } } temp = a[i]; a[i] = a[index]; a[index] = temp; } return a; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: for _ in range(int(input())): n = input() res = map(str, sorted(list( map(int,input().split())))) print(' '.join(res)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A[], size N containing positive integers. You need to arrange the elements of array in increasing order using selection sort.First line of the input denotes number of test cases 'T'. First line of the test case is the size of array and second line consists of array elements. Constraints: 1 <= T <= 100 1 <= N <= 10^3 1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input: 2 5 4 1 3 9 7 10 10 9 8 7 6 5 4 3 2 1 Output: 1 3 4 7 9 1 2 3 4 5 6 7 8 9 10, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom has a water bottle with the shape of a rectangular prism whose base is a square of side a cm and whose height is b cm. (The thickness of the bottle can be ignored) We will pour x cubic cm of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.Their is only one line of input which contain three integers a, b and x. Constraints:- 1 ≀ a ≀ 100 1 ≀ b ≀ 100 1 ≀ x ≀ (a^2)*bPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Print 10 digits after decimal.Sample Input: 2 2 4 Sample Output 45.0000000000 Sample Input 12 21 10 Sample Output 89.7834636934, 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 IOException { BufferedReader scan=new BufferedReader(new InputStreamReader(System.in)); String s[]=scan.readLine().split(" "); int width=Integer.parseInt(s[0]); int height=Integer.parseInt(s[1]); int givenVolume=Integer.parseInt(s[2]); double heightOfGivenVolume=(givenVolume)/(double)(width*width); double angleInDegree=0.0; if(heightOfGivenVolume==height) { angleInDegree=90.0; } else if(heightOfGivenVolume<=(height/2)) { double tanTheta=(2.0*width*heightOfGivenVolume)/(double)(height*height); double angleInRadian=Math.atan(tanTheta); angleInDegree=90.0-Math.toDegrees(angleInRadian); } else { double tanTheta=width/(2.0*(height-heightOfGivenVolume)); double angleInRadian=Math.atan(tanTheta); angleInDegree=90.0-Math.toDegrees(angleInRadian); } System.out.printf("%.10f",angleInDegree); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Tom has a water bottle with the shape of a rectangular prism whose base is a square of side a cm and whose height is b cm. (The thickness of the bottle can be ignored) We will pour x cubic cm of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.Their is only one line of input which contain three integers a, b and x. Constraints:- 1 ≀ a ≀ 100 1 ≀ b ≀ 100 1 ≀ x ≀ (a^2)*bPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Print 10 digits after decimal.Sample Input: 2 2 4 Sample Output 45.0000000000 Sample Input 12 21 10 Sample Output 89.7834636934, I have written this Solution Code: #include <bits/stdc++.h> // #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); double a,b,x; cin>>a>>b>>x; double ans; double pi = 2*acos(0.0); if(x<(a*a*b)/2 ) { double p= (a*b*b)/(2*x); ans = atan(p); ans= (ans*180)/pi; } else { double p = (2*((a*a*b) - x))/(a*a*a); ans = atan(p); ans= (ans*180)/pi; } cout <<std::fixed; cout<<setprecision(10)<<ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: a, b = list(map(int, input().split(" "))) print(str(a <= 10 and b >= 10).lower(), end=' ') print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ') print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers a and b, your task is to check following conditions:- 1. If a <= 10 and b >= 10 (Logical AND). 2. Atleast one from a or b will be even (Logical OR). 3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b. <b>Constraints:</b> 1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> . Sample Input:- 3 12 Sample Output:- true true true Explanation So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true. Sample Input:- 10 10 Sample Output:- true true false , I have written this Solution Code: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Main { static boolean Logical_AND(int a, int b){ if(a<=10 && b>=10){ return true;} return false;} static boolean Logical_OR(int a, int b){ if(a%2==0 || b%2==0){ return true;} return false;} static boolean Logical_NOT(int a, int b){ if(a!=b){ return true;} return false;} public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=in.nextInt(); int b=in.nextInt(); System.out.print(Logical_AND(a, b)+" "); System.out.print(Logical_OR(a,b)+" "); System.out.print(Logical_NOT(a,b)+" "); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: t=int(input()) while t>0: n=int(input()) a=map(int,input().split()) m=0 c=0 for i in a: c+=i if c>m:m=c elif c<0:c=0 print(m) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static long Sum(int a[], int size) { long max_so_far = -1000000007, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); while(t-->0){ int n = Integer.parseInt(br.readLine().trim()); int arr[] = new int[n]; String inputLine[] = br.readLine().trim().split(" "); for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(inputLine[i]); } System.out.println(Sum(arr,n)); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases. The first line of each test case contains an integer n, the length of the array A and the next line contains n integers. Constraints: 1<=T<=100 1 <= N <= 10^5 -10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input: 1 5 1 2 3 4 -10 Output: 10 Explanation:- 1+2+3+4=10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long long Sum(long long a[], int size) { long long max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; if (max_ending_here < 0) max_ending_here = 0; } return max_so_far; } int main(){ int t; cin>>t; while(t--){ int n; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } cout<<Sum(a,n)<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A circular array is called good if, for every index i (0 to N-1), there exists an index j such that i != j and sum of all the numbers in the clockwise direction from i to j is equal to the sum of all numbers in the anticlockwise direction from i to j. You are given an circular array of size N, Your task is to check whether the given array is good or not.First line of input contains a single integer N, the next line of input contains N space separated integes depicting values of the array. Constraints:- 1 <= N <= 100000 1 <= Arr[i] <= 1000000Print "Yes" if array is good else print "No"Sample Input:- 4 1 4 1 4 Sample Output:- Yes Explanation:- for index 1, j will be 3, then sum of elements from index 1 to 3 in clockwise direction will be 1 + 4 + 1 = 6 and the sum of elements from index 1 to 3 in anticlockwise direction will be 1 + 4 + 1 = 6. For index 2, j will be 4 For index 3, j will be 1 For index 4, j will be 2 Sample Input:- 4 1 2 3 4 Sample Output:- No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 10001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int INF = 4557430888798830399ll; signed main() { fast(); int n; cin>>n; int a[n]; FOR(i,n){ cin>>a[i];} if(n&1){out("No");return 0;} FOR(i,n/2){ if(a[i]!=a[n/2+i]){out("No");return 0;} } out("Yes"); } , In this Programming Language: Unknown, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., 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> #define rep(i,n) for (int i=0; i<(n); i++) ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int a[n]; for(int i=0;i<n;++i){ cin>>a[i]; } int ans=0; int v=0; for(int i=1;i<n;++i){ if(a[i]>a[i-1]) v=0; else ++v; ans=max(ans,v); } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int num = Integer.parseInt(br.readLine()); String s= br.readLine(); int[] arr= new int[num]; String[] s1 = s.split(" "); int ccount = 0, pcount = 0; for(int i=0;i<(num);i++) { arr[i]=Integer.parseInt(s1[i]); if(i+1 < num){ arr[i+1] = Integer.parseInt(s1[i+1]);} if(((i+1)< num) && (arr[i]>=arr[i+1]) ){ ccount++; }else{ if(ccount > pcount){ pcount = ccount; } ccount = 0; } } System.out.print(pcount); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N. The second line of input contains N integers, denoting the array height. <b>Constraints:</b> 1 <= N <= 10<sup>5</sup> 1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:- 5 5 4 1 2 1 Sample Output:- 2 <b>Explanation:</b> We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: N = int(input()) arr = iter(map(int,input().strip().split())) jumps = [] jump = 0 temp = next(arr) for i in arr: if i<=temp: jump += 1 temp = i continue temp = i jumps.append(jump) jump = 0 jumps.append(jump) print(max(jumps)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: def ispangram(str): alphabet = "abcdefghijklmnopqrstuvwxyz" for char in alphabet: if char not in str.lower(): return False return True N = int(input()) arr = [] for i in range(N): arr.append(input()) for i in range(N): if(ispangram(arr[i]) == True): print(1) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: function pangrams(s) { // write code here // do not console.log it // return 1 or 0 let alphabet = "abcdefghijklmnopqrstuvwxyz"; let regex = /\s/g; let lowercase = s.toLowerCase().replace(regex, ""); for(let i = 0; i < alphabet.length; i++){ if(lowercase.indexOf(alphabet[i]) === -1){ return 0; } } return 1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ String s = sc.next(); int check = 1; int p =0; for(char ch = 'a';ch<='z';ch++){ p=0; for(int i = 0;i<s.length();i++){ if(s.charAt(i)==ch){p=1;} } if(p==0){check=0;} } System.out.println(check); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S check if it is Pangram or not. A pangram is a sentence containing all 26 letters of the English Alphabet.First line of input contains of an integer T denoting number od test cases then T test cases follow. Each testcase contains a String S. Constraints: 1 <= T <= 100 1 <= |S| <= 1000 Note:- String will not contain any spacesFor each test case print in a new line 1 if its a pangram else print 0.Input: 2 Bawdsjogflickquartzvenymph sdfs Output: 0 0 Explanation : Testcase 1: In the given input, the letter 'x' of the english alphabet is not present. Hence, the output is 0. Testcase 2: In the given input, there aren't all the letters present in the english alphabet. Hence, the output is 0., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 int A[26],B[26]; signed main() { int t; cin>>t; string p; getline(cin,p); while(t>0) { t--; string s; getline(cin,s); int n=s.size(); memset(A,0,sizeof(A)); int ch=1; for(int i=0;i<n;i++) { int x=s[i]-'a'; if(x>=0 && x<26) { A[x]++; } x=s[i]-'A'; if(x>=0 && x<26) { A[x]++; } } for(int i=0;i<26;i++) { if(A[i]==0) ch=0; } cout<<ch<<endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: import math n = int(input()) for i in range(n): x = int(input()) count = 0 for i in range(1, int(math.sqrt(x))+1): if x % i == 0: if (i%2 == 0): count+=1 if ((x/i) %2 == 0): count+=1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); int count=0; for(int i=1;i<=Math.sqrt(n);i++){ if(n%i == 0) { if(i%2==0) { count++; } if(i*i != n && (n/i)%2==0) { count++; } } } System.out.println(count); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N Constraints: 1 <= T <= 50 1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input: 2 9 8 Output 0 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ long long n; cin>>n; if(n&1){cout<<0<<endl;continue;} long x=sqrt(n); int cnt=0; for(long long i=1;i<=x;i++){ if(!(n%i)){ if(!(i%2)){cnt++;} if(i*i!=n){ if(!((n/i)%2)){cnt++;} } } } cout<<cnt<<endl;} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., I have written this Solution Code: import java.io.*; import java.util.*; class Main { static int getMaxValue(int arr[], int arr_size) { int i, first, second; if (arr_size < 2) { return 0; } first = second = Integer.MIN_VALUE; for (i = 0; i < arr_size; i++) { if (arr[i] > first) { second = first; first = arr[i]; } else if (arr[i] > second && arr[i] != first) { second = arr[i]; } } if (second == Integer.MIN_VALUE) { return 0; } else { return second; } } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] num = br.readLine().split(" "); int arr[] = new int[n]; for(int i=0;i<n;i++) arr[i] =Integer.parseInt(num[i]); int max = Integer.MIN_VALUE; System.out.println(getMaxValue(arr, n)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) arr.sort() a=0 b=0 for i in range(n): if arr[i]>b: a=b b=arr[i] print(a%b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input: 5 8 6 7 9 4 Sample Output: 8 Explanation: i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., 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 long ll; const int mod = 1e9 + 7; const int INF = 1e9; void solve() { int n; cin >> n; vector<int> p(n); set<int> s; for(auto &i : p) cin >> i, s.insert(i); if(s.size() == 1){ cout << 0; } else{ auto it = s.rbegin(); it++; cout << (*it); } } 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 a binary tree, determine if it is height-balanced. Tree is rooted at 1. Height-balanced binary tree : is defined as a binary tree in which the depth of the two sub-trees of every node never differ by more than 1.The first line of the input contains an integer N, the number of nodes in the Binary Tree. The following N-1 lines contain two integers, u and v, denoting an edge. Constraints 1 <= N <= 100000 1 <= u, v <= N u and v are distinctOutput "YES" if tree is balanced, else output "NO".Sample Input 3 1 2 1 3 Sample Output YES Sample Input 3 1 2 2 3 Sample Output NO, I have written this Solution Code: import java.io.*; import java.util.*; class Node{ Node left, right; int data; Node(int data){this.data = data;} } class Main { public static int BalancedBinaryTree(Node root){ if(root == null) return 0; if(root.left == null && root.right == null) return 1; int l = BalancedBinaryTree(root.left); int r = BalancedBinaryTree(root.right); if(Math.abs(l - r) > 1 || l == -1 || r == -1) return -1; return Math.max(l, r) + 1; } public static void main (String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); Node[] Tree = new Node[n]; for(int i = 0; i < n; i++){ Tree[i] = new Node(i+1); } for(int i = 0; i < n-1; i++){ int u = input.nextInt(); int v = input.nextInt(); if(Tree[u-1].left == null) Tree[u-1].left = Tree[v-1]; else Tree[u-1].right = Tree[v-1]; } System.out.println(BalancedBinaryTree(Tree[0]) != -1 ? "YES" : "NO"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree, determine if it is height-balanced. Tree is rooted at 1. Height-balanced binary tree : is defined as a binary tree in which the depth of the two sub-trees of every node never differ by more than 1.The first line of the input contains an integer N, the number of nodes in the Binary Tree. The following N-1 lines contain two integers, u and v, denoting an edge. Constraints 1 <= N <= 100000 1 <= u, v <= N u and v are distinctOutput "YES" if tree is balanced, else output "NO".Sample Input 3 1 2 1 3 Sample Output YES Sample Input 3 1 2 2 3 Sample Output NO, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; bool flag = 1; vector<int> g[N]; int check(int u, int p){ int l = -1, r = -1; int x = 0, y = 0; for(auto i: g[u]){ if(i == p) continue; if(l == -1){ l = i; x = 1 + check(l, u); } else if(r == -1){ r = i; y = 1 + check(r, u); } } if(abs(x-y) > 1) flag = 0; return max(x, y); } signed main() { IOS; int n; cin >> n; for(int i = 1; i <= n-1; i++){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } check(1, 0); if(flag) cout << "YES"; else cout << "NO"; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: 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 2 non-negative integers m and n, find gcd(m, n) GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer. NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n Constraints:- 1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input: 6 9 Sample Output: 3 Sample Input:- 5 6 Sample Output:- 1, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n, m; cin >> n >> m; cout << __gcd(n, m); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given 2 non-negative integers m and n, find gcd(m, n) GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer. NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n Constraints:- 1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input: 6 9 Sample Output: 3 Sample Input:- 5 6 Sample Output:- 1, I have written this Solution Code: def hcf(a, b): if(b == 0): return a else: return hcf(b, a % b) li= list(map(int,input().strip().split())) print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given 2 non-negative integers m and n, find gcd(m, n) GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer. NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n Constraints:- 1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input: 6 9 Sample Output: 3 Sample Input:- 5 6 Sample Output:- 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sp = br.readLine().trim().split(" "); long m = Long.parseLong(sp[0]); long n = Long.parseLong(sp[1]); System.out.println(GCDAns(m,n)); } private static long GCDAns(long m,long n){ if(m==0)return n; if(n==0)return m; return GCDAns(n%m,m); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade β€˜A’ If the percentage is <80 and >=60 then print Grade β€˜B’ If the percentage is <60 and >=40 then print Grade β€˜C’ else print Grade β€˜D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.io.*; public class Main { static final int MOD = 1000000007; public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = br.readLine().trim().split(" "); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); int c = Integer.parseInt(str[2]); int d = Integer.parseInt(str[3]); int e = Integer.parseInt(str[4]); System.out.println(grades(a, b, c, d, e)); } static char grades(int a, int b, int c, int d, int e) { int sum = a+b+c+d+e; int per = sum/5; if(per >= 80) return 'A'; else if(per >= 60) return 'B'; else if(per >= 40) return 'C'; else return 'D'; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade β€˜A’ If the percentage is <80 and >=60 then print Grade β€˜B’ If the percentage is <60 and >=40 then print Grade β€˜C’ else print Grade β€˜D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: li = list(map(int,input().strip().split())) avg=0 for i in li: avg+=i avg=avg/5 if(avg>=80): print("A") elif(avg>=60 and avg<80): print("B") elif(avg>=40 and avg<60): print("C") else: print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N. Constraints:- 1 <= N <= 1000Print the Nth strange number.Sample Input:- 3 Sample Output:- 18 Explanation:- 0, 9, and 18 are the first three strange numbers. Sample Input:- 2 Sample Output:- 9, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x=sc.nextInt(); int ans = 9 * (x-1); System.out.print(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N. Constraints:- 1 <= N <= 1000Print the Nth strange number.Sample Input:- 3 Sample Output:- 18 Explanation:- 0, 9, and 18 are the first three strange numbers. Sample Input:- 2 Sample Output:- 9, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 1000001 #define MOD 1000000000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int cnt[max1]; signed main(){ int n; cin>>n; out((n-1)*9); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N. Constraints:- 1 <= N <= 1000Print the Nth strange number.Sample Input:- 3 Sample Output:- 18 Explanation:- 0, 9, and 18 are the first three strange numbers. Sample Input:- 2 Sample Output:- 9, I have written this Solution Code: a=int(input()) print(9*(a-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once. You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string. Constraints 1 <= N <= 100000 String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1: 7 aeiddou Sample output 1: 7 Sample input 2: 7 daeioud Sample output 2: 5 Sample input 3: 7 daeiodd Sample output 3: -1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static int nextI(String str,int i) { char c=str.charAt(i); return 0; } public static boolean vowel(char c) { if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') return true; else return false; } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String str=br.readLine(); if(n<5) { System.out.print(-1); return; } int i=0; while(i<n && !vowel(str.charAt(i))) ++i; if(i==n) { System.out.print(-1); return; } int min,max; int len=n; boolean found=false; int index,l; while(i<n) { max=-1; min=n; if(str.charAt(i)!='a') { index=str.indexOf('a',i+1); if(index==-1) break; if(index>max) max=index; if(index<min) min=index; } if(str.charAt(i)!='e') { index=str.indexOf('e',i+1); if(index==-1) break; if(index>max) max=index; if(index<min) min=index; } if(str.charAt(i)!='i') { index=str.indexOf('i',i+1); if(index==-1) break; if(index>max) max=index; if(index<min) min=index; } if(str.charAt(i)!='o') { index=str.indexOf('o',i+1); if(index==-1) break; if(index>max) max=index; if(index<min) min=index; } if(str.charAt(i)!='u') { index=str.indexOf('u',i+1); if(index==-1) break; if(index>max) max=index; if(index<min) min=index; } l=max-i+1; found=true; if(l<len) len=l; index=str.indexOf(str.charAt(i),i+1); if(index==-1) break; if(index<min) min=index; i=min; } System.out.print((found)?len:-1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once. You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string. Constraints 1 <= N <= 100000 String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1: 7 aeiddou Sample output 1: 7 Sample input 2: 7 daeioud Sample output 2: 5 Sample input 3: 7 daeiodd Sample output 3: -1, I have written this Solution Code: t=input() t=int(t) x=input() x=x[::-1] start=0 a=0 e=0 i=0 o=0 u=0 l=[] n=len(x) j=0 value=100000 while(j<n): if(x[j]=='a'): a+=1 l.append(x[j]) elif x[j]=='e': e+=1 l.append(x[j]) elif x[j]=='i': i+=1 l.append(x[j]) elif x[j]=='o': o+=1 l.append(x[j]) elif x[j]=='u': u+=1 l.append(x[j]) while(a>=1 and e>=1 and i>=1 and o>=1 and u>=1): if(value>(j-start+1)): value=j-start+1 if(x[start]=='a'): a-=1 elif(x[start]=='e'): e-=1 elif(x[start]=='i'): i-=1 elif(x[start]=='o'): o-=1 elif(x[start]=='u'): u-=1 if(l): l.pop(0) start=start+1 j+=1 if(value==100000): print("-1") else: print (value), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Rohit loves vowels and he likes a string if it contains all the vowels atleast once. You are given a String S of length N integers. Find minimum length substring of S which contains all vowels atleast once (it may contain other characters too).The first line contains string length and the second line contains the string. Constraints 1 <= N <= 100000 String contains lowercase english alphabetsThe output should contain only one integer which is the length of minimum length substring containing all vowels. If no such substring exists print -1.Sample input 1: 7 aeiddou Sample output 1: 7 Sample input 2: 7 daeioud Sample output 2: 5 Sample input 3: 7 daeiodd Sample output 3: -1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int t; t=1; while(t--){ int n; cin>>n; string s; cin>>s; map<char,int> m; m['a']=0; m['e']=0; m['i']=0; m['o']=0; m['u']=0; int cnt=0, ans=INT_MAX,j=0; for(int i=0;i<n;i++){ if(m.find(s[i])!=m.end()){ if(m[s[i]]==0){cnt++;} m[s[i]]++; } if(cnt==5){ ans=min(ans,i-j+1); while(1){ if(m.find(s[j])!=m.end()){m[s[j]]--; if(m[s[j]]==0){j++; break;} } j++; ans=min(ans,i-j+1); } cnt--; } } if(ans==INT_MAX){cout<<-1;return 0;} cout<<ans<<endl;} } , In this Programming Language: C++, 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
For this Question: An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or any 2 columns with each other. What is the minimum number of moves to transform the board into a "chessboard" - a board where no 0s and no 1s are 4-directionally adjacent? If the task is impossible, return -1.The input line contains T, denoting the number of test cases. Each test case contains two lines. First-line contains N, size of the matrix. Second-line contains N*N elements of binary matrix. <b>Constraints:</b> 1 <= T <= 100 2 <= N <= 50 0 <= mat[i][j] <= 1For each testcase you need to print the minimum number of swaps required.Input: 2 4 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 3 0 1 0 1 0 1 1 1 0 Output: 2 -1 Explanation: One potential sequence of moves is shown below, from left to right: 0110 1010 1010 0110 --> 1010 --> 0101 1001 0101 1010 1001 0101 0101 The first move swaps the first and second columns. The second move swaps the second and third row., I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main(String args[])throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while(t-- > 0) { String str[] = read.readLine().trim().split(" "); int N = Integer.parseInt(str[0]); //int K = Integer.parseInt(str[1]); //`int D = Integer.parseInt(str[1]); int arr[][] = new int[N][N]; for(int i = 0; i < N; i++) { str = read.readLine().trim().split(" "); for(int j = 0; j < N; j++) arr[i][j] = Integer.parseInt(str[j]); } //int res[] = moveZeroes(arr); //print(res); System.out.println(movesToChessboard(arr)); } } static void print(int list[]) { for(int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } public static int movesToChessboard(int[][] board) { if (board == null || board.length == 0 || board[0].length == 0) { return -1; } int N = board.length; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if ((board[0][0] ^ board[i][0] ^ board[0][j] ^ board[i][j]) == 1) { return -1; } } } int rowSum = 0; int colSum = 0; int rowSwap = 0; int colSwap = 0; for (int i = 0; i < N; ++i) { rowSum += board[0][i]; colSum += board[i][0]; if (board[i][0] == i % 2) { ++rowSwap; } if (board[0][i] == i % 2) { ++colSwap; } } if (N / 2 > rowSum || N / 2 > (N - rowSum) || N / 2 > colSum || N / 2 > (N - colSum)) { return -1; } if (N % 2 == 0) { rowSwap = Math.min(rowSwap, N - rowSwap); colSwap = Math.min(colSwap, N - colSwap); } else { if (colSwap % 2 == 1) { colSwap = N - colSwap; } if (rowSwap % 2 == 1) { rowSwap = N - rowSwap; } } return (rowSwap + colSwap) / 2; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line[] = br.readLine().split(" "); int n= Integer.parseInt(line[0]); int m =Integer.parseInt(line[1]); int r = m-n; long answer = 1; long mod = 1000000007; for(int i=m;i>r;i--){ answer = (answer* i)%mod; } System.out.println(answer); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, I have written this Solution Code: n,m = map(int,input().split()) a = 1 for i in range(n): a *= m m-=1 if(a > 1000000007): a = a%1000000007 print(a%1000000007), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array Arr is considered Good if its size is more than 1 and the cost of turning the array into palindrome is <b>less than</b> floor((size of Arr)/2). Here, the cost of changing an element of the array into another element is 1. So, the cost of turning the array [1, 2, 3, 2] into [1, 2, 2, 1] is 2. For example: An array of size 5 is good if the cost of turning it into palindrome is strictly <b>less than 2</b>. Given N and M you have to find number of arrays of size N consisting of integers values from 1 to M such that none of its subarray is Good. As the answer can be huge find the answer modulo 1000000007.The first and the only line of input contains two integers N and M. Constraints: 1 <= N <= 100000 1 <= M <= 1000000000Print the answer modulo 1000000007.Sample Input 1 2 3 Sample Output 1 6 Explanation: the arrays are: [1, 2] [1, 3] [2, 1] [2, 3] [3, 1] [3, 2] Sample Input 2 3 5 Sample Output 2 60, 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> #define rep(i,n) for (int i=0; i<(n); i++) ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int mo=1000000007; int n,m; cin>>n>>m; int ans=1; for(int i=0;i<n;++i){ ans=(ans*(m-i))%mo; } 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: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column. Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N. The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty. Constraints: 1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1: 4 0101 1000 1111 0101 Sample output 1: 2 Explanations: Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: n = int(input()) arr = [] for i in range(n): string = str(input()) string = string[:4] arr.append(string) rows = 0 for i in range(n): count = 0 for j in range(n): if arr[i] == arr[j]: count += 1 rows = max(rows,count) print(rows), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column. Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N. The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty. Constraints: 1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1: 4 0101 1000 1111 0101 Sample output 1: 2 Explanations: Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: import java.util.Scanner; public class Main { static String [] ar = new String[105]; public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n = sc.nextInt(); for(int i=0;i<n;i++){ ar[i] = sc.next(); } int ans = 0; for(int i=0;i<n;i++){ int counter = 0; for(int j=0;j<n;j++){ if(ar[i].equals(ar[j]))counter++; } ans = Math.max(ans, counter); } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list of N nodes. The task is to reverse the list by changing links between nodes (i.e if the list is 1->2->3->4 then it becomes 1<-2<-3<-4) and return the head of the modified list.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b> ReverseLinkedList</b> that takes head node as parameter. Constraints: 1 <=N <= 1000 1 <= Node.data<= 100Return the head of the modified linked list.Input-1: 6 1 2 3 4 5 6 Output-1: 6 5 4 3 2 1 Explanation: After reversing the list, elements are as 6->5->4->3->2->1. Input-2: 5 1 2 8 4 5 Output-2: 5 4 8 2 1, I have written this Solution Code: public static Node ReverseLinkedList(Node head) { Node prev = null; Node current = head; Node next = null; while (current != null) { next = current.next; current.next = prev; prev = current; current = next; } head = prev; return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: def countMultiples(N): return int(100/N) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: static int countMultiples(int N) { int i = 1, count = 0; while(i < 101){ if(i % N == 0) count++; i++; } return count; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b> Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 100You need to return the count.Sample Input: 3 Sample Output: 33 Sample Input: 4 Sample Output: 25, I have written this Solution Code: int countMultiples(int n){ return (100/n); } , 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: 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 an array of integers, and an integer β€˜K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively. The second line of the input contains N space separated integers denoting the elements of the array. Constraints: 1 <= N <= 100000 1 <= K <= 100000 1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input: 4 6 1 5 7 1 Sample Output: 2, I have written this Solution Code: n,k=input().split() n=int(n) k=int(k) arr=input().split() for i in range(0,n): arr[i]=int(arr[i]) x=[0]*100000 for i in range(0,n): x[arr[i]]+=1 count=0 for i in range(0,n): count+=x[k-arr[i]] if((k-arr[i])==arr[i]): count-=1 print (int(count/2)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers, and an integer β€˜K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively. The second line of the input contains N space separated integers denoting the elements of the array. Constraints: 1 <= N <= 100000 1 <= K <= 100000 1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input: 4 6 1 5 7 1 Sample Output: 2, I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define max1 1000008 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' typedef long int li; typedef unsigned long int uli; typedef long long int ll; typedef unsigned long long int ull; void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ull cnt[max1]; int main(){ int n,k; cin>>n>>k; int a[n]; unordered_map<int,int> m; ll ans=0; for(int i=0;i<n;i++){ cin>>a[i]; if(m.find(k-a[i])!=m.end()){ans+=m[k-a[i]];} m[a[i]]++; } cout<<ans<<endl; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers, and an integer β€˜K’, find the count of pairs of elements in the array whose sum is equal to 'K'.The first line of the input contains 2 space separated integers N and K denoting the size of array and the sum respectively. The second line of the input contains N space separated integers denoting the elements of the array. Constraints: 1 <= N <= 100000 1 <= K <= 100000 1 <= A[i] <= 100000Print the count of pairs of elements in the array whose sum is equal to the K.Sample Input: 4 6 1 5 7 1 Sample Output: 2, I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc = new Scanner(System.in); int arrSize = sc.nextInt(); int targetK = sc.nextInt(); int arr[] = new int[arrSize]; for(int i = 0; i < arrSize; i++) arr[i] = sc.nextInt(); System.out.println(countPairs(arr, arrSize, targetK)); } static long countPairs(int arr[], int arrSize, int targetK) { long ans = 0; HashMap<Integer, Integer> hash = new HashMap<>(); for(int i = 0; i < arrSize; i++) { int elem = arr[i]; if(hash.containsKey(targetK-elem) == true) ans += hash.get(targetK-elem); if(hash.containsKey(elem) == true) { int freq = hash.get(elem); hash.put(elem, freq+1); } else hash.put(elem, 1); } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable