Instruction
stringlengths
261
35k
Response
stringclasses
1 value
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 A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, I have written this Solution Code: size = int(input()) arr = list(map(int,input().split())) tempArr = arr.copy() def nearLeast(pos): for i in range(pos-1,-1,-1): if(tempArr[i]<=tempArr[pos]): return tempArr[i] return -1 for i in range(size): if(i==0): arr[0] = -1 else: arr[i] = nearLeast(i) print(*arr), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; stack<int> s; for(int i = 1; i <= n; i++){ cin >> a[i]; while(!s.empty() && a[s.top()] > a[i]) s.pop(); if(s.empty()) cout << -1 << " "; else cout << a[s.top()] << " "; s.push(i); } 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, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, 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 arr[] = new int[arrSize]; for(int i = 0; i < arrSize; i++) arr[i] = sc.nextInt(); nearSmaller(arr, arrSize); } static void nearSmaller(int arr[], int arrSize) { Stack<Integer> s = new Stack<>(); for(int i = 0; i < arrSize; i++) { while(!s.empty() == true && arr[s.peek()] > arr[i]) s.pop(); if(s.empty() == true) System.out.print(-1 +" "); else System.out.print(arr[s.peek()]+" "); s.push(i); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, I have written this Solution Code: size = int(input()) arr = list(map(int,input().split())) tempArr = arr.copy() def nearLeast(pos): for i in range(pos-1,-1,-1): if(tempArr[i]<=tempArr[pos]): return tempArr[i] return -1 for i in range(size): if(i==0): arr[0] = -1 else: arr[i] = nearLeast(i) print(*arr), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int n; cin >> n; stack<int> s; for(int i = 1; i <= n; i++){ cin >> a[i]; while(!s.empty() && a[s.top()] > a[i]) s.pop(); if(s.empty()) cout << -1 << " "; else cout << a[s.top()] << " "; s.push(i); } 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, find the nearest smaller element S[i] for every element A[i] in the array such that the element has an index smaller than i. More formally, S[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] <= A[i] Elements for which no smaller element exist, consider next smaller element as -1.The first line contains the size of array, n The next line n elements of the integer array, A[i] <b>Constraints:</b> 1 <= n <= 10^5 1 <= A[i] <= 10^6Print the integer array S such that S[i] contains nearest smaller number than A[i] such than index of S[i] is less than 'i'. If no such element occurs S[i] should be -1.Input: 5 4 5 2 10 8 Output: -1 4 -1 2 2 Explanation 1: index 1: No element less than 4 in left of 4, G[1] = -1 index 2: A[1] is only element less than A[2], G[2] = A[1] index 3: No element less than 2 in left of 2, G[3] = -1 index 4: A[3] is nearest element which is less than A[4], G[4] = A[3] index 4: A[3] is nearest element which is less than A[5], G[5] = A[3] Input: 5 1 2 3 4 5 Output: -1 1 2 3 4, 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 arr[] = new int[arrSize]; for(int i = 0; i < arrSize; i++) arr[i] = sc.nextInt(); nearSmaller(arr, arrSize); } static void nearSmaller(int arr[], int arrSize) { Stack<Integer> s = new Stack<>(); for(int i = 0; i < arrSize; i++) { while(!s.empty() == true && arr[s.peek()] > arr[i]) s.pop(); if(s.empty() == true) System.out.print(-1 +" "); else System.out.print(arr[s.peek()]+" "); s.push(i); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: def compound_interest(principle, rate, time): Amount = principle * (pow((1 + rate / 100), time)) CI = Amount - principle print( '%.2f'%CI) principle,rate,time=map(int, input().split()) compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: function calculateCI(P, R, T) { let interest = P * (Math.pow(1.0 + R/100.0, T) - 1); return interest.toFixed(2); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int p,r,t; cin>>p>>r>>t; double rate= (float)r/100; double amt = (float)p*(pow(1+rate,t)); cout << fixed << setprecision(2) << (amt - p); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s= br.readLine().split(" "); double[] darr = new double[s.length]; for(int i=0;i<s.length;i++){ darr[i] = Double.parseDouble(s[i]); } double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0]; System.out.printf("%.2f",ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: static int LastDigit(int N){ return N%10; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: int LastDigit(int N){ return N%10; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the last digit of the given integer.Sample Input:- 123 Sample Output:- 3 Sample Input:- 6 Sample Output:- 6, I have written this Solution Code: def LastDigit(N): return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: n=int(input()) for i in range(1,n+1): if i%3==0 and i%5==0: print("NewtonSchool",end=" ") elif i%3==0: print("Newton",end=" ") elif i%5==0: print("School",end=" ") else: print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static void NewtonSchool(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");} else if(i%5==0){System.out.print("School ");} else if(i%3==0){System.out.print("Newton ");} else{System.out.print(i+" ");} } } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int x= sc.nextInt(); NewtonSchool(x); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<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>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.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: def partition(array, low, high): pivot = array[high] i = low - 1 for j in range(low, high): if array[j] <= pivot: i = i + 1 (array[i], array[j]) = (array[j], array[i]) (array[i + 1], array[high]) = (array[high], array[i + 1]) return i + 1 def quick_sort(array, low, high): if low < high: pi = partition(array, low, high) quick_sort(array, low, pi - 1) quick_sort(array, pi + 1, high) t=int(input()) for i in range(t): n=int(input()) a=input().strip().split() a=[int(i) for i in a] quick_sort(a, 0, n - 1) for i in a: print(i,end=" ") print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<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>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.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[] quickSort(int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ int pi = partition(arr, low, high); // Recursively sort elements before // partition and after partition quickSort(arr, low, pi-1); quickSort(arr, pi+1, high); } return arr; } public static int partition(int arr[], int low, int high) { int pivot = arr[high]; int i = (low-1); // index of smaller element for (int j=low; j<high; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // swap arr[i] and arr[j] int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) int temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<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>quickSort()</b> which contains following arguments. <b>A[]:</b> input array <b>start:</b> starting index of array <b>end</b>: ending index of array Constraints 1 <= T <= 1000 1 <= N <= 10^4 1 <= A[i] <= 10^5 <b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.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: function quickSort(arr, low, high) { if(low < high) { let pi = partition(arr, low, high); quickSort(arr, low, pi-1); quickSort(arr, pi+1, high); } return arr; } function partition(arr, low, high) { let pivot = arr[high]; let i = (low-1); // index of smaller element for (let j=low; j<high; j++) { // If current element is smaller than the pivot if (arr[j] < pivot) { i++; // swap arr[i] and arr[j] let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) let temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a singly linked list of size <b>N</b>, and an integer <b>K</b>. You need to <b>swap the Kth node from beginning and Kth node from end</b> in linked list. <b>Note:</b> You need to swap the nodes through the links and not changing the content of the nodes.First line of input contains the number of testcases T. The first line of every testacase contains N, number of nodes in linked list and K, the nodes to be swapped and the second line of contains the elements of the linked list. <b>User task:</b> The task is to complete the function swapkthnode(), which has arguments head, num(no of nodes) and K, and it should return new head. The validation is done internally by the driver code to ensure that the swapping is done by changing references/pointers only. A correct code would always cause output as 1. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^3 1 <= K <= 10^3For each testcase, if the nodes are swapped correctly, the output will be <b>1</b>, else <b>0</b>.Input: 3 4 1 1 2 3 4 5 3 1 2 3 4 5 4 4 1 2 3 4 Output: 1 1 1 Explanation: Testcase 1: Here K = 1, hence after swapping the 1st node from beginning and end the new list will be 4 2 3 1. Testcase 2: Here k = 3, hence after swapping the 3rd node from beginning and end the new list will be 1 2 3 4 5. Testcase 3: Here k = 4, hence after swapping the 4th node from beginning and end the new list will be 4 2 3 1., I have written this Solution Code: // Should swap Kth node from beginning and Kth // node from end in list and return new head. static Node swapkthnode(Node head, int num, int K) { if(K > num) return head; if(2*K-1 == num) return head; Node x_prev = null; Node x = head; Node y_prev = null; Node y = head; int count = K-1; while(count-- > 0){ x_prev = x; x = x.next; } count = num - K; while(count-- > 0){ y_prev = y; y = y.next; } if(x_prev != null) x_prev.next = y; if(y_prev != null) y_prev.next = x; Node temp = x.next; x.next = y.next; y.next = temp; if(K == 1) head = y; if(K == num) head = x; return head; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≀ i ≀ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≀ n ≀ 3000 0 ≀ m ≀ 10000 1 ≀ x, y ≀ n 1 ≀ w ≀ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: import sys from collections import defaultdict from heapq import heappush, heappop n, m = map(int, input().split()) d = defaultdict(list) dist = [sys.maxsize]*n dist[0] = 0 for _ in range(m): start, dest, wt = map(int, input().split()) d[start-1].append((dest-1, wt)) d[dest-1].append((start-1, wt)) heap = [(0, 0, 0)] while heap: count, cost, u= heappop(heap) for vertex, weight in d[u]: if dist[vertex] > cost + weight*(count+1): dist[vertex] = cost + weight*(count+1) heappush(heap, (count+1, dist[vertex], vertex)) for d in dist: if d == sys.maxsize: print(-1) else: print(d), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≀ i ≀ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≀ n ≀ 3000 0 ≀ m ≀ 10000 1 ≀ x, y ≀ n 1 ≀ w ≀ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long const int INF =1e18; vector<tuple<int, int, int>> adj; void solve() { int n, m; cin>>n>>m; // assert(1<=n && n<=3000); // assert(0<=m && m<=10000); adj.resize(n); for(int i = 0;i<m;i++) { int x, y, w; cin>>x>>y>>w; x--; y--; // assert(0<=x && x<n); // assert(0<=y && y<n); // assert(1<=w && w<=1e9); adj.push_back({x, y, w}); adj.push_back({y, x, w}); } vector<int> dp_old(n, INF); vector<int> dp_new(n, INF); dp_old[0] = 0; for(int i = 1;i<=n;i++) { fill(dp_new.begin(), dp_new.end(), INF); for(auto [x, y,w]:adj) { dp_new[y]= min({dp_new[y], dp_old[x] + i * w}); } for(int j = 0;j<n;j++) dp_new[j] = min(dp_new[j], dp_old[j]); swap(dp_new, dp_old); } for(int i = 0;i<n;i++) { if(dp_old[i] == INF) dp_old[i] = -1; cout<<dp_old[i]<<"\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL); #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); } #endif solve(); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≀ i ≀ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≀ n ≀ 3000 0 ≀ m ≀ 10000 1 ≀ x, y ≀ n 1 ≀ w ≀ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java. util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*; import static java.lang.System.*; public class Main { public void tq()throws Exception { st=new StringTokenizer(bq.readLine()); int tq=1; sb=new StringBuilder(2000000); o: while(tq-->0) { int n=i(); int m=i(); LinkedList<int[]> l[]=new LinkedList[n]; for(int x=0;x<n;x++)l[x]=new LinkedList<>(); for(int x=0;x<m;x++) { int a=i()-1; int b=i()-1; int c=i(); l[a].add(new int[]{b,c}); l[b].add(new int[]{a,c}); } long d[]=new long[n]; for(int x=0;x<n;x++)d[x]=maxl; d[0]=0l; PriorityQueue<long[]> p=new PriorityQueue<>(5000,(a,b)->a[2]-b[2]<1l?-1:1); p.add(new long[]{0l,0,0}); while(p.size()>0) { long r[]=p.poll(); long di=r[0]; int no=(int)r[1]; long mu=r[2]; for(int e[]:l[no]) { int node=e[0]; int w=e[1]; long de=di+w*(mu+1); if(d[node]>de) { d[node]=de; p.add(new long[]{de,node,mu+1}); } } } for(long x:d) { sl(x==maxl?-1:x); } } p(sb); } int di[][]={{-1,0},{1,0},{0,-1},{0,1}}; int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}}; long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long. MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st; StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[]) {Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length; x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++) r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;} char[] so(char ar[]) {Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++) ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb. append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl (String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb .append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s) ;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);} long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a) {return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b) {while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!= s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1] =true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n; y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1) r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException {if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();} double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double. parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p) {out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p) {out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out. println(p);}void pl(boolean p) {out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a) {sb.append(e);sb.append(' ');}sb.append("\n");} void s(long a[]) {for(long e:a){sb.append(e);sb.append(' ') ;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append ("\n");}} void s(char a[]) {for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][]) {for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0; x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer (bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl (int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine()) ;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;} String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard (int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer (bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard (int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());} return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][] arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine(); for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[]) {StringBuilder sb=new StringBuilder (2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][]) {StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa); sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder (2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);} void p(long ar[][]) {StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa); sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1; StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);} void p(double ar[]) {StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a); sb.append(' ');}out.println(sb);}void p (double ar[][]){StringBuilder sb=new StringBuilder(2* ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n") ;}p(sb);}void p(char ar[]) {StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa); sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0] .length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: def MakeTheNumber(N) : for i in range (1,10000): cnt=0 for x in range (1,i+1): if(i%x==0): cnt=cnt+1 if(cnt==N): return i return -1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: public static int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } return -1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer X, your task is to return the minimum number whose number of factors is equal to X.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MakeTheNumber()</b> that takes the integer X as parameter. <b>Constraints:</b> 1 <= X <= 15Return the minimum integer whose number of factors is equal to X.Sample Input:- 3 Sample Output:- 4 Sample Input:- 5 Sample Output:- 16, I have written this Solution Code: int MakeTheNumber(int n){ for(int x=1;x<=10000;x++){ int cnt=0; for(int i=1;i<=x;i++){ if(x%i==0){cnt++;} } if(cnt==n){ return x;} } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree of N nodes with root 1. Initially all nodes have value 0. You have two type of queries 1 u x - add x to all nodes in subtree of node u 2 u - print the value of node uFirst line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively. Next N lines contains two integers denoting the left and right child of the i'th node respectively. If the node doesn't have a left or right child, it is denoted by '-1' Next Q lines contains queries of two types: 1 u x 2 x 1 <= N, Q <= 5000 1 <= u <= N 1 <= x <= 5000For each query of type 2 print a single line containing the answerSample Input 1: 9 5 2 4 5 3 6 -1 -1 7 -1 -1 -1 -1 9 8 -1 -1 -1 -1 1 2 5 1 1 3 2 7 1 4 2 2 6 Sample output 1: 3 8 Explanation: Given binary tree 1 / \ 2 4 / \ \ 5 3 7 / / \ 6 9 8 Query 1: add all nodes in subtree of 2 with 5 Query 2: add all nodes in subtree of 1 with 3 Query 3: value of node 7 is 3 now Query 4: add all nodes in subtree of 4 with 2 Query 5: value of node 6 is 8 now, I have written this Solution Code: import java.io.*; import java.util.*; class Main { Node rootNode; static class Node{ int data; Node left,right; Node parent; Node(int d){ this.data=d; } } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); int n=Integer.parseInt(s[0]); int q=Integer.parseInt(s[1]); Node nodes[]=new Node[n+1]; for(int i=1;i<=n;i++){ nodes[i]=new Node(0); } for(int i=1;i<=n;i++){ String s1[]=br.readLine().split(" "); int x=Integer.parseInt(s1[0]); int y=Integer.parseInt(s1[1]); if(x!=-1){ nodes[i].left=nodes[x]; nodes[x].parent = nodes[i]; } if(y!=-1){ nodes[i].right=nodes[y]; nodes[y].parent = nodes[i]; } } for(int i=1;i<=q;i++){ String s2[]=br.readLine().split(" "); int type=Integer.parseInt(s2[0]); if(type==1){ int x=Integer.parseInt(s2[1]); int y=Integer.parseInt(s2[2]); nodes[x].data += y; }else{ int y=Integer.parseInt(s2[1]); int value = parentSum(nodes[y]); System.out.println(value); } } } static int parentSum(Node node) { if(node.parent == null) return node.data; return node.data + parentSum(node.parent); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree of N nodes with root 1. Initially all nodes have value 0. You have two type of queries 1 u x - add x to all nodes in subtree of node u 2 u - print the value of node uFirst line contains the integer N and Q, denoting the number of nodes in the binary tree and the number of queries respectively. Next N lines contains two integers denoting the left and right child of the i'th node respectively. If the node doesn't have a left or right child, it is denoted by '-1' Next Q lines contains queries of two types: 1 u x 2 x 1 <= N, Q <= 5000 1 <= u <= N 1 <= x <= 5000For each query of type 2 print a single line containing the answerSample Input 1: 9 5 2 4 5 3 6 -1 -1 7 -1 -1 -1 -1 9 8 -1 -1 -1 -1 1 2 5 1 1 3 2 7 1 4 2 2 6 Sample output 1: 3 8 Explanation: Given binary tree 1 / \ 2 4 / \ \ 5 3 7 / / \ 6 9 8 Query 1: add all nodes in subtree of 2 with 5 Query 2: add all nodes in subtree of 1 with 3 Query 3: value of node 7 is 3 now Query 4: add all nodes in subtree of 4 with 2 Query 5: value of node 6 is 8 now, I have written this Solution Code: #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int l[N], r[N], d[N]; void dfs(int u, int x){ if(u == -1) return; d[u] += x; dfs(l[u], x); dfs(r[u], x); } void solve(){ int n, q; cin >> n >> q; for(int i = 1; i <= n; i++) cin >> l[i] >> r[i]; while(q--){ int t, x, y; cin >> t; if(t == 1){ cin >> x >> y; dfs(x, y); } else{ cin >> x; cout << d[x] << endl; } } } signed main() { IOS; clock_t start = clock(); int Test = 1; // cin >> Test; for(int tt = 0; tt < Test; tt++){ solve(); } cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: function LeapYear(year){ // write code here // return the output using return keyword // do not use console.log here if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) { return 0; } else { return 1 } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: year = int(input()) if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N <b>Constraint:</b> 1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); int area = LeapYear(side); if(area==1){ System.out.println("YES");} else{ System.out.println("NO");} } static int LeapYear(int year){ if(year%400==0){return 1;} if(year%100 != 0 && year%4==0){return 1;} else { return 0;} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: static int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: def RotationPolicy(A, B): cnt=0 for i in range (A,B+1): if(i-1)%2!=0 and (i-1)%3!=0: cnt=cnt+1 return cnt , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: function RotationPolicy(a, b) { // write code here // do no console.log the answer // return the output using return keyword let count = 0 for (let i = a; i <= b; i++) { if((i-1)%2 !== 0 && (i-1)%3 !==0){ count++ } } return count } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: int NthNumber(int N){ return 24+(N-1)*13; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: int NthNumber(int N){ return 24+(N-1)*13; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: def NthNumber(N): return 24+(N-1)*13 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a series and a number N, your task is to print the Nth number of the given series. Series:- 24, 37, 50, 63, 76,. .. .<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>NthNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 10000Return the Nth number.Sample Input:- 1 Sample Output:- 24 Sample Input:- 3 Sample Output:- 50, I have written this Solution Code: static int NthNumber(int N){ return 24+(N-1)*13; } , 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 the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5". Numbers <=5 and their corresponding words : 1 = one 2 = two 3 = three 4 = four 5 = fiveThe input contains a single integer N. Constraint: 1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input: 4 Sample Output four Sample Input: 6 Sample Output: Greater than 5, I have written this Solution Code: N = int(input()) if N > 5: print("Greater than 5") elif(N == 1): print("one") elif(N == 2): print("two") elif(N == 3): print("three") elif(N == 4): print("four") elif(N == 5): print("five"), 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 the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5". Numbers <=5 and their corresponding words : 1 = one 2 = two 3 = three 4 = four 5 = fiveThe input contains a single integer N. Constraint: 1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input: 4 Sample Output four Sample Input: 6 Sample Output: Greater than 5, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int side = scanner.nextInt(); String area = conditional(side); System.out.println(area); }static String conditional(int n){ if(n==1){return "one";} else if(n==2){return "two";} else if(n==3){return "three";} else if(n==4){return "four";} else if(n==5){return "five";} else{ return "Greater than 5";} }}, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is playing a game in which she is fighting with N monsters who are standing in a line. Each monster has some HP with him. At every second, Sara hits the monster standing at the front of the line. When the monster gets hit his HP decreases by 1 and he goes to the end of the line(which happens instantaneously). For example: if the monster's health are (1, 3, 2) After 1st hit:- 3, 2 (monster at index 0 dies) After 2nd hit:- 2, 2 After 3rd hit:- 2, 1 After 4th hit:- 1, 1 After 5th hit:- 1(monster who was originally at index 2 dies) After 6th hit:- (monster who was originally at index 1 dies) Now Sara who keeps track of the time wants to know the time when the Kth(0 indexing) monster dies(A monster dies when his HP hits 0).The first line of input contains two space separated integers depicting N and K. The next line contains N space separated integers depicting the HP of every monster. <b>Constraints:-</b> 1 <= N <= 100 0 <= K < N 1 <= HP <= 100Print the time when the Kth monster dies.Sample Input:- 3 2 1 3 2 Sample Output:- 5 Sample Input:- 4 0 5 1 1 1 Sample Output:- 8, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner s = new Scanner(System.in); int N=s.nextInt(); int K=s.nextInt(); int[] arr=new int[N]; for (int i=0;i<=N-1;i++){ arr[i]=s.nextInt(); } int count=0; int i=0; while(arr[K]>0){ i=i%N; if(arr[i]>0){ arr[i]--; count++; } i++; } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is playing a game in which she is fighting with N monsters who are standing in a line. Each monster has some HP with him. At every second, Sara hits the monster standing at the front of the line. When the monster gets hit his HP decreases by 1 and he goes to the end of the line(which happens instantaneously). For example: if the monster's health are (1, 3, 2) After 1st hit:- 3, 2 (monster at index 0 dies) After 2nd hit:- 2, 2 After 3rd hit:- 2, 1 After 4th hit:- 1, 1 After 5th hit:- 1(monster who was originally at index 2 dies) After 6th hit:- (monster who was originally at index 1 dies) Now Sara who keeps track of the time wants to know the time when the Kth(0 indexing) monster dies(A monster dies when his HP hits 0).The first line of input contains two space separated integers depicting N and K. The next line contains N space separated integers depicting the HP of every monster. <b>Constraints:-</b> 1 <= N <= 100 0 <= K < N 1 <= HP <= 100Print the time when the Kth monster dies.Sample Input:- 3 2 1 3 2 Sample Output:- 5 Sample Input:- 4 0 5 1 1 1 Sample Output:- 8, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long int solve(vector<int> a, int k){ int answer=a[k]*a.size(); for(int i=0;i<a.size();i++){ if(i<=k){ answer+=min((int)0,a[i]-a[k]); } else{ answer+=min((int)-1,a[i]-a[k]); } } return answer; } signed main(){ int n,k; cin>> n>>k; vector<int> a(n); for(int i=0;i<n;i++){ cin>>a[i]; } cout<<solve(a,k); } , 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: Given an array A of size N and an integer K, find and print the number of pairs of indices i, j (1 <= i < j <= N) such that A<sub>i</sub> * A<sub>j</sub> > K.First line of the input contains two integers N and K. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= K <= 10<sup>12</sup> 1 <= A<sub>i</sub> <= 10<sup>6</sup>Print the number of pairs of indices i, j (1 <= i < j <= N) such that A<sub>i</sub> * A<sub>j</sub> > K.Sample Input: 7 20 5 7 2 3 2 9 1 Sample Output: 5 Explanation: The following pairs of indices satisfy the condition (1-based indexing) (1, 2) -> 5 * 7 = 35 (1, 6) -> 5 * 9 = 45 (2, 4) -> 7 * 3 = 21 (2, 6) -> 7 * 9 = 63 (4, 6) -> 3 * 9 = 27 All these products are greater than K (= 20)., 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, k; cin >> n >> k; vector<int> a(n); for(auto &i : a) cin >> i; sort(all(a)); int ans = 0; for(int i = 0; i < n; i++){ int x = k/a[i]; if(x * a[i] < k) x++; int l = i + 1, r = n - 1, ind = n; while(l <= r){ int m = (l + r)/2; if(a[m] >= x){ r = m - 1; ind = m; } else l = m + 1; } ans += n - ind; } cout << ans; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N and an integer K, find and print the number of pairs of indices i, j (1 <= i < j <= N) such that A<sub>i</sub> * A<sub>j</sub> > K.First line of the input contains two integers N and K. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= K <= 10<sup>12</sup> 1 <= A<sub>i</sub> <= 10<sup>6</sup>Print the number of pairs of indices i, j (1 <= i < j <= N) such that A<sub>i</sub> * A<sub>j</sub> > K.Sample Input: 7 20 5 7 2 3 2 9 1 Sample Output: 5 Explanation: The following pairs of indices satisfy the condition (1-based indexing) (1, 2) -> 5 * 7 = 35 (1, 6) -> 5 * 9 = 45 (2, 4) -> 7 * 3 = 21 (2, 6) -> 7 * 9 = 63 (4, 6) -> 3 * 9 = 27 All these products are greater than K (= 20)., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long K = sc.nextLong(); long[] arr = new long[N]; for(int i=0; i<N; i++){ arr[i] = sc.nextLong(); } Arrays.sort(arr); int low = 0; int high = N-1; long count = 0; while(low<high){ long num = arr[low]*arr[high]; if(num>K){ count += high-low; high--; } else { low++; } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r. Constraints:- 1 <= N <= 100 1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:- 4 10 4 Sample Output:- Yes Sample Input:- 5 10 4 Sample Output:- No, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String a[] = br.readLine().split(" "); double n = Integer.parseInt(a[0]); double R = Integer.parseInt(a[1]); double r = Integer.parseInt(a[2]); R=R-r; double count = 0; double d = Math.asin(r/R); count = Math.PI/d; if(n<=count) 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: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r. Constraints:- 1 <= N <= 100 1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:- 4 10 4 Sample Output:- Yes Sample Input:- 5 10 4 Sample Output:- No, I have written this Solution Code: import math arr = list(map(int, input().split())) n = arr[0] R = arr[1] r = arr[2] if(r>R or n>1 and (R-r)*math.sin(math.acos(-1.0)/n)+1e-8<r): print("No") else: print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r. Constraints:- 1 <= N <= 100 1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:- 4 10 4 Sample Output:- Yes Sample Input:- 5 10 4 Sample Output:- No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int R,r,n; cin>>n>>R>>r; cout<<(r>R || n>1&& (R-r)*sin(acos(-1.0)/n)+1e-8<r ?"No":"Yes"); return 0; } //1340 , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main (String[] args)throws IOException { Reader sc = new Reader(); int N = sc.nextInt(); int[] arr = new int[N]; for(int i=0;i<N;i++){ arr[i] = sc.nextInt(); } int max=0; if(arr[0]<arr[N-1]) System.out.print(N-1); else{ for(int i=0;i<N-1;i++){ int j = N-1; while(j>i){ if(arr[i]<arr[j]){ if(max<j-i){ max = j-i; } break; } j--; } if(i==j) break; if(j==N-1) break; } if(max==0) System.out.print("-1"); else System.out.print(max); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long /* For a given array arr[], returns the maximum j – i such that arr[j] > arr[i] */ int maxIndexDiff(int arr[], int n) { int maxDiff; int i, j; int *LMin = new int[(sizeof(int) * n)]; int *RMax = new int[(sizeof(int) * n)]; /* Construct LMin[] such that LMin[i] stores the minimum value from (arr[0], arr[1], ... arr[i]) */ LMin[0] = arr[0]; for (i = 1; i < n; ++i) LMin[i] = min(arr[i], LMin[i - 1]); /* Construct RMax[] such that RMax[j] stores the maximum value from (arr[j], arr[j+1], ..arr[n-1]) */ RMax[n - 1] = arr[n - 1]; for (j = n - 2; j >= 0; --j) RMax[j] = max(arr[j], RMax[j + 1]); /* Traverse both arrays from left to right to find optimum j - i. This process is similar to merge() of MergeSort */ i = 0, j = 0, maxDiff = -1; while (j < n && i < n) { if (LMin[i] < RMax[j]) { maxDiff = max(maxDiff, j - i); j = j + 1; } else i = i + 1; } return maxDiff; } // Driver Code signed main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int maxDiff = maxIndexDiff(a, n); cout << maxDiff; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array. <b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array. <b>Constraints:-</b> 1 < = N < = 10<sup>5</sup> 1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:- 5 1 2 3 4 5 Sample Output 1:- 4 Sample Input 2:- 5 5 4 3 2 1 Sample Output 2:- -1 <b>Explanation 1:</b> The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0] , I have written this Solution Code: n=int(input()) arr=list(map(int,input().split())) rightMax = [0] * n rightMax[n - 1] = arr[n - 1] for i in range(n - 2, -1, -1): rightMax[i] = max(rightMax[i + 1], arr[i]) maxDist = -2**31 i = 0 j = 0 while (i < n and j < n): if (rightMax[j] >= arr[i]): maxDist = max(maxDist, j - i) j += 1 else: i += 1 if maxDist==0: maxDist=-1 print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: n = int(input()) if (n%4==0 and n%100!=0 or n%400==0): print("YES") elif n==0: print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int n = scanner.nextInt(); LeapYear(n); } static void LeapYear(int year){ if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");} else { System.out.println("NO");} } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args){ FastReader read = new FastReader(); int a = read.nextInt(); int b = read.nextInt(); System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(a/b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ InputStreamReader inr = new InputStreamReader(System.in); br = new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()) try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:- a+b a-b a*b a/bThe input contains two integers a and b separated by spaces. <b>Constraints:</b> 1 &le; b &le; a &le; 1000 <b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input: 15 3 Sample Output: 18 12 45 5 <b>Explanation:-</b> First operation is a+b so 15+3 = 18 The second Operation is a-b so 15-3 = 12 Third Operation is a*b so 15*3 = 45 Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split()) print(a+b) print(a-b) print(a*b) print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2. Constraints 1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1 2 1 Sample Output 1 Aniket Sample Input 2 4 8 Sample Output 2 Swapnil, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] str = br.readLine().trim().split(" "); long n1 = Long.parseLong(str[0]); long n2 = Long.parseLong(str[1]); long diff = Math.abs(n1-n2); long c =0; while(diff>1){ if(diff%2!=0) diff--; diff/=2; if(n1>n2){ n1 -= 2*diff; n2 += diff; } else{ n2 -= 2*diff; n1 += diff; } c += diff; diff = Math.abs(n1-n2); } if(c%2==0){ System.out.print("Aniket"); }else{ System.out.print("Swapnil"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2. Constraints 1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1 2 1 Sample Output 1 Aniket Sample Input 2 4 8 Sample Output 2 Swapnil, I have written this Solution Code: n1,n2 = map(int,input().split()) print('Aniket' if abs(n1-n2)==1 or n1==n2 else 'Swapnil'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2. Constraints 1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1 2 1 Sample Output 1 Aniket Sample Input 2 4 8 Sample Output 2 Swapnil, 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 inf 1e8+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(); ////////////// #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 x,y; cin>>x>>y; if(abs(x-y)<=1) { cout<<"Aniket"; } else cout<<"Swapnil"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N and a matrix of size (N x N). Check whether given matrix is identity or not. <b> Note </b> An identity matrix is a square matrix in which all the elements of principal diagonal are one, and all other elements are zeros.First line contain a single integer N Next N line contain N space- separated integer i. e. elements of matrix.If the given matrix is the identity matrix. print "Yes" otherwise print "NO" Constraints: 1<=N<=100Sample Input 1: 3 1 0 0 0 1 0 0 0 1 Sample Output 1: Yes Explanation: Given matrix is an identity matrix because all main diagonal elements are 1 and rest of elements are 0., I have written this Solution Code: import java.util.*; import java.io.*; public class Main { public static void main(String args[] ) throws Exception { Scanner s = new Scanner(System.in); int N = s.nextInt(); int [][]arr=new int[N][N]; for(int i=0;i<N;i++){ for(int j=0;j<N;j++) arr[i][j] = s.nextInt(); } boolean flag=false; for(int i=0;i<N;i++){ for(int j=0;j<N;j++) { if(i==j && arr[i][j]!=1)flag=true; else if(i!=j && arr[i][j]!=0)flag=true; } } if(flag==true){ System.out.println("No"); } else { System.out.println("Yes"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: #include <bits/stdc++.h> // #define ll long long using namespace std; #define ma 10000001 bool a[ma]; int main() { int n; cin>>n; for(int i=0;i<=n;i++){ a[i]=false; } for(int i=2;i<=n;i++){ if(a[i]==false){ for(int j=i+i;j<=n;j+=i){ a[j]=true; } } } int cnt=0; for(int i=2;i<=n;i++){ if(a[i]==false){cnt++;} } cout<<cnt; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, 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 br = new BufferedReader(new InputStreamReader(System.in)); long n = Integer.parseInt(br.readLine()); long i=2,j,count,noOfPrime=0; if(n<=1) System.out.println("0"); else{ while(i<=n) { count=0; for(j=2; j<=Math.sqrt(i); j++) { if( i%j == 0 ){ count++; break; } } if(count==0){ noOfPrime++; } i++; } System.out.println(noOfPrime); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: function numberOfPrimes(N) { let arr = new Array(N+1); for(let i = 0; i <= N; i++) arr[i] = 0; for(let i=2; i<= N/2; i++) { if(arr[i] === -1) { continue; } let p = i; for(let j=2; p*j<= N; j++) { arr[p*j] = -1; } } //console.log(arr); let count = 0; for(let i=2; i<= N; i++) { if(arr[i] === 0) { count++; } } //console.log(arr); return count; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: import math n = int(input()) n=n+1 if n<3: print(0) else: primes=[1]*(n//2) for i in range(3,int(math.sqrt(n))+1,2): if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1) print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter. Constraints: 1 <= P <= 10^3 1 <= Tm <= 20 1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input: 42 15 8 Output: 50 Explanation: Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: import math p,t,r = [int(x) for x in input().split()] res=p*t*r print(math.floor(res/100)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter. Constraints: 1 <= P <= 10^3 1 <= Tm <= 20 1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input: 42 15 8 Output: 50 Explanation: Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: static int SimpleInterest(int P, int R, int Tm){ return (P*Tm*R)/100; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given Q queries. In each query, determine whether there exists an array A of size N such that: 1. All the elements are positive integers. 2. The number of subarrays such that their XOR-sum is 0 is exactly K. In other words, there are exactly K pairs of integers (l, r) such that 1 &le; l &le; r &le; N and A<sub>l</sub> &oplus; A<sub>l+1</sub> &oplus; ... A<sub>r</sub> = 0. If there exists such an array, print "YES", otherwise print "NO".The first line of the input contains a single integer Q β€” the number of queries (1 &le; Q &le; 10<sup>5</sup>). Q lines follow, each line containing two space separated integers N (1 &le; N &le; 1000) and K (0 &le; K &le; N(N+1)/2).For each test case, print "YES", if there exists such an array, otherwise print "NO" (without the quotes). Note that the output is case sensitive.Sample Input 3 2 2 3 2 2 1 Sample Output NO YES YES, I have written this Solution Code: import java.io.*; import java.util.*; class Main { FastScanner in; PrintWriter out; boolean systemIO = true; int MAXSUM = 250000; int[] dp = new int[MAXSUM]; int[] minn = new int[MAXSUM]; public void precalc() { for (int i = 1; i < minn.length; i++) { minn[i] = 1002; dp[i] = 1002; } for (int step = 2; step <= 501; step++) { int delta = step * (step - 1) / 2; for (int j = 0; j + delta < MAXSUM; j++) { if (dp[j] + step < dp[j + delta]) { dp[j + delta] = dp[j] + step; minn[j + delta] = Math.min(minn[j + delta], Math.max(dp[j + delta] - 1, 2 * step - 2)); } } } } public boolean clever(int n, int k) { if (k >= MAXSUM) { return false; } return n >= minn[k]; } public void solve() { precalc(); for (int qwerty = in.nextInt(); qwerty > 0; --qwerty) { int n = in.nextInt(); int k = in.nextInt(); if (clever(n, k)) { out.println("YES"); } else { out.println("NO"); } } } public void run() { try { if (systemIO) { in = new FastScanner(System.in); out = new PrintWriter(System.out); } else { String fileName = "60-huge-inexact"; in = new FastScanner(new File(fileName + ".txt")); out = new PrintWriter(new File(fileName + ".out")); } solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String nextLine() { try { return br.readLine(); } catch (IOException e) { return null; } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] arg) { long time = System.currentTimeMillis(); new Main().run(); System.err.println(System.currentTimeMillis() - time); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given Q queries. In each query, determine whether there exists an array A of size N such that: 1. All the elements are positive integers. 2. The number of subarrays such that their XOR-sum is 0 is exactly K. In other words, there are exactly K pairs of integers (l, r) such that 1 &le; l &le; r &le; N and A<sub>l</sub> &oplus; A<sub>l+1</sub> &oplus; ... A<sub>r</sub> = 0. If there exists such an array, print "YES", otherwise print "NO".The first line of the input contains a single integer Q β€” the number of queries (1 &le; Q &le; 10<sup>5</sup>). Q lines follow, each line containing two space separated integers N (1 &le; N &le; 1000) and K (0 &le; K &le; N(N+1)/2).For each test case, print "YES", if there exists such an array, otherwise print "NO" (without the quotes). Note that the output is case sensitive.Sample Input 3 2 2 3 2 2 1 Sample Output NO YES YES, I have written this Solution Code: #include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e9; const ll mod = 1e9 + 7; //const ll mod = 998244353; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } struct info {int n, k, idx;}; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); read(t); vector<vector <info>> q(1001); FOR (i, 1, t) { readb(n, k); q[n/2 + 1].pb({n, k, i}); } vi dp(1001*500 + 5, inf); dp[0] = 0; bool ans[t + 1] = {}; FOR (i, 1, 502) { FOR (j, i*(i - 1)/2, 1001*500) dp[j] = min(dp[j], dp[j - i*(i - 1)/2] + i); for (auto x: q[i]) if (dp[x.k] <= x.n + 1) ans[x.idx] = 1; } FOR (i, 1, t) if (ans[i]) cout << "YES" << endl; else cout << "NO" << 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 of integers. Consider absolute difference between all the pairs of the the elements. You need to find Kth smallest absolute difference. If the size of the array is N then value of K will be less than N and more than or equal to 1.The first line of input contains number of test cases T. The first line of each test case contains a two integers N and K denoting the number of elements in the array A and difference you need to output. The second line of each test case contains N space separated integers denoting the elements of the array A Constraints: 1<= T <= 10 2 <= N <= 100000 1 <= K < N < 100000 0 <= A[i] <= 100000For each test case, output Kth smallest absolute difference.Input : 1 6 2 1 3 4 1 3 8 Output : 0 Explanation : Test case 1: First smallest difference is 0, between the pair (1, 1) and second smallest absolute difference difference is also 0 between the pairs (3, 3)., 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().trim()); while (t-- > 0) { String str[] = read.readLine().trim().split(" "); int n = Integer.parseInt(str[0]); int k = Integer.parseInt(str[1]); int arr[] = new int[n]; str = read.readLine().trim().split(" "); for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]); System.out.println(Math.abs(small(arr, k))); } } public static int small(int arr[], int k) { Arrays.sort(arr); int l = 0, r = arr[arr.length - 1] - arr[0]; while (r > l) { int mid = l + (r - l) / 2; if (count(arr, mid) < k) { l = mid + 1; } else { r = mid; } } return r; } public static int count(int arr[], int mid) { int ans = 0, j = 0; for (int i = 1; i < arr.length; ++i) { while (j < i && arr[i] - arr[j] > mid) { ++j; } ans += i - j; } return ans; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: def lenOfLongSubarr(arr, N, K): mydict = dict() sum = 0 maxLen = 0 for i in range(N): sum += arr[i] if (sum == K): maxLen = i + 1 elif (sum - K) in mydict: maxLen = max(maxLen, i - mydict[sum - K]) if sum not in mydict: mydict[sum] = i return maxLen if __name__ == '__main__': T = int(input()) #N,K=list(map(int,input().split())) for i in range(T): N,k= [int(N)for N in input("").split()] arr=list(map(int,input().split())) N = len(arr) print(lenOfLongSubarr(arr, N, k)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ unordered_map<long long,int> um; int n,k; cin>>n>>k; long arr[n]; int maxLen=0; for(int i=0;i<n;i++){cin>>arr[i];} long long sum=0; for(int i=0;i<n;i++){ sum += arr[i]; // when subarray starts from index '0' if (sum == k) maxLen = i + 1; // make an entry for 'sum' if it is // not present in 'um' if (um.find(sum) == um.end()) um[sum] = i; // check if 'sum-k' is present in 'um' // or not if (um.find(sum - k) != um.end()) { // update maxLength if (maxLen < (i - um[sum - k])) maxLen = i - um[sum - k]; } } cout<<maxLen<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array containing N integers and an integer K. Your task is to find the length of the longest Sub-Array with sum of the elements equal to the given value K.The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains two integers N and K and the second line contains N space-separated elements of the array. Constraints:- 1<=T<=500 1<=N,K<=10^5 -10^5<=A[i]<=10^5 Sum of N over all test cases does not exceed 10^5For each test case, print the required length of the longest Sub-Array in a new line. If no such sub-array can be formed print 0.Sample Input: 3 6 15 10 5 2 7 1 9 6 -5 -5 8 -14 2 4 12 3 6 -1 2 3 Sample Output: 4 5 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ if(t%10==0){ System.gc(); } int arrsize=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[arrsize]; for(int i=0;i<arrsize;i++){ arr[i]=sc.nextInt(); } int subsize=0; int sum=0; HashMap<Integer, Integer> hash=new HashMap<>(); for(int i=0;i<arrsize;i++){ sum+=arr[i]; if(sum==k){ subsize=i+1; } if(!hash.containsKey(sum)){ hash.put(sum,i); } if(hash.containsKey(sum-k)){ if(subsize<(i-hash.get(sum-k))){ subsize=i-hash.get(sum-k); } } } System.out.println(subsize); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given 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 an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value. <b>Note:</b> Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k. The next line contains n integers denoting elements of the array. <b>Constraints:</b> 1 < = k < = n < = 1000 -10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1: 4 4 1 2 3 4 Sample Output 1: 30 Sample Input 2: 2 1 1 10 Sample Output 2: 100 <b>Explanation:</b> Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int m = 100001; int main(){ int n,k; cin>>n>>k; long long a[n],sum=0; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]<0){ a[i]=-a[i]; } } sort(a,a+n); for(int i=0;i<k;i++){ sum+=a[n-i-1]*a[n-i-1]; } cout<<sum; } , 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value. <b>Note:</b> Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k. The next line contains n integers denoting elements of the array. <b>Constraints:</b> 1 < = k < = n < = 1000 -10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1: 4 4 1 2 3 4 Sample Output 1: 30 Sample Input 2: 2 1 1 10 Sample Output 2: 100 <b>Explanation:</b> Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); String[] NK = br.readLine().split(" "); String[] inputs = br.readLine().split(" "); int N = Integer.parseInt(NK[0]); int K = Integer.parseInt(NK[1]); long[] arr = new long[N]; long answer = 0; for(int i = 0; i < N; i++){ arr[i] = Math.abs(Long.parseLong(inputs[i])); } quicksort(arr, 0, N-1); for(int i = (N-K); i < N;i++){ answer += (arr[i]*arr[i]); } System.out.println(answer); } static void quicksort(long[] arr, int start, int end){ if(start < end){ int pivot = partition(arr, start, end); quicksort(arr, start, pivot-1); quicksort(arr, pivot+1, end); } } static int partition(long[] arr, int start, int end){ long pivot = arr[end]; int i = start - 1; for(int j = start; j < end; j++){ if(arr[j] < pivot){ i++; swap(arr, i, j); } } swap(arr, i+1, end); return (i+1); } static void swap(long[] arr, int i, int j){ long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } }, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value. <b>Note:</b> Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k. The next line contains n integers denoting elements of the array. <b>Constraints:</b> 1 < = k < = n < = 1000 -10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1: 4 4 1 2 3 4 Sample Output 1: 30 Sample Input 2: 2 1 1 10 Sample Output 2: 100 <b>Explanation:</b> Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: x,y = map(int,input().split()) arr = list(map(int,input().split())) s=0 for i in range(x): if arr[i]<0: arr[i]=abs(arr[i]) arr=sorted(arr,reverse=True) for i in range(0,y): s = s+arr[i]*arr[i] print(s) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s=br.readLine().toString(); int n=Integer.parseInt(s); int ch=0; if(n>0){ ch=1; } else if(n<0) ch=-1; switch(ch){ case 1: System.out.println("Positive");break; case 0: System.out.println("Zero");break; case -1: System.out.println("Negative");break; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: n = input() if '-' in list(n): print('Negative') elif int(n) == 0 : print('Zero') else: print('Positive'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to check whether a number is positive, negative or zero using switch case.The first line of the input contains the number <b>Constraints</b> -10<sup>9</sup> &le; n &le; 10<sup>9</sup>Print the single line wether it's "Positive", "Negative" or "Zero"Sample Input : 13 Sample Output : Positive Sample Input : -13 Sample Output : Negative, I have written this Solution Code: #include <stdio.h> int main() { int num; scanf("%d", &num); switch (num > 0) { // Num is positive case 1: printf("Positive"); break; // Num is either negative or zero case 0: switch (num < 0) { case 1: printf("Negative"); break; case 0: printf("Zero"); break; } break; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char str[] = br.readLine().toCharArray(); int ans = 0; char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; Set<String> set = new HashSet<>(); for(int i=0;i<str.length;i++){ char p = str[i]; for(char ch:arr){ if(ch==p) continue; str[i] = ch; if(isPallindrome(str)){ if(set.contains(String.valueOf(str))==false){ set.add(String.valueOf(str)); ans++; } } str[i] = p; } } System.out.println(ans); } static boolean isPallindrome(char[] str){ int i = 0; int j = str.length-1; while(i<j){ if(str[i]!=str[j]) return false; i++; j--; } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: n=input() n=list(n) ln=len(n) cnt=0 for i in range(ln//2): if not(n[i]==n[ln-i-1]): cnt+=1 if(cnt==1): print(2) elif(cnt==0 and ln%2==1): print(25) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n' #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define sz(x) ((ll)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x = min(x,y) #define maxi(x,y) x = max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(0, 1e9); // DEBUG FUNCTIONS START void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void deb() {cerr << "\n";} template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);} // DEBUG FUNCTIONS END const int N = 2e5 + 5; void solve(){ string s; cin >> s; int n = sz(s); int x = 0; rep(i, 0, n / 2){ x += s[i] != s[n - 1 - i]; } if(x == 1){ cout << 2 << endl; } else if(x > 1){ cout << 0 << endl; } else{ if(n & 1){ cout << 25 << endl; } else{ cout << 0 << endl; } } } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given 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 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: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L β€” the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.System.out; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader reader = new FastReader(); int n = reader.nextInt(); String S = reader.next(); int ncount = 0; int tcount = 0; for (char c : S.toCharArray()) { if (c == 'N') ncount++; else tcount++; } if (ncount > tcount) { out.print("Nutan\n"); } else { out.print("Tusla\n"); } out.flush(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L β€” the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input()) s = input() a1 = s.count('N') a2 = s.count('T') if(a1 > a2): print("Nutan") else: print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L β€” the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium //Time and Date: 02:18:28 24 March 2022 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll b, ll e) { ll r = 1ll; for(; e > 0; e /= 2, (b *= b) %= MOD) if(e % 2) (r *= b) %= MOD; return r; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //-----------------------------------------------------------------------------------------------------------// READV(N); string S; cin>>S; ll n=0,t=0; FORI(i,0,N) { if(S[i]=='N') { n++; } else if(S[i]=='T') { t++; } } if(n>t) { cout<<"Nutan"<<endl; } else { cout<<"Tusla"<<endl; } //-----------------------------------------------------------------------------------------------------------// return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array. Next line denotes N space-separated array elements. Constraints: 2 <= N <= 100000 0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input 4 0 2 5 7 Sample Output 2 Explanation: 0 xor 2 = 2 Sample Input 4 0 4 7 9 Sample Output 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { int ans = 0; int mini = Integer.MAX_VALUE; Scanner sc = new Scanner(System.in); int array_size = sc.nextInt(); int N[] = new int[array_size]; for (int i = 0; i < array_size; i++) { if(mini == 0){ break; } N[i] = sc.nextInt(); for (int j = i - 1; j >= 0; j--) { ans = N[i] ^ N[j]; if (mini > ans) { mini = ans; } } } System.out.println(mini); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable