Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main {
public static boolean isArrangementPossible(long arr[],int n,long sum){
if(n==1){
if(arr[0]==sum)
return true;
else
return false;
}
return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1]));
}
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String str1[]=br.readLine().trim().split(" ");
int n=Integer.parseInt(str1[0]);
long sum=Long.parseLong(str1[1]);
String str[]=br.readLine().trim().split(" ");
long arr[]=new long[n];
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
}
if(isArrangementPossible(arr,n,sum)){
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: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum):
if i == len(nums):
if currSum == targetSum:
return 1
return 0
if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)):
return 1
return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum)
n,k = map(int,input().split())
nums = list(map(int,input().split()))
if(checkIfGivenTargetIsPossible(nums,0,0,k)):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence.
Constraints:-
1 <= N <= 20
-10^15 <= K <= 10^15
0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:-
4 4
1 2 3 4
Sample Output:-
YES
Sample Input:-
4 1
1 2 3 4
Sample Output:-
NO, I have written this Solution Code: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define int long long
int k;
using namespace std;
int solve(int n, int a[], int i, int curr ){
if(i==n){
if(curr==k){return 1;}
return 0;
}
if(solve(n,a,i+1,curr+a[i])==1){return 1;}
return solve(n,a,i+1,curr-a[i]);
}
signed main() {
int n;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
if(solve(n,a,1,a[0])){
cout<<"YES";}
else{
cout<<"NO";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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 ≤ marks ≤ 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 ≤ marks ≤ 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: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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: 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: Alice is driving from her home to her office which is A kilometers away and will take her X hours to reach. Bob is driving from his home to his office which is B kilometers away and will take him Y hours to reach. Determine who is driving faster, else, if they are both driving at the same speed print EQUAL.The first line will contain T, the number of test cases. Then the test cases follow. Each test case consists of a single line of input, containing four integers A, X, B, and Y, the distances and and the times taken by Alice and Bob respectively.
<b>Constraints</b>
1 ≤ T ≤ 1000
1 ≤ A, X, B, Y ≤ 1000For each test case, if Alice is faster, print ALICE. Else if Bob is faster, print BOB. If both are equal, print EQUAL.Sample Input :
3
20 6 20 5
10 3 20 6
9 1 1 1
Sample Output :
Bob
Equal
Alice
Explanation :
<ul><li>Since Bob travels the distance between his office and house in 5 hours, whereas Alice travels the same distance of 20 kms in 6 hours, BOB is faster. </li><li>Since Alice travels the distance of 10 km between her office and house in 3 hours and Bob travels a distance of 20 km in 6 hours, they have equal speeds. </li><li> Since Alice travels the distance of 9 km between her office and house in 1 hour and Bob travels only a distance of 1 km in the same time, ALICE is faster. </li></ul>, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
vector<int> solve(int n) {
vector<int> sol;
for (int i = 1; i <= n; i++) {
sol.push_back(i);
}
// debug(sol);
return sol;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
auto start = std::chrono::high_resolution_clock::now();
int tt = 1;
cin >> tt;
while (tt--) {
float A, X, B, Y;
cin >> A >> X >> B >> Y;
float v1 = A / X;
float v2 = B / Y;
if (v1 > v2) {
cout << "ALICE\n";
} else if (v1 < v2) {
cout << "BOB\n";
} else {
cout << "EQUAL\n";
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, we define the set A<sub>N</sub> as {1, 2, 3, ... N-1, N}.
Find the size of the largest subset of A<sub>N</sub>, such that if x belongs to the subset, then 2x does not belong to the subset.The first line of the input contains a single integer T — the number of test cases.
Each test case consists of one line containing a single integer N.
<b>Constraints:</b>
1 ≤ T ≤ 10<sup>5</sup>
1 ≤ N ≤ 10<sup>9</sup>For each test case, print one integer — the size of the largest subset of A<sub>N</sub> satisfying the condition in the problem statement.Sample Input:
4
1
2
3
4
Sample Output:
1
1
2
3
Explanation:
For test case 4, where N = 4, the subset {1, 3, 4} is the largest subset satisfying the conditions.
1 is in the subset whereas 2 is not.
3 is in the subset whereas 6 is not.
4 is in the subset whereas 8 is not., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static long compute(long n){
if(n==1||n==2) return 1;
if(n==3) return 2;
if(n%2==0){
long ans=(n/2);
return ans+compute(ans/2);
}
else {
long ans=(n+1)/2;
if(ans%2==1) return ans+compute(ans/2);
else return ans+compute((ans/2)-1);
}
}
public static void main(String[] args) throws Exception
{
br= new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t=Integer.parseInt(br.readLine());
while(t-->0){
long n=Long.parseLong(br.readLine());
long ans=compute(n);
pw.println(ans);
}
pw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, we define the set A<sub>N</sub> as {1, 2, 3, ... N-1, N}.
Find the size of the largest subset of A<sub>N</sub>, such that if x belongs to the subset, then 2x does not belong to the subset.The first line of the input contains a single integer T — the number of test cases.
Each test case consists of one line containing a single integer N.
<b>Constraints:</b>
1 ≤ T ≤ 10<sup>5</sup>
1 ≤ N ≤ 10<sup>9</sup>For each test case, print one integer — the size of the largest subset of A<sub>N</sub> satisfying the condition in the problem statement.Sample Input:
4
1
2
3
4
Sample Output:
1
1
2
3
Explanation:
For test case 4, where N = 4, the subset {1, 3, 4} is the largest subset satisfying the conditions.
1 is in the subset whereas 2 is not.
3 is in the subset whereas 6 is not.
4 is in the subset whereas 8 is not., I have written this Solution Code: //Author: Xzirium
//Time and Date: 15:50:05 28 September 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(T);
while(T--)
{
READV(N);
ll ans=0;
while (N>0)
{
ans+=(N+1)/2;
N=N/4;
}
cout<<ans<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, 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();
String[] str = s.split(" ");
float a=Float.parseFloat(str[0]);
float b=Float.parseFloat(str[1]);
float c=Float.parseFloat(str[2]);
float div = (float)(b*b-4*a*c);
if(div>0.0){
float alpha= (-b+(float)Math.sqrt(div))/(2*a);
float beta= (-b-(float)Math.sqrt(div))/(2*a);
System.out.printf("%.2f\n",alpha);
System.out.printf("%.2f",beta);
}
else{
float rp=-b/(2*a);
float ip=(float)Math.sqrt(-div)/(2*a);
System.out.printf("%.2f+i%.2f\n",rp,ip);
System.out.printf("%.2f-i%.2f\n",rp,ip);
}
}
}, 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 roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: import math
a,b,c = map(int, input().split(' '))
disc = (b ** 2) - (4*a*c)
sq = disc ** 0.5
if disc > 0:
print("{:.2f}".format((-b + sq)/(2*a)))
print("{:.2f}".format((-b - sq)/(2*a)))
elif disc == 0:
print("{:.2f}".format(-b/(2*a)))
elif disc < 0:
r1 = complex((-b + sq)/(2*a))
r2 = complex((-b - sq)/(2*a))
print("{:.2f}+i{:.2f}".format(r1.real, abs(r1.imag)))
print("{:.2f}-i{:.2f}".format(r2.real, abs(r2.imag))), 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 roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠ 0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int main() {
float a, b, c;
float root1, root2, imaginary;
float discriminant;
scanf("%f%f%f", &a, &b, &c);
discriminant = (b * b) - (4 * a * c);
switch (discriminant > 0) {
case 1:
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
case 0:
switch (discriminant < 0) {
case 1:
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("%.2f + i%.2f\n%.2f - i%.2f", root1, imaginary, root2, imaginary);
break;
case 0:
root1 = root2 = -b / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Your task is to implement a stack using an array and perform given queries
<b>Note</b>: Description of each query is given in the <b>input and output format</b>User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the integer to be added and the maximum size of the array as a parameter.
<b>pop()</b>:- that takes no parameter.
<b>top()</b> :- that takes no parameter.
Constraints:
1 <= N(number of queries) <= 10<sup>3</sup>During a <b>pop</b> operation if the stack is empty you need to print "<b>Stack underflow</b>",
during <b>push</b> operation, if the maximum size of the array is reached you need to print "<b>Stack overflow</b>", <br> during <b>top</b> operation, you need to print the element which is at the top
if the stack is empty you need to print "<b>Empty stack</b>".
<b>Note</b>:- Each message or element is to be printed on a new line
Sample Input:-
6 3
pop
push 3
push 2
push 4
push 6
top
Sample Output:-
Stack underflow
Stack overflow
4
Explanation:-
Here maximum size of the array is 3, so element 6 can not be added to stack
Sample input:-
8 4
push 2
top
push 4
top
push 6
top
push 8
top
Sample Output:-
2
4
6
8
, I have written this Solution Code: void push(int x,int k)
{
if (top >= k-1) {
System.out.println("Stack overflow");
}
else {
a[++top] = x;
}
}
void pop()
{
if (top < 0) {
System.out.println("Stack underflow");
}
else {
int x = a[top--];
}
}
void top()
{
if (top < 0) {
System.out.println("Empty stack");
}
else {
int x = a[top];
System.out.println(x);
}
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).
Implement the Myqueue class:
void push(int x) Pushes element x to the back of the queue.
int pop() Removes the element from the front of the queue and returns it.
int peek() Returns the element at the front of the queue.
boolean empty() Returns true if the queue is empty, false otherwise.
Note:
You must use only standard operations of a stack, which means only push, peek, size, and is empty operations are valid.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions in class Myqueue.
Push : Takes the element to be pushed at end as parameter.
Pop : Remove the element from front of queue and returns it.
Peek : Returns the front element of queue.
Empty: Return true if the queue is empty.
Expected Time Complexities:
Push: O(Size of Queue)
Pop: O(1)
Peek: O(1)
Empty: O(1)No need to output anything. Just complete the functions.Sample Input 1:-
8
Push 10
Push 5
Push 3
Pop
Pop
Peek
Pop
Empty
Sample Output 1:-
10
5
3
3
YES
Explanation
Initially Queue : {}
Push 10 - > Queue : {10 }
Push 5 -> Queue : {10, 5}
Push 3 -> Queue : {10, 5, 3}
Pop -> Queue : {5 , 3}
Pop -> Queue : {3}
Peek -> 3
Pop -> Queue: {}
Yes it's empty now
Sample Input 2:-
4
Push 3
Pop
Push 5
Empty
Sample Output 2:-
3
NO
Explanation:
Initially Queue : {}
Push 3 -> Queue : {3}
Pop -> Queue: {}
Push 5 -> Queue : {5}
Empty -> NO, I have written this Solution Code: static class Myqueue{
Stack<Integer>s1=new Stack<Integer>();
Stack<Integer>s2=new Stack<Integer>();
public void push(int x) {
while(s1.size()>0){
s2.push(s1.peek());
s1.pop();
}
s1.push(x);
while(s2.size()>0){
s1.push(s2.peek());
s2.pop();
}
}
public int pop() {
return s1.pop();
}
public int peek() {
return s1.peek();
}
public boolean empty() {
if(s1.size()==0)return true;
else return false;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers – A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code: import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve(int TC) {
int n = ni(), k = ni();
long sum = 0L, tempSum = 0;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
sum += a[i];
}
if (sum % k != 0) {
pn("No");
return;
}
long req = sum / (long) k;
for (int i : a) {
tempSum += i;
if (tempSum == req) {
tempSum = 0;
} else if (tempSum > req) {
pn("No");
return;
}
}
pn(tempSum == 0 ? "Yes" : "No");
}
boolean TestCases = false;
public static void main(String[] args) throws Exception {
new Main().run();
}
void hold(boolean b) throws Exception {
if (!b) throw new Exception("Hold right there, Sparky!");
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for (int t = 1; t <= T; t++) solve(t);
out.flush();
if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() {
return Double.parseDouble(ns());
}
char nc() {
return (char) skip();
}
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) {
if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers – A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int n,k;
cin>>n>>k;
int a[n];
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum%k)
cout<<"No";
else
{
int tot=0;
int cur=0;
sum/=k;
for(int i=0;i<n;i++)
{
cur+=a[i];
if(cur==sum)
{
tot++;
cur=0;
}
}
if(cur==0 && tot==k)
cout<<"Yes";
else
cout<<"No";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N, with all values as non-negative integers. Bodega asked you whether it is possible to partition the array into exactly K non-empty subarrays such that the sum of values of each subarray is equal. If it is possible print "Yes", otherwise print "No".
Note:
Every element of the array should belong to exactly one subarray in the partition.The first line consists of two space-separated integers N and K respectively.
The second line consists of N space-separated integers – A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ K ≤ 20
0 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>
There exists at least one non-zero element in array A.Print a single word "Yes" if the array can be partitioned into K equal sum parts, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
5 2
2 2 1 2 2
Sample Output 1:
No
Sample Input 2:
10 3
3 0 1 2 0 0 6 0 1 5
Sample Output 2:
Yes
Explanation:
The array can be partitioned as {3, 0, 1, 2, 0, 0}, {6}, {0, 1, 5}., I have written this Solution Code: N,K=map(int,input().split())
S=0
a=input().split()
for i in a:
S+=int(i)
if S%K!=0:
print('No')
else:
su=0
count=0
asd=S/K
for i in range(N):
su+=int(a[i])
if su==asd:
count+=1
su=0
if count==K:
print('Yes')
else:
print('No'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., 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 values[] = br.readLine().trim().split(" ");
long N = Long.parseLong(values[0]);
long M = Long.parseLong(values[1]);
long X = Long.parseLong(values[2]);
long Y = Long.parseLong(values[3]);
if(M/X >= N){
System.out.print(N);
return;
}
else
{
long count = M/X;
M = M % X;
N = N - count;
if(((N-1)*Y+M)<X)
System.out.print(count);
else
System.out.print(count+ N - countSacrifice(1,N,M,X,Y));
}
}
public static long countSacrifice(long min,long max,long M,long X,long Y)
{
long N = max;
while(min<max)
{ long mid = min + (max-min)/2;
if((mid*Y + M)>=((N-mid)*X))
{
max = mid;
}
else
{
min = mid+1;
}
}
return min;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import math
N,M,X,Y = map(int,input().strip().split())
low = 0
high = N
def possible(mid,M,X,Y):
if M//X >= mid:
return True
elif (N-math.ceil(((X*mid)-M)/Y))>=mid:
return True
return False
while(low<=high):
mid = (high+low)>>1
if possible(mid,M,X,Y):
res = mid
low = mid+1
else:
high = mid-1
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define LL long long
void solve() {
LL n, m, x, y;
cin >> n >> m >> x >> y;
LL l = 0, r = n + 1, mid;
while(l < r-1) {
mid = (l + r) / 2;
if(mid * x <= m + (n - mid) * y) l = mid;
else r = mid;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tt = 1; //cin >> tt;
while(tt--) solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: def area(side_of_square):
print(side_of_square*side_of_square)
def main():
N = int(input())
area(N)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int side = Integer.parseInt(br.readLine());
System.out.print(side*side);
}
}, In this Programming Language: Java, 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: Newton is highly ambitious, and he currently has 10 rupees. He goes to the casino and plays against an infinitely rich man (never ending money) in order to win huge money.
The rules of the game are super simple. There are N turns and the following procedure is followed in each turn.
<ul>
<li>If one of the player has 0 money, nothing happens.
<li> Else, the losing player loses 1 rupee and the winning player wins 1 rupee.
</ul>
The probability of Newton winning in any turn is P/Q. Find the expected money he would have, if N is 5000<sup>5000<sup>5000</sup></sup>.The first and the only line of input contains two integers P and Q.
Constraints
1 <= P <= Q <= 1000000If the expected value is greater than 10^18, output 10^18, else output floor(expected value).Sample Input
1 1000000
Sample Output
0
Explanation
Given the probability of Newton winning is 0.000001.
It can be proved that the floor of expected money he has after infinite number of turns is 0., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int p, q; cin>>p>>q;
q = q-p;
if(p < q){
cout<<0;
}
else if(p==q)
cout<<10;
else{
cout<<1000000000000000000LL;
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Stickler the thief wants to loot money from a society having n houses in a single line. He is a weird person and follows a certain rule when looting the houses. According to the rule, he will never loot two consecutive houses. At the same time, he wants to maximise the amount he loots. The thief knows which house has what amount of money but is unable to come up with an optimal looting strategy. He asks for your help to find the maximum money he can get if he strictly follows the rule. Each house has a[i] amount of money present in it.The first line of input contains an integer T denoting the number of test cases. T testcases follow. Each test case contains an integer n which denotes the number of houses. Next line contains space separated numbers denoting the amount of money in each house.
1 <= T <= 100
1 <= n <= 10^4
1 <= a[i] <= 10^4For each testcase, in a newline, print an integer which denotes the maximum amount he can take home.Sample Input:
2
6
5 5 10 100 10 5
3
1 2 3
Sample Output:
110
4
Explanation:
Testcase1:
5 + 100 + 5 = 110
Testcase2:
1 + 3 = 4, I have written this Solution Code: def maximize_loot(hval, n):
if n == 0:
return 0
value1 = hval[0]
if n == 1:
return value1
value2 = max(hval[0], hval[1])
if n == 2:
return value2
max_val = None
for i in range(2, n):
max_val = max(hval[i]+value1, value2)
value1 = value2
value2 = max_val
return max_val
t=int(input())
for l in range(0,t):
n=int(input())
arr=input().split()
one=0
two=0
for i in range(0,n):
arr[i]=int(arr[i])
print (maximize_loot(arr,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Stickler the thief wants to loot money from a society having n houses in a single line. He is a weird person and follows a certain rule when looting the houses. According to the rule, he will never loot two consecutive houses. At the same time, he wants to maximise the amount he loots. The thief knows which house has what amount of money but is unable to come up with an optimal looting strategy. He asks for your help to find the maximum money he can get if he strictly follows the rule. Each house has a[i] amount of money present in it.The first line of input contains an integer T denoting the number of test cases. T testcases follow. Each test case contains an integer n which denotes the number of houses. Next line contains space separated numbers denoting the amount of money in each house.
1 <= T <= 100
1 <= n <= 10^4
1 <= a[i] <= 10^4For each testcase, in a newline, print an integer which denotes the maximum amount he can take home.Sample Input:
2
6
5 5 10 100 10 5
3
1 2 3
Sample Output:
110
4
Explanation:
Testcase1:
5 + 100 + 5 = 110
Testcase2:
1 + 3 = 4, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
#define ld long double
#define ll long long
#define pb push_back
#define endl '\n'
#define pi pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 1e4 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], dp[N][2];
void solve(){
int n; cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
dp[i][1] = a[i] + dp[i-1][0];
}
cout << max(dp[n][1], dp[n][0]) << endl;
}
void testcases(){
int tt = 1;
cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
long res = 0;
for(int i=N-1;i >-1; i--) {
res += arr[i]*i;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
l=[]
for i in range(n-1):
l.append(arr[i]*((n-1)-i))
print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;++i){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;++i)
ans+=(a[i]*(i-1));
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has two integer intervals [A, B] and [C, D] (the intervals are inclusive of both numbers). She wonders if Solo will be able to solve the following simple problem:
Choose an integer X from first interval and an integer Y from second interval. Now for all combinations of X and Y, what is the maximum value of X*Y.
As Solo is small, please help her solve the problem.The first and the only line of input contains 4 integers A, B, C, and D.
Constraints
-10<sup>9</sup> <= A <= B <= 10<sup>9</sup>
-10<sup>9</sup> <= C <= D <= 10<sup>9</sup>Output a single integer, the maximum value of the product.Sample Input
1 2 1 1
Sample Output
2
Explanation: Choose 2 from [1, 2] and 1 from [1, 1].
Sample Input
3 5 -4 -2
Sample Output
-6
Sample Input
-1000000000 0 -1000000000 0
Sample Output
1000000000000000000, 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[] arr=br.readLine().split(" ");
int a = Integer.parseInt(arr[0]);
int b = Integer.parseInt(arr[1]);
int c = Integer.parseInt(arr[2]);
int d= Integer.parseInt(arr[3]);
int secondMax = Math.max(a,b) < 0 ? Math.min(c,d) : Math.max(c,d);
int firstMax = Math.max(c,d) < 0 ? Math.min(a,b) : Math.max(a,b);
if(Math.abs(Math.min(a,b)) > Math.max(a,b) && Math.abs(Math.min(c,d)) > Math.max(c,d)){
long num= (long)Math.min(a,b) * Math.min(c,d);
System.out.println(num);
return;
}
long prod = (long)firstMax*secondMax;
System.out.println(prod);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has two integer intervals [A, B] and [C, D] (the intervals are inclusive of both numbers). She wonders if Solo will be able to solve the following simple problem:
Choose an integer X from first interval and an integer Y from second interval. Now for all combinations of X and Y, what is the maximum value of X*Y.
As Solo is small, please help her solve the problem.The first and the only line of input contains 4 integers A, B, C, and D.
Constraints
-10<sup>9</sup> <= A <= B <= 10<sup>9</sup>
-10<sup>9</sup> <= C <= D <= 10<sup>9</sup>Output a single integer, the maximum value of the product.Sample Input
1 2 1 1
Sample Output
2
Explanation: Choose 2 from [1, 2] and 1 from [1, 1].
Sample Input
3 5 -4 -2
Sample Output
-6
Sample Input
-1000000000 0 -1000000000 0
Sample Output
1000000000000000000, I have written this Solution Code: A,B,C,D=list(map(int,input().split()))
p=[A*C,A*D,B*C,B*D]
print(max(p)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has two integer intervals [A, B] and [C, D] (the intervals are inclusive of both numbers). She wonders if Solo will be able to solve the following simple problem:
Choose an integer X from first interval and an integer Y from second interval. Now for all combinations of X and Y, what is the maximum value of X*Y.
As Solo is small, please help her solve the problem.The first and the only line of input contains 4 integers A, B, C, and D.
Constraints
-10<sup>9</sup> <= A <= B <= 10<sup>9</sup>
-10<sup>9</sup> <= C <= D <= 10<sup>9</sup>Output a single integer, the maximum value of the product.Sample Input
1 2 1 1
Sample Output
2
Explanation: Choose 2 from [1, 2] and 1 from [1, 1].
Sample Input
3 5 -4 -2
Sample Output
-6
Sample Input
-1000000000 0 -1000000000 0
Sample Output
1000000000000000000, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int a, b, c, d; cin>>a>>b>>c>>d;
int a1 = max(a*c, b*d);
int a2 = max(a*d, b*c);
cout<<max(a1, a2);
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: import java.util.InputMismatchException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
int MAX = (int) 1e5, MOD = (int)1e9+7;
void solve(int TC) {
long n = nl();
long k = nl();
int p = 0;
while(n>0 && n%2==0) {
n/=2;
++p;
}
if(p>=k) {pn(0);return;}
k -= p;
long ans = (k+3L)/4L;
pn(ans);
}
boolean TestCases = false;
public static void main(String[] args) throws Exception { new Main().run(); }
long pow(long a, long b) {
if(b==0 || a==1) return 1;
long o = 1;
for(long p = b; p > 0; p>>=1) {
if((p&1)==1) o = (o*a) % MOD;
a = (a*a) % MOD;
} return o;
}
long inv(long x) {
long o = 1;
for(long p = MOD-2; p > 0; p>>=1) {
if((p&1)==1)o = (o*x)%MOD;
x = (x*x)%MOD;
} return o;
}
long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }
int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for(int t=1;t<=T;t++) solve(t);
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
void p(Object o) { out.print(o); }
void pn(Object o) { out.println(o); }
void pni(Object o) { out.println(o);out.flush(); }
double PI = 3.141592653589793238462643383279502884197169399;
int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() { return Double.parseDouble(ns()); }
char nc() { return (char)skip(); }
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
} return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))) {
sb.appendCodePoint(b); b = readByte();
} return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
} return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: [n,k]=[int(j) for j in input().split()]
a=0
while n%2==0:
a+=1
n=n//2
if k>a:
print((k-a-1)//4+1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,k;
cin>>n>>k;
while(k&&n%2==0){
n/=2;
--k;
}
cout<<(k+3)/4;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int n = Integer.parseInt(in.readLine());
int []donationList = new int[n];
int[] defaulterList = new int[n];
long totalDonations = 0L;
StringTokenizer st = new StringTokenizer(in.readLine());
for(int i=0 ; i<n ; i++){
donationList[i] = Integer.parseInt(st.nextToken());
}
int max = Integer.MIN_VALUE;
for(int i=0; i<n; i++){
totalDonations += donationList[i];
max = Math.max(max,donationList[i]);
if(i>0){
if(donationList[i] >= max)
defaulterList[i] = 0;
else
defaulterList[i] = max - donationList[i];
}
totalDonations += defaulterList[i];
}
for(int i=0; i<n ;i++){
System.out.print(defaulterList[i]+" ");
}
System.out.println();
System.out.print(totalDonations);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: n = int(input())
a = input().split()
b = int(a[0])
sum = 0
for i in a:
if int(i)<b:
print(b-int(i),end=' ')
else:
b = int(i)
print(0,end=' ')
sum = sum+b
print()
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After the decimation, the world went into chaos. People had to rebuild the planet so Shield came up with a donation strategy. They feel all the rich guys need to donate more than the poor guys. So, they make a rule. They would make a donation list in which the donation of each person would be shown. But the rule is that a person can’t pay less than what has already been paid before them. Find the extra amount each person will pay, and also, tell shield the total amount of donation.The first line contains n, the total number of people donating. The next line contains n space-separated integers denoting the amount of money paid by the people. The amounts are mentioned in the order in which the people paid.
<b>Constraints:-</b>
1 <= n <= 100000
0 <= money <= 100000The first line contains the extra money that each student has to pay after their teacher applied the rule. The second line contains the total amount collected by the teacher at the end.Sample Input 1:-
10
1 2 3 2 4 3 6 6 7 6
Sample Output 1:-
0 0 0 1 0 1 0 0 0 1
43
Sample Input 2:-
7
10 20 30 40 30 20 10
Sample Output 2:-
0 0 0 0 10 20 30
220, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin>>n;
int a[n];
int ma=0;
int cnt=0;
//map<int,int> m;
for(int i=0;i<n;i++){
cin>>a[i];
ma=max(ma,a[i]);
cout<<ma-a[i]<<" ";
cnt+=ma-a[i];
cnt+=a[i];
//m[a[i]]++;
}
cout<<endl;
cout<<cnt<<endl;
}
signed main(){
int t;
t=1;
while(t--){
solve();}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Classes at NITAP(the name of the college) are finally starting after the summer break, and students have to reach the campus to avoid the late fine of Rs 500 for semester registration. Mohan, Shreya, and Anuj live in the same town. They are deciding on a date to book their train ticket. Everyone has a demand.
• Mohan wants the ticket at least on date A.
• Shreya wants the ticket at most by date B.
• Anuj wants the ticket at least on date C.
If all three of them can get the ticket on the same day, then print "YES" otherwise "NO".The first line of input contains a single integer T, the number of test cases.
Each test case contains three space-separated integers A, B, and C
<b>Constraints</b>
1 ≤ T ≤ 10<sup>5</sup>
1 ≤ A, B, C ≤ 31For each testcase, output a line containing YES or NO.Sample Input
4
13 16 12
14 15 16
13 16 16
15 13 17
Sample Output
YES
NO
YES
NO, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while(T-->0){
StringTokenizer st = new StringTokenizer(br.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());
if(A<=B && C<=B){
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: Classes at NITAP(the name of the college) are finally starting after the summer break, and students have to reach the campus to avoid the late fine of Rs 500 for semester registration. Mohan, Shreya, and Anuj live in the same town. They are deciding on a date to book their train ticket. Everyone has a demand.
• Mohan wants the ticket at least on date A.
• Shreya wants the ticket at most by date B.
• Anuj wants the ticket at least on date C.
If all three of them can get the ticket on the same day, then print "YES" otherwise "NO".The first line of input contains a single integer T, the number of test cases.
Each test case contains three space-separated integers A, B, and C
<b>Constraints</b>
1 ≤ T ≤ 10<sup>5</sup>
1 ≤ A, B, C ≤ 31For each testcase, output a line containing YES or NO.Sample Input
4
13 16 12
14 15 16
13 16 16
15 13 17
Sample Output
YES
NO
YES
NO, I have written this Solution Code: n = int(input())
arr = []
for i in range(0,n):
a = list(map(int,input().split()))
arr.append(a)
for i in arr:
if(i[1]>=i[0] and i[1]>=i[2]):
print('YES')
else:
print('NO'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Classes at NITAP(the name of the college) are finally starting after the summer break, and students have to reach the campus to avoid the late fine of Rs 500 for semester registration. Mohan, Shreya, and Anuj live in the same town. They are deciding on a date to book their train ticket. Everyone has a demand.
• Mohan wants the ticket at least on date A.
• Shreya wants the ticket at most by date B.
• Anuj wants the ticket at least on date C.
If all three of them can get the ticket on the same day, then print "YES" otherwise "NO".The first line of input contains a single integer T, the number of test cases.
Each test case contains three space-separated integers A, B, and C
<b>Constraints</b>
1 ≤ T ≤ 10<sup>5</sup>
1 ≤ A, B, C ≤ 31For each testcase, output a line containing YES or NO.Sample Input
4
13 16 12
14 15 16
13 16 16
15 13 17
Sample Output
YES
NO
YES
NO, I have written this Solution Code: #include <stdio.h>
int main(void)
{
int t; scanf("%d", &t); while (t--)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (b < a || b < c) printf("NO\n"); else printf("YES\n");
}
return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, 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();
int sum=0;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
int k=c-'0';
sum+=k;}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
string s; cin>>s;
int ans = 0;
For(i, 0, sz(s)){
ans += (s[i]-'0');
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: s = input()
count = 0
for x in s:count+=int(x)
print(count) ;, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1073741824
#define read(type) readInt<type>()
#define max1 1000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
// Base case
if (r==0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
ll fastexp (ll a, ll b, ll n) {
ll res = 1;
while (b) {
if (b & 1) res = res*a%n;
a = a*a%n;
b >>= 1;
}
return res;
}
bool a[max1];
int main() {
FOR(i,max1){
a[i]=false;}
for(int i=2;i<max1;i++){
if(a[i]==false){
for(int j=i+i;j<max1;j+=i){
a[j]=true;
}
}}
vector<int> v;
map<int,int> m;
for(int i=2;i<max1;i++){
if(a[i]==false){
v.EB(i);
m[i]++;
}
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool win=false;
for(int i=0;i<v.size();i++){
if(m.find(n-v[i])!=m.end()){
if(v[i]>n){break;}
cout<<v[i]<<" "<<n-v[i]<<endl;win=true;break;
}
}
if(win==false){out(-1);}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static boolean isPrime(int n)
{
boolean ans=true;
if(n<=1)
{
ans=false;
}
else if(n==2 || n==3)
{
ans=true;
}
else if(n%2==0 || n%3==0)
{
ans=false;
}
else
{
for(int i=5;i*i<=n;i+=6)
{
if(n%i==0 || n%(i+2)==0)
{
ans=false;
break;
}
}
}
return ans;
}
public static void main (String[] args) throws IOException {
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(scan.readLine());
while(t-->0)
{
int n=Integer.parseInt(scan.readLine());
int a=0,b=0;
if(n%2==1)
{
if(isPrime(n-2))
{
a=2;b=n-2;
}
}
else
{
for(int i=2;i<=n/2;i++)
{
if(isPrime(i))
{
if(isPrime(n-i))
{
a=i;b=n-i;
break;
}
}
}
}
if(a!=0 && b!=0)
{
System.out.println(a+" "+b);
}
else
{
System.out.println(-1);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists.
NOTE: A solution will always exist if the number is even. Read Goldbach’s conjecture.
If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only
and not all possible solutions.The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 1000000Print the two prime numbers in a single line with space in between if exist else print -1.Sample Input:
2
8
3
Sample Output:
3 5
-1, I have written this Solution Code: def isprime(num):
if(num==1 or num==0):
return False
for i in range(2,int(num**0.5)+1):
if(num%i==0):
return False
return True
T = int(input())
for test in range(T):
N = int(input())
value = -1
if(N%2==0):
for i in range(2,int(N/2)+1):
if(isprime(i)):
if(isprime(N-i)):
value = i
break
else:
if(isprime(N-2)):
value = 2
if(value==-1):
print(value)
else:
print(str(value)+" "+str(N-value)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out= new PrintWriter(System.out);
int t=Integer.parseInt(br.readLine());
while(t>0){
t-=1;
int n=Integer.parseInt(br.readLine());
String s[]=br.readLine().split(" ");
int arr[]=new int[n];
int zero_counter=0,one_counter=0,two_counter=0;
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
if(arr[i]==0)
zero_counter+=1;
else if(arr[i]==1)
one_counter+=1;
else
two_counter+=1;
}
for(int i=0;i<zero_counter;i++){
out.print(0+" ");
}
for(int i=0;i<one_counter;i++){
out.print(1+" ");
}
for(int i=0;i<two_counter;i++){
out.print(2+" ");
}
out.flush();
out.println(" ");
}
out.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=input()
a=map(int,input().split())
z=o=tc=0
for i in a:
if i==0:z+=1
elif i==1:o+=1
else:tc+=1
while z>0:
z-=1
print(0,end=' ')
while o>0:
o-=1
print(1,end=' ')
while tc>0:
tc-=1
print(2,end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
int a[3] = {0};
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
a[1] += a[0];
a[2] += a[1];
for(int i = 1; i <= n; i++){
if(i <= a[0]) cout << "0 ";
else if(i <= a[1]) cout << "1 ";
else cout << "2 ";
}
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array.
Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow.
Each testcases contains two lines of input. The first line denotes the size of the array N.
The second lines contains the elements of the array A separated by spaces.
Constraints:
1 <= T <= 100
1 <= N <= 100000
0 <= Ai <= 2
Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input :
2
5
0 2 1 2 0
3
0 1 0
Output:
0 0 1 2 2
0 0 1
Explanation:
Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output.
Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: function zeroOneTwoSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 ≤ L ≤ 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 ≤ L ≤ 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 ≤ L ≤ 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 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: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(br.readLine());
String st = br.readLine();
String[] stArr = st.trim().split(" ");
int[] arr = new int[size];
for(int i=0; i<size; i++){
arr[i] = Integer.parseInt(stArr[i]);
}
Stack<Integer> stack = new Stack<>();
StringBuilder sb=new StringBuilder("");
for(int i=0; i<size; i++){
int count = 0;
if(stack.isEmpty()){
stack.push(i);
sb.append("1 ");
} else if(arr[stack.peek()] > arr[i]){
stack.push(i);
sb.append("1 ");
} else{
while(!stack.isEmpty() && arr[stack.peek()] <= arr[i]){
stack.pop();
}
if(stack.isEmpty()){
count = i+1;
} else{
count = i - stack.peek();
}
sb.append(count+" ");
stack.push(i);
}
}
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., I have written this Solution Code: n = int(input())
lst = list(map(int, input().strip().split()))
S = [0]*n
st = []
st.append(0)
for i in range(n):
while( len(st) > 0 and lst[st[-1]] <= lst[i]):
st.pop()
S[i] = i + 1 if len(st) <= 0 else (i - st[-1])
st.append(i)
for i in range(0, n):
print (S[i], end =" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days.
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
Explanation to the given example:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6.The first line of each test case is N, N is the size of the array. The second line of each test case contains N input A[i].
1 ≤ N ≤ 100000
1 ≤ A[i] ≤ 100000For each test case, print the span values for all days.Input
7
100 80 60 70 60 75 85
Output
1 1 1 2 1 4 6
Input
6
10 4 5 90 120 80
Output
1 1 2 4 5 1
Explanation:
Test case 1:
On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 2nd day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
Now on 3rd day we observe that stock price for last two consecutive days is less than or equal to current day i.e. (60, 70) thus count is 2
On 4th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens.
On 5th day we observe that stock price for last four consecutive days is less than or equal to current day i.e. (60, 70, 60, 75) thus count is 4.
On 6th day we observe that stock price for last six consecutive days is less than or equal to current day i.e. (80, 60, 70, 60, 75, 85) thus count is 6., 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;
a[0] = inf;
s.push(0);
for(int i = 1; i <= n; i++){
cin >> a[i];
while(!s.empty() && a[s.top()] <= a[i])
s.pop();
cout << i - 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 a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int n = s.length();
int left = 0, right = 0;
int maxlength = 0;
for(int i = 0; i < n; i++)
{
if (s.charAt(i) == '(')
left++;
else
right++;
if (left == right)
maxlength = Math.max(maxlength, 2 * right);
else if (right > left)
left = right = 0;
}
left = right = 0;
for(int i = n - 1; i >= 0; i--)
{
if (s.charAt(i) == '(')
left++;
else
right++;
if (left == right)
maxlength = Math.max(maxlength, 2 * left);
else if (left > right)
left = right = 0;
}
System.out.println(maxlength);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
4, I have written this Solution Code: def longestValidParentheses( S):
stack, ans = [-1], 0
for i in range(len(S)):
if S[i] == '(': stack.append(i)
elif len(stack) == 1: stack[0] = i
else:
stack.pop()
ans = max(ans, i - stack[-1])
return ans
n=input()
print(longestValidParentheses(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
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;
string s;
cin >> s;
int n = s.length();
s = "#" + s;
stack<int> st;
st.push(0);
int ans = 0;
for(int i = 1; i <= n; i++){
if(s[i] == '(')
st.push(i);
else{
if(s[st.top()] == '('){
int x = st.top();
a[i] = i-x+1 + a[x-1];
ans = max(ans, a[i]);
st.pop();
}
else
st.push(i);
}
}
cout << ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader inputMachine = new BufferedReader(new InputStreamReader(System.in));
int length = Integer.parseInt(inputMachine.readLine());
String[] arrText = inputMachine.readLine().trim().split(" ");
int[] nums = new int[length];
for (int i = 0; i < nums.length; i++) {
nums[i] = Integer.parseInt(arrText[i]);
}
Arrays.sort(nums);
int i = 0;
int j = length - 1;
long sum = 0;
while (i < j) {
sum += nums[j] - nums[i];
i++;
j--;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: n = int(input())
arr = list(map(int,input().split()))
arr.sort()
s = 0
for i in range(n//2):
s += arr[n-i-1]-arr[i]
print(s), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ans=0;
for(int i=0;i<n/2;++i){
ans+=abs(a[i]-a[n-i-1]);
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code: def Average(A,B,C):
return (A+B+C)//3
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
static int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
int n = in.nextInt();
out.println(n*n);
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static long ooo = Long.MAX_VALUE;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<(n*n)<<'\n';
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.