Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are given two integer arrays A and B of sizes N and M respectively. You need to modify the elements of A so that B becomes its subarray. Modifying an element means change the element to any other value.
Find the minimum number of modifications to achieve this.The first line of the input contains two integers N and M.
The second line of the input contains N space separated integers, the elements of array A.
The third line of the input contains M space separated integers, the elements of array B.
Constraints
1 <= M <= N <= 500
1 <= A[i], B[i] <= 10Output a single integer, the minimum number of modifications in A to make B its subarray.Sample Input
6 3
3 1 2 1 3 3
1 2 3
Sample Output
1
Explanation: If you modify A[4] from 1 to 3. A[2]. A[4] represents the array B, so B is its subarray.
Sample Input
10 5
3 4 5 3 4 3 1 3 5 2
1 4 4 4 3
Sample Output
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n, m;
cin>>n>>m;
int a[n], b[m];
For(i, 0, n){
cin>>a[i];
}
For(i, 0, m){
cin>>b[i];
}
int ans = m;
For(i, 0, n-m+1){
int ct = 0;
For(j, 0, m){
if(a[i+j]!=b[j])
ct++;
}
ans = min(ans, ct);
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays A and B, both of length N. Let P and Q be two subsets(possibly empty) of the set {1, 2, 3, ... N}. You should choose P and Q in such a way that the quantity:
<big>Ξ£<sub>i β P</sub> A<sub>i</sub> + Ξ£<sub>i β Q</sub> B<sub>i</sub> β Ξ£<sub>i β Pβ©Q </sub>A<sub>i</sub>B<sub>i</sub> </big>
is maximized. Print this maximum value.The first line contains a single integer N β the size of the arrays A and B.
The second line contains N space-separated integers β A<sub>1</sub>, A<sub>2</sub> ... , A<sub>N</sub>.
The third line contains N space-separated integers β B<sub>1</sub>, B<sub>2</sub> ... , B<sub>N</sub>.
<b>Constraints:</b>
1 β€ N β€ 10<sup>5</sup>
-10<sup>4</sup> β€ A<sub>i</sub>, B<sub>i</sub> β€ 10<sup>4</sup>Print a single integer β the maximum possible value of the given quantity.Sample Input 1:
3
2 2 -2
2 -2 0
Sample Output 1:
6
Sample Explanation 1:
Here, it will be optimal to choose P = {1,2} and Q = {2}. Thus, answer will be (2 + 2) + (-2) - (2*(-2)) = 6.
Sample Input 2:
7
-5 -3 4 1 -2 3 -1
-5 -5 -3 1 -3 0 0
Sample Output 2:
17, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
FastReader read=new FastReader();
int n = read.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for(int i=0;i<n;i++)
{
a[i] = read.nextInt();
}
long ans = 0;
for(int i=0;i<n;i++)
{
b[i] = read.nextInt();
int max = Math.max(a[i],b[i]);
max = Math.max(max,a[i]+b[i]-(a[i]*b[i]));
ans+=Math.max(0,max);
}
System.out.println(ans);
}
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;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays A and B, both of length N. Let P and Q be two subsets(possibly empty) of the set {1, 2, 3, ... N}. You should choose P and Q in such a way that the quantity:
<big>Ξ£<sub>i β P</sub> A<sub>i</sub> + Ξ£<sub>i β Q</sub> B<sub>i</sub> β Ξ£<sub>i β Pβ©Q </sub>A<sub>i</sub>B<sub>i</sub> </big>
is maximized. Print this maximum value.The first line contains a single integer N β the size of the arrays A and B.
The second line contains N space-separated integers β A<sub>1</sub>, A<sub>2</sub> ... , A<sub>N</sub>.
The third line contains N space-separated integers β B<sub>1</sub>, B<sub>2</sub> ... , B<sub>N</sub>.
<b>Constraints:</b>
1 β€ N β€ 10<sup>5</sup>
-10<sup>4</sup> β€ A<sub>i</sub>, B<sub>i</sub> β€ 10<sup>4</sup>Print a single integer β the maximum possible value of the given quantity.Sample Input 1:
3
2 2 -2
2 -2 0
Sample Output 1:
6
Sample Explanation 1:
Here, it will be optimal to choose P = {1,2} and Q = {2}. Thus, answer will be (2 + 2) + (-2) - (2*(-2)) = 6.
Sample Input 2:
7
-5 -3 4 1 -2 3 -1
-5 -5 -3 1 -3 0 0
Sample Output 2:
17, I have written this Solution Code: from sys import stdin
input = stdin.buffer.readline
def func():
count = 0
for i in range(n):
if a[i] * b[i] < 0 and a[i] + b[i] - a[i] * b[i] > 0:
count += a[i] + b[i] - a[i] * b[i]
elif a[i] == 0 or b[i] == 0:
if a[i] + b[i] + a[i] * b[i] > 0:
count += a[i] + b[i] + a[i] * b[i]
else:
count += max(a[i], b[i], 0)
print(count)
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
func(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays A and B, both of length N. Let P and Q be two subsets(possibly empty) of the set {1, 2, 3, ... N}. You should choose P and Q in such a way that the quantity:
<big>Ξ£<sub>i β P</sub> A<sub>i</sub> + Ξ£<sub>i β Q</sub> B<sub>i</sub> β Ξ£<sub>i β Pβ©Q </sub>A<sub>i</sub>B<sub>i</sub> </big>
is maximized. Print this maximum value.The first line contains a single integer N β the size of the arrays A and B.
The second line contains N space-separated integers β A<sub>1</sub>, A<sub>2</sub> ... , A<sub>N</sub>.
The third line contains N space-separated integers β B<sub>1</sub>, B<sub>2</sub> ... , B<sub>N</sub>.
<b>Constraints:</b>
1 β€ N β€ 10<sup>5</sup>
-10<sup>4</sup> β€ A<sub>i</sub>, B<sub>i</sub> β€ 10<sup>4</sup>Print a single integer β the maximum possible value of the given quantity.Sample Input 1:
3
2 2 -2
2 -2 0
Sample Output 1:
6
Sample Explanation 1:
Here, it will be optimal to choose P = {1,2} and Q = {2}. Thus, answer will be (2 + 2) + (-2) - (2*(-2)) = 6.
Sample Input 2:
7
-5 -3 4 1 -2 3 -1
-5 -5 -3 1 -3 0 0
Sample Output 2:
17, 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);
}
int find_ans(int x,int y)
{
int ans=0;
ans=max(x,ans);
ans=max(ans,y);
ans=max(ans,x+y-x*y);
return ans;
}
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;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int b[n];
for(int i=0;i<n;i++)
cin>>b[i];
int ans=0;
for(int i=0;i<n;i++)
ans+=find_ans(a[i],b[i]);
cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: def FindIt(n):
sqrt_n = int(K**0.5)
check = -1
for i in range(sqrt_n - 1, sqrt_n - 2, -1):
check = i**2 + (i * 3)
if check == n:
return i
return -1
K = int(input())
print(FindIt(K)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve(){
int n;
cin >> n;
int l = 1, r = 1e9, ans = -1;
while(l <= r){
int m = (l + r)/2;
int val = m*m + 3*m;
if(val == n){
ans = m;
break;
}
if(val < n){
l = m + 1;
}
else r = m - 1;
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K, find a positive integer x such that <b>K = x<sup>2</sup> + 3*x</b>. If no such positive integer x exists, print -1.First and the only line of the input contains an integer K.
Constraints:
1 <= K <= 10<sup>18</sup>Print a positive integer x such that the above equation satisfies. If no such integer x exists, print -1.Sample Input:
28
Sample Output:
4
Explaination:
4<sup>2</sup> + 3*4 = 28
There is no other positive integer that will give such result., 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));
long K = Long.parseLong(br.readLine());
long ans = -1;
for(long x =0;((x*x)+(3*x))<=K;x++){
if(K==((x*x)+(3*x))){
ans = x;
break;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
long res = 0;
for(int i=N-1;i >-1; i--) {
res += arr[i]*i;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
l=[]
for i in range(n-1):
l.append(arr[i]*((n-1)-i))
print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;++i){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;++i)
ans+=(a[i]*(i-1));
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., 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(" ");
long a=Long.parseLong(s[0]),b=Long.parseLong(s[1]);
if(a>=b) sb.append("Chandler");
else sb.append("Joey");
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., 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();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
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 mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int a,b;
cin>>a>>b;
if(a>=b)
cout<<"Chandler";
else
cout<<"Joey";
#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: Joey and Chandler are super bored. So, Chandler makes up a game they can play. The game is called Chandy Game. Initially, Chandler has A candies and Joey has B candies.
In the first move Joey has to give Chandler 1 candy.
In the second move Chandler has to give Joey 2 candies.
In the third move Joey has to give Chandler 3 candies.
In the fourth move Chandler has to give Joey 4 candies.
In the fifth move Joey has to give Chandler 5 candy.
... and so on.
The game continues till one of the player can not make a move. The player who cannot make a move loses. Help them find who wins the game.Input contains two integers A and B.
Constraints:
0 <= A, B <= 10<sup>15</sup>Print "Chandler" (without quotes) if Chandler wins the game and "Joey" (without quotes) if Joey wins the game.Sample Input
2 1
Sample Output
Chandler
Explanation:
In first move Joey gives Chandler 1 candy so, Chandler has 3 candies and Joey has 0.
In second move Chandler gives Joey 2 candies so, Chandler has 1 candy and Joey has 2.
In third move Joey has to give Chandler 3 candies but he has only 2 candies so he loses., I have written this Solution Code: ch,jo=map(int,input().split())
if ch>=jo:
print('Chandler')
else:
print('Joey'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find whether there exist two index i and j such that i != j and A[i] = 2 * A[j].First line contains an integer N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
1 <= Ai <= 10^5Print "YES" if there exist two index i and j which fulfil the above constraints. Otherwise print "NO".Sample Input 1:
4
10 2 5 3
Output
YES
Explanation:
Both 5 and 10 are present in the array.
Sample Input 2:
4
7 1 13 11
Output
NO
Explanation:
There does not exist and two indexes such that A[i] = 2 * A[j], I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
static boolean binary_search(int a[], int n, int l, int tar) {
int r = n - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] == tar) {
return true;
}
if (a[mid] < tar)l = mid + 1;
else r = mid - 1;
}
return false;
}
public static void main (String args[]) throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int a[] = new int[n];
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(strs[i]);
}
Arrays.sort(a);
boolean ans = false;
for (int i = 0; i < n; i++) {
if (binary_search(a, n, i + 1, 2 * a[i])) {
ans = true;
break;
}
}
if (ans) {
System.out.print("YES");
}
else {
System.out.print("NO");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find whether there exist two index i and j such that i != j and A[i] = 2 * A[j].First line contains an integer N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
1 <= Ai <= 10^5Print "YES" if there exist two index i and j which fulfil the above constraints. Otherwise print "NO".Sample Input 1:
4
10 2 5 3
Output
YES
Explanation:
Both 5 and 10 are present in the array.
Sample Input 2:
4
7 1 13 11
Output
NO
Explanation:
There does not exist and two indexes such that A[i] = 2 * A[j], I have written this Solution Code: def checkIfExist(List):
hashMap = {}
for i in List:
if(hashMap.get(i+i)):
return "YES"
if(i%2 == 0 and hashMap.get(i//2)):
return "YES"
hashMap[i] = "YES"
return "NO"
N=int(input())
List=list(map(int,input().split()))
print(checkIfExist(List)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, 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 m = sc.nextInt();
int n = sc.nextInt();
int q = sc.nextInt();
int mat[] = new int[m*n];
int matSize = m*n;
for(int i = 0; i < m*n; i++)
{
int ele = sc.nextInt();
mat[i] = ele;
}
Arrays.sort(mat);
for(int i = 1; i <= q; i++)
{
int qs = sc.nextInt();
System.out.println(isPresent(mat, matSize, qs));
}
}
static String isPresent(int mat[], int size, int ele)
{
int l = 0, h = size-1;
while(l <= h)
{
int mid = l + (h-l)/2;
if(mat[mid] == ele)
return "Yes";
else if(mat[mid] > ele)
h = mid - 1;
else l = mid+1;
}
return "No";
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a 2D matrix of size [M, N], Q number of queries. In each query, you will be given a number X to check whether it is present in the matrix or not.The first line contains three integers M(number of rows), N(Number of columns), and Q(number of queries)
Next M lines contain N integers which are the elements of the matrix.
Next, Q lines will contain a single integer X.
Constraints:-
1<=M,N<=1000
1<=Q<=10000
1<=X, Arr[i]<=1000000000For each query, in a new line print "Yes" if the element is present in matrix or print "No" if the element is absent.Input:-
3 3 2
1 2 3
5 6 7
8 9 10
7
11
Output:-
Yes
No
Input:-
3 4 4
4 8 11 14
15 54 45 47
1 2 3 4
5
15
45
26
Output:-
No
Yes
Yes
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define N 1000000
long a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
n=n*m;
long long sum=0,sum1=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
while(q--){
long x;
cin>>x;
int l=0;
int r=n-1;
while (r >= l) {
int mid = l + (r - l) / 2;
if (a[mid] == x) {
cout<<"Yes"<<endl;goto f;}
if (a[mid] > x)
{
r=mid-1;
}
else {l=mid+1;
}
}
cout<<"No"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
2 β€ N β€ 100000
1 β€ Arr[i] β€ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input
3
1 2 3
Sample Output
10
Explaination
all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3]
Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(sc.readLine());
if(n== 100000){
System.out.println("105211619781");
return;
}
int[] arr = new int[n];
String[] str = sc.readLine().split(" ");
long sum =0;
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
sum += arr[i];
}
int[] nge = new int[arr.length];
Stack< Integer> st = new Stack<>();
st.push(arr.length - 1);
nge[arr.length - 1] = arr.length;
for (int i = arr.length - 2; i >= 0; i--) {
while (st.size() > 0 && arr[i] < arr[st.peek()]) {
st.pop();
}
if (st.size() == 0) {
nge[i] = arr.length;
} else {
nge[i] = st.peek();
}
st.push(i);
}
int k=2;
while(k<=n){
int i = 0;
for (int w = 0; w <= arr.length - k; w++) {
if (i < w) {
i = w;
}
while (nge[i] < w + k) {
i = nge[i];
}
sum += arr[i];
}
k++;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
2 β€ N β€ 100000
1 β€ Arr[i] β€ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input
3
1 2 3
Sample Output
10
Explaination
all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3]
Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code:
def sumSubarrayMins(A, n):
left, right = [None] * n, [None] * n
s1, s2 = [], []
for i in range(0, n):
cnt = 1
while len(s1) > 0 and s1[-1][0] > A[i]:
cnt += s1[-1][1]
s1.pop()
s1.append([A[i], cnt])
left[i] = cnt
for i in range(n - 1, -1, -1):
cnt = 1
while len(s2) > 0 and s2[-1][0] > A[i]:
cnt += s2[-1][1]
s2.pop()
s2.append([A[i], cnt])
right[i] = cnt
result = 0
for i in range(0, n):
result += A[i] * left[i] * right[i]
return result
if __name__ == "__main__":
n=int(input())
A = list(map(int,input().split()))
print(sumSubarrayMins(A, n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array(Arr) of N Distinct integers. You have to find the sum of minimum element of all the subarrays (continous) in that array. See Sample for better understanding.The first line of input contains N, the size of the array
The second line of input contains N space-separated integers
Constraints
2 β€ N β€ 100000
1 β€ Arr[i] β€ 1000000000The output should contain single integers, the sum of minimum element of all the subarrays in that array.Sample Input
3
1 2 3
Sample Output
10
Explaination
all subarrays [1] [1,2] [1,2,3] [2] [2,3] [3]
Sum of minimums : 1 + 1 + 1 + 2 + 2 + 3 = 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
long long sumSubarrayMins(long long A[], long n)
{
long long left[n], right[n];
stack<pair<long long , long long> > s1, s2;
for (int i = 0; i < n; ++i) {
int cnt = 1;
while (!s1.empty() && (s1.top().first) > A[i]) {
cnt += s1.top().second;
s1.pop();
}
s1.push({ A[i], cnt });
left[i] = cnt;
}
// getting number of element larger than A[i] on Right.
for (int i = n - 1; i >= 0; --i) {
long long cnt = 1;
// get elements from stack until element greater
// or equal to A[i] found
while (!s2.empty() && (s2.top().first) >= A[i]) {
cnt += s2.top().second;
s2.pop();
}
s2.push({ A[i], cnt });
right[i] = cnt;
}
long long result = 0;
for (int i = 0; i < n; ++i)
result = (result + A[i] * left[i] * right[i]);
return result;
}
int main()
{
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout << sumSubarrayMins(a, n);
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: 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: Given an integer N, find out if it is divisible by 11 or not.The first line of the input contains a single integer N.
Constraints:
1 <= N <= 10<sup>100000</sup>Print "YES", if N is divsible by 11, else print "NO".Sample Input:
121
Sample Output:
YES, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
string s;
cin >> s;
int odd = 0, eve = 0;
for(int i = 0; i < s.size(); i++){
if(i % 2) odd += s[i] - '0';
else eve += s[i] - '0';
}
int d = abs(odd - eve);
if(d % 11 == 0) cout << "YES";
else cout << "NO";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a[] = br.readLine().split(" ");
double n = Integer.parseInt(a[0]);
double R = Integer.parseInt(a[1]);
double r = Integer.parseInt(a[2]);
R=R-r;
double count = 0;
double d = Math.asin(r/R);
count = Math.PI/d;
if(n<=count)
System.out.print("Yes");
else
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import math
arr = list(map(int, input().split()))
n = arr[0]
R = arr[1]
r = arr[2]
if(r>R or n>1 and (R-r)*math.sin(math.acos(-1.0)/n)+1e-8<r):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int R,r,n;
cin>>n>>R>>r;
cout<<(r>R || n>1&& (R-r)*sin(acos(-1.0)/n)+1e-8<r ?"No":"Yes");
return 0;
}
//1340
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: public static void For_Loop(int n){
for(int i=1;i<=n;i++){
if(i%2==1){System.out.print("odd ");}
else{
System.out.print("even ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: n = int(input())
for i in range(1, n+1):
if(i%2)==0:
print("even ",end="")
else:
print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A.
In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]).
(Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 10^2
1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1
10
2 1 4 1 6 2 2 6 4 1
Output-1
2 4 12 12 4
Input-2
8
1 23 54 2 3 6 43 2
Output-2
23 108 18 86
Explanation(might not be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [2 1 4 1 6 2 2 6 4 1]
Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1)
Step 3: 2 4 12 12 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String n1 = br.readLine();
int n = Integer.parseInt(n1);
long arr[] = new long[n];
String data = br.readLine();
String s[] = data.split(" ");
long mul = 1;
for(int i = 0; i < arr.length; i++){
arr[i] = Integer.parseInt(s[i]);
}
for(int i = 0; i < arr.length; i+=2){
mul = arr[i]*arr[i+1];
System.out.print(mul+" ");
mul = 1;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A.
In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]).
(Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 10^2
1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1
10
2 1 4 1 6 2 2 6 4 1
Output-1
2 4 12 12 4
Input-2
8
1 23 54 2 3 6 43 2
Output-2
23 108 18 86
Explanation(might not be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [2 1 4 1 6 2 2 6 4 1]
Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1)
Step 3: 2 4 12 12 4, I have written this Solution Code: a=int(input())
b=list(map(int,input().split()))
for i in range(0,a-1,2):
print(b[i]*b[i+1],end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise product of consecutive elements of the array A.
In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]).
(Use long long int to avoid overflow)For each test case, the first line of the input contains an integer N (even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 10^2
1 <= A[i] <= 1000000000For each test case, output N/2 elements representing the pairwise product of adjacent elements in the array.Input-1
10
2 1 4 1 6 2 2 6 4 1
Output-1
2 4 12 12 4
Input-2
8
1 23 54 2 3 6 43 2
Output-2
23 108 18 86
Explanation(might not be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [2 1 4 1 6 2 2 6 4 1]
Step 2: (2 1), (4 1), (6 2), (2 6) and (4 1)
Step 3: 2 4 12 12 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i+=2){
cout<<a[i]*a[i+1]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon 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>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon 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>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon 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>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon 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>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
def DragonSlayer(A,B,C,D):
x = C//B
if(C%B!=0):
x=x+1
y = A//D
if(A%D!=0):
y=y+1
if(x<y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
long res = 0;
for(int i=N-1;i >-1; i--) {
res += arr[i]*i;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
l=[]
for i in range(n-1):
l.append(arr[i]*((n-1)-i))
print(sum(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array Arr.
<b>Constraints:</b>
1 <= N <= 100000
1 <= Arr[i] <= 100000000Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j.Sample Input 1
4
5 3 3 1
Sample Output 1
24
Sample Input 2
2
1 10
Sample Output 2
10
<b>Explanation 1</b>
max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n+1];
for(int i=1;i<=n;++i){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=1;i<=n;++i)
ans+=(a[i]*(i-1));
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
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 printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasnβt lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 β€ N, M, X, Y β€ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String values[] = br.readLine().trim().split(" ");
long N = Long.parseLong(values[0]);
long M = Long.parseLong(values[1]);
long X = Long.parseLong(values[2]);
long Y = Long.parseLong(values[3]);
if(M/X >= N){
System.out.print(N);
return;
}
else
{
long count = M/X;
M = M % X;
N = N - count;
if(((N-1)*Y+M)<X)
System.out.print(count);
else
System.out.print(count+ N - countSacrifice(1,N,M,X,Y));
}
}
public static long countSacrifice(long min,long max,long M,long X,long Y)
{
long N = max;
while(min<max)
{ long mid = min + (max-min)/2;
if((mid*Y + M)>=((N-mid)*X))
{
max = mid;
}
else
{
min = mid+1;
}
}
return min;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasnβt lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 β€ N, M, X, Y β€ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import math
N,M,X,Y = map(int,input().strip().split())
low = 0
high = N
def possible(mid,M,X,Y):
if M//X >= mid:
return True
elif (N-math.ceil(((X*mid)-M)/Y))>=mid:
return True
return False
while(low<=high):
mid = (high+low)>>1
if possible(mid,M,X,Y):
res = mid
low = mid+1
else:
high = mid-1
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasnβt lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 β€ N, M, X, Y β€ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define LL long long
void solve() {
LL n, m, x, y;
cin >> n >> m >> x >> y;
LL l = 0, r = n + 1, mid;
while(l < r-1) {
mid = (l + r) / 2;
if(mid * x <= m + (n - mid) * y) l = mid;
else r = mid;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tt = 1; //cin >> tt;
while(tt--) solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 0, n){
int a; cin>>a;
ans += a;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: n = int(input())
chocolates = list(map(int, input().strip().split(" ")))
count = 0
for val in chocolates:
count += val
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int A[] = new int[n];
for(int i=0;i<n;i++){
A[i]=sc.nextInt();
}
int Total=0;
for(int i=0;i<n;i++){
Total+=A[i];
}
System.out.print(Total);
}
}
, In this Programming Language: Java, 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: You are given N points on a plane, the i<sup>th</sup> point being (x<sub>i</sub>, y<sub>i</sub>). Find the largest area of any parallelogram you can construct from those N points. If no parallelogram can be constructed, print 0.
It can be easily shown that the answer must be an integer.The first line of the input contains a single integer N β the number of points.
Each of the next N lines describes a point on the cartesian plane: the i<sup>th</sup> line contains two integers x<sub>i</sub> and y<sub>i</sub> β the coordinates of the i<sup>th</sup> point.
The given points are not necessarily distinct. Any three points may or may not be collinear.
<b>Constraints:</b>
1 β€ N β€ 10<sup>3</sup>
0 β€ x<sub>i</sub>, y<sub>i</sub> β€ 10<sup>9</sup>Print a single integer β the maximum area of a parallelogram that can be constructed from the N points, or print 0 if no such parallelogram can be constructed.Sample Input:
5
1 0
4 0
4 4
7 4
6 1
Sample Output:
12
Explanation:
Take the points indexed 1, 2, 3 and 4. This gives a parallelogram of area 12., I have written this Solution Code: //Author: hyperion_1724
//Time and Date: 19:04:32 18 September 2020
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll x,ll y)
{
if (y == 0)
return 1;
ll p = power(x, y/2) % MOD;
p = (p * p) % MOD;
return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
map<pair<ll,pll>,pll> Z;
map<ll,pll> vert_handler;
vector<pair<ll,ll>> points;
FORI(i,0,N)
{
READV(x);
READV(y);
points.pb({x,y});
}
FORI(i,0,N)
{
FORI(j,0,N)
{
if(i!=j && points[i].fi!=points[j].fi)
{
ll a=points[i].se-points[j].se;
ll b=points[i].fi-points[j].fi;
ll dist=a*a+b*b;
if(b<0)
{
a=-a;
b=-b;
}
ll c=b*points[i].se-a*points[i].fi;
if(a==0)
{
b=1;
}
else
{
ll g=__gcd(abs(a),abs(b));
a=a/g;
b=b/g;
}
if(Z.count({dist,{a,b}})==0)
{
Z[{dist,{a,b}}]={c,c};
}
else
{
Z[{dist,{a,b}}].fi=max(Z[{dist,{a,b}}].fi,c);
Z[{dist,{a,b}}].se=min(Z[{dist,{a,b}}].se,c);
}
}
else if(i!=j && points[i].fi==points[j].fi)
{
ll a=points[i].se-points[j].se;
ll b=points[i].fi-points[j].fi;
ll c=points[i].fi;
ll dist=abs(a);
if(vert_handler.count(dist)==0)
{
vert_handler[dist]={c,c};
}
else
{
vert_handler[dist].fi=max(vert_handler[dist].fi,c);
vert_handler[dist].se=min(vert_handler[dist].se,c);
}
}
}
}
ll ans=0;
for(auto x:vert_handler)
{
ll ans1=x.fi*(x.se.fi-x.se.se);
ans=max(ans,ans1);
}
for(auto x:Z)
{
ans=max(ans,x.se.fi-x.se.se);
}
cout<<ans<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char str[] = br.readLine().toCharArray();
int ans = 0;
char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
Set<String> set = new HashSet<>();
for(int i=0;i<str.length;i++){
char p = str[i];
for(char ch:arr){
if(ch==p) continue;
str[i] = ch;
if(isPallindrome(str)){
if(set.contains(String.valueOf(str))==false){
set.add(String.valueOf(str));
ans++;
}
}
str[i] = p;
}
}
System.out.println(ans);
}
static boolean isPallindrome(char[] str){
int i = 0;
int j = str.length-1;
while(i<j){
if(str[i]!=str[j]) return false;
i++;
j--;
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: n=input()
n=list(n)
ln=len(n)
cnt=0
for i in range(ln//2):
if not(n[i]==n[ln-i-1]):
cnt+=1
if(cnt==1):
print(2)
elif(cnt==0 and ln%2==1):
print(25)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 ≤ |<i>s</i>| ≤ 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1
abbb
Sample Output 1
2
Explanation:
The possible palindromes are:
1. abba
2. bbbb
========================================================================
Sample Input 2
abba
Sample Output 2
0
, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define sz(x) ((ll)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x = min(x,y)
#define maxi(x,y) x = max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);
// DEBUG FUNCTIONS START
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void deb() {cerr << "\n";}
template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);}
// DEBUG FUNCTIONS END
const int N = 2e5 + 5;
void solve(){
string s;
cin >> s;
int n = sz(s);
int x = 0;
rep(i, 0, n / 2){
x += s[i] != s[n - 1 - i];
}
if(x == 1){
cout << 2 << endl;
}
else if(x > 1){
cout << 0 << endl;
}
else{
if(n & 1){
cout << 25 << endl;
}
else{
cout << 0 << endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cout << fixed << setprecision(15);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement <code>createUserObj</code> which takes two arguments, email and password
and the funtion returns and object with key email and value as email argument and key password
and value as password.Function will take two arguments.Function will return object with keys email and passwordconst obj = createUserObj("akshat. sethi@newtonschool. co", "123456")
console. log(obj) // prints {email:"akshat. sethi@newtonschool. co", password:"123456"}, I have written this Solution Code: function createUserObj(email,password){
return {email,password}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples.
<b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>.
1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT:
1 2 3 4
OUTPUT:
14
Explanation:
Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int m1,a1,m2,a2;
cin >> m1 >> a1 >> m2 >> a2;
cout << (m1*a1)+(m2*a2) << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y):
cnt=0
if(X>2):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y>2):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
if(X<7):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y<7):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
return cnt;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a Java program to perform following operations:
1. Input an arraylist of size n
2. Sort the arraylist
3. Search for value 2 in arraylist , if present print out its index else print out -1.First line of input contains value of n.
second line of input contains n space-separated integers.
Constraints:-
1 < = N < = 1000
1 < = Arr[i] < = 100000 Print index of 2 if present else print out -1.Sample Input:-
6
1 2 3 4 5 6
Sample output:-
1
Explanation:
2 is present at index value 1 in the sorted arraylist., I have written this Solution Code: import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
list.add(sc.nextInt());
}
Collections.sort(list);
int index = Collections.binarySearch(list, 2);
if (index >= 0) {
System.out.println(index);
} else {
System.out.println("-1");
}
sc.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
if(str.contains(" ")) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: s = input()
if " " in s:
print("Yes")
else:
print("No")
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
for(int i=0;i<s.length();i++){
if(s[i]==' '){cout<<"Yes";return 0;}
}
cout<<"No";return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with β1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?The input consists of 4 space separated integers as follows :
A B C K
<b>Constraints</b>
All values in input are integers.
0≤A, B, C
1≤K≤A+B+C≤2Γ10^9Print the maximum possible sum of the numbers written on the cards chosen.<b>Sample Input 1</b>
2 1 1 3
<b>Sample Output 1</b>
2
<b>Sample Input 2</b>
1 2 3 4
<b>Sample Output 2</b>
0
<b>Sample Input 3</b>
2000000000 0 0 2000000000
<b>Sample Output 3</b>
2000000000, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
if(k <= a) cout << k << endl;
else if(k <= a + b) cout << a << endl;
else cout << a - (k - a - b) << 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 the following
- An Array A of size N
- An integer h
Your task is to print number of elements in A that are greater than h. You are given a total of K such tasks.The first line contains N denoting the size of array
The next line contains N space- separated integer denoting the elements of array A.
The next line contains an integer K denoting the number of tasks.
The next line contains an integer h.
<b>Constraints</b>
1 <= N <= 1e5
1 <= A[i] <= 1e9
1 <= K <= 1e5
1 <= h <= 1e9For each task, print the number of elements of A that are greater than h.Sample Input:
5
1 5 3 2 4
1
2
Sample Output :
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int A_size = Integer.parseInt(br.readLine().trim());
String[] arr_A = br.readLine().trim().split(" ");
int[] A = new int[A_size];
for (int i_A = 0; i_A < arr_A.length; i_A++) {
A[i_A] = Integer.parseInt(arr_A[i_A]);
}
int K_Array_size = Integer.parseInt(br.readLine().trim());
int[] K_Array = new int[K_Array_size];
for (int i_K_Array = 0; i_K_Array < K_Array_size; i_K_Array++) {
K_Array[i_K_Array] = Integer.parseInt(br.readLine().trim());
}
int[] out_ = process_queries(A, K_Array, A_size, K_Array_size);
for (int i_out_ = 0; i_out_ < out_.length; i_out_++) {
wr.println(out_[i_out_]);
}
wr.close();
br.close();
}
static int[] process_queries(int[] A, int[] K_Array, int N, int k) {
int ab[]=new int[k];
Arrays.sort(A);
int h=0;
while(h<k)
{ int f=K_Array[h];int l=0;
int r=N-1;int g=N;
while(l<=r)
{
int m=l+(r-l)/2;
if(A[m]>f)
{
g=m;
r=m-1;
}
else{
l=m+1;
}
}
ab[h]=N-g;
h++;
}
return ab;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given the following
- An Array A of size N
- An integer h
Your task is to print number of elements in A that are greater than h. You are given a total of K such tasks.The first line contains N denoting the size of array
The next line contains N space- separated integer denoting the elements of array A.
The next line contains an integer K denoting the number of tasks.
The next line contains an integer h.
<b>Constraints</b>
1 <= N <= 1e5
1 <= A[i] <= 1e9
1 <= K <= 1e5
1 <= h <= 1e9For each task, print the number of elements of A that are greater than h.Sample Input:
5
1 5 3 2 4
1
2
Sample Output :
3, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k;
cin >> k;
sort(a.begin(), a.end());
for (int i = 0; i < k; i++) {
int temp;
cin >> temp;
auto it = upper_bound(a.begin(), a.end(), temp) - a.begin();
cout << n - it << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer 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: You are given two strings S1 and S2 of length N. You need to make those strings equal by replacing any index in string S1 with any character. The cost incurred is as follows:
You pay X units for the first replacement, you do not pay anything for the second replacement, you pay X units for the third replacement, you do not pay anything for the fourth replacement, and so on.
Find the total units you need to pay to make S1 equal to S2.The first line of the input contains two integers, N and X.
The second and third lines of the input contain strings S1 and S2 respectively.
Constraints
1 <= N <= 200000
1 <= X <= 100
S1 and S2 contain lowercase characters of the english alphabet.Output a single integer, the number of units we need to pay.Sample Input
5 2
abcde
bbcce
Sample Output
2
Explanation:
Step 1: We replace character at index 1 from 'a' to 'b'. Total cost: 2.
Step 2: We replace character at index 4 from 'd' to 'c'. Total cost: 2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception
{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(input[0]);
long x = Long.parseLong(input[1]);
String s1 = br.readLine();
String s2 = br.readLine();
long count = 0;
for (int i=0; i<n; i++) {
if(s1.charAt(i) != s2.charAt(i))
count++;
}
long ans = count%2==0 ? (count/2)*x : (count/2)*x + x;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two strings S1 and S2 of length N. You need to make those strings equal by replacing any index in string S1 with any character. The cost incurred is as follows:
You pay X units for the first replacement, you do not pay anything for the second replacement, you pay X units for the third replacement, you do not pay anything for the fourth replacement, and so on.
Find the total units you need to pay to make S1 equal to S2.The first line of the input contains two integers, N and X.
The second and third lines of the input contain strings S1 and S2 respectively.
Constraints
1 <= N <= 200000
1 <= X <= 100
S1 and S2 contain lowercase characters of the english alphabet.Output a single integer, the number of units we need to pay.Sample Input
5 2
abcde
bbcce
Sample Output
2
Explanation:
Step 1: We replace character at index 1 from 'a' to 'b'. Total cost: 2.
Step 2: We replace character at index 4 from 'd' to 'c'. Total cost: 2., I have written this Solution Code: n,x=input().split()
n=int(n)
x=int(x)
str1=input()
str2=input()
count=0
cost=0
for i in range(0,n):
if(str1[i]!=str2[i]):
if(count%2==0):
cost+=x
count+=1
print (cost), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two strings S1 and S2 of length N. You need to make those strings equal by replacing any index in string S1 with any character. The cost incurred is as follows:
You pay X units for the first replacement, you do not pay anything for the second replacement, you pay X units for the third replacement, you do not pay anything for the fourth replacement, and so on.
Find the total units you need to pay to make S1 equal to S2.The first line of the input contains two integers, N and X.
The second and third lines of the input contain strings S1 and S2 respectively.
Constraints
1 <= N <= 200000
1 <= X <= 100
S1 and S2 contain lowercase characters of the english alphabet.Output a single integer, the number of units we need to pay.Sample Input
5 2
abcde
bbcce
Sample Output
2
Explanation:
Step 1: We replace character at index 1 from 'a' to 'b'. Total cost: 2.
Step 2: We replace character at index 4 from 'd' to 'c'. Total cost: 2., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n, x; cin>>n>>x;
string s1, s2; cin>>s1>>s2;
int ct = 0;
For(i, 0, n){
if(s1[i]!=s2[i])
ct++;
}
int ans = ((ct+1)/2)*x;
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Pattern()</b> that takes integer N as an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a class named 'Student' with String variable 'name' and integer variable 'rollNumber'.
You need to perform the below operations in <b>myFunction()</b>:
<ul>
<li>Assign the value of <b>rollNumber</b> as given by the user</li>
<li>Assign the value of <b>name</b> as given by the user</li>
</ul>The input contains a single line of String and integer value separated by space.You just have to assign values to Student class attributes. The driver code is handling the outputInput:
Gaurav 1
Output:
Gaurav 1
Input:
Swapnil 2
Output:
Swapnil 2, I have written this Solution Code:
class Student {
String name;
int rollNumber;
public void myFunction (String name, int rollNumber){
this.name = name;
this.rollNumber = rollNumber;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a class named 'Student' with String variable 'name' and integer variable 'rollNumber'.
You need to perform the below operations in <b>myFunction()</b>:
<ul>
<li>Assign the value of <b>rollNumber</b> as given by the user</li>
<li>Assign the value of <b>name</b> as given by the user</li>
</ul>The input contains a single line of String and integer value separated by space.You just have to assign values to Student class attributes. The driver code is handling the outputInput:
Gaurav 1
Output:
Gaurav 1
Input:
Swapnil 2
Output:
Swapnil 2, I have written this Solution Code: class Student:
def __init__(self, name, roll_no):
self.name, self.roll_no = name ,roll_no
def myFunction(name, roll_no):
obj = Student(name, roll_no)
return obj, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.