Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: a = []
a = list(map(int, input().split()))
if a[1]+a[2] > a[0] or a[1]*a[3] > a[0]:
defeat = 1
else:
defeat = 0
print(defeat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll M, Y, R, G;
cin >> M >> Y >> R >> G;
ll maxm = Y;
maxm = max(maxm, Y+R);
maxm = max(maxm, Y*G);
cout << (M < maxm) << "\n";
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: def DivisorProblem(N):
ans=0
while N>1:
cnt=2
while N%cnt!=0:
cnt=cnt+1
N = N//cnt
ans=ans+1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: static int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1.
Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations required.Sample Input:-
100
Sample Output:-
4
Explanation:-
100 - > 50
50 - > 25
25 - > 5
5 - > 1
Sample Input:-
10
Sample Output:-
2, I have written this Solution Code: int DivisorProblem(int N){
int ans=0;
while(N>1){
int cnt=2;
while(N%cnt!=0){
cnt++;
}
N/=cnt;
ans++;
}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a NxN matrix. You need to find the <a href = "https://en.wikipedia.org/wiki/Transpose">transpose</a> of the matrix.
The matrix is of form:
a b c ...
d e f ...
g h i ...
...........
There are N elements in each row.The first line of the input contains an integer N denoting the size of the square matrix.
The next N lines contain N single-spaced integers.
<b>Constraints</b>
1 <= N <= 100
1 <=Ai <= 100000Output the transpose of the matrix in similar format as that of the input.Sample Input
2
1 3
2 2
Sample Output
1 2
3 2
Sample Input:
1 2
3 4
Sample Output:
1 3
2 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main (String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String arr[][]=new String[n][n];
String transpose[][]=new String[n][n];
int row;
int cols;
for(row=0;row<n;row++)
{
String rowNum=br.readLine();
String rowVals[]=rowNum.split(" ");
for(cols=0; cols<n;cols++)
{
arr[row][cols]=rowVals[cols];
}
}
for(row=0;row<n;row++)
{
for(cols=0; cols<n;cols++)
{
transpose[row][cols]=arr[cols][row];
System.out.print(transpose[row][cols]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a NxN matrix. You need to find the <a href = "https://en.wikipedia.org/wiki/Transpose">transpose</a> of the matrix.
The matrix is of form:
a b c ...
d e f ...
g h i ...
...........
There are N elements in each row.The first line of the input contains an integer N denoting the size of the square matrix.
The next N lines contain N single-spaced integers.
<b>Constraints</b>
1 <= N <= 100
1 <=Ai <= 100000Output the transpose of the matrix in similar format as that of the input.Sample Input
2
1 3
2 2
Sample Output
1 2
3 2
Sample Input:
1 2
3 4
Sample Output:
1 3
2 4, I have written this Solution Code: x=int(input())
l1=[]
for i in range(x):
a1=list(map(int,input().split()))
l1.append(a1)
l4=[]
for j in range(x):
l3=[]
for i in range(x):
l3.append(l1[i][j])
l4.append(l3)
for i in range(x):
for j in range(x):
print(l4[i][j], end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a NxN matrix. You need to find the <a href = "https://en.wikipedia.org/wiki/Transpose">transpose</a> of the matrix.
The matrix is of form:
a b c ...
d e f ...
g h i ...
...........
There are N elements in each row.The first line of the input contains an integer N denoting the size of the square matrix.
The next N lines contain N single-spaced integers.
<b>Constraints</b>
1 <= N <= 100
1 <=Ai <= 100000Output the transpose of the matrix in similar format as that of the input.Sample Input
2
1 3
2 2
Sample Output
1 2
3 2
Sample Input:
1 2
3 4
Sample Output:
1 3
2 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[j][i];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N cities in a line and your initial position, you want to visit all the cities at least once. You can go to one coordinate P to P+D or P-D where D is the number of steps which you choose initially. Your task is to find the maximum value of D such that you can visit all the cities at least once.The first line of input contains two integers N and X(initial position). The second line of input contains N space separated integers representing the location of cities.
Constraints:-
1 <= N <= 100000
1 <= City[] <= 100000000Print the maximum value of D such that you can visit all the cities.Sample Input:-
3 3
1 7 11
Sample Output:-
2
Sample Input:-
3 81
33 105 57
Sample Output:-
24, 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());
}
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main (String[] args) {
FastReader inp = new FastReader();
int n = inp.nextInt();
int x = inp.nextInt();
int[] arr = new int[n];
int result =0;
for (int i = 0 ; i < n ; i++){
arr[i] = inp.nextInt();
arr[i] = Math.abs(arr[i] - x );
if (i ==0 ){
result = arr[i];
}else{
result = gcd(result,arr[i]);
}
}
System.out.print(result);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N cities in a line and your initial position, you want to visit all the cities at least once. You can go to one coordinate P to P+D or P-D where D is the number of steps which you choose initially. Your task is to find the maximum value of D such that you can visit all the cities at least once.The first line of input contains two integers N and X(initial position). The second line of input contains N space separated integers representing the location of cities.
Constraints:-
1 <= N <= 100000
1 <= City[] <= 100000000Print the maximum value of D such that you can visit all the cities.Sample Input:-
3 3
1 7 11
Sample Output:-
2
Sample Input:-
3 81
33 105 57
Sample Output:-
24, I have written this Solution Code: import math
b = []
N, P = input().split()
N = int(N)
P=int(P)
A = input().split()
for i in range(0,N):
A[i] = int(A[i])-P
i=0
while(i<N-1):
b.append(math.gcd(A[i],A[i+1]))
i+=1
b.sort()
print (b[0]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N cities in a line and your initial position, you want to visit all the cities at least once. You can go to one coordinate P to P+D or P-D where D is the number of steps which you choose initially. Your task is to find the maximum value of D such that you can visit all the cities at least once.The first line of input contains two integers N and X(initial position). The second line of input contains N space separated integers representing the location of cities.
Constraints:-
1 <= N <= 100000
1 <= City[] <= 100000000Print the maximum value of D such that you can visit all the cities.Sample Input:-
3 3
1 7 11
Sample Output:-
2
Sample Input:-
3 81
33 105 57
Sample Output:-
24, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int ans = abs(a[0]-k);
for(int i=1;i<n;i++){
ans=__gcd(ans,a[i]-a[i-1]);
}
cout<<ans;
}
, 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, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, I have written this Solution Code: def rightlarg(arr):
n = len(arr)
A =[None]*n
A[-1] = -1
Indx = [-1]*n
stack = []
s = 1
stack.append([arr[-1],n-1])
for i in range(n-2,-1,-1):
while s :
if stack[0][0]>arr[i] :
A[i] = stack[0][0]
Indx[i] = stack[0][1]
break
else:
stack.pop(0)
s -= 1
else:
A[i] = -1
stack.insert(0,[arr[i],i])
s += 1
for x in Indx:
#print("kjhx ",x," jhgk")
if x==-1:
print(x,end=" ")
else:
print(arr[x],end=" ")
n=int(input())
B=[int(x) for x in input().split()]
rightlarg(B), 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, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int arrSize = sc.nextInt();
int arr[] = new int[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
nextLarger(arr, arrSize);
}
static void nextLarger(int arr[], int arrSize)
{
Stack<Integer> s = new Stack<>();
int a = 0;
for(int i=arrSize-1;i>=0;i--)
{
a= arr[i];
while(!(s.empty() == true)){
if(s.peek()>a){break;}
s.pop();
}
if(s.empty() == true){arr[i]=-1;}
else{arr[i]=s.peek();}
s.push(a);
}
for(int i=0;i<arrSize;i++)
{
System.out.print(arr[i]+" ");
}
}
}, 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, the task is to find the nearest greater element G[i] for every element of A[i] such that the element has index greater than i, If no such element exists, output -1.
More formally:
G[i] for an element A[i] = an element A[j] such that
j is minimum possible AND
j > i AND
A[j] > A[i]Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^9For each test case, print the next greater element for each array element separated by space in order.Sample Input
4
1 3 2 4
Sample Output
3 4 4 -1
Sample Input
4
4 3 2 1
Sample Output
-1 -1 -1 -1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
stack <long long > s;
long long a,b[n];
for(int i=0;i<n;i++){
cin>>b[i];}
for(int i=n-1;i>=0;i--){
a=b[i];
while(!(s.empty())){
if(s.top()>a){break;}
s.pop();
}
if(s.empty()){b[i]=-1;}
else{b[i]=s.top();}
s.push(a);
}
for(int i=0;i<n;i++){
cout<<b[i]<<" ";
}
}
, 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: 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: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, 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: 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 an array <b>arr </b> of numbers, your task is to count the number of unique elements in it.The first line of the input contains n (Number of elements). The following line contains the information on the array.
<b>For python users, you have to complete the function.</b>
<b>Constraints</b>
1 ≤ n ≤ 10<sup>6</sup>
1 ≤ arr[i] ≤10<sup>9</sup>Print the number of unique elements in the array.
<b>For python users return the count of unique elements from the given function.</b>Sample Input 1
4
1 2 3 3
Sample Output 1
3
Sample Input 2
6
1 1 2 2 3 3
Sample Output 2
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args) throws IOException{
Reader s = new Reader();
int n = s.nextInt();
HashSet<Integer> hs = new HashSet<>();
for(int i=0;i<n;i++){
hs.add(s.nextInt());
}
System.out.println(hs.size());
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr </b> of numbers, your task is to count the number of unique elements in it.The first line of the input contains n (Number of elements). The following line contains the information on the array.
<b>For python users, you have to complete the function.</b>
<b>Constraints</b>
1 ≤ n ≤ 10<sup>6</sup>
1 ≤ arr[i] ≤10<sup>9</sup>Print the number of unique elements in the array.
<b>For python users return the count of unique elements from the given function.</b>Sample Input 1
4
1 2 3 3
Sample Output 1
3
Sample Input 2
6
1 1 2 2 3 3
Sample Output 2
3, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-10 12:51:16
**/
#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() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
set<int> a;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
a.insert(temp);
}
cout << a.size() << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr </b> of numbers, your task is to count the number of unique elements in it.The first line of the input contains n (Number of elements). The following line contains the information on the array.
<b>For python users, you have to complete the function.</b>
<b>Constraints</b>
1 ≤ n ≤ 10<sup>6</sup>
1 ≤ arr[i] ≤10<sup>9</sup>Print the number of unique elements in the array.
<b>For python users return the count of unique elements from the given function.</b>Sample Input 1
4
1 2 3 3
Sample Output 1
3
Sample Input 2
6
1 1 2 2 3 3
Sample Output 2
3, I have written this Solution Code: def uniqueElement(arr):
converted_set = set(arr)
return len(converted_set), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr </b> of numbers, your task is to count the number of unique elements in it.The first line of the input contains n (Number of elements). The following line contains the information on the array.
<b>For python users, you have to complete the function.</b>
<b>Constraints</b>
1 ≤ n ≤ 10<sup>6</sup>
1 ≤ arr[i] ≤10<sup>9</sup>Print the number of unique elements in the array.
<b>For python users return the count of unique elements from the given function.</b>Sample Input 1
4
1 2 3 3
Sample Output 1
3
Sample Input 2
6
1 1 2 2 3 3
Sample Output 2
3, I have written this Solution Code: import numpy as np
n=int(input())
a=np.array([input().strip().split()],int).flatten()
s=set()
for i in a:
s.add(i)
print(len(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of integers, sort the array according to frequency of elements. That is elements that have higher frequency come first. If frequencies of two elements are same, then smaller number comes first.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of an array. The second line contains N space-separated integers A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>N</sub> denoting the elements of the array.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤10<sup>5</sup>
1 ≤A[i] ≤ 10<sup>4</sup>
The Sum of N over all test cases does not exceed 2*10<sup>5</sup>
For each testcase, in a new line, print each sorted array in a separate line. For each array its numbers should be separated by space.Sample Input:
2
5
5 5 4 6 4
5
9 9 9 2 5
Sample Output:
4 4 5 5 6
9 9 9 2 5
<b>Explanation:</b>
Test Case 1: The highest frequency here is 2. Both 5 and 4 have that frequency. Now since the frequencies are the same then smaller element comes first. So 4 4 comes first then comes 5 5. Finally comes 6.
The output is 4 4 5 5 6.
Test Case2: The highest frequency here is 3. The element 9 has the highest frequency. So 9 9 9 comes first. Now both 2 and 5 have same frequency. So we print smaller element first.
The output is 9 9 9 2 5., 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 = 1e5+ 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], f[N];
bool cmp(int a, int b){
if(f[a] == f[b])
return a < b;
return f[a] > f[b];
}
signed main() {
IOS;
int t; cin >> t;
while(t--){
memset(f, 0, sizeof f);
int n; cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
f[a[i]]++;
}
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of integers, sort the array according to frequency of elements. That is elements that have higher frequency come first. If frequencies of two elements are same, then smaller number comes first.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of an array. The second line contains N space-separated integers A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>N</sub> denoting the elements of the array.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤10<sup>5</sup>
1 ≤A[i] ≤ 10<sup>4</sup>
The Sum of N over all test cases does not exceed 2*10<sup>5</sup>
For each testcase, in a new line, print each sorted array in a separate line. For each array its numbers should be separated by space.Sample Input:
2
5
5 5 4 6 4
5
9 9 9 2 5
Sample Output:
4 4 5 5 6
9 9 9 2 5
<b>Explanation:</b>
Test Case 1: The highest frequency here is 2. Both 5 and 4 have that frequency. Now since the frequencies are the same then smaller element comes first. So 4 4 comes first then comes 5 5. Finally comes 6.
The output is 4 4 5 5 6.
Test Case2: The highest frequency here is 3. The element 9 has the highest frequency. So 9 9 9 comes first. Now both 2 and 5 have same frequency. So we print smaller element first.
The output is 9 9 9 2 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner in = new Scanner (System.in);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int arr[] = new int[n];
for (int i=0; i<n; i++) {
arr[i] = in.nextInt();
}
int farr[] = new int[10003];
for (int i=0; i<n; i++) {
farr[arr[i]] ++;
}
int max = 0;
int index = 0;
while (true) {
for (int i=0; i<10003; i++) {
if (max < farr[i]) {
max = farr[i];
index = i;
}
}
for (int i=0; i<max; i++) {
System.out.print(index + " ");
}
if (max == 0) {
break;
}
farr[index] = 0;
index =0;
max = 0;
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of integers, sort the array according to frequency of elements. That is elements that have higher frequency come first. If frequencies of two elements are same, then smaller number comes first.The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of an array. The second line contains N space-separated integers A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>N</sub> denoting the elements of the array.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤10<sup>5</sup>
1 ≤A[i] ≤ 10<sup>4</sup>
The Sum of N over all test cases does not exceed 2*10<sup>5</sup>
For each testcase, in a new line, print each sorted array in a separate line. For each array its numbers should be separated by space.Sample Input:
2
5
5 5 4 6 4
5
9 9 9 2 5
Sample Output:
4 4 5 5 6
9 9 9 2 5
<b>Explanation:</b>
Test Case 1: The highest frequency here is 2. Both 5 and 4 have that frequency. Now since the frequencies are the same then smaller element comes first. So 4 4 comes first then comes 5 5. Finally comes 6.
The output is 4 4 5 5 6.
Test Case2: The highest frequency here is 3. The element 9 has the highest frequency. So 9 9 9 comes first. Now both 2 and 5 have same frequency. So we print smaller element first.
The output is 9 9 9 2 5., I have written this Solution Code: from collections import defaultdict
test = int(input())
while(test != 0):
test -= 1
n = int(input())
arr = list(map(int, input().split()))
freq = defaultdict(list)
temp = [0]*(max(arr) + 1)
for i in arr:
temp[i] += 1
for i in range(1,len(temp)):
if(temp[i] == 0):
continue
freq[temp[i]].append(i)
for i in sorted(freq.keys(), reverse=True):
x = freq[i]
x = sorted(x*i)
print(*x, end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int binarySearch( int k,int start,int end) {
int mid = start + (end - start)/2;
if (mid * mid == k) {
return (int) mid;
}
else if ((mid*mid) > end) {
return binarySearch( k, 0, mid - 1);
}
else if ((mid * mid < end)) {
return binarySearch( k, mid + 1, end);
}
else {
mid = (int) Math.sqrt(k);
}
return mid;
}
public static void main (String[] args) throws IOException{
InputStreamReader st = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(st);
int T = Integer.parseInt(br.readLine());
while (T-- > 0) {
int n = Integer.parseInt(br.readLine());
int k = n;
System.out.println(binarySearch( k, 0, n - 1));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
int sqr(int a) {
int A=a;
if(A<2) return A;
ll l=1,r=A;
ll k=1;
while(l<=r)
{
ll mid=(l+r)/2;
ll u=mid*mid;
if(u<=A)
{
k=max(mid,k);
l=mid+1;
}else
{
r=mid-1;
}
}
return k;
}
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
long a;
cin>>a;
long x = sqrt(a);
cout<<x<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: N=int(input())
for i in range(0,N):
M=int(input())
s=M**0.5
print(int(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. The task is to find the square root of N. If N is not a perfect square, then return floor(√N). Try to solve the problem using Binary Search.The first line of input contains the number of test cases T. For each test case, the only line contains the number N.
<b>Constraints:</b>
1 ≤ T ≤ 10000
0 ≤ x ≤ 10<sup>8</sup>For each testcase, print square root of given integer.Sample Input:
2
5
4
Sample Output:
2
2
<b>Explanation:</b.
Testcase 1: Since, 5 is not a perfect square, the floor of square_root of 5 is 2.
Testcase 2: Since 4 is a perfect square, its square root is 2., I have written this Solution Code: // n is the input number
function sqrt(n) {
// write code here
// do not console.log
// return the number
return Math.floor(Math.sqrt(n))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:-
i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P.
next line contains N space separated integers depicting the values of the Arr[].
Constraints:-
3 <= N <= 10<sup>5</sup>
1 <= Arr[i], P <= 10<sup>9</sup>
0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:-
5 4
1 3 2 5 9
Sample Output:-
4
Explanation:-
(1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets
Sample Input:-
5 3
1 8 4 2 9
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 str1 = br.readLine();
String str2[] = str1.split(" ");
int n = Integer.parseInt(str2[0]);
int k = Integer.parseInt(str2[1]);
String str3 = br.readLine();
String str4[] = str3.split(" ");
long[] arr = new long[n];
for(int i = 0; i < n; ++i) {
arr[i] = Long.parseLong(str4[i]);
}
Arrays.sort(arr);
int i=0,j=2;
long ans=0;
while(j!=n){
if(i==j-1){j++;continue;}
if((arr[j]-arr[i])>k){i++;}
else{
int x = j-i;
ans+=(x*(x-1))/2;
j++;
}
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:-
i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P.
next line contains N space separated integers depicting the values of the Arr[].
Constraints:-
3 <= N <= 10<sup>5</sup>
1 <= Arr[i], P <= 10<sup>9</sup>
0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:-
5 4
1 3 2 5 9
Sample Output:-
4
Explanation:-
(1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets
Sample Input:-
5 3
1 8 4 2 9
Sample Output:-
1, I have written this Solution Code: n, p = input().split(' ')
n = int(n)
p = int(p)
arr = input().split(' ')[:n]
for i in range(n):
arr[i] = int(arr[i])
arr.sort()
i = 0
k = 2
count = 0
while k!=n:
if i == k-1:
k = k + 1
continue
if (arr[k] - arr[i]) <= p:
count = count + (int)(((k-i)*(k-i-1))/2)
k = k + 1
else:
i = i + 1
print(count)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:-
i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P.
next line contains N space separated integers depicting the values of the Arr[].
Constraints:-
3 <= N <= 10<sup>5</sup>
1 <= Arr[i], P <= 10<sup>9</sup>
0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:-
5 4
1 3 2 5 9
Sample Output:-
4
Explanation:-
(1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets
Sample Input:-
5 3
1 8 4 2 9
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,p;
cin>>n>>p;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int i=0,j=2;
int ans=0;
while(j!=n){
if(i==j-1){j++;continue;}
if((a[j]-a[i])>p){i++;}
else{
int x = j-i;
ans+=(x*(x-1))/2;
j++;
}
}
cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: static int Multiply(int n, int m)
{
if(n==0 || m==0){return 0;}
if (m == 1)
{ return n;}
return n + Multiply(n,m-1);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<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>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ M, N ≤ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: def multiply_by_recursion(n,m):
# Base Case
if n==0 or m==0:
return 0
# Recursive Case
if m==1:
return n
return n + multiply_by_recursion(n,m-1)
# Driver Code
t=int(input())
while t>0:
l=list(map(int,input().strip().split()))
n=l[0]
m=l[1]
print(multiply_by_recursion(n,m))
t=t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, 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 s1=br.readLine();
int N=s1.length();
int index=0;
int count=0;
for(int i=N-2;i>=0;i--)
{
if(s1.charAt(i)!=s1.charAt(i+1))
{
index=i+1;
break;
}
}
if(index==N-1)
{
if(N%2==0)
{
System.out.print("Sasuke");
}
else{
System.out.print("Naruto");
}
}
else if(index==0)
{
System.out.print("Naruto");
}
else{
for(int i=0;i<index;i++)
{
count++;
}
if(count%2==0)
{
System.out.print("Naruto");
}
else{
System.out.print("Sasuke");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code: binary_string = input()
n = len(binary_string)-1
index = n
for i in range(n-1, -1, -1):
if binary_string[i] == binary_string[n]:
index = i
else:
break
if index % 2 == 0:
print("Naruto")
else:
print("Sasuke"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt[max1];
signed main(){
string s;
cin>>s;
int cnt=0;
FOR(i,s.length()){
if(s[i]=='0'){cnt++;}
}
if(cnt==s.length() || cnt==0){out("Naruto");return 0;}
if(s.length()%2==0){
out("Sasuke");
}
else{
out("Naruto");
}
}
, 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 an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, 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 "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",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 "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
arr=sorted(arr,key=int)
start=0
end=n-1
ans=0
while(start<end):
ans=max(ans,arr[end]+arr[start])
start+=1
end-=1
print (ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ma=0;
for(int i=0;i<n;++i){
ma=max(ma,a[i]+a[n-i-1]);
}
cout<<ma;
#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: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: for i in range(int(input())):
n, x = map(int, input().split())
if x >= 10:
print(0)
else:
print((10-x)*(n-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, 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, x;
cin >> n >> x;
if(x >= 10)
cout << 0 << endl;
else
cout << (10-x)*(n-1) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and X, where N is the number of total patients and X is the time duration (in minutes) after which a new patient arrives. Also, doctor will give only 10 minutes to each patient. The task is to calculate the time (in minutes) the last patient needs to wait.The first line of input contains the number of test cases T.
The next T subsequent lines denote the total number of patients N and time interval X (in minutes) in which the next patients are visiting.
Constraints:
1 <= T <= 100
0 <= N <= 100
0 <= X <= 30Output the waiting time of last patient.Input:
5
4 5
5 3
6 5
7 6
8 2
Output:
15
28
25
24
56, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T -->0){
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int p = Integer.parseInt(s[1]);
if (p<10)
System.out.println(Math.abs(n-1)*(10-p));
else System.out.println(0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: class Solution {
public static int Rare(int n, int k){
while(n>0){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: def Rare(N,K):
while N>0:
if(N%10)%K!=0:
return 0
N=N//10
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Bob applied for a company. There are N rounds of interview. He can predict the result of each rounds based on his skill and type of round. Result of each round was stored in a binary array "results". Where results[ i ] = 1 means he can clear that round otherwise not. For getting selected one has to clear at least ''X" round(s) of interview.
He has to select any K contiguous interview rounds which he wants to appear for. Selection decision will be made based on these rounds. Help bob find whether he can be selected or not.First line will be N, X, K, number of interview rounds, minimum number of interview(s) needed to be cleared for selection, and number of continuous interview Bob is going to appear.
Second line will have N space separated binary digits denoting predicted result of each round.
Constraints:
1 <= X <= K <= N<= 10^5
Output "YES" if he can be selected for X- Company, "NO" otherwise.Input:
8 2 3
1 0 1 1 0 1 0 1
Output:
YES
Explanation :
Bob can appear for round 6, 7 and 8. He can clear 2 out of these three rounds.
Input:
8 3 3
1 0 1 1 0 1 0 1
Output:
NO
Explanation :
There is now way to select 3 interviews, so that bob can clear at least 3 rounds.
, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int N = Integer.parseInt(in.next());
int X = Integer.parseInt(in.next());
int K = Integer.parseInt(in.next());
int a[] = new int[N];
for(int i = 0 ; i < N ; i++){
a[i] = Integer.parseInt(in.next());
}
int sum = 0;
for(int i = 0 ; i < K ; i++){
sum += a[i];
}
Boolean flag = false;
if(sum >= X){
flag = true;
}
for(int i = K ; i < N ; i++){
sum -= a[i - K];
sum += a[i];
if(sum >= X){
flag = true;
}
}
if(flag){
out.println("YES");
}else{
out.println("NO");
}
// for (int i = 1; i <= testCount; i++){
// int n = Integer.parseInt(in.next());
// ArrayList<Integer> a = solver.solve(n);
// for(int j=1 ; j<a.size() ; j++){
// if (((a.get(j) - a.get(j-1)) % j) > 0) {
// out.println("Not Correct");
// break;
// }
// }
// out.println("Correct");
// }
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 ≤ A, B ≤ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n and p. You need to find n raised to the power p.<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>RecursivePower</b> that takes the integer n and p as a parameter.
Constraints:
1 <= T <= 10
1 <= n, p <= 9Return n^p.Sample Input:
3
2 3
9 9
2 9
Sample Output:
8
387420489‬
512
Explanation:
Test case 2: 387420489 is the value obtained when 9 is raised to the power of 9.
Test case 3: 512 is the value obtained when 2 is raised to the power of 9, I have written this Solution Code:
static int Power(int n,int p)
{
if(p==0)
return 1;
return n*Power(n,p-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
StringTokenizer tokens = new StringTokenizer(reader.readLine());
int partitions = 0;
int c0 = 0, c1 = 0;
for(int i = 0; i < N; i++) {
int x = Integer.parseInt(tokens.nextToken());
if(x == 0) {
c0++;
} else {
c1++;
}
if(c0 > 0 || c1 > 0) {
if(c0 == c1) {
partitions++;
c0 = c1 = 0;
}
}
}
if(c1 > 0 || c0 > 0) {
partitions = -1;
}
System.out.println(partitions);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: n = int(input())
a = input().split()
o,z = 0,0
cnt = 0
for i in a:
if i == '1':
o += 1
else:
z +=1
if o == z:
cnt += 1
if o == z:
print(cnt)
else:
print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where each element is either 1 or 0. You have to divide the array into maximum number of subarrays such that each element of the array is in exactly one subarray such that each subarray has equal number of 1's and 0's.First line of input contains N.
Second line of input contains N space separated elements of the array.
Constraints:
1 <= N <= 100000
0 <= elements of the array <= 1Print the single integer which is the maximum number of subarrays the array can be divided into. If it is not possible then print -1.Sample input 1
4
1 0 1 0
Sample output 1
2
Sample input 2
4
1 1 0 0
Sample output 2
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int c=0;
int ans=0;
for(int i=0;i<n;++i){
int x;
cin>>x;
if(x==0)
++c;
else
--c;
if(c==0)
++ans;
}
if(c==0){
cout<<ans;
}else
{
cout<<"-1";
}
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 integer N. You need to print the squares of all numbers from 1 to N in different lines.The only input line contains an integer N.
Constraints:
1 <= N <= 1000Print N lines where the ith line (1-based indexing) contains an integer i<sup>2</sup>.Sample Input 1:
4
Output:
1
4
9
16
Explanation:
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
Sample Input 2:
2
Output:
1
4
Explanation:
1*1 = 1
2*2 = 4, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
print(i**2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N. You need to print the squares of all numbers from 1 to N in different lines.The only input line contains an integer N.
Constraints:
1 <= N <= 1000Print N lines where the ith line (1-based indexing) contains an integer i<sup>2</sup>.Sample Input 1:
4
Output:
1
4
9
16
Explanation:
1*1 = 1
2*2 = 4
3*3 = 9
4*4 = 16
Sample Input 2:
2
Output:
1
4
Explanation:
1*1 = 1
2*2 = 4, I have written this Solution Code: import java.io.*;
import java.util.Scanner;
class Main {
public static void main (String[] args) {
int n;
Scanner s = new Scanner(System.in);
n = s.nextInt();
for(int i=1;i<=n;i++){
System.out.println(i*i);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b. Your task is to find the sum of all the even divisors of each number from a to b inclusive.The input contains two integers a and b.
<b>Constraints:-</b>
1 ≤ a ≤ b ≤ 10<sup>8</sup>Print the sum of even divisors.Sample Input 1:-
1 10
Sample Output 1:-
42
Sample Input 2:-
1 20
Sample Output 2:-
174
<b>Explanation:</b>
Even divisors for 1:- NIL
Even divisors for 2:- 2
Even divisors for 3:- NIL
Even divisors for 4:- 2, 4
Even divisors for 5:- NIL
Even divisors for 6:- 2,6
Even divisors for 7:- NIL
Even divisors for 8:- 2, 4, 8
Even divisors for 9:- NIL
Even divisors for 10:- 2,10
Total :- 2+2+4+2+6+2+4+8+2+10 = 42, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
assert a>=1&&a<=100000000 : "Input not valid";
assert b>=a&&b<=100000000 : "Input not valid";
long ans=0;
for(int i=2;i<=b;i+=2){
int t=b/i;
t-=(a-1)/i;
ans+=t*i;
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b. Your task is to find the sum of all the even divisors of each number from a to b inclusive.The input contains two integers a and b.
<b>Constraints:-</b>
1 ≤ a ≤ b ≤ 10<sup>8</sup>Print the sum of even divisors.Sample Input 1:-
1 10
Sample Output 1:-
42
Sample Input 2:-
1 20
Sample Output 2:-
174
<b>Explanation:</b>
Even divisors for 1:- NIL
Even divisors for 2:- 2
Even divisors for 3:- NIL
Even divisors for 4:- 2, 4
Even divisors for 5:- NIL
Even divisors for 6:- 2,6
Even divisors for 7:- NIL
Even divisors for 8:- 2, 4, 8
Even divisors for 9:- NIL
Even divisors for 10:- 2,10
Total :- 2+2+4+2+6+2+4+8+2+10 = 42, I have written this Solution Code: // #include <bits/stdc++.h>
// using namespace std;
// long long int mod=1e9+7;
// #define inf INT_MAX
// #define f first
// #define s second
// #define psb push_back
// #define ppb pop_back
// #define psf push_front
// #define ppf pop_front
// #define umap unordered_map
// #define uset unordered_set
// typedef long long int ll;
// typedef long double ld;
// typedef pair<int,int> pi;
// typedef pair<long long int,long long int> pll;
// typedef vector<pair<int,int>> vpi;
// typedef vector<pair<long long int,long long int>> vpll;
// typedef vector<int> vi;
// typedef vector<vector<int>> vvi;
// typedef vector<vector<pair<int,int>>> vvpi;
// typedef vector<long long int> vll;
// typedef vector<string> vs;
// typedef vector<vector<long long int>> vvll;
// typedef vector<vector<vector<int>>> vvvi;
// typedef vector<vector<vector<long long int>>> vvvll;
// typedef vector<vector<pair<long long int,long long int>>> vvpll;
// typedef unsigned int ui;
// typedef unsigned long long int ull;
// ll long_max=((unsigned ll)1<<63)-1;
// int int_max=INT_MAX;
// ll powm(ll x,ll y){
// if(x==1||x==0) return x;
// if(y==0) return 1;
// if(y==1) return x;
// ll ans=powm(x,y/2);
// ans=(ans*ans)%mod;
// if(y%2==1){
// ans=(ans*x)%mod;
// }
// return ans;
// }
// vvll matmul(vvll &x,vvll &y){
// int n=x.size();
// vvll ans=x;
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// ans[i][j]=0;
// for(int k=0;k<n;k++){
// ans[i][j]+=x[i][k]*y[k][j];
// ans[i][j]%=mod;
// }
// }
// }
// return ans;
// }
// vvll matexp(vvll &x,ll y){
// // if(x==1||x==0) return x;
// // if(y==0) return 1;
// if(y==1) return x;
// vvll ans=matexp(x,y/2);
// ans=matmul(ans,ans);
// if(y%2==1){
// ans=matmul(ans,x);
// }
// return ans;
// }
// // in O(sqrt(n));
// vll factors(ll a){
// vll ans;
// ll i=1;
// while(i*i<=a){
// if(a%i==0){
// ans.psb(i);
// if(a/i!=i){
// ans.psb(a/i);
// }
// }
// i++;
// }
// sort(ans.begin(),ans.end());
// return ans;
// }
// // enable fac and invfac in main function to use
// // factorial and inverse factorial vectors;
// vll fc,invfc,inv;
// void fac(int n){
// fc.resize(n);
// fc[0]=1;
// for(int i=1;i<n;i++){
// fc[i]=(fc[i-1]*i)%mod;
// }
// }
// void invfac(int n){
// inv.resize(n);
// for(int i=0;i<n;i++){
// inv[i]=powm(i,mod-2);
// }
// invfc.resize(n);
// invfc[0]=1;
// invfc[1]=1;
// for(int i=2;i<n;i++){
// invfc[i]=(invfc[i-1]*inv[i])%mod;
// }
// }
// // enable fac() and invfac() in main function to use c;
// ll ncr(int n,int r){
// if(r>n) return 0;
// return (((fc[n]*invfc[r])%mod)*invfc[n-r])%mod;
// }
// ll npr(int n,int r){
// if(r>n) return 0;
// return ((fc[n]*invfc[n-r])%mod)%mod;
// }
// // enable siv() in main to use vector isprime;
// vi isprime;
// vi prime;
// void siv(int n){
// isprime.assign(n,1);
// isprime[1]=0;
// for(int i=2;i<n;i++){
// if(isprime[i]==0)continue;
// prime.psb(i);
// int j=i;
// while(i*(ll)j<n){
// isprime[i*j]=0;
// j++;
// }
// }
// }
// vi fps;
// void fp_sieve(int n){
// fps.assign(n,0);
// fps[1]=1;
// for(int i=2;i<n;i++){
// if(fps[i]==0){
// fps[i]=i;
// int j=i;
// while(i*(ll)j<n){
// if(fps[i*j]==0)
// fps[i*j]=i;
// j++;
// }
// }
// }
// }
// // enable fp_sieve to use this function and fps vector;
// // prime factorization in O(log(n));
// vpi pmfactors(int t){
// vpi ans;
// // vector using fps vector;
// while(t!=1){
// if(ans.size()==0||ans.back().f!=fps[t]) ans.psb({fps[t],1});
// else ans.back().s++;
// t/=fps[t];
// }
// reverse(ans.begin(),ans.end());
// return ans;
// }
// // prime factorization in O(sqrt(n));
// vpi abs_pmfactors(int t){
// vpi ans;
// int i=2;
// while(i*i<=t){
// if(t%i==0){
// ans.psb({i,0});
// while(t%i==0){
// t/=i;
// ans.back().s++;
// }
// }
// i++;
// }
// if(t!=1) ans.psb({t,1});
// sort(ans.begin(),ans.end());
// return ans;
// }
// ll mystoll(string &a){
// ll ans=0,t=1;
// while(a.size()>0){
// ans=(a.back()-'0')*t+ans;
// t*=10;
// a.pop_back();
// }
// return ans;
// }
// string itos(ll a){
// if(a==0) return "0";
// string ans="";
// bool vd=0;
// if(a<0){
// vd=1;
// a*=-1;
// }
// while(a>0){
// ans=(char)(a%10+'0')+ans;
// a/=10;
// }
// if(vd) ans="-"+ans;
// return ans;
// }
// bool ispal(string &a,int si,int ei){
// // int n=a.size();
// // int si=0,ei=n-1;
// while(si<ei&&a[si]==a[ei]) si++,ei--;
// if(si<ei) return 0;
// return 1;
// }
// ll absncr(ll n,ll k){
// if(k>n) return 0;
// ld ans=1;
// for(int i=1;i<=k;i++){
// ans=ans*(n-k+i)/i;
// ans=floor(ans+0.01);
// ll fns=ans;
// fns%=mod;
// ans=fns;
// }
// return floor(ans+0.01);
// }
// struct llnode{
// int val;
// llnode* next;
// llnode(int val){
// this->val=val;
// next=0;
// }
// ~llnode(){
// delete this->next;
// }
// };
// struct node{
// ll f,s,v;
// node(){};
// node(ll x,ll y,ll t):f(x),s(y),v(t){}
// };
// // vpi a;
// // struct mncomp{
// // bool operator()(const int &x,const int &y) const{
// // if(a[x].s>a[y].s) return 1;
// // else if(a[x].s<a[y].s) return 0;
// // else return a[x].f<a[y].f;
// // }
// // };
// // struct mxcomp{
// // bool operator()(const int &x,const int &y) const{
// // if(a[x][1]<a[y][1]) return 1;
// // else if(a[x][1]>a[y][1]) return 0;
// // else return a[x][2]>a[y][2];
// // }
// // };
// struct bstcomp{
// bool operator()(const pll &x,const pll &y) const{
// if(x.f<y.f) return 1;
// if(x.f>y.f) return 0;
// return x.s<y.s;
// // return 0;
// }
// };
// struct comp{
// bool operator()(const pll &x,const pll &y) const{
// if(x.f<y.f) return 1;
// // if(x.f<y.f) return 0;
// // return x.s<y.s;
// return 0;
// }
// };
// // // int n,m;
// vvi ed,up;
// vi vd;
// // // vi x,pt,rs;
// // // vll val,vd,ct,sum,pt,dt;
// // // vpi dpg,dpb;
// void dfs(int curr,int pnt){
// // up[curr][0]=pnt;
// // int i=1;
// // while(up[curr][i-1]!=-1){
// // up[curr][i]=up[up[curr][i-1]][i-1];
// // i++;
// // if(i>up[0].size())break;
// // }
// // dt[curr]=dpt;
// for(int i=0;i<ed[curr].size();i++){
// int cd=ed[curr][i];
// int vl=up[curr][i];
// if(cd==pnt) continue;
// if(vl==0){
// vd.psb(cd);
// }
// // cout<<"ff";
// dfs(cd,curr);
// }
// }
// /******************** code starts from here ***************************/
// void solve(){
// }
// // C:\Users\my\AppData\Roaming\Sublime Text 3\Packages\User
// int main(){
// // #ifndef ONLINE_JUDGE
// // // for getting input from input.txt
// // freopen("input.txt", "r", stdin);
// // // for writing output to output.txt
// // freopen("output.txt", "w", stdout);
// // #endif
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// // fac(1e6+1);
// // invfac(1e6+1);
// // siv(1e5+1);
// // fp_sieve(2e5+1);
// // for(int i=1;i<=3000;i++){
// // string x;
// // ll f=fun(i,x);
// // mp[i][x]=f;
// // }
// int t=1;
// cin>>t;
// int ct=1;
// while(t--){
// // cout<<"Case #"<<ct++<<": ";
// solve();
// }
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
#define int long long
int solve(int a,int b){
int ans=0;
for(int i=2;i<=b;i+=2){
int t=b/i;
t-=(a-1)/i;
ans+=t*i;
}
return ans;
}
signed main(){
int t;
t=1;
while(t--){
int a,b;
cin>>a>>b;
int ans = solve(a,b);
cout<<ans<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a set of positive integers. Find the maximum xor of a non-empty subset from the given set.The first line contains an integer N denoting the number of elements in the set.
The next line contains N integers denoting the elements of the set.
1 <= N <= 10^5
1 <= Elements of set <= 10^9Print the maximum subset Xor.Sample Input:
3
2 4 5
Sample Output:
7
Explanation:
Subset {2, 5} has the maximum xor
Sample Input:
3
9 8 5
Sample Output:
13
Explanation:
Subset {8, 5} has the maximum xor, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static final int INT_BITS = 32;
static int findMaxxor(int[] arr, int n){
int index = 0;
for (int i = INT_BITS - 1; i >= 0; i--)
{
int maxInd = index;
int maxEle = Integer.MIN_VALUE;
for (int j = index; j < n; j++) {
if ((arr[j] & (1 << i)) != 0 && arr[j] > maxEle)
{
maxEle = arr[j];
maxInd = j;
}
}
if (maxEle == -2147483648)
continue;
int temp = arr[index];
arr[index] = arr[maxInd];
arr[maxInd] = temp;
maxInd = index;
for (int j = 0; j < n; j++) {
if (j != maxInd && (arr[j] & (1 << i)) != 0)
arr[j] = arr[j] ^ arr[maxInd];
}
index++;
}
int res = 0;
for (int i = 0; i < n; i++)
res ^= arr[i];
return res;
}
public static void main (String[] args) throws Exception{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
int n = Integer.parseInt(br.readLine());
String[] sval = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i]=Integer.parseInt(sval[i]);
System.out.print(findMaxxor(arr,n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a set of positive integers. Find the maximum xor of a non-empty subset from the given set.The first line contains an integer N denoting the number of elements in the set.
The next line contains N integers denoting the elements of the set.
1 <= N <= 10^5
1 <= Elements of set <= 10^9Print the maximum subset Xor.Sample Input:
3
2 4 5
Sample Output:
7
Explanation:
Subset {2, 5} has the maximum xor
Sample Input:
3
9 8 5
Sample Output:
13
Explanation:
Subset {8, 5} has the maximum xor, I have written this Solution Code: INT_BITS=32
def maxSubarrayXOR(set,n):
index = 0
for i in range(INT_BITS-1,-1,-1):
maxInd = index
maxEle = -2147483648
for j in range(index,n):
if ( (set[j] & (1 << i)) != 0
and set[j] > maxEle ):
maxEle = set[j]
maxInd = j
if (maxEle ==-2147483648):
continue
temp=set[index]
set[index]=set[maxInd]
set[maxInd]=temp
maxInd = index
for j in range(n):
if (j != maxInd and
(set[j] & (1 << i)) != 0):
set[j] = set[j] ^ set[maxInd]
index=index + 1
res = 0
for i in range(n):
res =res ^ set[i]
return res
n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
print (maxSubarrayXOR(arr,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a set of positive integers. Find the maximum xor of a non-empty subset from the given set.The first line contains an integer N denoting the number of elements in the set.
The next line contains N integers denoting the elements of the set.
1 <= N <= 10^5
1 <= Elements of set <= 10^9Print the maximum subset Xor.Sample Input:
3
2 4 5
Sample Output:
7
Explanation:
Subset {2, 5} has the maximum xor
Sample Input:
3
9 8 5
Sample Output:
13
Explanation:
Subset {8, 5} has the maximum xor, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
int maxsubaXor(int n)
{
int index = 0;
for (int i = 31; i >= 0; i--)
{
int maxInd = index;
int maxEle = INT_MIN;
for (int j = index; j < n; j++)
{
if ( (a[j] & (1 << i)) != 0
&& a[j] > maxEle )
maxEle = a[j], maxInd = j;
}
if (maxEle == INT_MIN)
continue;
swap(a[index], a[maxInd]);
maxInd = index;
for (int j=0; j<n; j++)
{
if (j != maxInd &&
(a[j] & (1 << i)) != 0)
a[j] = a[j] ^ a[maxInd];
}
index++;
}
int res = 0;
for (int i = 0; i < n; i++)
res ^= a[i];
return res;
}
void solve(){
int n; cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
cout << maxsubaXor(n) << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice.
Given a number on one face of the dice , you need to print the number on the opposite face .
NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N.
Constraints:
1 <= T <= 100
1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input:
2
6
2
Output:
1
5
Explanation:
Testcase 1: For dice facing number 6 opposite face will have the number 1., I have written this Solution Code: def get_opposite_face(n):
return 7-n
t = int(input())
for n in range(t):
print(get_opposite_face(int(input()))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice.
Given a number on one face of the dice , you need to print the number on the opposite face .
NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N.
Constraints:
1 <= T <= 100
1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input:
2
6
2
Output:
1
5
Explanation:
Testcase 1: For dice facing number 6 opposite face will have the number 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;
cout << 7-n << endl;
}
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 cubic dice with 6 faces. All the individual faces have a numbers printed on them. The numbers are in the range of 1 to 6, like any ordinary dice.
Given a number on one face of the dice , you need to print the number on the opposite face .
NOTE : In a normal dice sum of numbers on opposite faces is 7 .The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each test case contains a single line of the input containing a positive integer N.
Constraints:
1 <= T <= 100
1 <= N <= 6For each testcase, print the number that is on the opposite side of the given face.Input:
2
6
2
Output:
1
5
Explanation:
Testcase 1: For dice facing number 6 opposite face will have the number 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));
int t=Integer.parseInt(br.readLine());
while(t-->0){
int n=Integer.parseInt(br.readLine());
System.out.println(6-n+1);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute volume of water it is able to trap after raining.
Please refer to Sample test case for more details.The first line of input contains the size of the array, n
The following line of input contains n space-separated integers
Constraints:-
1 <= n <= 50000
0<=A[i]<=10<sup>10</sup>The first and only line of output contains integer, in accordance to the task.Sample Input:
6
3 0 0 2 0 4
Sample Output:
10, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader y = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(y.readLine());
String [] z = y.readLine().split(" ");
long max = 0;
long sum = 0;
int si = 0;
int ei = 0;
for (int i=0;i<n;i++){
long num = Long.parseLong(z[i]);
if (max==0 && num!=0){
max=num;
si=i;
}else if (num>=max){
ei=i;
sum+=count(z,si,ei);
si=i;
max=num;
}
}
while (si<n-1){
ei=findmax(z,si+1,n);
sum+=count(z,si,ei);
si=ei;
}
System.out.println(sum);
}
public static long count(String z[], int si, int ei){
long num = Math.min(Long.parseLong(z[si]),Long.parseLong(z[ei]));
si++;
long count=0;
for (int i=si;i<ei;i++){
count+=(num-Long.parseLong(z[i]));
}
return count;
}
public static int findmax(String z[], int si, int n){
long max = Long.parseLong(z[si]);
int ind = si;
for (int i=si;i<n;i++){
if (max<=Long.parseLong(z[i])){
max=Long.parseLong(z[i]);
ind = i;
}
}
return ind;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute volume of water it is able to trap after raining.
Please refer to Sample test case for more details.The first line of input contains the size of the array, n
The following line of input contains n space-separated integers
Constraints:-
1 <= n <= 50000
0<=A[i]<=10<sup>10</sup>The first and only line of output contains integer, in accordance to the task.Sample Input:
6
3 0 0 2 0 4
Sample Output:
10, I have written this Solution Code: def water(a,n):
leftmin=0
rightmax=0
lo=0
hi=n-1
result=0
while(lo<=hi):
if a[lo]<a[hi]:
if a[lo]<leftmin:
result+=leftmin-a[lo]
lo+=1
else:
leftmin=a[lo]
lo=lo+1
else:
if a[hi]>rightmax:
rightmax=a[hi]
else:
result+=rightmax-a[hi]
hi-=1
return result
n=int(input())
b=list(input().split(" "))
a=[]
for i in b:
if i.isnumeric():
a.append(int(i))
print(water(a,n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute volume of water it is able to trap after raining.
Please refer to Sample test case for more details.The first line of input contains the size of the array, n
The following line of input contains n space-separated integers
Constraints:-
1 <= n <= 50000
0<=A[i]<=10<sup>10</sup>The first and only line of output contains integer, in accordance to the task.Sample Input:
6
3 0 0 2 0 4
Sample Output:
10, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], l[N], r[N], ans;
signed main() {
IOS;
int n; cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
l[i] = max(l[i-1], a[i]);
}
for(int i = n; i >= 1; i--)
r[i] = max(r[i+1], a[i]);
for(int i = 1; i <= n; i++)
ans += (min(l[i], r[i]) - a[i]);
cout << ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: static int LastDigit(int N){
return N%10;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.