Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: static int MagicKnight(int N, int T){
while(T-->0){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: def MagicKnight(N,T):
while T > 0:
N = N//2
N = N+2
if N == 3 or N ==4:
return N
T = T - 1
return N
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:-
Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters.
Constraints:-
3 <= N <= 1000000000
1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:-
7 2
Sample Output:-
3
Explanation:-
After 1 sec :- N = 7/2 + 2 = 5
After 2 sec :- N = 5/2 + 2 = 4
Sample Input:-
10 1
Sample Output:-
7, I have written this Solution Code: long MagicKnight(long N, long T){
while(T--){
N/=2;
N+=2;
if(N==3 || N==4){return N;}
}
return N;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: OASIS is a virtual reality created by the legendary James Halliday. After Halliday's death, a pre- recorded message left by him announced a game, which would grant the ownership and control of the OASIS to the first player who finds the Golden Easter Egg within it.
Shivali, an OASIS player, is obsessed with the game and finding the Easter Egg. But she has to fight the IOI clan, which wants to control OASIS for evil purposes. Both of them gather troops of different types and form a big army to fight each other.
IOI has <b>N</b> troops of lowercase letters forming a huge army.
Shivali has an army of length <b>M</b> of lowercase letters. She will win if the first k troops she takes from her army can kill any of the <b>K</b> consecutive troops of the IOI army.
Remember a troop of type 'a' can only kill a troop of type 'a'.
Your task is to find how many times she can winThe first line of input contains N, M, and k, space- separated. The next two lines contain the string of troops of length N and M respectively in lowercase letters.
Constraints:
1 <= N, M <= 10^6
1 <= K <= MOutput the number of wins she is going to take at the end of the day. Print -1 if she can't win.Sample Input :
3 2 1
bbb
bb
Sample Output:-
3
Explanation:-
k = 1, first 'K' troops in shivali's army 'b'
There are 3 'b' pr/esent in IOI army i. e at index 0, 1, 2 Hence shivali can win 3 times.
Sample Input:-
8 5 2
odotkrjz
rimlv
Sample Output:-
-1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] integerInputs = br.readLine().split(" ");
String ioiClan = br.readLine();
String shivali = br.readLine();
String shivaliArmy = shivali.substring(0, Integer.parseInt(integerInputs[2]));
int n = ioiClan.split(shivaliArmy, -1).length-1;
if(n>0){
System.out.print(n);
}else{
System.out.print(-1);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: OASIS is a virtual reality created by the legendary James Halliday. After Halliday's death, a pre- recorded message left by him announced a game, which would grant the ownership and control of the OASIS to the first player who finds the Golden Easter Egg within it.
Shivali, an OASIS player, is obsessed with the game and finding the Easter Egg. But she has to fight the IOI clan, which wants to control OASIS for evil purposes. Both of them gather troops of different types and form a big army to fight each other.
IOI has <b>N</b> troops of lowercase letters forming a huge army.
Shivali has an army of length <b>M</b> of lowercase letters. She will win if the first k troops she takes from her army can kill any of the <b>K</b> consecutive troops of the IOI army.
Remember a troop of type 'a' can only kill a troop of type 'a'.
Your task is to find how many times she can winThe first line of input contains N, M, and k, space- separated. The next two lines contain the string of troops of length N and M respectively in lowercase letters.
Constraints:
1 <= N, M <= 10^6
1 <= K <= MOutput the number of wins she is going to take at the end of the day. Print -1 if she can't win.Sample Input :
3 2 1
bbb
bb
Sample Output:-
3
Explanation:-
k = 1, first 'K' troops in shivali's army 'b'
There are 3 'b' pr/esent in IOI army i. e at index 0, 1, 2 Hence shivali can win 3 times.
Sample Input:-
8 5 2
odotkrjz
rimlv
Sample Output:-
-1, I have written this Solution Code: n,m,k=map(int,input().split())
s1=input()
s2=input()
flag=False
count=0
for i in range((n-k)+1):
if s2[0]==s1[i]:
if s2[:k]==s1[i:i+k]:
flag=True
count+=1
if flag:
print(count)
else:
print(-1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: OASIS is a virtual reality created by the legendary James Halliday. After Halliday's death, a pre- recorded message left by him announced a game, which would grant the ownership and control of the OASIS to the first player who finds the Golden Easter Egg within it.
Shivali, an OASIS player, is obsessed with the game and finding the Easter Egg. But she has to fight the IOI clan, which wants to control OASIS for evil purposes. Both of them gather troops of different types and form a big army to fight each other.
IOI has <b>N</b> troops of lowercase letters forming a huge army.
Shivali has an army of length <b>M</b> of lowercase letters. She will win if the first k troops she takes from her army can kill any of the <b>K</b> consecutive troops of the IOI army.
Remember a troop of type 'a' can only kill a troop of type 'a'.
Your task is to find how many times she can winThe first line of input contains N, M, and k, space- separated. The next two lines contain the string of troops of length N and M respectively in lowercase letters.
Constraints:
1 <= N, M <= 10^6
1 <= K <= MOutput the number of wins she is going to take at the end of the day. Print -1 if she can't win.Sample Input :
3 2 1
bbb
bb
Sample Output:-
3
Explanation:-
k = 1, first 'K' troops in shivali's army 'b'
There are 3 'b' pr/esent in IOI army i. e at index 0, 1, 2 Hence shivali can win 3 times.
Sample Input:-
8 5 2
odotkrjz
rimlv
Sample Output:-
-1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int ans = 0;
void checker(int p_len, string &pattern, vector<int> &v)
{
int j = 0;
for (int i = 1; i < p_len; ++i)
{
while (j >= 0 and pattern[j] != pattern[i])
{
if (j > 0)
j = v[j - 1];
else
j = -1;
}
j += 1;
v[i] = j;
}
}
bool find_occurence(int t_len, int p_len, string &text,
string &pattern, vector<int> &v)
{
bool found = false;
int j = 0;
for (int i = 0; i < t_len; ++i)
{
while (j >= 0 and text[i] != pattern[j])
{
if (j > 0)
j = v[j - 1];
else
j = -1;
}
j += 1;
if (j == p_len)
{
j = v[p_len - 1];
ans++;
found = true;
}
}
return found;
}
int main()
{
int n, m, k;
string text, temp, pattern = "";
cin >> n >> m >> k;
cin >> text >> temp;
for (int i = 0; i < k; ++i)
pattern += temp[i];
int t_len = text.size();
int p_len = pattern.size();
vector<int> v(p_len, 0);
checker(p_len, pattern, v);
bool found = find_occurence(t_len, p_len, text,
pattern, v);
if (found == false)
cout << -1 << endl;
else
cout << ans << endl;
}
, In this Programming Language: C++, 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: You are given N points on a plane, the i<sup>th</sup> point being (x<sub>i</sub>, y<sub>i</sub>). Find the largest area of any parallelogram you can construct from those N points. If no parallelogram can be constructed, print 0.
It can be easily shown that the answer must be an integer.The first line of the input contains a single integer N — the number of points.
Each of the next N lines describes a point on the cartesian plane: the i<sup>th</sup> line contains two integers x<sub>i</sub> and y<sub>i</sub> — the coordinates of the i<sup>th</sup> point.
The given points are not necessarily distinct. Any three points may or may not be collinear.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>3</sup>
0 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 10<sup>9</sup>Print a single integer — the maximum area of a parallelogram that can be constructed from the N points, or print 0 if no such parallelogram can be constructed.Sample Input:
5
1 0
4 0
4 4
7 4
6 1
Sample Output:
12
Explanation:
Take the points indexed 1, 2, 3 and 4. This gives a parallelogram of area 12., I have written this Solution Code: //Author: hyperion_1724
//Time and Date: 19:04:32 18 September 2020
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll x,ll y)
{
if (y == 0)
return 1;
ll p = power(x, y/2) % MOD;
p = (p * p) % MOD;
return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
map<pair<ll,pll>,pll> Z;
map<ll,pll> vert_handler;
vector<pair<ll,ll>> points;
FORI(i,0,N)
{
READV(x);
READV(y);
points.pb({x,y});
}
FORI(i,0,N)
{
FORI(j,0,N)
{
if(i!=j && points[i].fi!=points[j].fi)
{
ll a=points[i].se-points[j].se;
ll b=points[i].fi-points[j].fi;
ll dist=a*a+b*b;
if(b<0)
{
a=-a;
b=-b;
}
ll c=b*points[i].se-a*points[i].fi;
if(a==0)
{
b=1;
}
else
{
ll g=__gcd(abs(a),abs(b));
a=a/g;
b=b/g;
}
if(Z.count({dist,{a,b}})==0)
{
Z[{dist,{a,b}}]={c,c};
}
else
{
Z[{dist,{a,b}}].fi=max(Z[{dist,{a,b}}].fi,c);
Z[{dist,{a,b}}].se=min(Z[{dist,{a,b}}].se,c);
}
}
else if(i!=j && points[i].fi==points[j].fi)
{
ll a=points[i].se-points[j].se;
ll b=points[i].fi-points[j].fi;
ll c=points[i].fi;
ll dist=abs(a);
if(vert_handler.count(dist)==0)
{
vert_handler[dist]={c,c};
}
else
{
vert_handler[dist].fi=max(vert_handler[dist].fi,c);
vert_handler[dist].se=min(vert_handler[dist].se,c);
}
}
}
}
ll ans=0;
for(auto x:vert_handler)
{
ll ans1=x.fi*(x.se.fi-x.se.se);
ans=max(ans,ans1);
}
for(auto x:Z)
{
ans=max(ans,x.se.fi-x.se.se);
}
cout<<ans<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: def For_Loop(n):
string = ""
for i in range(1, n+1):
if i % 2 == 0:
string += "%s " % i
return string
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 <= n <= 100
<b>Note:</b>
<i>But there is a catch here, given user function has already code in it which may or may not be correct, now you need to figure out these and correct them if it is required</i>Print all the even numbers from 1 to n. (print all the numbers in the same line, space-separated)Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N initially. We take the GCD of all adjacent elements. Now we obtain N-1 integers. Take this array as new array A. Keep repeating this process until you obtain an array of only 1 element. Find that last element that you get.
See explanation of example section for more clarity.First line contains an integers N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
0 <= Ai<= 10^9Print the last element remaining.Sample Input 1:
3
1 2 3
Output
1
Explanation:
Array ={1, 2, 3}
Taking GCD of adjacent elements, Array ={1, 1}
Taking GCD of adjacent elements, Array ={1}
Now we stop as only one element is left.
Sample Input 2:
6
3 6 6 9 3 3
Output
3
Explanation
Array ={3, 6, 6, 9, 3, 3}
Taking GCD of adjacent elements, Array ={3, 6, 3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3}
Taking GCD of adjacent elements, Array ={3}
Now we stop as only one element is left., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define fo(n) for(int j=0;j<n;j++)
#define foo(n) for(int i=1;i<=n;i++)
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define test int tt; cin>>tt; while(tt--)
#define mod 1000000007
void fastio()
{
ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("Input 1.txt", "r", stdin);
freopen("Output 1.txt", "w", stdout);
#endif
}
int main() {
fastio();
int n;
cin >> n;
int a[n];
f(n)cin >> a[i];
int ans = 0;
f(n) {
ans = __gcd(ans, a[i]);
}
cout << ans << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N initially. We take the GCD of all adjacent elements. Now we obtain N-1 integers. Take this array as new array A. Keep repeating this process until you obtain an array of only 1 element. Find that last element that you get.
See explanation of example section for more clarity.First line contains an integers N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
0 <= Ai<= 10^9Print the last element remaining.Sample Input 1:
3
1 2 3
Output
1
Explanation:
Array ={1, 2, 3}
Taking GCD of adjacent elements, Array ={1, 1}
Taking GCD of adjacent elements, Array ={1}
Now we stop as only one element is left.
Sample Input 2:
6
3 6 6 9 3 3
Output
3
Explanation
Array ={3, 6, 6, 9, 3, 3}
Taking GCD of adjacent elements, Array ={3, 6, 3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3, 3}
Taking GCD of adjacent elements, Array ={3, 3}
Taking GCD of adjacent elements, Array ={3}
Now we stop as only one element is left., I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.BigInteger;
class Main {
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int [n];
int ans=0;
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
ans=gcd(ans,a[i]);
}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<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>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A circular array is called good if, for every index i (0 to N-1), there exists an index j such that i != j and sum of all the numbers in the clockwise direction from i to j is equal to the sum of all numbers in the anticlockwise direction from i to j.
You are given an circular array of size N, Your task is to check whether the given array is good or not.First line of input contains a single integer N, the next line of input contains N space separated integes depicting values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 1000000Print "Yes" if array is good else print "No"Sample Input:-
4
1 4 1 4
Sample Output:-
Yes
Explanation:-
for index 1, j will be 3, then sum of elements from index 1 to 3 in clockwise direction will be 1 + 4 + 1 = 6 and the sum of elements from index 1 to 3 in anticlockwise direction will be 1 + 4 + 1 = 6.
For index 2, j will be 4
For index 3, j will be 1
For index 4, j will be 2
Sample Input:-
4
1 2 3 4
Sample Output:-
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 10001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int INF = 4557430888798830399ll;
signed main()
{
fast();
int n;
cin>>n;
int a[n];
FOR(i,n){
cin>>a[i];}
if(n&1){out("No");return 0;}
FOR(i,n/2){
if(a[i]!=a[n/2+i]){out("No");return 0;}
}
out("Yes");
}
, In this Programming Language: Unknown, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int cost(int n){
if(n == 0) return 0;
int g = (n-1)/3 + 1;
return g*g + cost(n-g);
}
signed main() {
IOS;
clock_t start = clock();
int q; cin >> q;
while(q--){
int n;
cin >> n;
cout << cost(n) << endl;
}
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
long q = Long.parseLong(br.readLine());
while(q-->0)
{
long N = Long.parseLong(br.readLine());
System.out.println(candyCrush(N,0,0));
}
}
static long candyCrush(long N, long cost,long group)
{
if(N==0)
{
return cost;
}
if(N%3==0)
{
group = N/3;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
else
{
group = (N/3)+1;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A robot is initially placed at the origin of the number line. The robot also has a happiness counter with an initial value of 0.
A command string is also given. Each character of this string denotes an operation on the robot. Each character of the string can be one of the following:
• 'C': Changes the robot's position by moving in either direction by one unit along the number line.
• '+': If the robot's current position is X, then add X to the happiness counter of the robot.
• '-': If the robot's current position is X, then subtract X from the happiness counter of the robot.
The robot will start executing the command string, i.e., it will execute each character one by one in the given order. However, the robot must return back to the origin after execution of the command string is finished. Thus, among all possible paths the robot can take, you must choose an assignment of directions in such a way that the robot finally ends up at the origin.
Note that the robot's coordinates and happiness can be negative while executing the string. Find the maximum possible happiness of the robot after executing the string.The first line of the input contains a single integer N (2 ≤ N ≤ 2×10<sup>5</sup>).
The next line contains the command string S of length N. The string only consists of characters '+', '-' and 'C'. The total number of appearances of 'C' in the string is guaranteed to be even.Print a single integer denoting the maximum possible happiness of the robot.Sample Input 1:
4
C-C-
Sample Output 1:
1
Sample Explanation 1:
There are only two possible paths the robot can take as it has to return to origin. The paths are 0 -> 1 -> 0 and 0 -> -1 -> 0. The path 0 -> -1 -> 0 gives the maximum happiness of 1.
Sample Input 2:
5
C+-C+
Sample Output 2:
0
Sample Explanation 2:
There are again only two possible paths the robot can take, both of which give happiness 0.
Sample Input 3:
6
C+CC-C
Sample Output 3:
2, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
fs = new FastReader();
out = new PrintWriter(System.out);
int n = fs.nextInt();
char s[] = fs.next().toCharArray();
ArrayList<Integer> ar = new ArrayList<>();
for (int i = n - 1, c = 0; i >= 0; --i) {
if (s[i] == '+') ++c;
else if (s[i] == '-') --c;
else ar.add(c);
}
Collections.sort(ar);
long ans = 0;
for (int i = 0; i < ar.size(); ++i) {
ans += i < ar.size() / 2 ? -ar.get(i) : ar.get(i);
}
out.println(ans);
out.close();
}
public static PrintWriter out;
public static FastReader fs;
public static final Random random = new Random();
public static void ruffleSort(int[] a) {
int n = a.length;
for (int i = 0; i < n; ++i) {
int oi = random.nextInt(n), tmp = a[oi];
a[oi] = a[i];
a[i] = tmp;
}
Arrays.sort(a);
}
public static class FastReader {
private BufferedReader br;
private StringTokenizer st = new StringTokenizer("");
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String file_name) throws FileNotFoundException {
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(file_name))));
}
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; ++i)
a[i] = nextInt();
return a;
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A robot is initially placed at the origin of the number line. The robot also has a happiness counter with an initial value of 0.
A command string is also given. Each character of this string denotes an operation on the robot. Each character of the string can be one of the following:
• 'C': Changes the robot's position by moving in either direction by one unit along the number line.
• '+': If the robot's current position is X, then add X to the happiness counter of the robot.
• '-': If the robot's current position is X, then subtract X from the happiness counter of the robot.
The robot will start executing the command string, i.e., it will execute each character one by one in the given order. However, the robot must return back to the origin after execution of the command string is finished. Thus, among all possible paths the robot can take, you must choose an assignment of directions in such a way that the robot finally ends up at the origin.
Note that the robot's coordinates and happiness can be negative while executing the string. Find the maximum possible happiness of the robot after executing the string.The first line of the input contains a single integer N (2 ≤ N ≤ 2×10<sup>5</sup>).
The next line contains the command string S of length N. The string only consists of characters '+', '-' and 'C'. The total number of appearances of 'C' in the string is guaranteed to be even.Print a single integer denoting the maximum possible happiness of the robot.Sample Input 1:
4
C-C-
Sample Output 1:
1
Sample Explanation 1:
There are only two possible paths the robot can take as it has to return to origin. The paths are 0 -> 1 -> 0 and 0 -> -1 -> 0. The path 0 -> -1 -> 0 gives the maximum happiness of 1.
Sample Input 2:
5
C+-C+
Sample Output 2:
0
Sample Explanation 2:
There are again only two possible paths the robot can take, both of which give happiness 0.
Sample Input 3:
6
C+CC-C
Sample Output 3:
2, I have written this Solution Code: //Author: Xzirium
//Time and Date: 00:13:26 24 May 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()
{
#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;
vector<ll> C;
ll curr = 0;
FORI(i, 1, N+1)
{
if (S[N - i] == 'C')
{
C.push_back(curr);
}
else if (S[N - i] == '+')
{
curr++;
}
else
{
curr--;
}
}
ll ans=0;
sort(C.begin(), C.end());
FORI(i, 0, C.size())
{
if(i < C.size()/2)
{
ans-=C[i];
}
else
{
ans+=C[i];
}
}
cout<<ans<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A robot is initially placed at the origin of the number line. The robot also has a happiness counter with an initial value of 0.
A command string is also given. Each character of this string denotes an operation on the robot. Each character of the string can be one of the following:
• 'C': Changes the robot's position by moving in either direction by one unit along the number line.
• '+': If the robot's current position is X, then add X to the happiness counter of the robot.
• '-': If the robot's current position is X, then subtract X from the happiness counter of the robot.
The robot will start executing the command string, i.e., it will execute each character one by one in the given order. However, the robot must return back to the origin after execution of the command string is finished. Thus, among all possible paths the robot can take, you must choose an assignment of directions in such a way that the robot finally ends up at the origin.
Note that the robot's coordinates and happiness can be negative while executing the string. Find the maximum possible happiness of the robot after executing the string.The first line of the input contains a single integer N (2 ≤ N ≤ 2×10<sup>5</sup>).
The next line contains the command string S of length N. The string only consists of characters '+', '-' and 'C'. The total number of appearances of 'C' in the string is guaranteed to be even.Print a single integer denoting the maximum possible happiness of the robot.Sample Input 1:
4
C-C-
Sample Output 1:
1
Sample Explanation 1:
There are only two possible paths the robot can take as it has to return to origin. The paths are 0 -> 1 -> 0 and 0 -> -1 -> 0. The path 0 -> -1 -> 0 gives the maximum happiness of 1.
Sample Input 2:
5
C+-C+
Sample Output 2:
0
Sample Explanation 2:
There are again only two possible paths the robot can take, both of which give happiness 0.
Sample Input 3:
6
C+CC-C
Sample Output 3:
2, I have written this Solution Code: from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(input())
def st(): return input()
def mj(): return map(int,input().strip().split(" "))
def msj(): return list(map(str,input().strip().split(" ")))
def le(): return list(map(int,input().split()))
def rc(): return map(float,input().split())
def lebe():return list(map(int, input()))
def dmain():
sys.setrecursionlimit(1000000)
threading.stack_size(1024000)
thread = threading.Thread(target=main)
thread.start()
def joro(L):
return(''.join(map(str, L)))
def joron(L):
return('\n'.join(map(str, L)))
def decimalToBinary(n): return bin(n).replace("0b","")
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def npr(n, r):
return factorial(n) // factorial(n - r) if n >= r else 0
def ncr(n, r):
return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0
def lower_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer # min index where x is not less than num
def upper_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer # max index where x is not greater than num
def tir(a,b,c):
if(0==c):
return 1
if(len(a)<=b):
return 0
if(c!=-1):
return (tir(a,1+b,c+a[b]) or tir(a,b+1,c-a[b]) or tir(a,1+b,c))
else:
return (tir(a,1+b,a[b]) or tir(a,b+1,-a[b]) or tir(a,1+b,-1))
def abs(x):
return x if x >= 0 else -x
def binary_search(li, val, lb, ub):
ans = -1
while (lb <= ub):
mid = (lb + ub) // 2
if li[mid] > val:
ub = mid - 1
elif val > li[mid]:
lb = mid + 1
else:
ans = mid # return index
break
return ans
def kadane(x): # maximum sum contiguous subarray
sum_so_far = 0
current_sum = 0
for i in x:
current_sum += i
if current_sum < 0:
current_sum = 0
else:
sum_so_far = max(sum_so_far, current_sum)
return sum_so_far
def pref(li):
pref_sum = [0]
for i in li:
pref_sum.append(pref_sum[-1] + i)
return pref_sum
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
li = []
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, len(prime)):
if prime[p]:
li.append(p)
return li
def primefactors(n):
factors = []
while (n % 2 == 0):
factors.append(2)
n //= 2
for i in range(3, int(sqrt(n)) + 1, 2): # only odd factors left
while n % i == 0:
factors.append(i)
n //= i
if n > 2: # incase of prime
factors.append(n)
return factors
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def tr(n):
return n*(n+1)//2
boi=int(998244353)
doi=int(1e9+7)
hoi=int(3e6+5)
poi=int(3e5+20)
y="Yes"
n="No"
def gosa(x, y):
while(y):
x, y = y, x % y
return x
def iu():
import sys
import math as my
input=sys.stdin.readline
from collections import deque, defaultdict
m=so()
L=[]
t=list(st())
g=0
t.reverse()
for i in t:
if(i=='+'):
g+=1
elif(i=='-'):
g-=1
else:
L.append(g)
L.sort()
f=len(L)
bec=0
for i in range(f//2):
bec=bec-L[i]+L[f-1-i]
print(bec)
def main():
for i in range(1):
iu()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have N coins with either an integer (between 0-9) written on one side and an english letter (a- z) written on the other side.
The following statement must be true for all coins:
<b>If the coin has a vowel on one side, then it must have an even integer on other side. </b>
For example coin having 'b' and '3' is valid (since 'b' is not a vowel, other side can be anything), coin having 'a' and '4' is valid, but coin having 'a' and '5' is invalid.
Now you're given just one side of each coin, find the minimum number of coins you need to flip to check the authenticity of the statement.The first and only line of input contains a string S, where each character in S depicts a side of the coin.
<b>Constraints:</b>
1 ≤ |S| ≤ 50Output a single integer, the minimum number of coins you need to flip.Sample Input
ee
Sample Output
2
Explanation: You need to flip both the coins to make sure an even integer is there on the other side of coin.
Sample Input
0ay1
Sample Output
2, I have written this Solution Code: x = list(input())
c = 0
for i in x:
if i in ['a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9']:
c += 1
print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have N coins with either an integer (between 0-9) written on one side and an english letter (a- z) written on the other side.
The following statement must be true for all coins:
<b>If the coin has a vowel on one side, then it must have an even integer on other side. </b>
For example coin having 'b' and '3' is valid (since 'b' is not a vowel, other side can be anything), coin having 'a' and '4' is valid, but coin having 'a' and '5' is invalid.
Now you're given just one side of each coin, find the minimum number of coins you need to flip to check the authenticity of the statement.The first and only line of input contains a string S, where each character in S depicts a side of the coin.
<b>Constraints:</b>
1 ≤ |S| ≤ 50Output a single integer, the minimum number of coins you need to flip.Sample Input
ee
Sample Output
2
Explanation: You need to flip both the coins to make sure an even integer is there on the other side of coin.
Sample Input
0ay1
Sample Output
2, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = s.length();
int cnt=0;
for(int i=0;i<n;i++){
if(s.charAt(i)>='a' && s.charAt(i)<='z'){
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='o' || s.charAt(i)=='i' ||s.charAt(i)=='u'){
cnt++;
}
}
else{
int x = s.charAt(i)-'0';
if(x%2==1){cnt++;}
}
}
System.out.print(cnt);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have N coins with either an integer (between 0-9) written on one side and an english letter (a- z) written on the other side.
The following statement must be true for all coins:
<b>If the coin has a vowel on one side, then it must have an even integer on other side. </b>
For example coin having 'b' and '3' is valid (since 'b' is not a vowel, other side can be anything), coin having 'a' and '4' is valid, but coin having 'a' and '5' is invalid.
Now you're given just one side of each coin, find the minimum number of coins you need to flip to check the authenticity of the statement.The first and only line of input contains a string S, where each character in S depicts a side of the coin.
<b>Constraints:</b>
1 ≤ |S| ≤ 50Output a single integer, the minimum number of coins you need to flip.Sample Input
ee
Sample Output
2
Explanation: You need to flip both the coins to make sure an even integer is there on the other side of coin.
Sample Input
0ay1
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pb push_back
#define ll long long
#define mp make_pair
#define F first
#define S second
int main(){
string s;
cin>>s;
int ct=0;
for(int i=0; i<s.length(); i++){
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='1' || s[i]=='3' || s[i]=='5' || s[i]=='7' || s[i]=='9'){
ct++;
}
}
cout<<ct;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , I have written this Solution Code: from math import sqrt
a=int(input())
c=0
i=2
while(i*i < a):
if(a%i==0):
c=c+1
i=i+1
for i in range(int(sqrt(a)), 0, -1):
if (a % i == 0):
c=c+1
print(c+1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , 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 count = 0;
for(long i = 1; i*i <= N; i++){
if(N % i == 0){
if(i*i < N){
count += 2;
}else if(i*i == N){
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 a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
long long n;
cin>>n;
long long x=sqrt(n);
unordered_map<long long ,int> m;
for(int i=1;i<=x;i++){
if(n%i==0){m[i]++;
if(n/i!=i){m[n/i]++;}}
}
cout<<m.size();
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long x;
BigInteger sum = new BigInteger("0");
for(int i=0;i<n;i++){
x=sc.nextLong();
sum= sum.add(BigInteger.valueOf(x));
}
sum=sum.divide(BigInteger.valueOf(n));
System.out.print(sum);
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, cur = 0, rem = 0;
cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
cur += (p + rem)/n;
rem = (p + rem)%n;
}
cout << cur;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: n = int(input())
a =list
a=list(map(int,input().split()))
sum=0
for i in range (0,n):
sum=sum+a[i]
print(int(sum//n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an integer n, you have to print a Increasing power of 2 pattern of size n.The first line contains a single Integer n.
<b>Constraints</b>
1 ≤ n ≤ 15Print Increasing power of 2 pattern of size n.Sample Input:
4
Sample Output:
*
**
****
********
<b>Explanation</b>
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8, I have written this Solution Code: import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<=n; i++) {
for(int j=1; j<=Math.pow(2, i-1); j++) {
System.out.print("*");
}
System.out.println();
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
for(int k=0; k<n; k++)
{
String str=br.readLine();
StringBuilder s=new StringBuilder(str);
char last=s.charAt(s.length()-1);
int secondlast=s.charAt(s.length()-2);
if(last=='a')
{
s.append("s");
}
else if(last=='i')
{
s.append("os");
}
else if(last=='y')
{
s.delete(s.length()-1,s.length());
s.append("ios");
}
else if(last=='l')
{
s.append("es");
}
else if(last=='n')
{
s.delete(s.length()-1,s.length());
s.append("anes");
}
else if(last=='e' && secondlast=='n')
{
s.delete(s.length()-2,s.length());
s.append("anes");
}
else if(last=='o')
{
s.append("s");
}
else if(last=='r')
{
s.append("es");
}
else if(last=='t')
{
s.append("as");
}
else if(last=='u')
{
s.append("s");
}
else if(last=='v')
{
s.append("es");
}
else if(last=='w')
{
s.append("as");
}
else
{
s.append("us");
}
System.out.println(s);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: translate = {"y":"ios","a":"as","i":"ios","l":"les","n":"anes",
"ne" :"anes","o" :"os","r" :"res","t" :"tas","u" :"us","v" :"ves","w" :"was"}
for i in range(int(input())):
a = input().rstrip()
if(a[-2:]!="ne"):
print(a[:-1]+translate.get(a[-1],a[-1]+"us"))
else:
print(a[:-2]+translate.get(a[-2:],"us")), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main()
{
// string arr[12][2] = {
// {"a","as"},
// {"i","ios"},
// {"l","les"},
// {"n","anes"},
// {"ne","anes"},
// {"o","os"},
// {"r","res"},
// {"t","tas"},
// {"u","us"},
// {"v","ves"},
// {"w","was"},
// {"y","ios"}
// }
// ;
int t;
cin>>t;
while(t--)
{
string str;
cin>>str;
if(str[str.length()-1]=='e' && str[str.length()-2]=='n')
{
str = str.substr(0,str.length()-2);
str += "anes";
}
else if(str[str.length()-1]=='a')
{
str = str.substr(0,str.length()-1);
str += "as";
}
else if(str[str.length()-1]=='i')
{
str = str.substr(0,str.length()-1);
str += "ios";
}
else if(str[str.length()-1]=='l')
{
str = str.substr(0,str.length()-1);
str += "les";
}
else if(str[str.length()-1]=='n')
{
str = str.substr(0,str.length()-1);
str += "anes";
}
else if(str[str.length()-1]=='o')
{
str = str.substr(0,str.length()-1);
str += "os";
}
else if(str[str.length()-1]=='r')
{
str = str.substr(0,str.length()-1);
str += "res";
}
else if(str[str.length()-1]=='t')
{
str = str.substr(0,str.length()-1);
str += "tas";
}
else if(str[str.length()-1]=='u')
{
str = str.substr(0,str.length()-1);
str += "us";
}
else if(str[str.length()-1]=='v')
{
str = str.substr(0,str.length()-1);
str += "ves";
}
else if(str[str.length()-1]=='w')
{
str = str.substr(0,str.length()-1);
str += "was";
}
else if(str[str.length()-1]=='y')
{
str = str.substr(0,str.length()-1);
str += "ios";
}
else
{
str += "us";
}
cout<<str<<endl;
}
return 0;
}, 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: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2.
Constraints
1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1
2 1
Sample Output 1
Aniket
Sample Input 2
4 8
Sample Output 2
Swapnil, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().trim().split(" ");
long n1 = Long.parseLong(str[0]);
long n2 = Long.parseLong(str[1]);
long diff = Math.abs(n1-n2);
long c =0;
while(diff>1){
if(diff%2!=0)
diff--;
diff/=2;
if(n1>n2){
n1 -= 2*diff;
n2 += diff;
}
else{
n2 -= 2*diff;
n1 += diff;
}
c += diff;
diff = Math.abs(n1-n2);
}
if(c%2==0){
System.out.print("Aniket");
}else{
System.out.print("Swapnil");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2.
Constraints
1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1
2 1
Sample Output 1
Aniket
Sample Input 2
4 8
Sample Output 2
Swapnil, I have written this Solution Code: n1,n2 = map(int,input().split())
print('Aniket' if abs(n1-n2)==1 or n1==n2 else 'Swapnil'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Aniket and Swapnil are playing a game in which they have two piles of stones with N1 and N2 stones respectively. They take turns picking any even positive number of stones from one of the pile and keep half of them on the other pile and throw away the other half. Whoever can not make a move loses. Given N1 and N2 find who will win. Swapnil makes the first move.The first and only line of input contains two integers N1 and N2.
Constraints
1 <= N1, N2 <= 1000000000000000Print "Swapnil" if Swapnil wins the game and print "Aniket" if Aniket wins the game.Sample Input 1
2 1
Sample Output 1
Aniket
Sample Input 2
4 8
Sample Output 2
Swapnil, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define inf 1e8+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int x,y;
cin>>x>>y;
if(abs(x-y)<=1)
{
cout<<"Aniket";
}
else
cout<<"Swapnil";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, 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));
String str[]=br.readLine().split(" ");
int a[]=new int[str.length];
int sum=0;
for(int i=0;i<str.length;i++)
{
a[i]=Integer.parseInt(str[i]);
sum=sum+a[i];
}
System.out.println(sum/4);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: a,b,c,d = map(int,input().split())
print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary.
Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N.
Next N lines contains two integers x[i] and y[i].
Constraints:
2 <= N <= 100000
0 <= x[i], y[i] <= 1000000000
Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input
2
0 0
1 1
Sample Output
1
Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE;
for(int i = 0; i < N; i++) {
StringTokenizer tokens = new StringTokenizer(reader.readLine());
int x = Integer.parseInt(tokens.nextToken());
int y = Integer.parseInt(tokens.nextToken());
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
}
long X = maxX - minX;
long Y = maxY - minY;
long area = X * Y;
System.out.println(X * Y);
reader.close();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary.
Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N.
Next N lines contains two integers x[i] and y[i].
Constraints:
2 <= N <= 100000
0 <= x[i], y[i] <= 1000000000
Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input
2
0 0
1 1
Sample Output
1
Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), I have written this Solution Code:
minx = 1000000000
maxx= 0
miny=1000000000
maxy=0
n = int(input())
while(n):
a,b = map(int,input().split())
minx = min(minx,a);
maxx = max(maxx,a);
miny = min(miny,b);
maxy = max(maxy,b);
n -=1
l = (maxx-minx);
b = (maxy-miny);
print(l*b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary.
Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N.
Next N lines contains two integers x[i] and y[i].
Constraints:
2 <= N <= 100000
0 <= x[i], y[i] <= 1000000000
Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input
2
0 0
1 1
Sample Output
1
Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), 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 mix=infi,maax=0;
int miy=infi,may=0;
for(int i=0;i<n;++i){
int x,y;
cin>>x>>y;
mix=min(mix,x);
miy=min(miy,y);
maax=max(maax,x);
may=max(may,y);
}
cout<<(maax-mix)*(may-miy);
#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: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";}
else if(i%5==0){cout<<"Buzz ";}
else if(i%3==0){cout<<"Fizz ";}
else{cout<<i<<" ";}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton's garden has N apple trees. Initially, there are A<sub>i</sub> apples attached to the ith tree. Also, there are M apples which newton has to attach to these tress for testing gravity laws.
In one minute, at most B<sub>i</sub> apples fall from the ith tree.
Help newton find the minimum time he has to wait after which he can safely sit under any apple tree.The first line contains two space-separated integers – N and M indicating the number of apple trees and the number of apples to be attached.
Each of the next N lines contains two integers A<sub>i</sub> and B<sub>i</sub> specifying the initial count of apples and rate of fall of apples per minute for ith tree.
<b> Constraints: </b>
1 <= N <= 2*10<sup>5</sup>
0 <= A<sub>i</sub> <= 10<sup>6</sup>
1 <= M, B<sub>i</sub> <= 10<sup>6</sup>Output minimum time Newton has to waitInput:
3 6
4 3
7 4
1 5
Output:
2
Explanation:
Attach 2, 1, 3 apples to 1st, 2nd, 3rd tree respectively. Then, 2, 2, 1 minutes are required for all apples to fall from 1st, 2nd, 3rd tree respectively. So, Wait time is max(2, 2, 1) = 2., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 2*1e5+5;
ll n,m;
vector<ll> a(N),b(N);
bool possible(ll time) {
ll lim = 0;
for(int i=0 ; i<n ; i++) lim += b[i] * time;
ll tot = m;
for(int i=0 ; i<n ; i++) tot += a[i];
if (tot > lim) return false;
for(int i=0 ; i<n ; i++) if (a[i] > b[i]*time) return false;
return true;
}
int main(){
cin >> n >> m;
for(int i=0 ; i<n ; i++){
cin >> a[i] >> b[i];
}
ll lo = 1, hi = 2*1e6+1000;
while(hi - lo > 1) {
ll mid = (hi+lo)/2;
if (possible(mid)){
hi = mid;
}else{
lo = mid;
}
}
cout << hi << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] input = in.readLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
int c = Integer.parseInt(input[2]);
if(a==b && b==c && c == a) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: a,b,c=map(int,input().split())
if a==b and b==c:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three positive integers A, B and C. If all the three integers are equal, print "Yes". Otherwise, print "No".
Note that the quotation marks are not part of the string, thus you should print your answer without the quotation marks.The input consists of three space separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 100Print a single word "Yes" if all the integers are equal, otherwise print "No" (without the quotes). Note that the output is case- sensitive.Sample Input 1:
1 3 1
Sample Output 1:
No
Sample Input 2:
5 5 5
Sample Output 2:
Yes, I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == b && b == c) cout << "Yes";
else cout << "No";
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String values[] = br.readLine().trim().split(" ");
long N = Long.parseLong(values[0]);
long M = Long.parseLong(values[1]);
long X = Long.parseLong(values[2]);
long Y = Long.parseLong(values[3]);
if(M/X >= N){
System.out.print(N);
return;
}
else
{
long count = M/X;
M = M % X;
N = N - count;
if(((N-1)*Y+M)<X)
System.out.print(count);
else
System.out.print(count+ N - countSacrifice(1,N,M,X,Y));
}
}
public static long countSacrifice(long min,long max,long M,long X,long Y)
{
long N = max;
while(min<max)
{ long mid = min + (max-min)/2;
if((mid*Y + M)>=((N-mid)*X))
{
max = mid;
}
else
{
min = mid+1;
}
}
return min;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import math
N,M,X,Y = map(int,input().strip().split())
low = 0
high = N
def possible(mid,M,X,Y):
if M//X >= mid:
return True
elif (N-math.ceil(((X*mid)-M)/Y))>=mid:
return True
return False
while(low<=high):
mid = (high+low)>>1
if possible(mid,M,X,Y):
res = mid
low = mid+1
else:
high = mid-1
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define LL long long
void solve() {
LL n, m, x, y;
cin >> n >> m >> x >> y;
LL l = 0, r = n + 1, mid;
while(l < r-1) {
mid = (l + r) / 2;
if(mid * x <= m + (n - mid) * y) l = mid;
else r = mid;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tt = 1; //cin >> tt;
while(tt--) solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int ans = 9 * (x-1);
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt[max1];
signed main(){
int n;
cin>>n;
out((n-1)*9);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number X (X>=0) is called strange if the sum of its digits is divisible by 9. Given an integer N, your task is to find the Nth strange number.The input contains a single line containing the value of N.
Constraints:-
1 <= N <= 1000Print the Nth strange number.Sample Input:-
3
Sample Output:-
18
Explanation:-
0, 9, and 18 are the first three strange numbers.
Sample Input:-
2
Sample Output:-
9, I have written this Solution Code: a=int(input())
print(9*(a-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you have to perform only two types of operations on the number:-
1) If N is odd increase it by 1
2) If N is even divide it by 2
Your task is to find the number of operations it takes to make N equal to 1.<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>MakeOne()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:-
7
Sample Output:-
4
Explanation:-
7 - > 8 - > 4 - > 2 - > 1
Sample Input:-
3
Sample Output:-
3, I have written this Solution Code: int MakeOne(int N){
int cnt=0;
int a =N;
while(a!=1){
if(a&1){a++;}
else{a/=2;}
cnt++;
}
return cnt;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you have to perform only two types of operations on the number:-
1) If N is odd increase it by 1
2) If N is even divide it by 2
Your task is to find the number of operations it takes to make N equal to 1.<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>MakeOne()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:-
7
Sample Output:-
4
Explanation:-
7 - > 8 - > 4 - > 2 - > 1
Sample Input:-
3
Sample Output:-
3, I have written this Solution Code: static int MakeOne(int N){
int cnt=0;
int a =N;
while(a!=1){
if(a%2==1){a++;}
else{a/=2;}
cnt++;
}
return cnt;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you have to perform only two types of operations on the number:-
1) If N is odd increase it by 1
2) If N is even divide it by 2
Your task is to find the number of operations it takes to make N equal to 1.<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>MakeOne()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:-
7
Sample Output:-
4
Explanation:-
7 - > 8 - > 4 - > 2 - > 1
Sample Input:-
3
Sample Output:-
3, I have written this Solution Code: int MakeOne(int N){
int cnt=0;
int a =N;
while(a!=1){
if(a&1){a++;}
else{a/=2;}
cnt++;
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you have to perform only two types of operations on the number:-
1) If N is odd increase it by 1
2) If N is even divide it by 2
Your task is to find the number of operations it takes to make N equal to 1.<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>MakeOne()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 100000Return the number of operations it takes to make the number N equal to 1.Sample Input:-
7
Sample Output:-
4
Explanation:-
7 - > 8 - > 4 - > 2 - > 1
Sample Input:-
3
Sample Output:-
3, I have written this Solution Code: def MakeOne(N):
cnt=0
while N!=1:
if N%2==1:
N=N+1
else:
N=N//2
cnt=cnt+1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: static int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: def Phone(N,K,M):
if N*K < M :
return -1
x = M//K
if M%K!=0:
x=x+1
return x, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long x;
BigInteger sum = new BigInteger("0");
for(int i=0;i<n;i++){
x=sc.nextLong();
sum= sum.add(BigInteger.valueOf(x));
}
sum=sum.divide(BigInteger.valueOf(n));
System.out.print(sum);
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, cur = 0, rem = 0;
cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
cur += (p + rem)/n;
rem = (p + rem)%n;
}
cout << cur;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Straight and Simple.
Given N numbers, A[1], A[2],. , A[N], find their average.
Refer <a href="https://en.wikipedia.org/wiki/Average">here</a> for better understanding of average.The first line of the input contains a single integer N.
The second line of the input contains N singly spaced integers, A[1]...A[N].
Constraints
1 <= N <= 300000
0 <= A[i] <= 10<sup>18</sup> (for i = 1 to N)If the average is X, report <b>floor(X)</b>.Sample Input
5
1 2 3 4 6
Sample Output
3
Explanation:
(1 + 2 + 3 + 4 + 6) / 5 = 3.2. floor(3.2) = 3.
Sample Input
5
3 60 9 28 30
Sample Output
26, I have written this Solution Code: n = int(input())
a =list
a=list(map(int,input().split()))
sum=0
for i in range (0,n):
sum=sum+a[i]
print(int(sum//n))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two integer arrays A and B of sizes N and M respectively. You need to modify the elements of A so that B becomes its subarray. Modifying an element means change the element to any other value.
Find the minimum number of modifications to achieve this.The first line of the input contains two integers N and M.
The second line of the input contains N space separated integers, the elements of array A.
The third line of the input contains M space separated integers, the elements of array B.
Constraints
1 <= M <= N <= 500
1 <= A[i], B[i] <= 10Output a single integer, the minimum number of modifications in A to make B its subarray.Sample Input
6 3
3 1 2 1 3 3
1 2 3
Sample Output
1
Explanation: If you modify A[4] from 1 to 3. A[2]. A[4] represents the array B, so B is its subarray.
Sample Input
10 5
3 4 5 3 4 3 1 3 5 2
1 4 4 4 3
Sample Output
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
int listn[] = new int[n];
int listm[] = new int[m];
str = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
listn[i]=Integer.parseInt(str[i]);
str = read.readLine().trim().split(" ");
for(int i = 0; i < m; i++)
listm[i]=Integer.parseInt(str[i]);
int ans =m;
for(int i=0; i < n-m+1 ; i++){
int ct=0;
for(int j=0;j <m; j++){
if(listn[i+j] != listm[j]){
ct++;
}
}
ans = Math.min(ans,ct);
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two integer arrays A and B of sizes N and M respectively. You need to modify the elements of A so that B becomes its subarray. Modifying an element means change the element to any other value.
Find the minimum number of modifications to achieve this.The first line of the input contains two integers N and M.
The second line of the input contains N space separated integers, the elements of array A.
The third line of the input contains M space separated integers, the elements of array B.
Constraints
1 <= M <= N <= 500
1 <= A[i], B[i] <= 10Output a single integer, the minimum number of modifications in A to make B its subarray.Sample Input
6 3
3 1 2 1 3 3
1 2 3
Sample Output
1
Explanation: If you modify A[4] from 1 to 3. A[2]. A[4] represents the array B, so B is its subarray.
Sample Input
10 5
3 4 5 3 4 3 1 3 5 2
1 4 4 4 3
Sample Output
3, I have written this Solution Code: n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = 0
matched = 0
while(n-k >= m):
c = 0
for i in range(m):
if(a[k:][i] == b[i]):
c += 1
matched = max(matched,c)
k += 1
print(m-matched), 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.