Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
fizzbuzz(x);
}
static void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");}
else if(i%5==0){System.out.print("Buzz ");}
else if(i%3==0){System.out.print("Fizz ");}
else{System.out.print(i+" ");}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n):
for i in range (1,n+1):
if (i%3==0 and i%5==0):
print("FizzBuzz",end=' ')
elif i%3==0:
print("Fizz",end=' ')
elif i%5==0:
print("Buzz",end=' ')
else:
print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:-
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:-
3
Sample Output:-
1 2 Fizz
Sample Input:-
5
Sample Output:-
1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){printf("FizzBuzz ");}
else if(i%5==0){printf("Buzz ");}
else if(i%3==0){printf("Fizz ");}
else{printf("%d ",i);}
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all the numbers less than N which contains only digits 3, 4, and 5. Each digit should be present at least one time.The input contains a single integer N.
Constraints:-
1 <= N <= 1000000000Print the count of such numbers which contains only digits 3, 4, and 5.Sample Input:-
500
Sample Output:-
4
Explanation:-
345. 435. 453, 354
Sample Input:-
1000
Sample Output:-
6, 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);
long n = sc.nextLong();
int count = recursive(n, 0, false, false, false);
System.out.println(count);
}
private static int recursive(long n, long num, boolean three, boolean four, boolean five) {
if(num > n){
return 0;
}
int count = 0;
if(three && four && five){
count ++;
}
count += recursive(n, num*10 + 3, true, four, five);
count += recursive(n, num*10 + 4, three, true, five);
count += recursive(n, num*10 + 5, three, four, true);
return count;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find all the numbers less than N which contains only digits 3, 4, and 5. Each digit should be present at least one time.The input contains a single integer N.
Constraints:-
1 <= N <= 1000000000Print the count of such numbers which contains only digits 3, 4, and 5.Sample Input:-
500
Sample Output:-
4
Explanation:-
345. 435. 453, 354
Sample Input:-
1000
Sample Output:-
6, I have written this Solution Code: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
int ans = 0;
int n = 0;
int ok;
void dfs(ll x,int ok){
if(x > n) return;
if(ok==7) ans++;
dfs(x * 10 + 3,ok|1);
dfs(x * 10 + 4,ok|2);
dfs(x * 10 + 5,ok|4);
return;
}
int main(){
cin >> n;
int x = 0;
dfs(x,0);
cout << ans << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function <code>convertTheArray</code> which accepts two parameters which are an <code>array</code> and a <code>word</code>.
It returns a new array where all the array elements are converted to lowercase and then the second parameter which is a string word is concatenated to each element of the array.
Note for passing input in Sample Output generator<ol>
<li>Type the word
<li>Hit Enter
<li>Type words separated by space
</ol>The function will take two arguments
1) 1st argument will be a string
2) 2nd argument will be strings separated by space containing a combination of upper case and lower case letters in itThe function will return an array of strings <pre>
<code>
const word="KHAN"
const arr=[ 'SaifAli', 'ShahRukh', 'Salman' ]
const answer=convertTheArray(arr,word)
//returns an array of concatenated words with array elements converted to lower case
console.log(answer)
//[ 'saifaliKHAN', 'shahrukhKHAN', 'salmanKHAN' ]
const word="World"
const arr=[ 'HeLLo', 'Bye', 'Bonjour' ]
const answer=convertTheArray(arr,word)
//returns an array of concatenated words with array elements converted to lower case
console.log(answer)
//[ 'helloWorld', 'byeWorld', 'bonjourWorld' ]
</code>
</pre>
, I have written this Solution Code: function convertTheArray(array,word){
Array.prototype.lowerCaseConcat = function(charc) {
var i;
for (i = 0; i < this.length; i++) {
this[i] = this[i].toLowerCase();
this[i]=this[i].concat(charc)
}
};
array.lowerCaseConcat(word)
return array;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: def countMultiples(N):
return int(100/N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code: static int countMultiples(int N)
{
int i = 1, count = 0;
while(i < 101){
if(i % N == 0)
count++;
i++;
}
return count;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, you need to count the integers which are multiple of N between 1 to 100. Return the count.<b>User task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>countMultiples()</b> which contains N as a parameter.
<b>Constraints:</b>
1 <= N <= 100You need to return the count.Sample Input:
3
Sample Output:
33
Sample Input:
4
Sample Output:
25, I have written this Solution Code:
int countMultiples(int n){
return (100/n);
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a circular linked list consisting of N nodes, your task is to exchange the first and last node of the list.
<b>Note:
Examples in Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>exchangeNodes()</b> that takes head node as parameter.
Constraints:
3 <= N <= 1000
1 <= Node. data<= 1000Return the head of the modified linked list.Sample Input 1:-
3
1- >2- >3
Sample Output 1:-
3- >2- >1
Sample Input 2:-
4
1- >2- >3- >4
Sample Output 2:-
4- >2- >3- >1, I have written this Solution Code: public static Node exchangeNodes(Node head) {
Node p = head;
while (p.next.next != head)
p = p.next;
p.next.next = head.next;
head.next = p.next;
p.next = head;
head = head.next;
return head;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the heads of two singly linked lists head1 and head2, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null
For example, the following two linked lists begin to intersect at node c1<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>intersection()</b> that takes the head node of both lists as a parameter.
The first line of the test case contains:
<ul>
<li>the size of the 1st linked list</li>
<li>size of 2nd linked list</li>
<li>the size of the common part of two linked lists</li>
</ul>
The rest of the test case contains:
<ul>
<li>elements of 1st linked list</li>
<li>elements of 2nd linked list</li>
<li>common part of two linked lists</li>
</ul>Return the node of intersectionSample Input:-
4 3 4
1 2 3 4
5 6 7
9 10 11 12
Sample Output:-
9
Explanation:
1 -> 2 -> 3 -> 4
      |
       9 -> 10 -> 11 -> 12
      |
  5 -> 6 -> 7, I have written this Solution Code:
public static Node intersection(Node head1,Node head2){ int aLength = getLength(head1), bLength = getLength(head2);
Node currA = head1, currB = head2;
if (bLength > aLength)
for (int i = 0; i < bLength - aLength; i++) currB = currB.next;
if (aLength > bLength)
for (int i = 0; i < aLength - bLength; i++) currA = currA.next;
while (currA != null && currB != null) {
if (currA == currB) return currA;
currA = currA.next;
currB = currB.next;
}
return null;
}
private static int getLength(Node head) {
Node curr = head;
int len = 0;
while (curr != null) {
curr = curr.next;
len++;
}
return len;
}
, 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, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: N = int(input())
Nums = list(map(int,input().split()))
f = False
for n in Nums:
if n < 0:
f = True
break
if (f):
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 array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
bool win=false;
for(int i=0;i<n;i++){
cin>>a;
if(a<0){win=true;}}
if(win){
cout<<"Yes";
}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 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);
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;i++){
if(a[i]<0){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: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y):
cnt=0
if(X>2):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y>2):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
if(X<7):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y<7):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
return cnt;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
for(int k=0; k<n; k++)
{
String str=br.readLine();
StringBuilder s=new StringBuilder(str);
char last=s.charAt(s.length()-1);
int secondlast=s.charAt(s.length()-2);
if(last=='a')
{
s.append("s");
}
else if(last=='i')
{
s.append("os");
}
else if(last=='y')
{
s.delete(s.length()-1,s.length());
s.append("ios");
}
else if(last=='l')
{
s.append("es");
}
else if(last=='n')
{
s.delete(s.length()-1,s.length());
s.append("anes");
}
else if(last=='e' && secondlast=='n')
{
s.delete(s.length()-2,s.length());
s.append("anes");
}
else if(last=='o')
{
s.append("s");
}
else if(last=='r')
{
s.append("es");
}
else if(last=='t')
{
s.append("as");
}
else if(last=='u')
{
s.append("s");
}
else if(last=='v')
{
s.append("es");
}
else if(last=='w')
{
s.append("as");
}
else
{
s.append("us");
}
System.out.println(s);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: translate = {"y":"ios","a":"as","i":"ios","l":"les","n":"anes",
"ne" :"anes","o" :"os","r" :"res","t" :"tas","u" :"us","v" :"ves","w" :"was"}
for i in range(int(input())):
a = input().rstrip()
if(a[-2:]!="ne"):
print(a[:-1]+translate.get(a[-1],a[-1]+"us"))
else:
print(a[:-2]+translate.get(a[-2:],"us")), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English pseudo-Latin
-a -as
-i, -y -ios
-l -les
-n, -ne -anes
-o -os
-r -res
-t -tas
-u -us
-v -ves
-w -was
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.The input starts with a line containing an integer, n, where n is the number of English words.
The next n lines contain n English words.
Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
Constraints
1 <= n <= 20For an English word, print exactly one pseudo-Latin word in a new line.Sample Input
2
toy
engine
Sample Output
toios
engianes
Sample Input
3
cup
water
cappuccino
Sample Output
cupus
wateres
cappuccinos, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main()
{
// string arr[12][2] = {
// {"a","as"},
// {"i","ios"},
// {"l","les"},
// {"n","anes"},
// {"ne","anes"},
// {"o","os"},
// {"r","res"},
// {"t","tas"},
// {"u","us"},
// {"v","ves"},
// {"w","was"},
// {"y","ios"}
// }
// ;
int t;
cin>>t;
while(t--)
{
string str;
cin>>str;
if(str[str.length()-1]=='e' && str[str.length()-2]=='n')
{
str = str.substr(0,str.length()-2);
str += "anes";
}
else if(str[str.length()-1]=='a')
{
str = str.substr(0,str.length()-1);
str += "as";
}
else if(str[str.length()-1]=='i')
{
str = str.substr(0,str.length()-1);
str += "ios";
}
else if(str[str.length()-1]=='l')
{
str = str.substr(0,str.length()-1);
str += "les";
}
else if(str[str.length()-1]=='n')
{
str = str.substr(0,str.length()-1);
str += "anes";
}
else if(str[str.length()-1]=='o')
{
str = str.substr(0,str.length()-1);
str += "os";
}
else if(str[str.length()-1]=='r')
{
str = str.substr(0,str.length()-1);
str += "res";
}
else if(str[str.length()-1]=='t')
{
str = str.substr(0,str.length()-1);
str += "tas";
}
else if(str[str.length()-1]=='u')
{
str = str.substr(0,str.length()-1);
str += "us";
}
else if(str[str.length()-1]=='v')
{
str = str.substr(0,str.length()-1);
str += "ves";
}
else if(str[str.length()-1]=='w')
{
str = str.substr(0,str.length()-1);
str += "was";
}
else if(str[str.length()-1]=='y')
{
str = str.substr(0,str.length()-1);
str += "ios";
}
else
{
str += "us";
}
cout<<str<<endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement the function <code>correctMistake</code>, which should take a string which will be the string we want to change the mistake in, and another string which is the wrong word or character, and third string which is the correct version and return its result as a string with mistakes (Use JS In built functions)Function will take 3 args,
1) line arg which is the string with mistakes
2) incorrectWord(or char) which is the char/word which needs to be replaced
3) toBeReplacedWithChar which is a stringFunction will return string with corrected mistakesconsole. log(correctMistake("Hi World world", "world", "of coding")) // prints "Hi World of coding" since world is replaced by empty char
console. log(correctMistake("hi hi hi", "hi", "hello")) // prints "hello hello hello", I have written this Solution Code: function correctMistake(line, charToBeReplaced, what) {
// write code here
// return the output , do not use console.log here
return line.replace(new RegExp(charToBeReplaced,'g'), what)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, I have written this Solution Code: x0,y0 =map(int,input().split(" "))
x1,y1 = map(int,input().split(" "))
N = "North " if y0<y1 else "South " if y0> y1 else ""
E = "East " if x0<x1 else "West " if x0> x1 else ""
print(N+E), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(x1 == x2){
if(y1 < y2)
cout << "North";
else
cout << "South";
}
else if(y1 == y2){
if(x1 < x2)
cout << "East";
else
cout << "West";
}
else if(x1 < x2 && y1 < y2)
cout << "North East";
else if(x1 < x2 && y1 > y2)
cout << "South East";
else if(x1 > x2 && y1 < y2)
cout << "North West";
else
cout << "South West";
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice wants to go to Bob's house. The location of their houses is given on a 2-D coordinate system. There are a total of 8 directions:
North - Directly above
South - Directly below
East - To the right
West - To the left
North East - In between north and east
North West - In between north and west
South East - In between south and east
South West - In between south and west
Find the direction in which Alice must go to reach Bob's house.There are two lines of input. The first line contains the x and y coordinate of Alice's house. The second line contains x and y coordinate of Bob's house. It is given that these two locations are different.
-100 <= Coordinates <= 100Print a single string denoting the direction in which Alice must move to reach Bob's house.Sample Input 1:
2 5
11 25
Sample Output 1:
North East
Sample Input 2:
23 12
-85 12
Sample Output 2:
West, 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 x1, y1, x2, y2;
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
if(x1 == x2){
if(y1 < y2)
System.out.print("North");
else
System.out.print("South");
}
else if(y1 == y2){
if(x1 < x2)
System.out.print("East");
else
System.out.print("West");
}
else if(x1 < x2 && y1 < y2)
System.out.print("North East");
else if(x1 < x2 && y1 > y2)
System.out.print("South East");
else if(x1 > x2 && y1 < y2)
System.out.print("North West");
else
System.out.print("South West");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is an array having unique elements is given as input. Find the index of an element k if present in the array, else -1.There is an integer n is given(size of array nums).
In second line, n space seperated integers are given.
in third line, an integer k is given.
1 <= n <= 10<sup>5</sup>
0 <= nums[i] <= 10<sup>6</sup>
0 <= i <= n-1Find the index of an element k if present in the array, else -1.Sample Input:
5
1 4 3 2 5
3
Sample Output:
2
Explanation: Index of element 3 is 2. So the answer will be 2., I have written this Solution Code: import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> v=new ArrayList<>();
for(int i=0;i<n;i++){
int a=sc.nextInt();
v.add(a);
}
int k=sc.nextInt();
int ans=v.indexOf(k);
System.out.println(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
int f, s;
cin >> f >> s;
cout << (8*f)/s << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, 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 f = sc.nextInt();
int s = sc.nextInt();
int ans = (8*f)/s;
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Internet download speed is often expressed in bit per second whereas file size is expressed in Bytes. It is known that 1 Byte = 8 bits. Given file size in megabytes(MB) and internet speed in megabits per seconds(Mbps), find the time taken in seconds to download the file.The only line of input contains two integers denoting the file size in MB and download speed in Mbps.
1 <= file size <= 1000
1 <= download speed <= 1000Print a single integer denoting the time taken to download the file in seconds.
It is guaranteed that the result will be an integer.Sample Input:
10 16
Sample Output:
5, I have written this Solution Code: a = list(map(int,input().strip().split()))[:2]
print(int((a[0]*8)/a[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given Q queries. In each query, determine whether there exists an array A of size N such that:
1. All the elements are positive integers.
2. The number of subarrays such that their XOR-sum is 0 is exactly K. In other words, there are exactly K pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ N and A<sub>l</sub> ⊕ A<sub>l+1</sub> ⊕ ... A<sub>r</sub> = 0.
If there exists such an array, print "YES", otherwise print "NO".The first line of the input contains a single integer Q — the number of queries (1 ≤ Q ≤ 10<sup>5</sup>).
Q lines follow, each line containing two space separated integers N (1 ≤ N ≤ 1000) and K (0 ≤ K ≤ N(N+1)/2).For each test case, print "YES", if there exists such an array, otherwise print "NO" (without the quotes).
Note that the output is case sensitive.Sample Input
3
2 2
3 2
2 1
Sample Output
NO
YES
YES, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
FastScanner in;
PrintWriter out;
boolean systemIO = true;
int MAXSUM = 250000;
int[] dp = new int[MAXSUM];
int[] minn = new int[MAXSUM];
public void precalc() {
for (int i = 1; i < minn.length; i++) {
minn[i] = 1002;
dp[i] = 1002;
}
for (int step = 2; step <= 501; step++) {
int delta = step * (step - 1) / 2;
for (int j = 0; j + delta < MAXSUM; j++) {
if (dp[j] + step < dp[j + delta]) {
dp[j + delta] = dp[j] + step;
minn[j + delta] = Math.min(minn[j + delta], Math.max(dp[j + delta] - 1, 2 * step - 2));
}
}
}
}
public boolean clever(int n, int k) {
if (k >= MAXSUM) {
return false;
}
return n >= minn[k];
}
public void solve() {
precalc();
for (int qwerty = in.nextInt(); qwerty > 0; --qwerty) {
int n = in.nextInt();
int k = in.nextInt();
if (clever(n, k)) {
out.println("YES");
} else {
out.println("NO");
}
}
}
public void run() {
try {
if (systemIO) {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
} else {
String fileName = "60-huge-inexact";
in = new FastScanner(new File(fileName + ".txt"));
out = new PrintWriter(new File(fileName + ".out"));
}
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] arg) {
long time = System.currentTimeMillis();
new Main().run();
System.err.println(System.currentTimeMillis() - time);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given Q queries. In each query, determine whether there exists an array A of size N such that:
1. All the elements are positive integers.
2. The number of subarrays such that their XOR-sum is 0 is exactly K. In other words, there are exactly K pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ N and A<sub>l</sub> ⊕ A<sub>l+1</sub> ⊕ ... A<sub>r</sub> = 0.
If there exists such an array, print "YES", otherwise print "NO".The first line of the input contains a single integer Q — the number of queries (1 ≤ Q ≤ 10<sup>5</sup>).
Q lines follow, each line containing two space separated integers N (1 ≤ N ≤ 1000) and K (0 ≤ K ≤ N(N+1)/2).For each test case, print "YES", if there exists such an array, otherwise print "NO" (without the quotes).
Note that the output is case sensitive.Sample Input
3
2 2
3 2
2 1
Sample Output
NO
YES
YES, I have written this Solution Code: #include <bits/stdc++.h>
#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 = 1e9;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
struct info {int n, k, idx;};
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
read(t);
vector<vector <info>> q(1001);
FOR (i, 1, t)
{
readb(n, k);
q[n/2 + 1].pb({n, k, i});
}
vi dp(1001*500 + 5, inf);
dp[0] = 0;
bool ans[t + 1] = {};
FOR (i, 1, 502)
{
FOR (j, i*(i - 1)/2, 1001*500)
dp[j] = min(dp[j], dp[j - i*(i - 1)/2] + i);
for (auto x: q[i])
if (dp[x.k] <= x.n + 1) ans[x.idx] = 1;
}
FOR (i, 1, t)
if (ans[i]) cout << "YES" << endl;
else cout << "NO" << endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code:
// X and Y are numbers
// ignore number of testcases variable
function pow(X, Y) {
// write code here
// console.log the output in a single line,like example
console.log(Math.pow(X, Y).toFixed(2))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K):
return ("{0:.2f}".format(N**K))
T=int(input())
for i in range(T):
X,N = map(float,input().strip().split())
print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
double X = Double.parseDouble(str[0]);
int N = Integer.parseInt(str[1]);
System.out.println(String.format("%.2f", myPow(X, N)));
}
}
public static double myPow(double x, int n) {
if (n == Integer.MIN_VALUE)
n = - (Integer.MAX_VALUE - 1);
if (n == 0)
return 1.0;
else if (n < 0)
return 1 / myPow(x, -n);
else if (n % 2 == 1)
return x * myPow(x, n - 1);
else {
double sqrt = myPow(x, n / 2);
return sqrt * sqrt;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ld long double
#define int long long int
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
ld power(ld x, ld n){
if(n == 0)
return 1;
else
return x*power(x, n-1);
}
signed main() {
speed;
int t; cin >> t;
while(t--){
double x; int n;
cin >> x >> n;
if(n < 0)
x = 1.0/x, n *= -1;
cout << setprecision(2) << fixed << power(x, n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Binary Tree, find the maximum width of it. <b>Maximum width</b> is defined as the maximum number of nodes in any level.
For example, maximum width of following tree is 4 as there are 4 nodes at 3rd level.
<pre>
1
/ \
2 3
/ \ / \
4 5 6 7
\
8
</pre><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>getMaxWidth()</b> that takes "root" node as parameter.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^5
1 <= node values <= 10^5
Sum of "N" over all testcases does not exceed 10^6
For <b>Custom Input:</b>
First line of input should contains the number of test cases T. For each test case, there will be two lines of input.
First line contains number of nodes N. Second line will be a string representing the tree as described below:
The values in the string are in the order of level order traversal of the tree where, numbers denote node values, and a character “N” denotes NULL child.
<b>Note:</b> If a node has been declared Null using 'N', no information about its children will be given further in the array.Return the maximum width of Binary Tree.Sample Input:
2
3
1 2 3
5
10 20 30 40 60
Sample Output:
2
2
Explanation:
Testcase1: The tree is <pre>
1
/ \
2 3
</pre>
The second level has 2 nodes and hence the width is 2.
Testcase2: The tree is <pre>
10
/ \
20 30
/ \
40 60
</pre>Both second and third level have 2 nodes and hence max width is 2., I have written this Solution Code: static int getMaxWidth(Node root)
{
if (root == null)
return 0;
int maxWidth = 0;
Queue<Node> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
int levelSize = queue.size();
maxWidth = Math.max(maxWidth, levelSize);
while (levelSize > 0) {
Node node = queue.poll();
if (node.left != null)
queue.add(node.left);
if (node.right != null)
queue.add(node.right);
levelSize--;
}
}
return maxWidth;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: import math as m
def closestNum(n):
val = m.log(n, 3)
low = int(pow(3,int(val)))
high = int(pow(3,int(val)+1))
sumn = int((pow(3,int(val)+1)-1)//2)
if(n > sumn):
return high
elif(n - low == 0):
return low
else:
return low + closestNum(n-low);
t = int(input())
while(t > 0):
n = int(input())
print(closestNum(n))
t = t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int p[N], s[N];
int f(int x){
if(x <= 0)
return 0;
int ans = 0;
for(int i = 0; i <= 39; i++){
if(s[i] >= x){
ans = p[i] + f(x-p[i]);
break;
}
}
return ans;
}
signed main() {
IOS;
int t; cin >> t;
p[0] = s[0] = 1;
for(int i = 1; i <= 39; i++){
p[i] = 3*p[i-1];
s[i] = s[i-1] + p[i];
}
while(t--){
int n; cin >> n;
cout << f(n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Swapnil is challenged to build a tower of a height greater than or equal to N. To build the tower he is given blocks of heights which are powers of 3. He can only use one type of block only once and is given infinite types of blocks. Help him make a tower of minimum height just greater than or equal to N.The first line of the input contains one integer T the number of tests. Then T test cases follow.
Each test case contains a single integer N.
<b>Constraints:-</b>
1 ≤ t ≤ 100
0 ≤ N ≤ 10<sup>18</sup>For each test case, print the height of the minimum possible tower greater than or equal to N.Sample Input
5
1
8
4
6
5
Sample Output
1
9
4
9
9
<b>Explanation:</b>
N=1 => use one brick of height 3<sup>0</sup>
N=8 => use one brick of height 3<sup>2</sup>
N=4 => use two bricks of heights 3<sup>0</sup> and 3<sup>1</sup>
N=6 => use one brick of height 3<sup>2</sup>. We can not use 2 bricks of the same type so can't use two bricks of height 3<sup>1</sup>., I have written this Solution Code: import java.io.*;
import java.lang.*;
class Main
{
public static void main(String args[])throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int t = Integer.parseInt(br.readLine());
while(t-- >0)
{
long n = Long.parseLong(br.readLine());
if(n == 0)
{
System.out.println(1);
continue;
}
System.out.println(powerOfThree(n));
}
}
public static long powerOfThree(long n)
{
if(n<=0)
return 0;
long p = (long)(Math.log(n)/Math.log(3));
if(gpSum(p)>=n)
return power(3,p) + powerOfThree(n - power(3,p));
else
return power(3,p+1);
}
public static long gpSum(long p)
{
return (power(3,p+1)-1)/2;
}
public static long power(long base, long p)
{
if(p==0)
return 1;
else
return(base*power(base,p-1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: function simpleArrangement(n, arr) {
// write code here
// do not console.log
// return the output as an array
const newArr = []
// for (let i = 0; i < n; i++) {
// arr[i] += (arr[arr[i]] % n) * n;
// }
// Second Step: Divide all values by n
for (let i = 0; i < n; i++) {
newArr.push(arr[arr[i]])
}
return newArr
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: n = int(input())
a = input().split()
print(" ".join(a[int(x)] for x in a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
String[] str = s.split(" ");
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
for(int i =0;i<n;i++){
System.out.print(arr[arr[i]]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[a[i]]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code:
// X and Y are numbers
// ignore number of testcases variable
function pow(X, Y) {
// write code here
// console.log the output in a single line,like example
console.log(Math.pow(X, Y).toFixed(2))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: def power(N,K):
return ("{0:.2f}".format(N**K))
T=int(input())
for i in range(T):
X,N = map(float,input().strip().split())
print(power(X,N)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
double X = Double.parseDouble(str[0]);
int N = Integer.parseInt(str[1]);
System.out.println(String.format("%.2f", myPow(X, N)));
}
}
public static double myPow(double x, int n) {
if (n == Integer.MIN_VALUE)
n = - (Integer.MAX_VALUE - 1);
if (n == 0)
return 1.0;
else if (n < 0)
return 1 / myPow(x, -n);
else if (n % 2 == 1)
return x * myPow(x, n - 1);
else {
double sqrt = myPow(x, n / 2);
return sqrt * sqrt;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement pow(X, N), which calculates x raised to the power N i.e. (X^N).
Try using a recursive approachThe first line contains T, denoting the number of test cases. Each test case contains a single line containing X, and N.
<b>Constraints:</b>
1 ≤ T ≤ 100
-10.00 ≤ X ≤10.00
-10 ≤ N ≤ 10
For each test case, you need to print the value of X^N. Print up to two places of decimal.
<b>Note:</b>
Please take care that the output can be very large but it will not exceed double the data type value.Input:
1
2.00 -2
Output:
0.25
<b>Explanation:</b>
2^(-2) = 1/2^2 = 1/4 = 0.25, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ld long double
#define int long long int
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
ld power(ld x, ld n){
if(n == 0)
return 1;
else
return x*power(x, n-1);
}
signed main() {
speed;
int t; cin >> t;
while(t--){
double x; int n;
cin >> x >> n;
if(n < 0)
x = 1.0/x, n *= -1;
cout << setprecision(2) << fixed << power(x, n) << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.System.out;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader reader = new FastReader();
int n = reader.nextInt();
String S = reader.next();
int ncount = 0;
int tcount = 0;
for (char c : S.toCharArray()) {
if (c == 'N') ncount++;
else tcount++;
}
if (ncount > tcount) {
out.print("Nutan\n");
} else {
out.print("Tusla\n");
}
out.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
String array[] = br.readLine().trim().split(" ");
StringBuilder sb = new StringBuilder("");
int[] arr = new int[n];
int oddCount = 0,
evenCount = 0;
for(int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(array[i]);
if(arr[i] % 2 == 0)
++evenCount;
else
++oddCount;
}
if(evenCount > 0 && oddCount > 0)
Arrays.sort(arr);
for(int i = 0; i < n; i++)
sb.append(arr[i] + " ");
System.out.println(sb.substring(0, sb.length() - 1));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 3, I have written this Solution Code: n=int(input())
p=[int(x) for x in input().split()[:n]]
o=0;e=0
for i in range(n):
if (p[i] % 2 == 1):
o += 1;
else:
e += 1;
if (o > 0 and e > 0):
p.sort();
for i in range(n):
print(p[i], end = " ");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of length N in which you can swap two elements if their sum is odd i.e for every i (1 to N) and j (1 to N) if (Arr[i] + Arr[j]) is odd then you can swap these elements.
What is the lexicographically smallest array you can obtain?First line of input contains a single integer N. Next line contains N space separated integers depicting the elements of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 100000Print N space separated elements i. e the array which is the lexicographically smallest possibleSample Input:-
3
4 1 7
Sample Output:-
1 4 7
Explanation:-
Swap numbers at indices 1 and 2 as their sum 4 + 1 = 5 is odd
Sample Input:-
2
2 4
Sample Output:-
2 4
Sample Input:-
2
5 3
Sample Output:-
5 3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
long long a[n];
bool win=false,win1=false;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]&1){win=true;}
if(a[i]%2==0){win1=true;}
}
if(win==true && win1==true){sort(a,a+n);}
for(int i=0;i<n;i++){
cout<<a[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 "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String values[] = br.readLine().trim().split(" ");
long N = Long.parseLong(values[0]);
long M = Long.parseLong(values[1]);
long X = Long.parseLong(values[2]);
long Y = Long.parseLong(values[3]);
if(M/X >= N){
System.out.print(N);
return;
}
else
{
long count = M/X;
M = M % X;
N = N - count;
if(((N-1)*Y+M)<X)
System.out.print(count);
else
System.out.print(count+ N - countSacrifice(1,N,M,X,Y));
}
}
public static long countSacrifice(long min,long max,long M,long X,long Y)
{
long N = max;
while(min<max)
{ long mid = min + (max-min)/2;
if((mid*Y + M)>=((N-mid)*X))
{
max = mid;
}
else
{
min = mid+1;
}
}
return min;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: import math
N,M,X,Y = map(int,input().strip().split())
low = 0
high = N
def possible(mid,M,X,Y):
if M//X >= mid:
return True
elif (N-math.ceil(((X*mid)-M)/Y))>=mid:
return True
return False
while(low<=high):
mid = (high+low)>>1
if possible(mid,M,X,Y):
res = mid
low = mid+1
else:
high = mid-1
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Australia hasn’t lost a Test Match at the Gabba since 1988. India has to win this one, but unfortunately all of their players are injured.
You are given the following information:
1. A total of N players are available, all are injured initially.
2. You have M magic pills. Using X pills, you can make any one player fit for match.
3. Alternatively, you can exchange any player for Y magic pills.
Compute the maximum number of players you can make fit for the Gabba Test Match.
Note: "Exchanging" a player means that player will no longer be available and you will gain Y extra magic pills for the exchangeThe input contains a single line containing 4 integers N M X Y.
Constraints:-
0 ≤ N, M, X, Y ≤ 10^9The output should contain a single integer representing the maximum number of players you can make fit before the match.Sample Input:-
5 10 2 1
Sample Output:-
5
Explanation:-
You can make all players fit if you use all the pills.
Sample Input:-
3 10 4 2
Sample Output:-
2
Explanation:-
You can make 2 players fit using the initial candies. Otherwise, Exchanging one player would result in a total of 10+2=12 magic pills. This is enough to make 3 players fit, but you won't have 3 players remaining., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define LL long long
void solve() {
LL n, m, x, y;
cin >> n >> m >> x >> y;
LL l = 0, r = n + 1, mid;
while(l < r-1) {
mid = (l + r) / 2;
if(mid * x <= m + (n - mid) * y) l = mid;
else r = mid;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tt = 1; //cin >> tt;
while(tt--) solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, 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, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, 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, you need to create an array B such that B(i) is the Xor of all the elements of A except A(i).The first line of the input contains an integer N, the number of elements in array A.
The second line of input contains N singly spaced integers, the elements of the array A.
Constraints
1 <= N <= 300000
0 <= A(i) <= 1000000000Output the required array B.Sample Input
4
3 5 7 6
Sample Output
4 2 0 1
Explanation:
B(0) = 5^7^6 = 4
B(1) = 3^7^6 = 2
B(2) = 3^5^6 = 0
B(3) = 3^5^7 = 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void cal(long arr[], int n){
long xor = 0;
for(int i = 0; i < arr.length; i++) {
xor = xor ^ arr[i];
}
for(int i = 0; i < arr.length; i++) {
long temp = xor ^ arr[i];
System.out.print(temp+" ");
}
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nD = br.readLine();
String nDArr[] = nD.split(" ");
int n = Integer.parseInt(nDArr[0]);
long arr[]= new long[n];
String input = br.readLine();
String sar[] = input.split(" ");
for(int i = 0; i < n; i++){
arr[i] = Long.parseLong(sar[i]);
}
cal(arr, n);
}
}, 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, you need to create an array B such that B(i) is the Xor of all the elements of A except A(i).The first line of the input contains an integer N, the number of elements in array A.
The second line of input contains N singly spaced integers, the elements of the array A.
Constraints
1 <= N <= 300000
0 <= A(i) <= 1000000000Output the required array B.Sample Input
4
3 5 7 6
Sample Output
4 2 0 1
Explanation:
B(0) = 5^7^6 = 4
B(1) = 3^7^6 = 2
B(2) = 3^5^6 = 0
B(3) = 3^5^7 = 1, I have written this Solution Code: n= int(input())
arr = list(map(int,input().split()))
for i in range(0,n):
sums = 0
for j in range(0,n):
if(i==j):
continue
else:
sums = sums ^ arr[j]
print(sums,end=" "), 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, you need to create an array B such that B(i) is the Xor of all the elements of A except A(i).The first line of the input contains an integer N, the number of elements in array A.
The second line of input contains N singly spaced integers, the elements of the array A.
Constraints
1 <= N <= 300000
0 <= A(i) <= 1000000000Output the required array B.Sample Input
4
3 5 7 6
Sample Output
4 2 0 1
Explanation:
B(0) = 5^7^6 = 4
B(1) = 3^7^6 = 2
B(2) = 3^5^6 = 0
B(3) = 3^5^7 = 1, I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int i,j;
for(i=0;i<n;i++)
cin>>a[i];
int xor1=0;
for(i=0;i<n;i++)
xor1=xor1^a[i];
for(i=0;i<n;i++)
cout<<(xor1^a[i])<<" ";
cout<<endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException
{
InputStreamReader pk = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(pk);
String[] strNums;
int num[] = new int[4];
strNums = in.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
if((num[0]<(num[1]+num[2])) || (num[0]<(num[1]*num[3])))
System.out.println("1");
else
System.out.println("0");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: a = []
a = list(map(int, input().split()))
if a[1]+a[2] > a[0] or a[1]*a[3] > a[0]:
defeat = 1
else:
defeat = 0
print(defeat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll M, Y, R, G;
cin >> M >> Y >> R >> G;
ll maxm = Y;
maxm = max(maxm, Y+R);
maxm = max(maxm, Y*G);
cout << (M < maxm) << "\n";
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: A pair is called lucky if its sum is even and positive. Given three numbers find if there exists a lucky pair or not.The only line contains three integers a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>
<b>Constraints:</b>
-10<sup>9</sup> <= a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub> <= 10<sup>9</sup>Print "YES" without quotes if there exists a lucky pair otherwise print "NO" without quotes.Sample Input 1:
23 32 12
Sample Output 1:
YES
Sample Input 2:
1 -1 2
Sample Output 2:
NO, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define fr first
#define sc second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
typedef long long ll;
typedef long long unsigned int llu;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
void solve(){
vector<ll>a(3);
for(ll i = 0;i<3;i++)cin >> a[i];
for(ll i = 0;i<3;i++){
for(ll j = i+1;j<3;j++){
if((a[i]+a[j])>0 && (a[i]+a[j])%2 == 0){
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout.tie(NULL);
#ifdef LOCALFLAG
freopen("Input.txt", "r", stdin);
freopen("Output2.txt", "w", stdout);
#endif
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: def inv(a,b,m):
res = 1
while(b):
if b&1:
res = (res*a)%m
a = (a*a)%m
b >>= 1
return res
n,x = map(int,input().split())
a = list(map(int,input().split()))
m = 1000000007
for i in a:
x = (x*inv(i,m-2,m))%m
print(x), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
int power_mod(int a,int b,int mod){
int ans = 1;
while(b){
if(b&1)
ans = (ans*a)%mod;
b = b/2;
a = (a*a)%mod;
}
return ans;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int x;
cin>>x;
int mo=1000000007;
int mu=1;
for(int i=0;i<n;++i){
int d;
cin>>d;
mu=(mu*d)%mo;
}
cout<<(x*power_mod(mu,mo-2,mo))%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is trying to find the chamber of secrets but the chamber of secrets is well protected by dark spells. To find the chamber Harry needs to find the initial position of the chamber. Harry knows the final position of the chamber is X. He also knows that in total, the chamber has been repositioned N times. During the i<sup>th</sup> repositioning, the position of the chamber is changed to (previous position * Arr[i]) % 1000000007.
Given X and Arr, help Harry find the initial position of the chamber.
Note:- The initial position of the chamber is less than 1000000007.The first line of the input contains two integers N and X.
The second line of the input contains N integers denoting Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] < 1000000007Print a single integer denoting the initial position of the chamber.Sample Input
5 480
1 4 4 3 1
Sample Output
10
Explanation: Initial position = 10
After first repositioning position = (10*1)%1000000007 = 10
After second repositioning position = (10*4)%1000000007 = 40
After third repositioning position = (40*4)%1000000007 = 160
After fourth repositioning position = (160*3)%1000000007 = 480
After fifth repositioning position = (480*1)%1000000007 = 480, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;
public class Main
{
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;StringBuilder sb;
public void tq()throws Exception
{
st=new StringTokenizer(br.readLine());
int tq=1;
o:
while(tq-->0)
{
int n=i();
long k=l();
long ar[]=arl(n);
long v=1l;
for(long x:ar)v=(v*x)%mod;
v=(k*(mul(v,mod-2,mod)))%mod;
pl(v);
}
}
public static void main(String[] a)throws Exception{new Main().tq();}
int[] so(int ar[]){Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[])
{Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];
Arrays.sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.append(s);}
void s(char s){sb.append(s);}void s(double s){sb.append(s);}
void ss(){sb.append(' ');}void sl(String s){sb.append(s);sb.append("\n");}
void sl(int s){sb.append(s);sb.append("\n");}
void sl(long s){sb.append(s);sb.append("\n");}void sl(char s){sb.append(s);sb.append("\n");}
void sl(double s){sb.append(s);sb.append("\n");}void sl(){sb.append("\n");}
int min(int a,int b){return a<b?a:b;}
int min(int a,int b,int c){return a<b?a<c?a:c:b<c?b:c;}
int max(int a,int b){return a>b?a:b;}
int max(int a,int b,int c){return a>b?a>c?a:c:b>c?b:c;}
long min(long a,long b){return a<b?a:b;}
long min(long a,long b,long c){return a<b?a<c?a:c:b<c?b:c;}
long max(long a,long b){return a>b?a:b;}
long max(long a,long b,long c){return a>b?a>c?a:c:b>c?b:c;}
int abs(int a){return Math.abs(a);}
long abs(long a){return Math.abs(a);}
int sq(int a){return (int)Math.sqrt(a);}long sq(long a){return (long)Math.sqrt(a);}
long gcd(long a,long b){return b==0l?a:gcd(b,a%b);}
boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;return true;}
boolean[] si(int n)
{boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]=true;for(int x=4;x<=n;x+=2)bo[x]=true;
for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;y+=vv)bo[y]=true;}}
return bo;}long mul(long a,long b,long m)
{long r=1l;a%=m;while(b>0){if((b&1)==1)r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}
int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());}
long l()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());}String s()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
return Double.parseDouble(st.nextToken());}void p(Object p){System.out.print(p);}
void p(String p){System.out.print(p);}void p(int p){System.out.print(p);}
void p(double p){System.out.print(p);}void p(long p){System.out.print(p);}
void p(char p){System.out.print(p);}void p(boolean p){System.out.print(p);}
void pl(Object p){System.out.println(p);}void pl(String p){System.out.println(p);}
void pl(int p){System.out.println(p);}void pl(char p){System.out.println(p);}
void pl(double p){System.out.println(p);}void pl(long p){System.out.println(p);}
void pl(boolean p){System.out.println(p);}void pl(){System.out.println();}
void s(int a[]){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[]){for(long e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
void s(char a[]){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}
void s(char ar[][]){for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}
int[] ari(int n)throws IOException
{int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}
int[][] ari(int n,int m)throws IOException
{int ar[][]=new int[n][m];for(int x=0;x<n;x++){if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}
long[] arl(int n)throws IOException
{long ar[]=new long[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());return ar;}
long[][] arl(int n,int m)throws IOException
{long ar[][]=new long[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException
{String ar[]=new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++) ar[x]=st.nextToken();return ar;}
double[] ard(int n)throws IOException
{double ar[]=new double[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}
double[][] ard(int n,int m)throws IOException
{double ar[][]=new double[n][m];for(int x=0;x<n;x++)
{if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());}return ar;}
char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}
char[][] arc(int n,int m)throws IOException{char ar[][]=new char[n][m];
for(int x=0;x<n;x++){String s=br.readLine();for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}
void p(int ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(int a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(int ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(int a[]:ar){for(int aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(long ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(long a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(long ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(long a[]:ar){for(long aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;StringBuilder sb=new StringBuilder(c);
for(String a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(double a:ar){sb.append(a);sb.append(' ');}System.out.println(sb);}
void p(double ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
void p(char ar[]){StringBuilder sb=new StringBuilder(2*ar.length);
for(char aa:ar){sb.append(aa);sb.append(' ');}System.out.println(sb);}
void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 5000
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input:
5
1 5 2 2 1
Sample Output:
YES
Explanation:
We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: def sunpal(n,a):
ok=False
for i in range(n):
for j in range(i+2,n):
if a[i]==a[j]:
ok=True
return("YES" if ok else "NO")
if __name__=="__main__":
n=int(input())
a=input().split()
res=sunpal(n,a)
print(res), 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. You have to find whether A has some subsequence of length at least 3 that is a palindrome.First line of the input contains an integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 5000
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print "YES" if A has some subseqeuence of length at least 3 that is a palindrome, else print "NO", without the quotes.Sample Input:
5
1 5 2 2 1
Sample Output:
YES
Explanation:
We pick the elements at indices 1, 3, 4, 5 (1- indexed) making the subsequence: [1, 2, 2, 1], which is a palindrome., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 1e18;
void solve(){
int N;
cin >> N;
map<int, int> mp;
string ans = "NO";
for(int i = 1; i <= N; i++) {
int a;
cin >> a;
if(mp[a] != 0 and mp[a] <= i - 2) {
ans = "YES";
}
if(mp[a] == 0) mp[a] = i;
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y):
cnt=0
if(X>2):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y>2):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
if(X<7):
if(Y>1):
cnt=cnt+1
if(Y<8):
cnt=cnt+1
if(Y<7):
if(X>1):
cnt=cnt+1
if(X<8):
cnt=cnt+1
return cnt;
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move .
Note:- Rows and Columns are numbered through 1 to N.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Knight()</b> that takes integers X and Y as arguments.
Constraints:-
1 <= X <= 8
1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:-
4 5
Sample Output:-
8
Explanation:-
Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4)
Sample input:-
1 1
Sample Output:-
2
Explanation:-
Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){
int cnt=0;
if(X>2){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y<7){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
if(X<7){
if(Y>1){cnt++;}
if(Y<8){cnt++;}
}
if(Y>2){
if(X>1){cnt++;}
if(X<8){cnt++;}
}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.