Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: There are N participants in a programming contest. You are given an integer array A of size N. The i<sup>th</sup> element of the array A denotes the score of the i<sup>th</sup> participant. Find the rank of all the participants. 1st place participant has the highest score, the 2nd place participant has the 2nd highest score, and so on. If two participants have same score, the participant with higher index will be placed above the participant with lower index in rank list.First line contains an integer N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
1 <= Ai<= 10^5Print N space separated integers where the i<sup>th</sup> integer is the rank of the i<sup>th</sup> participant.Sample Input 1:
3
3 2 1
Output
1 2 3
Explanation:
Participant 1 has highest score, so his rank is 1.
Participant 2 has second highest score, so his rank is 2.
Participant 3 has lowest score, so his rank is 3.
Sample Input 2:
4
7 7 7 7
Output
4 3 2 1
Explanation
As all participants have same score, the participant with higher index will be placed above in rank list., I have written this Solution Code: /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
class Main{
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
int a[] = new int[n];
int ans[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(strs[i]);
}
PriorityQueue<Pair> p = new PriorityQueue<Pair>(n, new cmp());
for(int i=0;i<n;i++){
p.add(new Pair(a[i], i));
}
int ind = 1;
while (p.size() > 0) {
ans[p.peek().c] = ind;
ind++;
p.poll();
}
for(int i=0;i<n;i++){
System.out.print(ans[i]+ " ");
}
}
}
class cmp implements Comparator<Pair>{
public int compare(Pair s1, Pair s2) {
if (s1.f < s2.f)
return 1;
else if (s1.f > s2.f)
return -1;
else{
if(s1.c<s2.c)return 1;
else return -1;
}
}
}
class Pair {
public int f;
public int c;
public Pair(int f, int c) {
this.f = f;
this.c = c;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: static void printString(String stringVariable){
System.out.println(stringVariable);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: S=input()
print(S), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, your task is to print the string S.You don't have to worry about taking input, you just have to complete the function <b>printString</b>Print the string S.Sample Input 1:-
NewtonSchool
Sample Output 1:-
NewtonSchool
Sample Input 2:-
Hello
Sample Output 2:-
Hello, I have written this Solution Code: void printString(string s){
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Assuming that the database is SQLite, how can we list down all the tables present in the selected database?nannannan, I have written this Solution Code: .table, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
Set<Integer> set=new HashSet<>();
String s[]=bu.readLine().split(" ");
for(String x:s) set.add(Integer.parseInt(x));
int mex=0;
while(set.contains(mex)) mex++;
System.out.println(mex);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: p=input()
q=list(p.split(" "))
for i in range(0,int(q[1])+2):
if(int(q[0])!=i and int(q[1])!=i):
print(i)
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two non-negative integers, A and B. You are required to print the smallest non-negative integer such that it is not equal to both A and B.The input consists of two space separated integers A and B.
Constraints:
0 ≤ A ≤ 10
0 ≤ B ≤ 10
A ≠ B
Print a single integer denoting the answer.Sample Input 1:
0 1
Sample Output 1:
2
Sample Input 2:
4 5
Sample Output 2:
0, I have written this Solution Code: //Author: Xzirium
//Time and Date: 15:00:01 23 April 2022
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
int A,B;
cin>>A>>B;
for(int i=0 ; i<=10 ; i++)
{
if(i!=A && i!=B)
{
cout<<i<<endl;
break;
}
}
return 0;
}, 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: 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 and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int T= sc.nextInt();
for(int i=0;i<T;i++){
int arrsize=sc.nextInt();
int max=0,secmax=0,thirdmax=0,j;
for(int k=0;k<arrsize;k++){
j=sc.nextInt();
if(j>max){
thirdmax=secmax;
secmax=max;
max=j;
}
else if(j>secmax){
thirdmax=secmax;
secmax=j;
}
else if(j>thirdmax){
thirdmax=j;
}
if(k%10000==0){
System.gc();
}
}
System.out.println(max+" "+secmax+" "+thirdmax+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: t=int(input())
while t>0:
t-=1
n=int(input())
l=list(map(int,input().strip().split()))
li=[0,0,0]
for i in l:
x=i
for j in range(0,3):
y=min(x,li[j])
li[j]=max(x,li[j])
x=y
print(li[0],end=" ")
print(li[1],end=" ")
print(li[2]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
vector<long> a(n);
long ans[3]={0};
long x,y;
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
for(int j=0;j<3;j++){
y=min(x,ans[j]);
ans[j]=max(x,ans[j]);
// cout<<ans[j]<<" ";
x=y;
}
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
if(ans[2]<ans[1]){
swap(ans[1],ans[2]);
}
if(ans[1]<ans[0]){
swap(ans[1],ans[0]);
}
cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, you need to find its maximum, 2<sup>nd</sup> maximum and 3<sup>rd</sup> maximum element.
Try solving it in O(N) per test caseThe first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N denoting the number of elements in the array A. The following line contains N (space-separated) elements of A.
<b>Constraints:</b>
1 <= T <= 100
3 <= N <= 10<sup>6</sup>
1 <= A[i] <= 10<sup>9</sup>
<b>Note</b>:-It is guaranteed that the sum of N over all text cases does not exceed 10<sup>6</sup>For each test case, output the first, second and third maximum elements in the array.Sample Input:
3
5
1 4 2 4 5
6
1 3 5 7 9 8
7
11 22 33 44 55 66 77
Sample Output:
5 4 4
9 8 7
77 66 55
<b>Explanation:</b>
Testcase 1:
[1 4 2 4 5]
First max = 5
Second max = 4
Third max = 4, I have written this Solution Code: function maxNumbers(arr,n) {
// write code here
// do not console.log the answer
// return the answer as an array of 3 numbers
return arr.sort((a,b)=>b-a).slice(0,3)
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton has shifted to a new house and it came to his notice that there is only one socket in his house !!!
Newton does a lot of experiments using electricity and wants at least B sockets in his house.
Furthermore, he has an ample amount of extension cords and each extension has A sockets and takes one socket. In others words, an extension cord extends one socket into A sockets. You need to tell Newton how many extension cords will be required so that he can have at least B sockets.The first and the only line of the input contains 2 single integers A and B
<b>Constraints:</b>
1) 2 ≤ A ≤ 200
2) 1 ≤ B ≤ 200Print the answerSample Input 1:
4 10
Sample Output 1:
3
Sample Input 2:
8 9
Sample Output 2:
2
<b>Explanation 1:</b>
3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.
, I have written this Solution Code: ///#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#define pi acos(-1.0)
#define nl "\n"
/*data type ------------------------------------*/
#define ulli unsigned long long int
#define lli long long int
#define ld long double
/*---------------------------------------------*/
/*container -----------------------------------*/
#define vint vector<int>
#define vll vector<long long>
#define vlli vector<long long int>
#define vchar vector<char>
/*---------------------------------------------*/
/*container input and output-------------------*/
#define inv(v) for(auto& i:v) cin>>i
#define outv(v) for(auto& i:v) cout<<i<<" "
/*---------------------------------------------*/
/*container function --------------------------*/
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define Sort(a) ( sort((a).begin(), (a).end()))
#define Sort_d(a) ( sort(a.begin(), a.end(), greater<int>()))
/*---------------------------------------------*/
#define precision(n) fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
/*my function ------------------------------------*/
#define max2(x,y) ((x>y)?x:y)
#define min2(x,y) ((x<y)?x:y)
#define lcm(x,y) ((x*y)/(__gcd(x,y)))
#define mod 1000000007
/*bit manipulation---------------------------------*/
#define twopower(n) (1<<n)
#define MAX INT_MAX
#define MIN INT_MIN
#define ishigh(num, position) ((num&(1<<position))>0? 1:0)
#define ll_count_high(num) (__builtin_popcountll(num))
#define int_count_high(num) (__builtin_popcount(num))
#define toupper(char) (char & '_')
//cout<<(char)toupper('a')<<nl; out:A
#define tolower(char) (char | ' ')
//cout<<(char)tolower('B')<<nl; out:b
/*-------------------------------------------------*/
/*string convert_int_to_string(int number)
{
stringstream convert;
convert<<number;
string s = convert.str();
return s;
}*/
//find big factorial using python-3
/*
#User function Template for python3
import math
class Solution:
def factorial(self, N):
x = math.factorial(N)
list = []
s = str(x)
for j in s:
list.append(int(j))
return list
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__ == '__main__':
t=int(input())
for _ in range(t):
N = int(input())
ob = Solution()
ans = ob.factorial(N);
for i in ans:
print(i,end="")
print()
*/
/*vector<lli>All_perfect_square(lli range)
{
vector<lli>perfect_square;
for(lli x = 0; x*x<=range; x++)
{
perfect_square.push_back(x*x);
}
return perfect_square;
}*/
/*lli find_near_perfect_square(vector<lli>&vect, lli number)
{
//use binary search
lli ans = -1;
lli left = 0, right = vect.size()-1, mid = (left+right)/2;
while(left<=right)
{
if(vect[mid]>=number){ans = vect[mid];right = mid-1; mid = (left+right)/2;}
else {left = mid+1;mid = (left+right)/2;}
}
return ans;
}*/
//sieve algorithm
/*vector<int>all_prime;
long long int index_array[5000] = {0};
void seive(int N)
{
index_array[0] = 1;
index_array[1] = 1;
all_prime.push_back(2);
for(long long int i = 3; i<=N; i+=2)
{
if(index_array[i]==0)
{
all_prime.push_back(i);
for(long long int j = i*i; j<=N; j+=i*2)
{
index_array[j] = 1;
}
}
}
}
*/
//find x power y using bit manipulation. complexity O(log N)
/*int bitwise_pow(int a, int n)
{
int ans = 1;// Stores final answer
while (n > 0) {
bool last_bit = (n & 1);
// Check if current LSB is set
if (last_bit){ans = ans * a;}
a = a * a;
n = n >> 1;// Right shift
}
return ans;
}
*/
/*bool isPrime(int n)
{
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
lli N = 100000;
*/
/*vint ar;
vint ar2;
int p = 1;
int check(int n)
{
//cout<<n<<endl;
int sz = ar.size(), sz2 = ar2.size(), no = 0;
for(int i = p; i<n; i*=n)
{
cout<<"i = "<<i<<nl;
no = 0;
for(int j = 0; j<sz; j++)
{
if(ar[j]%i==0){no = 1;break;}
}
if(n%i==0&&no==0)return i;
}
return 0;
}
void solve_the_problem()
{
int n, cnt = 0, ans = 0, x;cin>>n;
string s;cin>>s;
for(int i = 1; i<=n; i++)
{
if(s[i-1]=='0')
{
x = check(i);
//cout<<x<<nl;
if(x==0)
{
ans+=i;
}
else ans+=x;
cout<<ans<<nl;
}
else ar.push_back(i);
}
cout<<ans<<nl;
ar.clear();
p = 1;
// cout<<"......"<<endl;
// outv(ar);
// cout<<nl;
}
*/
void solve_the_problem(int T)
{
int a, b, cnt = 0;
cin>>a>>b;
int soket = 1;
while(soket<b)
{
soket--;
soket+=a;
cnt++;
}
cout<<cnt<<nl;
}
int main()
{
//int t; cin>>t;
int t = 1;
for(int i = 1; i<=t; i++) solve_the_problem(t);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t — the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 ≤ t ≤ 10<sup>4</sup>
1 ≤ x, y ≤ 10<sup>15</sup>
max(x, y) < z ≤ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which she is fighting with N monsters who are standing in a line. Each monster has some HP with him. At every second, Sara hits the monster standing at the front of the line. When the monster gets hit his HP decreases by 1 and he goes to the end of the line(which happens instantaneously).
For example:
if the monster's health are (1, 3, 2)
After 1st hit:- 3, 2 (monster at index 0 dies)
After 2nd hit:- 2, 2
After 3rd hit:- 2, 1
After 4th hit:- 1, 1
After 5th hit:- 1(monster who was originally at index 2 dies)
After 6th hit:- (monster who was originally at index 1 dies)
Now Sara who keeps track of the time wants to know the time when the Kth(0 indexing) monster dies(A monster dies when his HP hits 0).The first line of input contains two space separated integers depicting N and K.
The next line contains N space separated integers depicting the HP of every monster.
<b>Constraints:-</b>
1 <= N <= 100
0 <= K < N
1 <= HP <= 100Print the time when the Kth monster dies.Sample Input:-
3 2
1 3 2
Sample Output:-
5
Sample Input:-
4 0
5 1 1 1
Sample Output:-
8, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
int N=s.nextInt();
int K=s.nextInt();
int[] arr=new int[N];
for (int i=0;i<=N-1;i++){
arr[i]=s.nextInt();
}
int count=0;
int i=0;
while(arr[K]>0){
i=i%N;
if(arr[i]>0){
arr[i]--;
count++;
}
i++;
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which she is fighting with N monsters who are standing in a line. Each monster has some HP with him. At every second, Sara hits the monster standing at the front of the line. When the monster gets hit his HP decreases by 1 and he goes to the end of the line(which happens instantaneously).
For example:
if the monster's health are (1, 3, 2)
After 1st hit:- 3, 2 (monster at index 0 dies)
After 2nd hit:- 2, 2
After 3rd hit:- 2, 1
After 4th hit:- 1, 1
After 5th hit:- 1(monster who was originally at index 2 dies)
After 6th hit:- (monster who was originally at index 1 dies)
Now Sara who keeps track of the time wants to know the time when the Kth(0 indexing) monster dies(A monster dies when his HP hits 0).The first line of input contains two space separated integers depicting N and K.
The next line contains N space separated integers depicting the HP of every monster.
<b>Constraints:-</b>
1 <= N <= 100
0 <= K < N
1 <= HP <= 100Print the time when the Kth monster dies.Sample Input:-
3 2
1 3 2
Sample Output:-
5
Sample Input:-
4 0
5 1 1 1
Sample Output:-
8, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
int solve(vector<int> a, int k){
int answer=a[k]*a.size();
for(int i=0;i<a.size();i++){
if(i<=k){
answer+=min((int)0,a[i]-a[k]);
}
else{
answer+=min((int)-1,a[i]-a[k]);
}
}
return answer;
}
signed main(){
int n,k;
cin>> n>>k;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<solve(a,k);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: def MaximumProduct(N):
ans=N//4
if N %4 !=0:
ans=ans+1
return ans, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: static int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: You are given three integers A, B and C, which are the side lengths of a triangle in some order. Print "Yes" if this triangle is right-angled, otherwise print "No".The input consists of a single line containing three space-separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 1000Print a single word "Yes" if the given triangle is right-angled, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
3 4 5
Sample Output 1:
Yes
Sample Input 2:
10 9 10
Sample Output 2:
No
Sample Input 3:
5 4 3
Sample Output 3:
Yes, 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));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] inp = br.readLine().split(" ");
int a = Integer.parseInt(inp[0]);
int b = Integer.parseInt(inp[1]);
int c = Integer.parseInt(inp[2]);
if(a * a == b * b + c * c)
bw.write("Yes"+"\n");
else if(b * b == a * a + c * c)
bw.write("Yes"+"\n");
else if(c * c == b * b + a * a)
bw.write("Yes"+"\n");
else
bw.write("No"+"\n");
bw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three integers A, B and C, which are the side lengths of a triangle in some order. Print "Yes" if this triangle is right-angled, otherwise print "No".The input consists of a single line containing three space-separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 1000Print a single word "Yes" if the given triangle is right-angled, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
3 4 5
Sample Output 1:
Yes
Sample Input 2:
10 9 10
Sample Output 2:
No
Sample Input 3:
5 4 3
Sample Output 3:
Yes, I have written this Solution Code: a,b,c=map(int,input().split())
if(a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a):
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 integers A, B and C, which are the side lengths of a triangle in some order. Print "Yes" if this triangle is right-angled, otherwise print "No".The input consists of a single line containing three space-separated integers A, B and C.
Constraints:
1 ≤ A, B, C ≤ 1000Print a single word "Yes" if the given triangle is right-angled, otherwise print "No".
Note:
The quotation marks are only for clarity, you should not print them in output.
The output is case-sensitive.Sample Input 1:
3 4 5
Sample Output 1:
Yes
Sample Input 2:
10 9 10
Sample Output 2:
No
Sample Input 3:
5 4 3
Sample Output 3:
Yes, I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int a[3];
for(int i=0;i<3;i++)
cin>>a[i];
sort(a,a+3);
if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])
cout<<"Yes";
else
cout<<"No";
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
def DragonSlayer(A,B,C,D):
x = C//B
if(C%B!=0):
x=x+1
y = A//D
if(A%D!=0):
y=y+1
if(x<y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine().trim();
char n[] = s.toCharArray();
int posMin = 0;
for(int i=0;i<n.length;i++){
if(n[posMin]>n[i])
posMin = i;
}
for(int i=0;i<n.length;i++)
n[i] = n[posMin];
System.out.print(String.valueOf(n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
char c='z';
for(auto r:s)
c=min(c,r);
for(int i=0;i<s.length();++i)
cout<<c;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rachel got a string as a gift from Ross. She wants to exchange this string with another string of same length. A string with all the same characters is fashionable string. Find Rachel lexicographically minimum fashionable string but make sure that the new string has at least one character common with the string Ross gave her otherwise he will get upset.Input contains a single string S, denoting the string Ross gave.
Constraints:
1 <= |S| <= 10000
S contains only lowercase english letters.Print the new string Rachel gets.Sample Input
bccde
Sample Output
bbbbb
Explanation: "bbbbb" is lexicographically minimum fashionable string which has atleast one character common with the initial string.
Sample Input
a
Sample Output
a, I have written this Solution Code: s=input()
l=len(s)
k=min(s)
m=k*l
print(m), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int n = s.length();
int left = 0, right = 0;
int maxlength = 0;
for(int i = 0; i < n; i++)
{
if (s.charAt(i) == '(')
left++;
else
right++;
if (left == right)
maxlength = Math.max(maxlength, 2 * right);
else if (right > left)
left = right = 0;
}
left = right = 0;
for(int i = n - 1; i >= 0; i--)
{
if (s.charAt(i) == '(')
left++;
else
right++;
if (left == right)
maxlength = Math.max(maxlength, 2 * left);
else if (left > right)
left = right = 0;
}
System.out.println(maxlength);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
4, I have written this Solution Code: def longestValidParentheses( S):
stack, ans = [-1], 0
for i in range(len(S)):
if S[i] == '(': stack.append(i)
elif len(stack) == 1: stack[0] = i
else:
stack.pop()
ans = max(ans, i - stack[-1])
return ans
n=input()
print(longestValidParentheses(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length N.
Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()
Output
2
Input
)()())
Output
4, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
string s;
cin >> s;
int n = s.length();
s = "#" + s;
stack<int> st;
st.push(0);
int ans = 0;
for(int i = 1; i <= n; i++){
if(s[i] == '(')
st.push(i);
else{
if(s[st.top()] == '('){
int x = st.top();
a[i] = i-x+1 + a[x-1];
ans = max(ans, a[i]);
st.pop();
}
else
st.push(i);
}
}
cout << ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c
<b>Constraint:</b>
1<=integers<=10000Print the maximum integer among the given integers.Sample Input:-
2 6 3
Sample Output:-
6
Sample Input:-
48 100 100
Sample Output:
100, I have written this Solution Code: a,b,c=[int(a) for a in input().split()]
print(max(a,b,c)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c
<b>Constraint:</b>
1<=integers<=10000Print the maximum integer among the given integers.Sample Input:-
2 6 3
Sample Output:-
6
Sample Input:-
48 100 100
Sample Output:
100, 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 p = scanner.nextInt();
int tm = scanner.nextInt();
int r = scanner.nextInt();
int intrst = MaxInteger(p,tm,r);
System.out.println(intrst);
}
static int MaxInteger(int a ,int b, int c){
if(a>=b && a>=c){return a;}
if(b>=a && b>=c){return b;}
return c;}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces.
Constraints:
1 <= T <= 100
1 <= n, m <= 30
0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input:
4
4 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
3 4
12 11 10 9 8 7 6 5 4 3 2 1
1 4
1 2 3 4
4 1
1 2 3 4
Output:
1 2 3 4 8 12 16 15 14 13 9 5
12 11 10 9 5 1 2 3 4 8
1 2 3 4
1 2 3 4
Explanation:
Testcase1: The matrix is:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5
Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8.
Testcase 3: Boundary Traversal will be 1 2 3 4.
Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code:
def boundaryTraversal(matrix, N, M): #N = 3, M = 4
start_row = 0
start_col = 0
count = 0
if N != 1 and M != 1:
total = 2 * (N - 1) + 2 * (M - 1)
else:
total = max(M, N)
#First row
for i in range(start_col, M, 1): #0,1, 2, 3
count += 1
print(matrix[start_row][i], end = " ")
if count == total:
return
start_row += 1
#Last column
for i in range(start_row, N, 1): # 1, 2
count += 1
print(matrix[i][M - 1], end = " ")
if count == total:
return
M -= 1
#Last Row
for i in range(M - 1, start_col - 1, -1): # 2, 1, 0
count += 1
print(matrix[N - 1][i], end = " ")
if count == total:
return
#First Column
N -= 1 # 2
for i in range(N - 1, start_row - 1, -1):
count += 1
print(matrix[i][start_col], end = " ")
start_col += 1
testcase = int(input().strip())
for test in range(testcase):
dim = input().strip().split(" ")
N = int(dim[0])
M = int(dim[1])
matrix = []
elements = input().strip().split(" ") #N * M
start = 0
for i in range(N):
matrix.append(elements[start : start + M]) # (0, M - 1) | (M, 2*m-1)
start = start + M
boundaryTraversal(matrix, N, M)
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces.
Constraints:
1 <= T <= 100
1 <= n, m <= 30
0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input:
4
4 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
3 4
12 11 10 9 8 7 6 5 4 3 2 1
1 4
1 2 3 4
4 1
1 2 3 4
Output:
1 2 3 4 8 12 16 15 14 13 9 5
12 11 10 9 5 1 2 3 4 8
1 2 3 4
1 2 3 4
Explanation:
Testcase1: The matrix is:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5
Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8.
Testcase 3: Boundary Traversal will be 1 2 3 4.
Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code: import java.io.*;
import java.lang.*;
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n1 = sc.nextInt();
int m1 = sc.nextInt();
int arr1[][] = new int[n1][m1];
for(int i = 0; i < n1; i++)
{
for(int j = 0; j < m1; j++)
arr1[i][j] = sc.nextInt();
}
boundaryTraversal(n1, m1,arr1);
System.out.println();
}
}
static void boundaryTraversal( int n1, int m1, int arr1[][])
{
// base cases
if(n1 == 1)
{
int i = 0;
while(i < m1)
System.out.print(arr1[0][i++] + " ");
}
else if(m1 == 1)
{
int i = 0;
while(i < n1)
System.out.print(arr1[i++][0]+" ");
}
else
{
// traversing the first row
for(int j=0;j<m1;j++)
{
System.out.print(arr1[0][j]+" ");
}
// traversing the last column
for(int j=1;j<n1;j++)
{
System.out.print(arr1[j][m1-1]+ " ");
}
// traversing the last row
for(int j=m1-2;j>=0;j--)
{
System.out.print(arr1[n1-1][j]+" ");
}
// traversing the first column
for(int j=n1-2;j>=1;j--)
{
System.out.print(arr1[j][0]+" ");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find whether there exist two index i and j such that i != j and A[i] = 2 * A[j].First line contains an integer N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
1 <= Ai <= 10^5Print "YES" if there exist two index i and j which fulfil the above constraints. Otherwise print "NO".Sample Input 1:
4
10 2 5 3
Output
YES
Explanation:
Both 5 and 10 are present in the array.
Sample Input 2:
4
7 1 13 11
Output
NO
Explanation:
There does not exist and two indexes such that A[i] = 2 * A[j], I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
static boolean binary_search(int a[], int n, int l, int tar) {
int r = n - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] == tar) {
return true;
}
if (a[mid] < tar)l = mid + 1;
else r = mid - 1;
}
return false;
}
public static void main (String args[]) throws IOException
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int a[] = new int[n];
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(strs[i]);
}
Arrays.sort(a);
boolean ans = false;
for (int i = 0; i < n; i++) {
if (binary_search(a, n, i + 1, 2 * a[i])) {
ans = true;
break;
}
}
if (ans) {
System.out.print("YES");
}
else {
System.out.print("NO");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find whether there exist two index i and j such that i != j and A[i] = 2 * A[j].First line contains an integer N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 10^5
1 <= Ai <= 10^5Print "YES" if there exist two index i and j which fulfil the above constraints. Otherwise print "NO".Sample Input 1:
4
10 2 5 3
Output
YES
Explanation:
Both 5 and 10 are present in the array.
Sample Input 2:
4
7 1 13 11
Output
NO
Explanation:
There does not exist and two indexes such that A[i] = 2 * A[j], I have written this Solution Code: def checkIfExist(List):
hashMap = {}
for i in List:
if(hashMap.get(i+i)):
return "YES"
if(i%2 == 0 and hashMap.get(i//2)):
return "YES"
hashMap[i] = "YES"
return "NO"
N=int(input())
List=list(map(int,input().split()))
print(checkIfExist(List)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: static int LastDigit(int N){
return N%10;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: def LastDigit(N):
return N%10, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int sum=0;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
int k=c-'0';
sum+=k;}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
string s; cin>>s;
int ans = 0;
For(i, 0, sz(s)){
ans += (s[i]-'0');
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a large integer N. Find the sum of its digits. Eg:- if the integer is 1234, the answer is 1+2+3+4=10.The first and only line of input contains the integer N.
Constraints
The number of digits in N won't exceed 100000.Output a single integer, the sum of digits in N.Sample Input
1234
Sample Output
10
Sample Input
11111111111111111111
Sample Output
20, I have written this Solution Code: s = input()
count = 0
for x in s:count+=int(x)
print(count) ;, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 3
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
long[] arr = new long[N];
StringTokenizer st = new StringTokenizer(read.readLine());
long arrSum = 0;
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(st.nextToken());
arrSum += arr[i];
}
int Q = Integer.parseInt(read.readLine());
while(Q-- > 0) {
StringTokenizer newLR = new StringTokenizer(read.readLine());
int L = Integer.parseInt(newLR.nextToken());
int R = Integer.parseInt(newLR.nextToken());
long firstSum = 0;
for(int i=L-1; i<R; i++) {
firstSum += arr[i];
}
long res = (long)((arrSum - firstSum)%(Math.pow(10,9)+7));
System.out.println(res);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 3
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(n+1);
vector<int> pre(n+1, 0);
int tot = 0;
For(i, 1, n+1){
cin>>a[i];
assert(a[i]>0LL && a[i]<=1000000000LL);
tot += a[i];
pre[i]=pre[i-1]+a[i];
}
int q; cin>>q;
while(q--){
int l, r; cin>>l>>r;
int s = tot - (pre[r]-pre[l-1]);
s %= MOD;
cout<<s<<"\n";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 3
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: def prefixSum(arr,n):
prefixSum = [0]*(n+1)
prefixSum[1] = arr[1]
for i in range(2,n+1):
prefixSum[i] = prefixSum[i-1]+arr[i]
return prefixSum
n = int(input())
arr = list(map(int,input().split()))
arr = [0] + arr
Q = int(input())
prefixSum = prefixSum(arr,n)
for i in range(Q):
L,R = map(int,input().split())
sum1 = (prefixSum[n] - (prefixSum[R] - prefixSum[L-1]))%1000000007
print(sum1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to find the smallest positive number which is not present in the given array.First line of input contains a single integer N, next line contains N space separated integers depicting the values of array.
Constraints:-
1 < = N < = 1000000
-10^6 < = Arr[i] < = 10^6Print the smallest positive integer not present in the given array.Sample Input:-
5
-2 1 0 4 5
Sample Output:-
2
Sample Output:-
4
-1 1 2 3
Sample Output:-
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
int[] arr = new int[1000001];
int res=-1;
int max= Integer.MIN_VALUE;
for(int i=0;i<n;i++){
int val=Integer.parseInt(st.nextToken());
if(val>0)
arr[val] = 1;
if(val > max){
max= val;
}
}
for(int i=1;i<=1000000;i++){
if(arr[i]==0){
res=i;
break;
}
}
if(res==-1){
res= max+1;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to find the smallest positive number which is not present in the given array.First line of input contains a single integer N, next line contains N space separated integers depicting the values of array.
Constraints:-
1 < = N < = 1000000
-10^6 < = Arr[i] < = 10^6Print the smallest positive integer not present in the given array.Sample Input:-
5
-2 1 0 4 5
Sample Output:-
2
Sample Output:-
4
-1 1 2 3
Sample Output:-
4, I have written this Solution Code: def find_missing_number(nums):
distinct = {*nums}
index = 1
while True:
if index not in distinct:
return index
index += 1
try:
n = int(input())
arr = list(map(int, input().split()))
print(find_missing_number(arr))
except:
pass, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, your task is to find the smallest positive number which is not present in the given array.First line of input contains a single integer N, next line contains N space separated integers depicting the values of array.
Constraints:-
1 < = N < = 1000000
-10^6 < = Arr[i] < = 10^6Print the smallest positive integer not present in the given array.Sample Input:-
5
-2 1 0 4 5
Sample Output:-
2
Sample Output:-
4
-1 1 2 3
Sample Output:-
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define max1 1000002
int a[max1];
signed main(){
int n;
cin>>n;
int x;
for(int i=0;i<n;i++){
cin>>x;
if(x>=1){
a[x]++;
}
}
for(int i=1;i<max1;i++){
if(a[i]==0){cout<<i;return 0;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
System.out.print("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: def print_fun():
print ("Hello World")
def main():
print_fun()
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 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: You are given an array of N natural numbers and asks him to solve the following queries:-
Query 0:- modify the element present at index i to x.
Query 1:- Print the maximum number in range l to r inclusive.First line of the input contains the number N. Next line contains N natural numbers.
Next line contains an integer Q followed by Q queries.
0 x y - modify the number at index x to y.
1 l r - Print the maximum number in range l to r inclusive.
<b>Constraints</b>
1<=N, Q<=1e5
1<=l<=r<=N
0<=Ai<=1e4
1<=x<=N
0<=y<=1e4
<b>Note<b> : Index starts from 1Solve the query and print the result.Input :
6
1 2 3 4 5 6
4
1 1 2
0 1 5
0 2 6
1 1 3
Output :
2
6, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-18 01:39:40
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
struct segtree {
struct node {
// initial values for leaves
int odd = 0;
int even = 0;
int sum = 0;
int add = 0;
int mx = 0;
void apply(int l, int r, long long v) {
mx += v;
sum += (r - l + 1) * v;
add += v;
odd = (v & 1) ? 1 : 0;
even = (v & 1) ? 0 : 1;
}
};
static node unite(const node &a, const node &b) {
node res;
res.mx = max(a.mx, b.mx);
res.sum = a.sum + b.sum;
res.odd = a.odd + b.odd;
res.even = a.even + b.even;
return res;
}
void push(int x, int l, int r) {
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
if (tree[x].add != 0) {
tree[x + 1].apply(l, m, tree[x].add);
tree[y].apply(m + 1, r, tree[x].add);
tree[x].add = 0;
}
}
void pull(int x, int y) { tree[x] = unite(tree[x + 1], tree[y]); }
int n;
vector<node> tree;
void build(int x, int l, int r) {
if (l == r) {
return;
}
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
build(x + 1, l, m);
build(y, m + 1, r);
pull(x, y);
}
template <class T>
void build(int x, int l, int r, const vector<T> &v) {
if (l == r) {
tree[x].apply(l, r, v[l]);
return;
}
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
build(x + 1, l, m, v);
build(y, m + 1, r, v);
pull(x, y);
}
node get(int x, int l, int r, int ll, int rr) {
if (ll <= l && r <= rr) {
return tree[x];
}
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
push(x, l, r);
node res;
if (rr <= m) {
res = get(x + 1, l, m, ll, rr);
} else {
if (ll > m) {
res = get(y, m + 1, r, ll, rr);
} else {
res = unite(get(x + 1, l, m, ll, rr), get(y, m + 1, r, ll, rr));
}
}
pull(x, y);
return res;
}
template <class T>
void modify(int x, int l, int r, int ll, int rr, const T &v) {
if (ll <= l && r <= rr) {
tree[x].apply(l, r, v);
return;
}
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
push(x, l, r);
if (ll <= m) {
modify(x + 1, l, m, ll, rr, v);
}
if (rr > m) {
modify(y, m + 1, r, ll, rr, v);
}
pull(x, y);
}
segtree(int _n) : n(_n) {
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1);
}
template <class T>
segtree(const vector<T> &v) {
n = v.size();
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1, v);
}
node get(int ll, int rr) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return get(0, 0, n - 1, ll, rr);
}
node get(int p) {
assert(0 <= p && p <= n - 1);
return get(0, 0, n - 1, p, p);
}
template <class T>
void modify(int ll, int rr, const T v) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
modify(0, 0, n - 1, ll, rr, v);
}
int find_first(int ll, int rr, const function<bool(const node &)> &f, int x,
int l, int r) {
if (ll <= l && r <= rr && !f(tree[x])) {
return -1;
}
if (l == r) {
return l;
}
push(x, l, r);
int m = (l + r) >> 1;
int y = x + ((m - l + 1) << 1);
int res = -1;
if (ll <= m) {
res = find_first(ll, rr, f, x + 1, l, m);
}
if (rr > m && res == -1) {
res = find_first(ll, rr, f, y, m + 1, r);
}
pull(x, y);
return res;
}
// calls all FALSE elements to the left of the sought position exactly once
int find_first(int ll, int rr, const function<bool(const node &)> &f) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return find_first(ll, rr, f, 0, 0, n - 1);
}
};
// Returns min(p | p<=rr && sum[ll..p]>=sum). If no such p exists, returns -1
int sum_lower_bound(segtree &t, int ll, int rr, long long sum) {
long long sumSoFar = 0;
return t.find_first(ll, rr, [&](const segtree::node &node) {
if (sumSoFar + node.sum >= sum) return true;
sumSoFar += node.sum;
return false;
});
}
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
segtree seg(v);
int Q;
cin >> Q;
while (Q--) {
int step, x, y;
cin >> step >> x >> y;
switch (step) {
case 0:
x -= 1;
seg.modify(x, x, -v[x]);
seg.modify(x, x, y);
break;
case 1:
x -= 1, y -= 1;
cout << seg.get(x, y).mx << "\n";
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
while (tc--) {
solve();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code: function bubbleSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => b - a)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code: def bubbleSort(arr):
arr.sort(reverse = True)
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int t;
for(int i=1;i<n;i++){
if(a[i]>a[i-1]){
for(int j=i;j>0;j--){
if(a[j]>a[j-1]){
t=a[j];
a[j]=a[j-1];
a[j-1]=t;
}
}
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, sort the array in reverse order by simply swapping its adjacent elements.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in descending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=100000Output sorted array in descending order where each element is space separated.Sample Input:
6
3 1 2 7 9 87
Sample Output:
87 9 7 3 2 1, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const int N = 3e5+5;
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
using vl = vector<ll>;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
long long phi[max1], result[max1],F[max1];
// Precomputation of phi[] numbers. Refer below link
// for details : https://goo.gl/LUqdtY
void computeTotient()
{
// Refer https://goo.gl/LUqdtY
phi[1] = 1;
for (int i=2; i<max1; i++)
{
if (!phi[i])
{
phi[i] = i-1;
for (int j = (i<<1); j<max1; j+=i)
{
if (!phi[j])
phi[j] = j;
phi[j] = (phi[j]/i)*(i-1);
}
}
}
for(int i=1;i<=100000;i++)
{
for(int j=i;j<=100000;j+=i)
{ int p=j/i;
F[j]+=(i*phi[p])%mod;
F[j]%=mod;
}
}
}
int gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
g = gcd(abs(a), abs(b), x0, y0);
if (c % g) {
return false;
}
x0 *= c / g;
y0 *= c / g;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
return true;
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n,greater<int>());
FOR(i,n){
out1(a[i]);}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, 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().split(" ");
int N=Integer.parseInt(str[0]);
int K=Integer.parseInt(str[1]);
str=br.readLine().split(" ");
int[] arr=new int[N];
for(int i=0;i<N;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
Arrays.sort(arr);
int i=0;
boolean flag=false;
int index=binarySearch(arr,0,N-1,K-i);
while(index!=-1)
{
i++;
index=binarySearch(arr,0,index,K-i);
if(index!=-1)
{
index=binarySearch(arr,index,N-1,K+i);
}
else
flag=true;
}
if(flag)
System.out.print(K-i);
else
System.out.print(K+i);
}
public static int binarySearch(int[] arr,int start,int end,int key)
{
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]==key)
return mid;
else if(arr[mid]>key)
end=mid-1;
else
start=mid+1;
}
return -1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, I have written this Solution Code: size,k = map(int,input().split())
lis = list(map(int,input().split()))
l=[]
m=0
for i in lis:
if(k+m in lis and k-m in lis):
m=m+1
else:
if(k-m in lis):
print(k+m)
else:
print(k-m)
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int x, n; cin>>n>>x;
set<int> s;
For(i, 0, n){
int a; cin>>a;
s.insert(a);
}
int v = INF;
int cur = -INF;
For(i, -1, 20001){
if(s.find(i)!=s.end())
continue;
if(abs(i-x)<v){
cur = i;
v = abs(i-x);
}
}
cout<<cur;
}
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 marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String args[]) throws IOException {
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().trim().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
int d = Integer.parseInt(str[3]);
int e = Integer.parseInt(str[4]);
System.out.println(grades(a, b, c, d, e));
}
static char grades(int a, int b, int c, int d, int e)
{
int sum = a+b+c+d+e;
int per = sum/5;
if(per >= 80)
return 'A';
else if(per >= 60)
return 'B';
else if(per >= 40)
return 'C';
else
return 'D';
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: li = list(map(int,input().strip().split()))
avg=0
for i in li:
avg+=i
avg=avg/5
if(avg>=80):
print("A")
elif(avg>=60 and avg<80):
print("B")
elif(avg>=40 and avg<60):
print("C")
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ann, John, and Elsa like playing games. Their favorite game is the Game of Battle War.
In this game, the players virtually fight with each other. Each fight has two players. Suppose the initial energy of the players is L and M, then, after the fight, the energy of both players reduces by min(L, M). Let the initial energy levels of Ann, John, and Elsa be X, Y, and Z respectively. The game rules say that each pair of players can fight exactly once.
Find out if Ann can finish the battle with a positive energy level considering that you can schedule the fights between each pair in any sequence.The first line of input will contain a single integer T, denoting the number of test cases. The first and only line of each test case contains three space- separated integers X, Y, and Z- the initial energy levels of Ann, John and Elsa.
<b>Constraints</b>
1 ≤ T ≤ 1000
0 ≤ X, Y, Z ≤ 1000For each test case, output on a new line, YES, if you can schedule the fight between each pair in an order such that Ann can have an energy level t the end of the battle. Otherwise, output NO.Sample Input :
3
4 2 0
2 7 4
5 1 4
Sample Output :
YES
NO
YES, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> a >> b >> c;
int x = b - min(b, c);
int y = c - min(b, c);
if (x > y) {
a = a - x;
if (a > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else {
a = a - y;
if (a > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
for i in range(0,n-2):
if li[i]==li[i+1] and li[i+1]==li[i+2]:
print("Yes",end="")
exit()
print("No",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(n);
bool fl = false;
For(i, 0, n){
cin>>a[i];
if(i>=2){
if(a[i]==a[i-1] && a[i]==a[i-2]){
fl = true;
}
}
}
if(fl){
cout<<"Yes";
}
else
cout<<"No";
}
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 an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n-2;i++){
if(a[i]==a[i+1] && a[i+1]==a[i+2]){
System.out.print("Yes");
return;
}
}
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: s = input("")
print (s[::-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, 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();
for(int i = s.length()-1;i>=0;i--){
System.out.print(s.charAt(i));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: function PokemonMaster(a,b) {
// write code here
// do no console.log the answer
// return the output using return keyword
const ans = (a - b >= 0) ? 1 : 0
return ans
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: def PokemonMaster(A,B):
if(A>=B):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has A number of Pokeballs with her and there are B pokemons in front of Sara. Considering each pokemon takes one Pokeball, your task is to tell Sara if she can catch all the pokemons or not.
Sara can catch a pokemon if she is having at least one pokeball for that pokemon.<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>PokemonMaster()</b> that takes integers A and B as arguments.
Constraints:-
1 <= A, B <= 8Return 1 if Sara can catch all the pokemon else return 0.Sample Input:-
4 3
Sample Output:-
1
Sample Input:-
4 6
Sample Output:-
0, I have written this Solution Code: static int PokemonMaster(int A, int B){
if(A>=B){return 1;}
return 0;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.