Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
out.println(sumTotient(ni()/ni()));
}
public static int[] enumTotientByLpf(int n, int[] lpf)
{
int[] ret = new int[n+1];
ret[1] = 1;
for(int i = 2;i <= n;i++){
int j = i/lpf[i];
if(lpf[j] != lpf[i]){
ret[i] = ret[j] * (lpf[i]-1);
}else{
ret[i] = ret[j] * lpf[i];
}
}
return ret;
}
public static int[] enumLowestPrimeFactors(int n)
{
int tot = 0;
int[] lpf = new int[n+1];
int u = n+32;
double lu = Math.log(u);
int[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];
for(int i = 2;i <= n;i++)lpf[i] = i;
for(int p = 2;p <= n;p++){
if(lpf[p] == p)primes[tot++] = p;
int tmp;
for(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){
lpf[tmp] = primes[i];
}
}
return lpf;
}
public static long sumTotient(int n)
{
if(n == 0)return 0L;
if(n == 1)return 1L;
int s = (int)Math.sqrt(n);
long[] cacheu = new long[n/s];
long[] cachel = new long[s+1];
int X = (int)Math.pow(n, 0.66);
int[] lpf = enumLowestPrimeFactors(X);
int[] tot = enumTotientByLpf(X, lpf);
long sum = 0;
int p = cacheu.length-1;
for(int i = 1;i <= X;i++){
sum += tot[i];
if(i <= s){
cachel[i] = sum;
}else if(p > 0 && i == n/p){
cacheu[p] = sum;
p--;
}
}
for(int i = p;i >= 1;i--){
int x = n/i;
long all = (long)x*(x+1)/2;
int ls = (int)Math.sqrt(x);
for(int j = 2;x/j > ls;j++){
long lval = i*j < cacheu.length ? cacheu[i*j] : cachel[x/j];
all -= lval;
}
for(int v = ls;v >= 1;v--){
long w = x/v-x/(v+1);
all -= cachel[v]*w;
}
cacheu[(int)i] = all;
}
return cacheu[1];
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Main().run(); }
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), 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>
/////////////
ull X[20000001];
ull cmp(ull N){
return N*(N+1)/2;
}
ull solve(ull N){
if(N==1)
return 1;
if(N < 20000001 && X[N] != 0)
return X[N];
ull res = 0;
ull q = floor(sqrt(N));
for(int k=2;k<N/q+1;++k){
res += solve(N/k);
}
for(int m=1;m<q;++m){
res += (N/m - N/(m+1)) * solve(m);
}
res = cmp(N) - res;
if(N < 20000001)
X[N] = res;
return res;
}
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int l,x;
cin>>l>>x;
if(l<x)
cout<<0;
else
cout<<solve(l/x);
#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: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: def inv(a,b,m):
res = 1
while(b):
if b&1:
res = (res*a)%m
a = (a*a)%m
b >>= 1
return res
n,x = map(int,input().split())
a = list(map(int,input().split()))
m = 1000000007
for i in a:
x = (x*inv(i,m-2,m))%m
print(x), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, 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>
/////////////
int power_mod(int a,int b,int mod){
int ans = 1;
while(b){
if(b&1)
ans = (ans*a)%mod;
b = b/2;
a = (a*a)%mod;
}
return ans;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x;
cin>>x;
int mo=1000000007;
int mu=1;
for(int i=0;i<n;++i){
int d;
cin>>d;
mu=(mu*d)%mo;
}
cout<<(x*power_mod(mu,mo-2,mo))%mo;
#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: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;
public class Main
{
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;StringBuilder sb;
public void tq()throws Exception
{
st=new StringTokenizer(br.readLine());
int tq=1;
o:
while(tq-->0)
{
int n=i();
long k=l();
long ar[]=arl(n);
long v=1l;
for(long x:ar)v=(v*x)%mod;
v=(k*(mul(v,mod-2,mod)))%mod;
pl(v);
}
}
public static void main(String[] a)throws Exception{new Main().tq();}
int[] so(int ar[]){Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[])
{Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.append(s);}
void s(char s){sb.append(s);}void s(double s){sb.append(s);}
void ss(){sb.append(' ');}void sl(String s){sb.append(s);sb.append("\n");}
void sl(int s){sb.append(s);sb.append("\n");}
void sl(long s){sb.append(s);sb.append("\n");}void sl(char s){sb.append(s);sb.append("\n");}
void sl(double s){sb.append(s);sb.append("\n");}void sl(){sb.append("\n");}
int min(int a,int b){return a<b?a:b;}
int min(int a,int b,int c){return a<b?a<c?a:c:b<c?b:c;}
int max(int a,int b){return a>b?a:b;}
int max(int a,int b,int c){return a>b?a>c?a:c:b>c?b:c;}
long min(long a,long b){return a<b?a:b;}
long min(long a,long b,long c){return a<b?a<c?a:c:b<c?b:c;}
long max(long a,long b){return a>b?a:b;}
long max(long a,long b,long c){return a>b?a>c?a:c:b>c?b:c;}
int abs(int a){return Math.abs(a);}
long abs(long a){return Math.abs(a);}
int sq(int a){return (int)Math.sqrt(a);}long sq(long a){return (long)Math.sqrt(a);}
long gcd(long a,long b){return b==0l?a:gcd(b,a%b);}
boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;return true;}
boolean[] si(int n)
{boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]=true;for(int x=4;x<=n;x+=2)bo[x]=true;
for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;y+=vv)bo[y]=true;}}
return bo;}long mul(long a,long b,long m)
{long r=1l;a%=m;while(b>0){if((b&1)==1)r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}
int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());}
long l()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());}String s()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Double.parseDouble(st.nextToken());}void p(Object p){System.out.print(p);}
void p(String p){System.out.print(p);}void p(int p){System.out.print(p);}
void p(double p){System.out.print(p);}void p(long p){System.out.print(p);}
void p(char p){System.out.print(p);}void p(boolean p){System.out.print(p);}
void pl(Object p){System.out.println(p);}void pl(String p){System.out.println(p);}
void pl(int p){System.out.println(p);}void pl(char p){System.out.println(p);}
void pl(double p){System.out.println(p);}void pl(long p){System.out.println(p);}
void pl(boolean p){System.out.println(p);}void pl(){System.out.println();}
void s(int a[]){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[]){for(long e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
void s(char a[]){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(char ar[][]){for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
int[] ari(int n)throws IOException
{int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}
int[][] ari(int n,int m)throws IOException
{int ar[][]=new int[n][m];for(int x=0;x<n;x++){if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}
long[] arl(int n)throws IOException
{long ar[]=new long[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());return ar;}
long[][] arl(int n,int m)throws IOException
{long ar[][]=new long[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException
{String ar[]=new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=st.nextToken();return ar;}
double[] ard(int n)throws IOException
{double ar[]=new double[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}
double[][] ard(int n,int m)throws IOException
{double ar[][]=new double[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());}return ar;}
char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}
char[][] arc(int n,int m)throws IOException{char ar[][]=new char[n][m];
for(int x=0;x<n;x++){String s=br.readLine();for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}
void p(int ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(int a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(int ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(int a[]:ar){for(int aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(long ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(long a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(long ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(long a[]:ar){for(long aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;StringBuilder sb=new StringBuilder(c);
for(String a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(double a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(char ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(char aa:ar){sb.append(aa);sb.append(' ');}System.out.println(sb);}
void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array of size N and a string token. Find the sum of 4 largest number of the array. For the final output encode the sum as follows :
Reverse the sum and the token and add them together using a ":".A single integer N.
Next line contains N space separated integers.
Next line contains token.
<b>Constraints</b>
4 ≤ N ≤ 10<sup>5</sup>
1 ≤ arr[i] ≤ 10<sup>9</sup>
1 ≤ | token | ≤ 10<sup>5</sup>
token contains only lowercase English letters.A single line denoting final encoded output.Input:
6
6 2 3 8 9 12
deep
Output:
53:peed
Explanation:
4 largest numbers = 12, 9, 8, 6
sum = 35
reverse sum and token and append => 53:peed, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int n=Integer.parseInt(in.next());
Integer a[] = new Integer[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(in.next());
}
Arrays.sort(a,Collections.reverseOrder());
String token = in.next();
int sum = a[0] + a[1] + a[2] + a[3];
String s1 = new StringBuilder(Integer.toString(sum)).reverse().toString();
String s2 = ":" + new StringBuilder(token).reverse().toString();
String ans=s1.concat(s2);
out.print(ans);
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine().toString();
String[] str = s.split(" ");
float a=Float.parseFloat(str[0]);
float b=Float.parseFloat(str[1]);
float c=Float.parseFloat(str[2]);
float div = (float)(b*b-4*a*c);
if(div>0.0){
float alpha= (-b+(float)Math.sqrt(div))/(2*a);
float beta= (-b-(float)Math.sqrt(div))/(2*a);
System.out.printf("%.2f\n",alpha);
System.out.printf("%.2f",beta);
}
else{
float rp=-b/(2*a);
float ip=(float)Math.sqrt(-div)/(2*a);
System.out.printf("%.2f+i%.2f\n",rp,ip);
System.out.printf("%.2f-i%.2f\n",rp,ip);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: import math
a,b,c = map(int, input().split(' '))
disc = (b ** 2) - (4*a*c)
sq = disc ** 0.5
if disc > 0:
print("{:.2f}".format((-b + sq)/(2*a)))
print("{:.2f}".format((-b - sq)/(2*a)))
elif disc == 0:
print("{:.2f}".format(-b/(2*a)))
elif disc < 0:
r1 = complex((-b + sq)/(2*a))
r2 = complex((-b - sq)/(2*a))
print("{:.2f}+i{:.2f}".format(r1.real, abs(r1.imag)))
print("{:.2f}-i{:.2f}".format(r2.real, abs(r2.imag))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the roots of a quadratic equation.
<b>Note</b>: Try to do it using Switch Case.
<b>Quadratic equations</b> are the polynomial equations of degree 2 in one variable of type f(x) = ax<sup>2</sup> + bx + c = 0 where a, b, c, ∈ R and a ≠0. It is the general form of a quadratic equation where 'a' is called the leading coefficient and 'c' is called the absolute term of f (x).The first line of the input contains the three integer values a, b, and c of equation ax^2 + bx + c.
<b>Constraints</b>
1 ≤ a, b, c ≤ 50Print the two roots in two different lines and for imaginary roots print real and imaginary part of one root with (+/- and i )sign in between in one line and other in next line. For clarity see sample Output 2.
<b>Note</b> Imaginary roots can also be there and roots are considered upto 2 decimal places.Sample Input 1 :
4 -2 -10
Sample Output 2 :
1.85
-1.35
Sample Input 2 :
2 1 10
Sample Output 2:
-0.25+i2.22
-0.25-i2.22, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-19 02:44:22
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int main() {
float a, b, c;
float root1, root2, imaginary;
float discriminant;
scanf("%f%f%f", &a, &b, &c);
discriminant = (b * b) - (4 * a * c);
switch (discriminant > 0) {
case 1:
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
case 0:
switch (discriminant < 0) {
case 1:
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("%.2f + i%.2f\n%.2f - i%.2f", root1, imaginary, root2, imaginary);
break;
case 0:
root1 = root2 = -b / (2 * a);
printf("%.2f\n%.2f", root1, root2);
break;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: def MaximumProduct(N):
ans=N//4
if N %4 !=0:
ans=ans+1
return ans, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<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>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: static int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Modulo exponentiation is super awesome. But can you still think of a solution to the following problem?
Given three integers {a, b, c}, find the value of a<sup>b<sup>c</sup></sup> % 1000000007.
Here a<sup>b</sup> means a raised to the power b or pow(a, b). Expression evaluates to pow(a, pow(b, c)) % 1000000007.
(Read Euler's Theorem before solving this problem)The first input line has an integer t: the number of test cases.
After this, there are n lines, each containing three integers a, b and c.
Constraints
1≤ t ≤ 100
0 ≤ a, b, c ≤ 1000000000For each test case, output the value corresponding to the expression.Sample Input
3
3 7 1
15 2 2
3 4 5
Sample Output
2187
50625
763327764
Explaination:
In the first test, a = 3, b = 7, c = 1
b<sup>c</sup> = 7<sup>1</sup> = 7
a<sup>b<sup>c</sup></sup> = 3<sup>7</sup> = 2187, 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());
for(int k=0;k<T;k++)
{
String[] str= br.readLine().split(" ");
int a=Integer.parseInt(str[0]);
int b=Integer.parseInt(str[1]);
int c=Integer.parseInt(str[2]);
int M=1000000007;
System.out.print(superExponentation(a,superExponentation(b,c,M-1),M));
System.out.println();
}
}
public static long superExponentation(long a,long b,int m)
{
long res=1;
while(b>0)
{
if(b%2!=0)
res=(long)(res%m*a%m)%m;
a=((a%m)*(a%m))%m;
b=b>>1;
}
return res;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Modulo exponentiation is super awesome. But can you still think of a solution to the following problem?
Given three integers {a, b, c}, find the value of a<sup>b<sup>c</sup></sup> % 1000000007.
Here a<sup>b</sup> means a raised to the power b or pow(a, b). Expression evaluates to pow(a, pow(b, c)) % 1000000007.
(Read Euler's Theorem before solving this problem)The first input line has an integer t: the number of test cases.
After this, there are n lines, each containing three integers a, b and c.
Constraints
1≤ t ≤ 100
0 ≤ a, b, c ≤ 1000000000For each test case, output the value corresponding to the expression.Sample Input
3
3 7 1
15 2 2
3 4 5
Sample Output
2187
50625
763327764
Explaination:
In the first test, a = 3, b = 7, c = 1
b<sup>c</sup> = 7<sup>1</sup> = 7
a<sup>b<sup>c</sup></sup> = 3<sup>7</sup> = 2187, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<long long> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
ll fastexp (ll a, ll b, ll n) {
ll res = 1;
while (b) {
if (b & 1) res = res*a%n;
a = a*a%n;
b >>= 1;
}
return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fast();
ll a,b,c;
int t, n, k;
cin >> t;
while(t--) {
cin >> a >>b >>c;
ll mod = 1e9+7;
ll k = fastexp(b,c,mod-1);
ll ans= fastexp(a,k,mod);
cout<<ans<<endl;
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: import math as m
def closestNum(n):
val = m.log(n, 3)
low = int(pow(3,int(val)))
high = int(pow(3,int(val)+1))
sumn = int((pow(3,int(val)+1)-1)//2)
if(n > sumn):
return high
elif(n - low == 0):
return low
else:
return low + closestNum(n-low);
t = int(input())
while(t > 0):
n = int(input())
print(closestNum(n))
t = t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int p[N], s[N];
int f(int x){
if(x <= 0)
return 0;
int ans = 0;
for(int i = 0; i <= 39; i++){
if(s[i] >= x){
ans = p[i] + f(x-p[i]);
break;
}
}
return ans;
}
signed main() {
IOS;
int t; cin >> t;
p[0] = s[0] = 1;
for(int i = 1; i <= 39; i++){
p[i] = 3*p[i-1];
s[i] = s[i-1] + p[i];
}
while(t--){
int n; cin >> n;
cout << f(n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: import java.io.*;
import java.lang.*;
class Main
{
public static void main(String args[])throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int t = Integer.parseInt(br.readLine());
while(t-- >0)
{
long n = Long.parseLong(br.readLine());
if(n == 0)
{
System.out.println(1);
continue;
}
System.out.println(powerOfThree(n));
}
}
public static long powerOfThree(long n)
{
if(n<=0)
return 0;
long p = (long)(Math.log(n)/Math.log(3));
if(gpSum(p)>=n)
return power(3,p) + powerOfThree(n - power(3,p));
else
return power(3,p+1);
}
public static long gpSum(long p)
{
return (power(3,p+1)-1)/2;
}
public static long power(long base, long p)
{
if(p==0)
return 1;
else
return(base*power(base,p-1));
}
}, 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: 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: 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: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code: def Average(A,B,C):
return (A+B+C)//3
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
static int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: static int focal_length(int R, char Mirror)
{
int f=R/2;
if((R%2==1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: def focal_length(R,Mirror):
f=R/2;
if(Mirror == ')'):
f=-f
if R%2==1:
f=f-1
return int(f)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect 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>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect 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>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect 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>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: static int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect 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>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: def PerfectNumber(N):
cnt=0
while N>0:
cnt=cnt+int(N%10)
N=int(N/10)
if (cnt%5==0):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int c = 0;
String str = br.readLine();
for(int i=0;i<n;i++){
if(str.charAt(i) == 'a'){
c++;
}
}
if((n-c)<c){
System.out.println(n-c);
}else{
System.out.println(c);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: input()
s = input()
a = s.count("a")
b = s.count("b")
print(a if a<b else b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string S of length N consisting of lowercase characters 'a' and 'b'. In one operation, you can select a character and make it equal to one of its adjacent characters. For example, if S = "aab", in one operation you can convert it to any of the following:
1. "aab": By changing the 1<sup>st</sup> character to the 2<sup>nd</sup> character.
2. "aab": By changing the 2<sup>nd</sup> character to the 1<sup>st</sup> character.
3. "abb": By changing the 2<sup>nd</sup> character to the 3<sup>rd</sup> character.
4. "aaa": By changing the 3<sup>rd</sup> character to the 2<sup>nd</sup> character.
Find the minimum number of operations to make all the characters in the string equal.The first line of the input contains a single integer N.
The second line contains a string S of length N consisting of only 'a' and 'b'.
<b> Constraints: </b>
1 ≤ N ≤ 5000Print the minimum number of operations to make all the characters in the string equal.Sample Input 1:
4
abaa
Sample Output 1:
1
Sample Explanation 1:
You can replace the 'b' at the second position by the 'a' at the first position. Now the string becomes "aaaa".
Sample Input 2:
5
bbbaa
Sample Output 2:
2
, I have written this Solution Code: //Author: Xzirium
//Time and Date: 03:04:29 27 December 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll a=0,b=0;
FORI(i,0,N)
{
if(S[i]=='a')
{
a++;
}
else
{
b++;
}
}
cout<<min(a,b)<<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: Given a directed graph of N vertices, Print 1 if you can perform a topological sort on the given graph. Otherwise, print 0.
There are no self-loops or multiple edges.The first line contains two integers N and E, denoting the number of nodes and number of edges in the graph respectively. Next E lines contain two integers u and v, denoting an edge from u to v
Constraints
1 <= N, E <= 1000
0 <= u, v <= N-1
u != vPrint 1 if topological sort can be done correctly. Otherwise, print 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output 1:
0
Sample Input 2:
4 3
0 1
1 2
2 3
Sample Output 2:
1
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static ArrayList<ArrayList<Integer>> adj;
static void graph(int v){
adj =new ArrayList<>();
for(int i=0;i<=v;i++) adj.add(new ArrayList<Integer>());
}
static void addedge(int u, int v){
adj.get(u).add(v);
}
static boolean dfs(int i, boolean [] vis, int parent[]){
vis[i] = true; parent[i] = 1;
for(Integer it: adj.get(i)){
if(vis[it]==false) {
if(dfs(it, vis, parent)==true) return true;
}
else if(parent[it]==1) return true;
}
parent[i] = 0;
return false;
}
static boolean helper(int n){
boolean vis[] = new boolean [n+1];
int parent[] = new int[n+1];
int i=1;
if(vis[i]==false){
if(dfs(i, vis, parent)) return true;
}
return false;
}
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String t[] = br.readLine().split(" ");
int n = Integer.parseInt(t[0]);
graph(n);
int e = Integer.parseInt(t[1]);
for(int i=0;i<e;i++) {
String num[] = br.readLine().split(" ");
int u = Integer.parseInt(num[0]);
int v = Integer.parseInt(num[1]);
addedge(u, v);
}
if(helper(n)) System.out.println("0");
else System.out.println("1");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a directed graph of N vertices, Print 1 if you can perform a topological sort on the given graph. Otherwise, print 0.
There are no self-loops or multiple edges.The first line contains two integers N and E, denoting the number of nodes and number of edges in the graph respectively. Next E lines contain two integers u and v, denoting an edge from u to v
Constraints
1 <= N, E <= 1000
0 <= u, v <= N-1
u != vPrint 1 if topological sort can be done correctly. Otherwise, print 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output 1:
0
Sample Input 2:
4 3
0 1
1 2
2 3
Sample Output 2:
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;
vector<int> g[N];
int vis[N];
bool flag = 0;
void dfs(int u, int p){
vis[u] = 1;
for(auto i: g[u]){
if(i == p) continue;
if(vis[i] == 1)
flag = 1;
if(vis[i] == 0) dfs(i, u);
}
vis[u] = 2;
}
signed main() {
IOS;
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
}
for(int i = 0; i < n; i++){
if(vis[i]) continue;
dfs(i, n);
}
if(!flag)
cout << 1;
else
cout << 0;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find songs that are ranked between 8-10.
Output the name of the track along with the corresponding position ordered ascendingly.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'spotify_worldwide_daily_song_ranking', 'columns': [{'name': 'id', 'type': 'int64'}, {'name': 'position', 'type': 'int64'}, {'name': 'trackname', 'type': 'object'}, {'name': 'artist', 'type': 'object'}, {'name': 'streams', 'type': 'int64'}, {'name': 'url', 'type': 'object'}, {'name': 'date', 'type': 'datetime64[ns]'}, {'name': 'region', 'type': 'object'}]}]</schema>Each row in the new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: # DataFrame already loaded with name <strong>spotify_worldwide_daily_song_ranking<strong>
mask_lt = spotify_worldwide_daily_song_ranking['position'] <11
mask_gt = spotify_worldwide_daily_song_ranking['position'] > 7
df = spotify_worldwide_daily_song_ranking[mask_gt & mask_lt]
df = df.sort_values(by= ['position'])
for i, r in df.iterrows():
print(f"{r['trackname']}|{r['position']}"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find songs that are ranked between 8-10.
Output the name of the track along with the corresponding position ordered ascendingly.DataFrame/SQL Table with the following schema -
<schema>[{'name': 'spotify_worldwide_daily_song_ranking', 'columns': [{'name': 'id', 'type': 'int64'}, {'name': 'position', 'type': 'int64'}, {'name': 'trackname', 'type': 'object'}, {'name': 'artist', 'type': 'object'}, {'name': 'streams', 'type': 'int64'}, {'name': 'url', 'type': 'object'}, {'name': 'date', 'type': 'datetime64[ns]'}, {'name': 'region', 'type': 'object'}]}]</schema>Each row in the new line and each value of a row separated by a |, i.e.,
0|1|2
1|2|3
2|3|4-, I have written this Solution Code: SELECT
trackname,position
FROM spotify_worldwide_daily_song_ranking
WHERE
position IN (8,9,10)
order by position, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X find an integer Y such that Y has exactly two set bits in its binary representaion and abs(X- Y) is minimum.Input contains a single integer X.
Constraints
1 <= X <= 10^15Print a single integer, the minimum value of abs(X- Y).Sample input 1
5
Sample output 1
0
Explanation: Y=5.
Sample input 2
1
Sample output 2
2
Explanation: Y=3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
long N = Long.parseLong(br.readLine());
long minDiff = Long.MAX_VALUE;
for(long i = 0; i < 63; i++){
for(long j = (i+1); j < 63; j++){
long targetNumber = (1l<<i)|(1l<<j);
long diff = Math.abs(N - targetNumber);
if(diff < minDiff){
minDiff = diff;
}
}
}
System.out.println(minDiff);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X find an integer Y such that Y has exactly two set bits in its binary representaion and abs(X- Y) is minimum.Input contains a single integer X.
Constraints
1 <= X <= 10^15Print a single integer, the minimum value of abs(X- Y).Sample input 1
5
Sample output 1
0
Explanation: Y=5.
Sample input 2
1
Sample output 2
2
Explanation: Y=3, I have written this Solution Code: n = int(input())
ans = 10000000000000000
count = 0
temp = n
while (temp // 2 > 0):
count += 1
temp //= 2
if (n == 1 or n == 2 or n == 3):
print(3-n)
else:
for i in range(count + 1, -1, -1):
for j in range(i-1, -1, -1):
ans = min(ans, abs(n - ((1 << i) + (1 << j))))
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer X find an integer Y such that Y has exactly two set bits in its binary representaion and abs(X- Y) is minimum.Input contains a single integer X.
Constraints
1 <= X <= 10^15Print a single integer, the minimum value of abs(X- Y).Sample input 1
5
Sample output 1
0
Explanation: Y=5.
Sample input 2
1
Sample output 2
2
Explanation: Y=3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int ans=1000000000000000;
for(int i=0;i<60;++i){
for(int j=i+1;j<60;++j){
ans=min(ans,abs(n-(1ll<<i)-(1ll<<j)));
}
}
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: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine().trim();
char n[] = s.toCharArray();
int posMin = 0;
for(int i=0;i<n.length;i++){
if(n[posMin]>n[i])
posMin = i;
}
for(int i=0;i<n.length;i++)
n[i] = n[posMin];
System.out.print(String.valueOf(n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, 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
string s;
cin>>s;
char c='z';
for(auto r:s)
c=min(c,r);
for(int i=0;i<s.length();++i)
cout<<c;
#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: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: s=input()
l=len(s)
k=min(s)
m=k*l
print(m), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., 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));
StringTokenizer st = new StringTokenizer(br.readLine());
int T = Integer.parseInt(st.nextToken());
while(T-->0){
st = new StringTokenizer(br.readLine());
int roomNo = Integer.parseInt(st.nextToken());
String gender = st.nextToken();
if(roomNo%2==0){
if(gender.equals("B")) System.out.println("PAPUM L");
else System.out.println("PAPUM U");
} else {
if(gender.equals("B")) System.out.println("LOHIT L");
else System.out.println("LOHIT U");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., I have written this Solution Code: n = int(input())
for i in range(n):
a = input().split()
if int(a[0])%2==0:
print("PAPUM",end=" ")
else:
print("LOHIT",end = " ")
if a[1]=='G':
print("U")
else:
print("L"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohan was so excited to visit his college NIT Arunachal Pradesh campus after COVID along with his friends Shreya and Anuj. The Warden allocated the hostel room for him but he was curious to know about the fact that how students are getting rooms.
The warden told him that those students whose roll no is divisible by 2 will get PAPUM HOSTEL and if it is odd then they will get "LOHIT HOSTEL". If the student is a girl, then she will get "Upper Wing" otherwise ‘Lower Wing’.The first line of input will contain a single integer t denoting the no. of test cases
Each test case contains only one line containing two space-separated inputs R for Roll No and S
for denoting Sex ‘B’ for boy and ‘G’ for girl
<b>Constraints</b>
1 ≤ t ≤ 10000
1 ≤ R ≤ 300Print the hostel name (LOHIT/PAPUM) with the upper wing (U) and lower wing (L).Sample Input
2
30 B
35 G
Sample Output
PAPUM L
LOHIT U
<b>Explanation:</b>
Here 30 is evenly divisible by two and B is the boy so he gets the Papum Hostel and is allocated a room in the lower wing., I have written this Solution Code: #include <stdio.h>
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
int roll;
char sex;
scanf("%d %c", &roll, &sex);
if (roll % 2)
printf("LOHIT %s\n", sex == 'B' ? "L" : "U");
else
printf("PAPUM %s\n", sex == 'B' ? "L" : "U");
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 1000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
int main(){
int t;
cin>>t;
while(t--){
int n,p;
cin>>p>>n;
int a[n];
li sum;
ll cur=0;
int b[p];
FOR(i,p){
b[i]=-1;}
unordered_map<ll,int> m;
ll cnt=0;
FOR(i,n){cin>>a[i];}
for(int i=0;i<min(n,p);i++){
cur=a[i]%p;
int j=0;
while(b[(cur+j)%p]!=-1){
j++;
}
b[(cur+j)%p]=a[i];
}
FOR(i,p){
out1(b[i]);
}
END;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., 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 t = Integer.parseInt(read.readLine());
while(t-- > 0){
String str[] = read.readLine().trim().split("\\s+");
int hashSize = Integer.parseInt(str[0]);
int N = Integer.parseInt(str[1]);
int arr[] = new int[N];
str = read.readLine().trim().split("\\s+");
for(int i = 0; i < N; i++){
arr[i] = Integer.parseInt(str[i]);
}
int hashTable[] = new int[hashSize];
for(int i=0; i<hashSize; i++){
hashTable[i] = -1;
}
for(int i = 0; i< Math.min(N, hashSize); i++){
int idx = arr[i] % hashSize;
int j = 0;
while(hashTable[(idx + j) % hashSize] != -1){
j++;
}
hashTable[(idx + j) % hashSize] = arr[i];
}
for(int i=0; i<hashSize; i++){
System.out.print(hashTable[i] +" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Linear probing is a collision handling technique in hashing. Linear probing says that whenever a collision occurs, search for the immediate next position.
In this question, we'll learn how to fill up the hash table using linear probing technique. You are given hash table size which you'll use to insert elements into their correct position in the hash table i.e.(arr[i]%hashSize). You are also given an array arr of size n. You need to fill up the hash table using linear probing and print the resultant hash table.
Note: All the positions that are unoccupied are denoted by -1 in the hash table.
If there is no more space to insert, then just drop that element.The first line of input contains T denoting the number of test cases. T-test cases follow. Each test case contains 2 lines of input. The first line contains the size of the hashtable and the size of the array. The third line contains elements of the array.
<b>Constraints:-</b>
1 ≤ T ≤ 100
1 ≤ hashSize ≤ 10<sup>3</sup>
1 ≤ sizeOfArray ≤ 10<sup>3</sup>
0 ≤ Array[] ≤ 10<sup>5</sup>
For each testcase, in a new line, print the hash table as shown in example.Input:
2
10 4
4 14 24 44
10 4
9 99 999 9999
Output:
-1 -1 -1 -1 4 14 24 44 -1 -1
99 999 9999 -1 -1 -1 -1 -1 -1 9
Explanation:
Testcase1: 4%10=4. So put 4 in hashtable[4]. Now, 14%10=4, but hashtable[4] is already filled so put 14 in the next slot and so on.
Testcase2: 9%10=9. So put 9 in hashtable[9]. Now, 99%10=9, but hashtable[9] is already filled so put 99 in the (99+1)%10 =0 slot so 99 goes into hashtable[0] and so on., I have written this Solution Code: t = int(input())
for _ in range(t):
n,arrSize = map(int,input().split())
nums = list(map(int,input().split()))
hashSet = [-1]*n
for i in nums:
if hashSet[i%n] == -1:
hashSet[i%n] = i
else:
j = i%n + 1
while j!=i%n:
if hashSet[j%n] == -1:
hashSet[j%n] = i
break
j += 1
if hashSet.count(-1) == 0:
break
print(*hashSet), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: a=int(input())
for i in range(a):
n, m = map(int,input().split())
k=[]
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=sum(l)
k.append(l)
if(a==9):
print("NO")
elif(k[n-1][m-1]!=k[0][0]):
print("NO")
elif((n+m-1)*k[0][0]==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: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n, m;
vvi a, down, rt;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin >> n >> m;
a.clear();
down.clear();
rt.clear();
a.resize(n + 2, vi(m + 2));
down.resize(n + 2, vi(m + 2));
rt.resize(n + 2, vi(m + 2));
FOR (i, 1, n)
FOR (j, 1, m)
cin >> a[i][j];
FOR (i, 1, n)
{
if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1];
FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j];
}
bool flag=true;
FOR (i, 1, n)
{
if(flag==0)
break;
FOR (j, 1, m)
{
if (rt[i][j] < 0 || down[i][j] < 0 )
{
flag=false;
break;
}
if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j]))
{
flag=false;
break;
}
if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j]))
{
flag=false;
break;
}
}
}
if(flag)
cout << "YES\n";
else
cout<<"NO\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
int mat[][] = new int[n][m];
for(int i = 0; i<n; i++)arr[i] = sc.readArray(m);
mat[0][0] = arr[0][0];
int i = 0, j = 0;
while(i<n && j<n) {
if(arr[i][j] != mat[i][j]) {
System.out.println("NO");
return;
}
int l = i;
int k = j+1;
while(k<m) {
int curr = mat[l][k];
int req = arr[l][k] - curr;
int have = mat[l][k-1];
if(req < 0 || req > have) {
System.out.println("NO");
return;
}
have-=req;
mat[l][k-1] = have;
mat[l][k] = arr[l][k];
k++;
}
if(i+1>=n)break;
for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k];
i++;
}
System.out.println("YES");
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), 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, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import math
n = int(input())
for i in range(n):
x = int(input())
count = 0
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0:
if (i%2 == 0):
count+=1
if ((x/i) %2 == 0):
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
int n = Integer.parseInt(br.readLine());
int count=0;
for(int i=1;i<=Math.sqrt(n);i++){
if(n%i == 0)
{
if(i%2==0) {
count++;
}
if(i*i != n && (n/i)%2==0) {
count++;
}
}
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n&1){cout<<0<<endl;continue;}
long x=sqrt(n);
int cnt=0;
for(long long i=1;i<=x;i++){
if(!(n%i)){
if(!(i%2)){cnt++;}
if(i*i!=n){
if(!((n/i)%2)){cnt++;}
}
}
}
cout<<cnt<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
bool check_increasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] < a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] <= a[cur-1])
return 0;
cur++;
}
return 1;
}
bool check_decreasing(int n){
int id = 0;
for(int i = 2; i <= n; i++){
if(a[i] > a[i-1]){
id = i;
break;
}
}
if(id == 0) return 0;
int cur = id+1;
while(cur != id+n){
if(a[cur] >= a[cur-1])
return 0;
cur++;
}
return 1;
}
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i], a[i+n] = a[i];
if(check_increasing(n))
cout << "Yes" << endl;
else if(check_decreasing(n))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code:
cases = int(input())
for _ in range(cases):
size = int(input())
orig = list(map(int,input().split()))
givenList = orig.copy()
givenList.sort()
flag = False
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
givenList.sort()
givenList.reverse()
for _ in range(size-1):
ele = givenList.pop()
givenList.insert(0,ele)
if givenList == orig:
print("Yes")
flag = True
break
if not flag:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>arr[]</b> of <b>N</b> distinct integers, check if this array is Sorted and Rotated clockwise. A sorted array is not considered sorted and rotated, i.e., there should be at least one rotation.
<b>Note:-</b>
The array can be sorted both increasingly and decreasinglyThe first line of input contains the number of test cases T. Each test case contains 2 lines, the first line contains N, the number of elements in the array, and the second line contains N space-separated elements of the array.
<b>Constraints:</b>
1 <= T <= 50
3 <= N <= 10^3
1 <= A[i] <= 10^4
Print "<b>Yes</b>" if the given array is sorted and rotated, else Print "<b>No</b>", without Inverted commas.Sample Input:
2
4
3 4 1 2
3
1 3 2
Sample Output:
Yes
Yes
<b>Explanation:</b>
Testcase 1: The array is sorted (1, 2, 3, 4) and rotated twice (3, 4, 1, 2).
Testcase 2: The array is sorted (3, 2, 1) and rotated once (1, 3, 2)., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim()); //Inputting the testcases
while(t-->0){
long n = Long.parseLong(br.readLine());
int arr[] = new int[(int)n];
String inputLine[] = br.readLine().trim().split("\\s+");
for(long i=0; i<n; i++){
arr[(int)i] = Integer.parseInt(inputLine[(int)i]);
}
long mini = Integer.MAX_VALUE, maxi = Integer.MIN_VALUE;
long max_index = 0, min_index = 0;
for(long i=0; i<n; i++){
if(maxi < arr[(int)i]){
maxi = arr[(int)i];
max_index = i;
}
if(mini > arr[(int)i]){
mini = arr[(int)i];
min_index = i;
}
}
int flag = 0;
if(max_index == min_index -1)
flag = 1;
else if(min_index == max_index - 1)
flag = -1;
if(flag == 1){
for(long i = 1; flag==1 && i<=max_index; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
for(long i = min_index+1; flag==1 && i<n; ++i){
if(arr[(int)i-1] >= arr[(int)i])
flag = 0;
}
if(arr[0]<=arr[(int)n-1])
flag = 0;
} else if(flag == -1){
for(long i = 1; flag ==-1 && i<=min_index; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
for(long i = max_index+1; flag==-1 && i<n; ++i){
if(arr[(int)i-1] <= arr[(int)i])
flag = 0;
}
if(arr[0]>=arr[(int)n-1])
flag = 0;
}
if(flag == 0)
System.out.println("No");
else
System.out.println("Yes");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, I have written this Solution Code: a=int(input())
lis=list(map(int,input().split()))
mNow = max(lis)
qr=int(input())
for _ in range(qr):
inp = list(map(int,input().split()))
if(inp[0]==1):
if(inp[1]>mNow):
lis.append(inp[1])
mNow = inp[1]
else:
print(mNow), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const int N = 3e5+5;
#define read(type) readInt<type>()
#define max1 20000001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
int main()
{
priority_queue<ll> q;
int n;
cin>>n;
ll x;
FOR(i,n){
cin>>x;
q.push(x);}
int qa;
cin>>qa;
int i;
while(qa--){
cin>>i;
if(i==1){
cin>>x;
q.push(x);
}
else{out(q.top());}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have been given a sequence A of N digits. Each digit in this sequence ranges from 1 to 10^9. You need to perform 2 types of operations on this list:
Add(x): Add element x to the end of the list.
Max(list): Find the maximum element in the current sequence.
For each query of type 2, you need to print the result of that operation.The first line consists of a single integer N denoting the size of the initial sequence. The next line consists of N space-separated integers denoting the elements of the initial sequence. The next line contains a single integer q denoting the number of queries. The next q lines contain the details of the operation. The first integer type indicates the type of query. If typei ==1, it is followed by another integer x and you need to perform an operation of type 1 else operations of type 2
Constraints
1 < = N < = 10^5
1 < = Ai < = 10^9
1 < = q < = 10^4For each operation of the second type, print a single integer on a new line.Sample Input
5
1 2 3 4 5
6
1 1
1 2
1 3
2
1 8
2
Sample Output
5
8, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static long mod= (long) (1e9 +7);
static InputReader s;
static PrintWriter out;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try{
solve();
out.flush();
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}, "1", 1 << 26).start();
}
public static void solve() throws IOException{
s= new InputReader(System.in);
OutputStream outputStream= System.out;
out= new PrintWriter(outputStream);
PriorityQueue<Integer> q= new PriorityQueue<>(Collections.reverseOrder());
int n= s.nextInt();
for(int i=0;i<n;i++){
q.add(s.nextInt());
}
int query = s.nextInt();
while(query-->0){
int type= s.nextInt();
if(type==1){
q.add(s.nextInt());
}
else{
out.println(q.peek());
}
}
}
static long combinations(long n,long r){
if(r==0 || r==n) return 1;
r= Math.min(r, n-r);
long ans=n;
for(int i=1;i<r;i++){
ans= (ans*(n-i))%mod;
ans= (ans*modulo(i+1,mod-2,mod))%mod;
}
return ans;
}
static long modulo(long x,long y,long p)
{
long res = 1;
x = x % p;
while (y > 0)
{
if (y%2==1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
static HashSet<Integer> primeFactors(int n)
{
HashSet<Integer> arr= new HashSet<>();
while (n%2 == 0)
{
arr.add(2);
n = n/2;
}
for (int i = 3; i <= Math.sqrt(n); i = i+2)
{
while (n%i == 0)
{
arr.add(i);
n = n/i;
}
}
if (n > 2)
arr.add(n);
return arr;
}
public static long expo(long a, long b){
if (b==0)
return 1;
if (b==1)
return a;
if (b==2)
return a*a;
if (b%2==0){
return expo(expo(a,(b/2)),2);
}
else{
return a*expo(expo(a,(b-1)/2),2);
}
}
static class Pair implements Comparable<Pair>
{
String x;
String y;
Pair(String ii, String cc)
{
x=ii;
y=cc;
}
public int compareTo(Pair o)
{
return this.x.compareTo(o.x);
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return x == other.x && y == other.y;
}
public String toString() {
return "[x=" + x + ", y=" + y + "]";
}
}
public static int[] sieve(int N){
int arr[]= new int[N+1];
for(int i=2;i<=Math.sqrt(N);i++){
if(arr[i]==0){
for(int j= i*i;j<= N;j= j+i){
arr[j]=1;
}
}
}
return arr;
}
static int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
public static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static void catalan_numbers(int n) {
long catalan[]= new long[n+1];
catalan[1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i - 1; j++) {
catalan[i] = catalan[i] + ((catalan[j]) * catalan[i - j]);
}
}
}
static final class InputReader{
private final InputStream stream;
private final byte[] buf=new byte[1024];
private int curChar;
private int Chars;
public InputReader(InputStream stream){this.stream=stream;}
private int read()throws IOException{
if(curChar>=Chars){
curChar=0;
Chars=stream.read(buf);
if(Chars<=0)
return -1;
}
return buf[curChar++];
}
public final int nextInt()throws IOException{return (int)nextLong();}
public final long nextLong()throws IOException{
int c=read();
while(isSpaceChar(c)){
c=read();
if(c==-1) throw new IOException();
}
boolean negative=false;
if(c=='-'){
negative=true;
c=read();
}
long res=0;
do{
if(c<'0'||c>'9')throw new InputMismatchException();
res*=10;
res+=(c-'0');
c=read();
}while(!isSpaceChar(c));
return negative?(-res):(res);
}
public final int[] nextIntBrray(int size)throws IOException{
int[] arr=new int[size];
for(int i=0;i<size;i++)arr[i]=nextInt();
return arr;
}
public final String next()throws IOException{
int c=read();
while(isSpaceChar(c))c=read();
StringBuilder res=new StringBuilder();
do{
res.append((char)c);
c=read();
}while(!isSpaceChar(c));
return res.toString();
}
public final String nextLine()throws IOException{
int c=read();
while(isSpaceChar(c))c=read();
StringBuilder res=new StringBuilder();
do{
res.append((char)c);
c=read();
}while(c!='\n'&&c!=-1);
return res.toString();
}
private boolean isSpaceChar(int c){
return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Daemon has 2 dragon eggs, one is made of A grams of Gold and the other is made of B grams of Silver.
We know that Gold costs G coins per gram and Silver costs S coins per gram. You need to determine which of the two dragon eggs are more valuable.The input contains 4 space-separated integers G, S, A, B.
<b> Constraints: </b>
1 ≤ G, S, A, B ≤ 10<sup>4</sup>Print "Gold" (without quotes) if the Gold egg costs <b>equal to or more than</b> the silver egg. Otherwise, print "Silver" (without quotes).
Note that the output is case-sensitive.Sample Input 1:
5 4 4 5
Sample Output 1:
Gold
Sample Input 2:
1 1 2 3
Sample Output 2:
Silver, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
int [] num = new int[4];
String[] str = bi.readLine().split(" ");
for(int i = 0; i < str.length; i++)
num[i] = Integer.parseInt(str[i]);
if((num[0] * num[2]) >= (num[1] * num[3]))
System.out.print("Gold");
else
System.out.print("Silver");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Daemon has 2 dragon eggs, one is made of A grams of Gold and the other is made of B grams of Silver.
We know that Gold costs G coins per gram and Silver costs S coins per gram. You need to determine which of the two dragon eggs are more valuable.The input contains 4 space-separated integers G, S, A, B.
<b> Constraints: </b>
1 ≤ G, S, A, B ≤ 10<sup>4</sup>Print "Gold" (without quotes) if the Gold egg costs <b>equal to or more than</b> the silver egg. Otherwise, print "Silver" (without quotes).
Note that the output is case-sensitive.Sample Input 1:
5 4 4 5
Sample Output 1:
Gold
Sample Input 2:
1 1 2 3
Sample Output 2:
Silver, I have written this Solution Code:
G, S, A, B = input().split()
g = int(G)
s = int(S)
a = int(A)
b = int(B)
gold = (g*a)
silver = (s*b)
if(gold>=silver):
print("Gold")
else:
print("Silver"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Daemon has 2 dragon eggs, one is made of A grams of Gold and the other is made of B grams of Silver.
We know that Gold costs G coins per gram and Silver costs S coins per gram. You need to determine which of the two dragon eggs are more valuable.The input contains 4 space-separated integers G, S, A, B.
<b> Constraints: </b>
1 ≤ G, S, A, B ≤ 10<sup>4</sup>Print "Gold" (without quotes) if the Gold egg costs <b>equal to or more than</b> the silver egg. Otherwise, print "Silver" (without quotes).
Note that the output is case-sensitive.Sample Input 1:
5 4 4 5
Sample Output 1:
Gold
Sample Input 2:
1 1 2 3
Sample Output 2:
Silver, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main() {
int g, s, a, b;
cin >> g >> s >> a >> b;
cout << ((g * a >= s * b) ? "Gold" : "Silver");
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code: function bubbleSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => b - a)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code: def bubbleSort(arr):
arr.sort(reverse = True)
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int t;
for(int i=1;i<n;i++){
if(a[i]>a[i-1]){
for(int j=i;j>0;j--){
if(a[j]>a[j-1]){
t=a[j];
a[j]=a[j-1];
a[j-1]=t;
}
}
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const int N = 3e5+5;
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
using vl = vector<ll>;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
long long phi[max1], result[max1],F[max1];
// Precomputation of phi[] numbers. Refer below link
// for details : https://goo.gl/LUqdtY
void computeTotient()
{
// Refer https://goo.gl/LUqdtY
phi[1] = 1;
for (int i=2; i<max1; i++)
{
if (!phi[i])
{
phi[i] = i-1;
for (int j = (i<<1); j<max1; j+=i)
{
if (!phi[j])
phi[j] = j;
phi[j] = (phi[j]/i)*(i-1);
}
}
}
for(int i=1;i<=100000;i++)
{
for(int j=i;j<=100000;j+=i)
{ int p=j/i;
F[j]+=(i*phi[p])%mod;
F[j]%=mod;
}
}
}
int gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
g = gcd(abs(a), abs(b), x0, y0);
if (c % g) {
return false;
}
x0 *= c / g;
y0 *= c / g;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
return true;
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n,greater<int>());
FOR(i,n){
out1(a[i]);}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: def inv(a,b,m):
res = 1
while(b):
if b&1:
res = (res*a)%m
a = (a*a)%m
b >>= 1
return res
n,x = map(int,input().split())
a = list(map(int,input().split()))
m = 1000000007
for i in a:
x = (x*inv(i,m-2,m))%m
print(x), 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.