Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Nutan is a college student. Nutan arrived at college and listened to his friends discussing 'loyal' numbers in a matrix. But Nutan had no idea what 'loyal' numbers were, so he asked his friends. A 'loyal' number, according to one of his friends, is a matrix element that is the smallest in its row and the largest in its column.
Now it's time to test Nutan's understanding. He is given a m x n matrix of distinct numbers and is asked to return all βloyalβ numbers in any order.
As a friend of Nutan, help him to solve the problem.The first line contains the numbers of rows r and number of columns c as space separated.
For the next r lines, contains the c elements of the matrix each line as a space separated.
<b>Constraints</b>
m == mat. length
n == mat[i]. length
1 <= n, m <= 10
-100 <= matrix[i][j] <= 100.
All elements in the matrix are distinct.Print the elements of the array containing the loyal numbers in a single line space separated, if it's not present then print -1.Sample Input
2 2
7 8
1 2
Sample Output
7
Explanation
7 is the only loyal number since it is the minimum in its row and the maximum in its column., I have written this Solution Code: m,n = list(map(int,input().split()))
mat = []
for i in range(m):
mat.append(list(map(int,input().split())))
loyal = []
i = 0
for i in range(m):
flag = 0
index = mat[i].index(min(mat[i]))
max_val = min(mat[i])
for j in mat:
if j[index]>max_val:
flag = 1
break
if flag==0:
loyal.append(max_val)
if loyal==[]:
print(-1)
else:
print(*loyal), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan is a college student. Nutan arrived at college and listened to his friends discussing 'loyal' numbers in a matrix. But Nutan had no idea what 'loyal' numbers were, so he asked his friends. A 'loyal' number, according to one of his friends, is a matrix element that is the smallest in its row and the largest in its column.
Now it's time to test Nutan's understanding. He is given a m x n matrix of distinct numbers and is asked to return all βloyalβ numbers in any order.
As a friend of Nutan, help him to solve the problem.The first line contains the numbers of rows r and number of columns c as space separated.
For the next r lines, contains the c elements of the matrix each line as a space separated.
<b>Constraints</b>
m == mat. length
n == mat[i]. length
1 <= n, m <= 10
-100 <= matrix[i][j] <= 100.
All elements in the matrix are distinct.Print the elements of the array containing the loyal numbers in a single line space separated, if it's not present then print -1.Sample Input
2 2
7 8
1 2
Sample Output
7
Explanation
7 is the only loyal number since it is the minimum in its row and the maximum in its column., I have written this Solution Code: // C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to find all the matrix elements
// which are minimum in its row and maximum
// in its column
vector<int> minmaxNumbers(vector<vector<int> >& matrix, vector<int>& res)
{
// Initialize unordered set
unordered_set<int> set;
// Traverse the matrix
for (int i = 0; i < matrix.size(); i++) {
int minr = INT_MAX;
for (int j = 0; j < matrix[i].size(); j++) {
// Update the minimum
// element of current row
minr = min(minr, matrix[i][j]);
}
// Insert the minimum
// element of the row
set.insert(minr);
}
for (int j = 0; j < matrix[0].size(); j++) {
int maxc = INT_MIN;
for (int i = 0; i < matrix.size(); i++) {
// Update the maximum
// element of current column
maxc = max(maxc, matrix[i][j]);
}
// Checking if it is already present
// in the unordered_set or not
if (set.find(maxc) != set.end()) {
res.push_back(maxc);
}
}
return res;
}
// Driver Code
int main()
{
vector<vector<int>> mat;
int r, c;
cin >> r >> c;
for(int i = 0; i < r; i++){
vector<int> row;
for(int j = 0; j < c; j++){
int value;
cin >> value;
row.push_back(value);
}
mat.push_back(row);
}
vector<int> ans;
// Function call
minmaxNumbers(mat, ans);
// If no such matrix
// element is found
if (ans.size() == 0)
cout << "-1" << endl;
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, 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 s1=br.readLine();
int N=s1.length();
int index=0;
int count=0;
for(int i=N-2;i>=0;i--)
{
if(s1.charAt(i)!=s1.charAt(i+1))
{
index=i+1;
break;
}
}
if(index==N-1)
{
if(N%2==0)
{
System.out.print("Sasuke");
}
else{
System.out.print("Naruto");
}
}
else if(index==0)
{
System.out.print("Naruto");
}
else{
for(int i=0;i<index;i++)
{
count++;
}
if(count%2==0)
{
System.out.print("Naruto");
}
else{
System.out.print("Sasuke");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code: binary_string = input()
n = len(binary_string)-1
index = n
for i in range(n-1, -1, -1):
if binary_string[i] == binary_string[n]:
index = i
else:
break
if index % 2 == 0:
print("Naruto")
else:
print("Sasuke"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are playing a game in which they are given a binary string S. The rules of the game are given as:-
Players play in turns
The game ends when all the characters in the string are same, and the player who has the current turn wins.
The current player has to delete the i<sup>th</sup> character from the string. (1 <= i <= |S|)
If both the players play optimally and Naruto goes first, find who will win the game.The Input contains only string S.
Constraints:-
1 <= |S| <= 100000Print "Naruto" if Naruto wins else print "Sasuke".Sample Input:-
0101
Sample Output:-
Sasuke
Explanation:-
First Naruto will delete the character 0 from index 1. string:- 101
Then Sasuke will delete the character 1 from index 1. string 01
It doesn't matter which character Naruto removes now, Sasuke will definitely win.
Sample Input:-
1111
Sample Output:-
Naruto
Explanation:-
All the characters in the string are already same hence Naruto wins, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int cnt[max1];
signed main(){
string s;
cin>>s;
int cnt=0;
FOR(i,s.length()){
if(s[i]=='0'){cnt++;}
}
if(cnt==s.length() || cnt==0){out("Naruto");return 0;}
if(s.length()%2==0){
out("Sasuke");
}
else{
out("Naruto");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice and Bob are playing a game where Bob gives Alice an array <b>A</b> of size N. There are some positions in the array where the index (According to 1-based indexing) and the element at that index both are prime numbers. Alice has to find those elements and give that to Bob in order of their appearance in the array. Your task is to help Alice complete his task and print the elements.The first line of the input contains an integer N representing the number of elements in the array that Bob gave.
The second line of the input contains n space-separated elements of the array <b>A</b>.
<b>Constraints</b>
1 ≤ N ≤ 10<sup>4</sup>
1 ≤ A[i] ≤ 10<sup>4</sup>Print the required elements separated by space in a single line.<b>Sample Input</b>
10
2 3 5 7 11 13 17 19 23 29
<b>Sample Output</b>
3 5 11 17
<b>Explanation</b>
The array indexing is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] so the prime number according to the array indexing are 2, 3, 5, 7, and elements belonging to respective indexes are 3, 5, 11, 17. Hence the elements which are prime and are also at prime indexes are 3, 5, 11, and 17., I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
// operator overload of << for vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (const auto &x : v)
os << x << " ";
return os;
}
bool prime[10001];
void SieveOfEratosthenes(int n) {
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
}
void BobsPrimeArray(int n, vector<int> &arr) {
SieveOfEratosthenes(10000);
bool ansFound = false;
for (int i = 1; i < n; ++i) {
if (arr[i] != 1 && arr[i]!=0 && prime[i + 1] && prime[arr[i]]) {
cout << arr[i] << " ";
ansFound = true;
}
}
if (!ansFound) {
cout << "-1\n";
}
}
int32_t main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
BobsPrimeArray(n, arr);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code: static int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code:
int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code: def maximumMarks(X):
if X>5:
return (X)
return (10-X)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<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>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code:
int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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 playing a solitaire game with three piles of stones of sizes aββββββ, b,ββββββ and cββββββ respectively. Each turn you choose two different non-empty piles, take one stone from each and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).
Given three integers aβββββ, b,βββββ and cβββββ, return the maximum score you can get.The first line of the input contains the integer value of a.
The second line of the input contains the integer value of b.
The third line of the input contains the integer value of c.
<b>Constraints</b>
1 ≤ a,b,c ≤ 10<sup>5</sup>Return the maximum score you can get.<b>Sample Input</b>
2
4
6
<b>Sample output</b>
6
<b>Explanation</b>
The starting state is (2, 4, 6). One optimal set of moves is:
- Take from 1st and 3rd piles, state is now (1, 4, 5)
- Take from 1st and 3rd piles, state is now (0, 4, 4)
- Take from 2nd and 3rd piles, state is now (0, 3, 3)
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
There are fewer than two non-empty piles, so the game ends. Total: 6 points., I have written this Solution Code: import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] piles = new int[3];
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
piles[i] = scanner.nextInt();
}
Main solution = new Main();
int result = solution.maximumScore(piles);
System.out.println(result);
scanner.close();
}
public int maximumScore(int[] piles) {
Arrays.sort(piles);
int score = 0;
while (piles[1] > 0) {
piles[2]--;
piles[1]--;
score++;
Arrays.sort(piles);
}
return score;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: import java.util.InputMismatchException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
int MAX = (int) 1e5, MOD = (int)1e9+7;
void solve(int TC) {
long n = nl();
long k = nl();
int p = 0;
while(n>0 && n%2==0) {
n/=2;
++p;
}
if(p>=k) {pn(0);return;}
k -= p;
long ans = (k+3L)/4L;
pn(ans);
}
boolean TestCases = false;
public static void main(String[] args) throws Exception { new Main().run(); }
long pow(long a, long b) {
if(b==0 || a==1) return 1;
long o = 1;
for(long p = b; p > 0; p>>=1) {
if((p&1)==1) o = (o*a) % MOD;
a = (a*a) % MOD;
} return o;
}
long inv(long x) {
long o = 1;
for(long p = MOD-2; p > 0; p>>=1) {
if((p&1)==1)o = (o*x)%MOD;
x = (x*x)%MOD;
} return o;
}
long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }
int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for(int t=1;t<=T;t++) solve(t);
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
void p(Object o) { out.print(o); }
void pn(Object o) { out.println(o); }
void pni(Object o) { out.println(o);out.flush(); }
double PI = 3.141592653589793238462643383279502884197169399;
int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() { return Double.parseDouble(ns()); }
char nc() { return (char)skip(); }
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
} return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))) {
sb.appendCodePoint(b); b = readByte();
} return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
} return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: [n,k]=[int(j) for j in input().split()]
a=0
while n%2==0:
a+=1
n=n//2
if k>a:
print((k-a-1)//4+1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).
Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K.
Constraints
1 <= N <= 10^18
1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1
40 4
Sample Output 1
1
Sample Input
40 3
Sample Output
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,k;
cin>>n>>k;
while(k&&n%2==0){
n/=2;
--k;
}
cout<<(k+3)/4;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code: def solve(a):
maxi = 0
mini = 1e7+1
for i in a:
if(i < mini):
mini = i
if(i > maxi):
maxi = i
return mini,maxi, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findMinMax(arr, n);
System.out.println();
}
}
public static void findMinMax(int arr[], int n)
{
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++)
{
min = Math.min(arr[i], min);
max = Math.max(arr[i], max);
}
System.out.print(max + " " + min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of integers. Consider absolute difference between all the pairs of the the elements. You need to find Kth smallest absolute difference. If the size of the array is N then value of K will be less than N and more than or equal to 1.The first line of input contains number of test cases T.
The first line of each test case contains a two integers N and K denoting the number of elements in the array A and difference you need to output. The second line of each test case contains N space separated integers denoting the elements of the array A
Constraints:
1<= T <= 10
2 <= N <= 100000
1 <= K < N < 100000
0 <= A[i] <= 100000For each test case, output Kth smallest absolute difference.Input :
1
6 2
1 3 4 1 3 8
Output :
0
Explanation :
Test case 1: First smallest difference is 0, between the pair (1, 1) and second smallest absolute difference difference is also 0 between the pairs (3, 3)., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine().trim());
while (t-- > 0) {
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
System.out.println(Math.abs(small(arr, k)));
}
}
public static int small(int arr[], int k) {
Arrays.sort(arr);
int l = 0, r = arr[arr.length - 1] - arr[0];
while (r > l) {
int mid = l + (r - l) / 2;
if (count(arr, mid) < k) {
l = mid + 1;
} else {
r = mid;
}
}
return r;
}
public static int count(int arr[], int mid) {
int ans = 0, j = 0;
for (int i = 1; i < arr.length; ++i) {
while (j < i && arr[i] - arr[j] > mid) {
++j;
}
ans += i - j;
}
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str[]=br.readLine().split(" ");
int a[]=new int[str.length];
int sum=0;
for(int i=0;i<str.length;i++)
{
a[i]=Integer.parseInt(str[i]);
sum=sum+a[i];
}
System.out.println(sum/4);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: a,b,c,d = map(int,input().split())
print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: a, b, v = map(int, input().strip().split(" "))
c = abs(a-b)
t = c//v
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?The input contains three integers A, B, and S separated by spaces.
Constraints:-
1 <= A, B, V <= 1000
Note:- It is guaranteed that the calculated distance will always be divisible by V.Print the Time taken in seconds by Kazama to reach Shinchan.
Note:- Remember Distance can not be negativeSample Input:-
5 2 3
Sample Output:-
1
Explanation:-
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
Sample Input:-
9 1 2
Sample Output:-
4, I have written this Solution Code: /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]);
int ans=2;
if(a==b) ans=0;
else if(a%b==0 || b%a==0 || a+1==b || b+1==a) ans=1;
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: l=list(map(int, input().split()))
A=l[0]
B=l[1]
if A==B:
print(0)
elif A%B==0 or B%A==0 or abs(A-B)==1:
print(1)
else:
print(2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two integers, X and Y. Initially, they are equal to A and B, respectively. In one move, you can do exactly one of the following operations:
1. Set X = X+1
2. Set Y = Y+1.
3. Let d be any divisor of X, then set X = d
4. Let d be any divisor of Y, then set Y = d.
Find the minimum number of moves so that X = Y.The input consists of two space separated integers A and B.
Constraints:
1 β€ A, B β€ 10<sup>9</sup>Print a single integer, the minimum number of moves so that X = Y.Sample 1:
1 8
Output 1:
1
Explanation 1:
We do only one operation, we let Y = 1 by the fourth operation. Then X = Y = 1.
Sample 2:
5 5
Output 2:
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a == b) cout << 0;
else if (abs(a - b) == 1) cout << 1;
else if (a % b == 0 || b % a == 0) cout << 1;
else cout << 2;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, we define the set A<sub>N</sub> as {1, 2, 3, ... N-1, N}.
Find the size of the largest subset of A<sub>N</sub>, such that if x belongs to the subset, then 2x does not belong to the subset.The first line of the input contains a single integer T β the number of test cases.
Each test case consists of one line containing a single integer N.
<b>Constraints:</b>
1 β€ T β€ 10<sup>5</sup>
1 β€ N β€ 10<sup>9</sup>For each test case, print one integer β the size of the largest subset of A<sub>N</sub> satisfying the condition in the problem statement.Sample Input:
4
1
2
3
4
Sample Output:
1
1
2
3
Explanation:
For test case 4, where N = 4, the subset {1, 3, 4} is the largest subset satisfying the conditions.
1 is in the subset whereas 2 is not.
3 is in the subset whereas 6 is not.
4 is in the subset whereas 8 is not., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static long compute(long n){
if(n==1||n==2) return 1;
if(n==3) return 2;
if(n%2==0){
long ans=(n/2);
return ans+compute(ans/2);
}
else {
long ans=(n+1)/2;
if(ans%2==1) return ans+compute(ans/2);
else return ans+compute((ans/2)-1);
}
}
public static void main(String[] args) throws Exception
{
br= new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t=Integer.parseInt(br.readLine());
while(t-->0){
long n=Long.parseLong(br.readLine());
long ans=compute(n);
pw.println(ans);
}
pw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, we define the set A<sub>N</sub> as {1, 2, 3, ... N-1, N}.
Find the size of the largest subset of A<sub>N</sub>, such that if x belongs to the subset, then 2x does not belong to the subset.The first line of the input contains a single integer T β the number of test cases.
Each test case consists of one line containing a single integer N.
<b>Constraints:</b>
1 β€ T β€ 10<sup>5</sup>
1 β€ N β€ 10<sup>9</sup>For each test case, print one integer β the size of the largest subset of A<sub>N</sub> satisfying the condition in the problem statement.Sample Input:
4
1
2
3
4
Sample Output:
1
1
2
3
Explanation:
For test case 4, where N = 4, the subset {1, 3, 4} is the largest subset satisfying the conditions.
1 is in the subset whereas 2 is not.
3 is in the subset whereas 6 is not.
4 is in the subset whereas 8 is not., I have written this Solution Code: //Author: Xzirium
//Time and Date: 15:50:05 28 September 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(T);
while(T--)
{
READV(N);
ll ans=0;
while (N>0)
{
ans+=(N+1)/2;
N=N/4;
}
cout<<ans<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 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: Complete the object <code>sayHiMixin</code> and the function <code>setPrototype</code>. You should implement the following:
<b>setPrototype</b>, this should set the prototype of a pre- defined class (not visible to you)<code>User</code> to <code> sayHiMixin</code>.
<b>sayHiMixin</b>, this must override the method <b>say</b> of an already defined object (not visible to you) <code>sayMixin</code>. This overridden method <b>say</b> should call the a <say> function of the already defined object <code>sayMixin</code>
<b>Note: </b> The method "say" in <code>sayMixin</code> takes a single parameter as string (which in this case the <code>name</code> attribute of the User class) and returns a number based on it.Name of the person as <b>string</b> s.You should return the same value as the <code>say</code> function in <b>sayMixin</b> returns.<pre>
// This is what you have to implement.
let sayHiMixin = {
// this should inherit from sayMixin, and invoke it's "say" method somehow
// for example,
const say = (name) => sayMixin.say(name);
// name is a string, which will infact be the `name` attribute of a `User` object
};
// You must setPrototype of User class to that of sayHiMixin object.
function setPrototype(){
// some code here
}
// Finally, when
// const obj = new User("Newton School")
// console.log(obj.say()) // this should print whatever sayHiMixin.say returns, which in this case is 39
</pre>, I have written this Solution Code: function setPrototype() {
Object.assign(User.prototype, sayHiMixin);
}
let sayHiMixin = {
__proto__: sayMixin, // (or we could use Object.setPrototypeOf to set the prototype here)
say() {
// call parent method
return super.say(`${this.name}`); // (*)
},
};
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: def compound_interest(principle, rate, time):
Amount = principle * (pow((1 + rate / 100), time))
CI = Amount - principle
print( '%.2f'%CI)
principle,rate,time=map(int, input().split())
compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: function calculateCI(P, R, T)
{
let interest = P * (Math.pow(1.0 + R/100.0, T) - 1);
return interest.toFixed(2);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int p,r,t;
cin>>p>>r>>t;
double rate= (float)r/100;
double amt = (float)p*(pow(1+rate,t));
cout << fixed << setprecision(2) << (amt - p);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R.
<b>Note:</b> Compound interest is the interest you earn on interest.
This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm.
<b>Constraints:- </b>
1 < = P < = 10^3
1 < = R < = 100
1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input:
100 1 2
Sample Output:-
2.01
Sample Input:
1 99 2
Sample Output:-
2.96, 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 Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s= br.readLine().split(" ");
double[] darr = new double[s.length];
for(int i=0;i<s.length;i++){
darr[i] = Double.parseDouble(s[i]);
}
double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0];
System.out.printf("%.2f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
if(str.contains(" ")) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: s = input()
if " " in s:
print("Yes")
else:
print("No")
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, check if the given string contains any white space or not.Input contains a single string S.
Constraints:-
1 < = |S| < = 20
Note:- String will only contain lowercase english letters.Print "Yes" if the given string contains a whitespace else print "No"Sample Input:-
newton school
Sample Output:-
Yes
Sample Input:-
newtonschool
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
for(int i=0;i<s.length();i++){
if(s[i]==' '){cout<<"Yes";return 0;}
}
cout<<"No";return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer β the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
int n = in.nextInt();
out.println(n*n);
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static long ooo = Long.MAX_VALUE;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer β the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<(n*n)<<'\n';
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer β the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code: n=int(input())
print(n*n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size n, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int m = 100001;
int main(){
int n,k;
cin>>n>>k;
long long a[n],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]<0){
a[i]=-a[i];
}
}
sort(a,a+n);
for(int i=0;i<k;i++){
sum+=a[n-i-1]*a[n-i-1];
}
cout<<sum;
}
, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
String[] NK = br.readLine().split(" ");
String[] inputs = br.readLine().split(" ");
int N = Integer.parseInt(NK[0]);
int K = Integer.parseInt(NK[1]);
long[] arr = new long[N];
long answer = 0;
for(int i = 0; i < N; i++){
arr[i] = Math.abs(Long.parseLong(inputs[i]));
}
quicksort(arr, 0, N-1);
for(int i = (N-K); i < N;i++){
answer += (arr[i]*arr[i]);
}
System.out.println(answer);
}
static void quicksort(long[] arr, int start, int end){
if(start < end){
int pivot = partition(arr, start, end);
quicksort(arr, start, pivot-1);
quicksort(arr, pivot+1, end);
}
}
static int partition(long[] arr, int start, int end){
long pivot = arr[end];
int i = start - 1;
for(int j = start; j < end; j++){
if(arr[j] < pivot){
i++;
swap(arr, i, j);
}
}
swap(arr, i+1, end);
return (i+1);
}
static void swap(long[] arr, int i, int j){
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}, 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, and an integer k. Find the maximum force by involving only k elements. The Force of an element is the square of its value.
<b>Note:</b>
Elements are not needed to be continuous.The first line of the input contains two integers denoting n and k.
The next line contains n integers denoting elements of the array.
<b>Constraints:</b>
1 < = k < = n < = 1000
-10^7 <= A[i] <= 10^7Output the maximum force.Sample Input 1:
4 4
1 2 3 4
Sample Output 1:
30
Sample Input 2:
2 1
1 10
Sample Output 2:
100
<b>Explanation:</b>
Force = 1*1 + 2*2 + 3*3 + 4*4 = 30, I have written this Solution Code: x,y = map(int,input().split())
arr = list(map(int,input().split()))
s=0
for i in range(x):
if arr[i]<0:
arr[i]=abs(arr[i])
arr=sorted(arr,reverse=True)
for i in range(0,y):
s = s+arr[i]*arr[i]
print(s)
, In this Programming Language: Python, 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: A company is formed over N years. The company has sold X products (numbered through 1 to X) over the span of N years.
For every product, company has noted 3 integers a, b, and c.
It means the company gained a profit of "c" from years "a" to "b" (inclusive of both) where 1<=a<=b<=N. (Note: The company gained the profit "c" every year in the given range).
After updating all the profits your task is to calculate the maximum sum of profits over any contiguous range of years.
Note: Profit value can be negative.
For better understanding see the example.First line of input contains two integers N and X
Next X lines contains three integers a,b,c starting year ,ending year and the profit value
Constraints:-
1<=N, X<=10^5
-10^5<=c<=10^5
1<=a<=b<=NPrint a single integer containing the maximum sum of profit value over contiguous years.Sample Input:-
4 3
1 3 5
2 4 6
1 2 -10
Sample Output:-
18
Explanation:-
After updating the products , The final profits values over N years are: -5 1 11 6
maximum sum=18 (1+11+6), 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));
StringTokenizer st= new StringTokenizer(br.readLine());
int n= Integer.parseInt(st.nextToken());
int x= Integer.parseInt(st.nextToken());
int[] arr = new int[n+1];
for(int i=1; i<=x; i++){
StringTokenizer st1= new StringTokenizer(br.readLine());
int a= Integer.parseInt(st1.nextToken());
int b= Integer.parseInt(st1.nextToken());
int c= Integer.parseInt(st1.nextToken());
for(int j=a; j<=b; j++){
arr[j]+= c;
}
}
long currMax=0, maxSoFar=0, maxNo=Integer.MIN_VALUE;
for(int i=1; i<=n; i++){
long val= arr[i];
currMax+= val;
if(currMax > maxSoFar)
maxSoFar = currMax;
if(currMax<0)
currMax =0;
if(maxNo< val){
maxNo= val;
}
}
if(maxSoFar>0)
System.out.println(maxSoFar);
else{
System.out.println(maxNo);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A company is formed over N years. The company has sold X products (numbered through 1 to X) over the span of N years.
For every product, company has noted 3 integers a, b, and c.
It means the company gained a profit of "c" from years "a" to "b" (inclusive of both) where 1<=a<=b<=N. (Note: The company gained the profit "c" every year in the given range).
After updating all the profits your task is to calculate the maximum sum of profits over any contiguous range of years.
Note: Profit value can be negative.
For better understanding see the example.First line of input contains two integers N and X
Next X lines contains three integers a,b,c starting year ,ending year and the profit value
Constraints:-
1<=N, X<=10^5
-10^5<=c<=10^5
1<=a<=b<=NPrint a single integer containing the maximum sum of profit value over contiguous years.Sample Input:-
4 3
1 3 5
2 4 6
1 2 -10
Sample Output:-
18
Explanation:-
After updating the products , The final profits values over N years are: -5 1 11 6
maximum sum=18 (1+11+6), I have written this Solution Code: n,x=map(int,input().split())
l=[0 for i in range(n)]
for _ in range(x):
a,b,c=map(int,input().split())
l[a-1]+=c
if(b!=n):
l[b]-=c
for i in range(1,n):
l[i]=l[i]+l[i-1]
maxi=l[0]
s=0
for i in range(n):
s+=l[i]
if s>maxi:
maxi=s
if s<0:
s=0
print(maxi), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A company is formed over N years. The company has sold X products (numbered through 1 to X) over the span of N years.
For every product, company has noted 3 integers a, b, and c.
It means the company gained a profit of "c" from years "a" to "b" (inclusive of both) where 1<=a<=b<=N. (Note: The company gained the profit "c" every year in the given range).
After updating all the profits your task is to calculate the maximum sum of profits over any contiguous range of years.
Note: Profit value can be negative.
For better understanding see the example.First line of input contains two integers N and X
Next X lines contains three integers a,b,c starting year ,ending year and the profit value
Constraints:-
1<=N, X<=10^5
-10^5<=c<=10^5
1<=a<=b<=NPrint a single integer containing the maximum sum of profit value over contiguous years.Sample Input:-
4 3
1 3 5
2 4 6
1 2 -10
Sample Output:-
18
Explanation:-
After updating the products , The final profits values over N years are: -5 1 11 6
maximum sum=18 (1+11+6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long long kadane(long long a[], int size)
{
long long max_so_far = a[0];
long long curr_max = a[0];
for (int i = 1; i < size; i++)
{
curr_max = max(a[i], curr_max+a[i]);
max_so_far = max(max_so_far, curr_max);
}
return max_so_far;
}
int main(){
int t;
t=1;
while(t--){
long n,k;
cin>>n>>k;
long a[n+1];
for(int i=0;i<=n;i++){
a[i]=0;
}
int x,y,c;
while(k--){
cin>>x>>y>>c;
a[x-1]+=c;
a[y]-=c;
}
long long b[n];
long long sum=0;
for(int i=0;i<n;i++){
sum+=a[i];
b[i]=sum;
}
cout<<kadane(b,n)<<endl;
}}
, 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: You are given a string <em>S</em> and an integer <em>A</em>. You have to check whether or not the given integer A is smaller than 3200 or not. If it's smaller, print "red", otherwise print the string S.The first line of the input contains an integer A
The second line of the input contains a string S
<b>Constraints:</b>
1) 2800 ≤ A ≤ 5000Print the output string.<b>Sample Input 1:</b>
3400
lol
<b>Sample Output 1:</b>
lol
<b>Sample Input 2:</b>
3000
lol
<b>Sample Output 2:</b>
red, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main() {
int A;
string S;
cin >> A >> S;
if(A < 3200){
cout << "red" << endl;
}
else{
cout << S << endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a stack of integers and N queries. Your task is to perform these operations:-
<b>push:- </b>this operation will add an element to your current stack.
<b>pop:- </b>remove the element that is on top
<b>top:- </b>print the element which is currently on top of stack
<b>getMin:- </b> print the minimum element from the stack
<b>Note:- </b>if stack is already empty than pop operation will do nothing,-1 will printed as minimum element and 0 will be printed as a top element of stack if it is empty.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the stack and the integer to be added as a parameter.
<b>pop()</b>:- that takes the stack as parameter.
<b>top()</b> :- that takes the stack as parameter.
<b>getMin()</b> that takes the stack as parameter.
<b>Constraints:</b>
1 <= N <= 500000You don't need to print anything else other than in the <b>getMin()</b> function in which you need to print the minimum element of the stack, or -1 if the stack is empty and in the <b>top()</b> function in which need to print the top most element of your stack or 0 if the stack is empty.
<b>Note</b>:- Each output is to be printed in a new line.Sample Input:-
6
push 3
push 5
getMin
top
pop
top
Sample Output:-
3
5
3, I have written this Solution Code:
static Integer minEle;
public static void push (Stack < Integer > s, int x)
{
if (s.isEmpty())
{
minEle = x;
s.push(x);
return;
}
// If new number is less than original minEle
if (x < minEle)
{
s.push(2*x - minEle);
minEle = x;
}
else
s.push(x);
}
// Function to pop element from stack
public static void pop (Stack < Integer > s)
{
if (s.isEmpty())
{
return;
}
Integer t = s.pop();
// Minimum will change as the minimum element
// of the stack is being removed.
if (t < minEle)
{
minEle = 2*minEle - t;
}
}
// Function to return top of stack
public static void top(Stack < Integer > s)
{
if (s.isEmpty())
{
System.out.println("0");
return;
}
Integer t = s.peek(); // Top element.
// If t < minEle means minEle stores
// value of t.
if (t < minEle)
System.out.println(minEle);
else
System.out.println(t);
}
public static void getMin(Stack<Integer> s)
{
if (s.isEmpty())
System.out.println(-1);
// variable minEle stores the minimum element
// in the stack.
else
System.out.println(minEle);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: def QueenAttack(X, Y, P, Q):
if X==P or Y==Q or abs(X-P)==abs(Y-Q):
return 1
return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given first term A and the common ratio R of a GP (Geometric Progression) and an integer N, your task is to calculate its Nth term.<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>NthGP()</b> that takes the integer A, R and N as parameter.
<b>Constraints</b>
1 <= A, R <= 100
1 <= N <= 10
Return the Nth term of the given GP.
<b>Note:</b> It is guaranteed that the Nth term of this GP will always fit in 10^9.Sample Input:
3 2
5
Sample Output:-
48
Sample Input:-
2 2
10
Sample Output:
1024
<b>Explanation:-</b>
For Test Case 1:- 3 6 12 24 48 96., I have written this Solution Code:
static int NthGP(int l, int b, int h){
int ans=l;
h--;
while(h-->0){
ans*=b;
}
return ans;
}
, 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: 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: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, 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());
String s[]=br.readLine().split(" ");
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
}
int count=0;
int i=0;
int ans=0;
while(true)
{
if(arr[i]-count<=0)
{
ans=i+1;
break;
}
i=(++i)%n;
count++;
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, I have written this Solution Code: n = int(input())
a = list(map(int,input().split()))
i=0
while(True):
if(a[i%n]-i<=0):
print(i%n+1)
break
i+=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is playing a game in which there are N monsters standing in a circle and the ith (1 <= i <= N) monster has A[i] HP.
Rules:-
At the end of each second, all the monster's HP decreases by 1 if it is not 0.
At the end of each second, the player will jump to the next monster (monster standing to the right of the current).
The game ends when the current monster has 0 health.
If the player starts at index 1 then find the index at which the game ends.First line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of the array.
Constraints:-
1 <= N <= 100000
0 <= A[i] <= 1000000000Print a single index at which the game ends.Sample Input:-
5
3 2 3 2 1
Sample Output:-
4
Explanation:-
[ 3(P), 2, 3, 2, 1] - > [2, 1(P), 2, 1, 0] - > [1, 0, 1(P), 0, 0 ] - > [0, 0, 0, 0(P), 0]
Sample Input:-
3
10 10 10
Sample Output:-
2, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
fast();
int n;
cin>>n;
int a[n];
FOR(i,n){
cin>>a[i];}
int ans=0;
int l=0;
int h=1e10;
int m;
ans=h;
int p;
FOR(i,n){
int k;
l=0;
h=1e10;
while(l<h){
m=l+h;
m/=2;
// out1(l);out(h);
if(a[i]<=(m*n+i)){
h=m;
}
else{
l=m+1;
}
}
//out(l);
if((l*n+i)<ans){
ans=l*n+1;
p=i+1;
}
}
out(p);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four positive integers A, B, C, and D, can a rectangle have these integers as its sides?The input consists of a single line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 β€ A, B, C, D β€ 1000Output "Yes" if a rectangle is possible; otherwise, "No" (without quotes).Sample Input 1:
3 4 4 3
Sample Output 1:
Yes
Sample Explanation 1:
A rectangle is possible with 3, 4, 3, and 4 as sides in clockwise order.
Sample Input 2:
3 4 3 5
Sample Output 2:
No
Sample Explanation 2:
No rectangle can be made with these side lengths., I have written this Solution Code: #include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==c) &&(b==d)){
cout << "Yes\n";
}else if((a==b) && (c==d)){
cout << "Yes\n";
}else if((a==d) && (b==c)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to 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: You are given a stream of integers represented by an array <b>arr[]</b> of size <b>N</b>. Whenever you encounter an element arr[i], you need to increment its <b>first occurrence</b>(on the left side)if present in the stream by 1 and append this element in the array. You don't have to do this when you encounter arr[i] for the first time as it is the only occurrence till then. Finally, you need to print the updated array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, size of array. Second line contains elements of array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
For each testcase you need to print the updated array in a new line.Input:
1
10
1 2 3 2 3 1 4 2 1 3
Output:
4 5 3 2 3 2 4 2 1 3
Explanation:
Testcase 1: We encounter 1, 2, 3. We encounter 2 again so we increment its leftmost occurrence by 1. The updated array becomes 1 3 3 2. We encounter 3 next. So we increment its left most occurrence by 1. So updated array is 1 4 3 2 3. Next we encounter 1, so we increment the leftmost occurrence of 1 by 1. New updated array is 2 4 3 2 3 1. Next we encounter 4, so we do the same and increase its first occurrence by 1. New updated array is. 2 5 3 2 3 1 4. Next we encounter 2, so we do the same and increase its first occurrence by 1. New updated array is. 3 5 3 2 3 1 4 2. Next we encounter 1, so we do the same and increase its first occurrence by 1. New updated array is 3 5 3 2 3 2 4 2 1. Next we encounter 3, so we do the same and increase its first occurrence by 1. New updated array is 4 5 3 2 3 2 4 2 1 3. , I have written this Solution Code: from collections import deque
from heapq import heapify,heappush,heappop
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
hash_map = {}
new_arr = []
# for i in range(n):
# # print(hash_map)
# # print(new_arr)
# if arr[i] not in hash_map:
# hash_map[arr[i]] = i
# new_arr.append(arr[i])
# else:
# temp = hash_map[arr[i]]
# new_arr[temp] += 1
# hash_map[new_arr[temp]] = temp
# new_arr.append(arr[i])
# if arr[i] not in hash_map:
# hash_map[arr[i]] = i
# else:
# hash_map[arr[i]] = new_arr.index(arr[i])
for i in range(n):
# print(hash_map)
if arr[i] not in hash_map:
heap = []
heapify(heap)
heappush(heap,i)
hash_map[arr[i]] = heap
new_arr.append(arr[i])
else:
index = heappop(hash_map[arr[i]])
# print(index)
new_arr[index] += 1
if new_arr[index] not in hash_map:
heap1 = []
heapify(heap1)
heappush(heap1,index)
hash_map[new_arr[index]] = heap1
else:
heappush(hash_map[new_arr[index]],index)
heappush(hash_map[arr[i]],i)
new_arr.append(arr[i])
# temp = heappop(hash_map[1])
# print(hash_map)
for i in new_arr:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a stream of integers represented by an array <b>arr[]</b> of size <b>N</b>. Whenever you encounter an element arr[i], you need to increment its <b>first occurrence</b>(on the left side)if present in the stream by 1 and append this element in the array. You don't have to do this when you encounter arr[i] for the first time as it is the only occurrence till then. Finally, you need to print the updated array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, size of array. Second line contains elements of array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
For each testcase you need to print the updated array in a new line.Input:
1
10
1 2 3 2 3 1 4 2 1 3
Output:
4 5 3 2 3 2 4 2 1 3
Explanation:
Testcase 1: We encounter 1, 2, 3. We encounter 2 again so we increment its leftmost occurrence by 1. The updated array becomes 1 3 3 2. We encounter 3 next. So we increment its left most occurrence by 1. So updated array is 1 4 3 2 3. Next we encounter 1, so we increment the leftmost occurrence of 1 by 1. New updated array is 2 4 3 2 3 1. Next we encounter 4, so we do the same and increase its first occurrence by 1. New updated array is. 2 5 3 2 3 1 4. Next we encounter 2, so we do the same and increase its first occurrence by 1. New updated array is. 3 5 3 2 3 1 4 2. Next we encounter 1, so we do the same and increase its first occurrence by 1. New updated array is 3 5 3 2 3 2 4 2 1. Next we encounter 3, so we do the same and increase its first occurrence by 1. New updated array is 4 5 3 2 3 2 4 2 1 3. , I have written this Solution Code: import java.util.*;
import java.io.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findAns(arr, n);
System.out.println();
}
}
static void findAns(int arr[], int n)
{
HashMap<Integer, PriorityQueue<Integer>> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
int val = arr[i];
if (!map.containsKey(val)) {
PriorityQueue<Integer> q = new PriorityQueue<>();
q.add(i);
map.put(val, q);
}
else {
int la = map.get(val).poll();
map.get(val).add(i);
arr[la]++;
if (map.containsKey(arr[la])) {
map.get(arr[la]).add(la);
}
else {
PriorityQueue<Integer> q = new PriorityQueue<>();
q.add(la);
map.put(arr[la], q);
}
}
}
for (int val : arr)
System.out.print(val + " ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a stream of integers represented by an array <b>arr[]</b> of size <b>N</b>. Whenever you encounter an element arr[i], you need to increment its <b>first occurrence</b>(on the left side)if present in the stream by 1 and append this element in the array. You don't have to do this when you encounter arr[i] for the first time as it is the only occurrence till then. Finally, you need to print the updated array.The input line contains T, denoting the number of testcases. Each testcase contains two lines. First line contains N, size of array. Second line contains elements of array separated by space.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^4
1 <= arr[i] <= 10^5
For each testcase you need to print the updated array in a new line.Input:
1
10
1 2 3 2 3 1 4 2 1 3
Output:
4 5 3 2 3 2 4 2 1 3
Explanation:
Testcase 1: We encounter 1, 2, 3. We encounter 2 again so we increment its leftmost occurrence by 1. The updated array becomes 1 3 3 2. We encounter 3 next. So we increment its left most occurrence by 1. So updated array is 1 4 3 2 3. Next we encounter 1, so we increment the leftmost occurrence of 1 by 1. New updated array is 2 4 3 2 3 1. Next we encounter 4, so we do the same and increase its first occurrence by 1. New updated array is. 2 5 3 2 3 1 4. Next we encounter 2, so we do the same and increase its first occurrence by 1. New updated array is. 3 5 3 2 3 1 4 2. Next we encounter 1, so we do the same and increase its first occurrence by 1. New updated array is 3 5 3 2 3 2 4 2 1. Next we encounter 3, so we do the same and increase its first occurrence by 1. New updated array is 4 5 3 2 3 2 4 2 1 3. , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
void solve(){
int n;//size of array
cin>>n;
int arr[n];//intitializing array
unordered_map<int,set<int>> first_occur;
for(int i=0;i<n;i++){
cin>>arr[i];
if(first_occur.find(arr[i])==first_occur.end()){
first_occur[arr[i]].insert(i);//check if element is repeated or not
}
else {
arr[*first_occur[arr[i]].begin()]++;//increasing element which occured first
first_occur[arr[i]+1].insert(*first_occur[arr[i]].begin());//adding index of first occurance to the increased element
first_occur[arr[i]].erase(first_occur[arr[i]].begin());// deleting first occurance index
first_occur[arr[i]].insert(i);// adding the current index to the current element
}
}
// print array
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
cout<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args)throws IOException {
Reader sc = new Reader();
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0;i<N;i++){
arr[i] = sc.nextInt();
}
int max=0;
if(arr[0]<arr[N-1])
System.out.print(N-1);
else{
for(int i=0;i<N-1;i++){
int j = N-1;
while(j>i){
if(arr[i]<arr[j]){
if(max<j-i){
max = j-i;
} break;
}
j--;
}
if(i==j)
break;
if(j==N-1)
break;
}
if(max==0)
System.out.print("-1");
else
System.out.print(max);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
/* For a given array arr[],
returns the maximum j β i such that
arr[j] > arr[i] */
int maxIndexDiff(int arr[], int n)
{
int maxDiff;
int i, j;
int *LMin = new int[(sizeof(int) * n)];
int *RMax = new int[(sizeof(int) * n)];
/* Construct LMin[] such that
LMin[i] stores the minimum value
from (arr[0], arr[1], ... arr[i]) */
LMin[0] = arr[0];
for (i = 1; i < n; ++i)
LMin[i] = min(arr[i], LMin[i - 1]);
/* Construct RMax[] such that
RMax[j] stores the maximum value from
(arr[j], arr[j+1], ..arr[n-1]) */
RMax[n - 1] = arr[n - 1];
for (j = n - 2; j >= 0; --j)
RMax[j] = max(arr[j], RMax[j + 1]);
/* Traverse both arrays from left to right
to find optimum j - i. This process is similar to
merge() of MergeSort */
i = 0, j = 0, maxDiff = -1;
while (j < n && i < n)
{
if (LMin[i] < RMax[j])
{
maxDiff = max(maxDiff, j - i);
j = j + 1;
}
else
i = i + 1;
}
return maxDiff;
}
// Driver Code
signed main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int maxDiff = maxIndexDiff(a, n);
cout << maxDiff;
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 integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
rightMax = [0] * n
rightMax[n - 1] = arr[n - 1]
for i in range(n - 2, -1, -1):
rightMax[i] = max(rightMax[i + 1], arr[i])
maxDist = -2**31
i = 0
j = 0
while (i < n and j < n):
if (rightMax[j] >= arr[i]):
maxDist = max(maxDist, j - i)
j += 1
else:
i += 1
if maxDist==0:
maxDist=-1
print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given 2 parameters: a low and high number. Your goal is to print all numbers between low and high,
and for each of these numbers print whether or not the number is divisible by 3. If the number is divisible by 3,
print the word "div3" directly after the number.2 numbers, one will be low and other high.
0<=low<=high<=10000If the number is divisible by 3, print the word "div3" directly after the number.Sample input:-
1 6
Sample output:-
1 2 3 div3 4 5 6 div3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int low = sc.nextInt();
int high = sc.nextInt();
for(int i = low; i <= high; i++){
if(i%3 == 0){
System.out.print(i);
System.out.print(" ");
System.out.print("div"+3);
System.out.print(" ");
}
else{
System.out.print(i);
System.out.print(" ");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given 2 parameters: a low and high number. Your goal is to print all numbers between low and high,
and for each of these numbers print whether or not the number is divisible by 3. If the number is divisible by 3,
print the word "div3" directly after the number.2 numbers, one will be low and other high.
0<=low<=high<=10000If the number is divisible by 3, print the word "div3" directly after the number.Sample input:-
1 6
Sample output:-
1 2 3 div3 4 5 6 div3, I have written this Solution Code: inp = input("").split(" ")
init = []
for i in range(int(inp[0]),int(inp[1])+1):
if(i%3 == 0):
init.append(str(i)+" div3")
else:
init.append(str(i))
print(" ".join(init)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given 2 parameters: a low and high number. Your goal is to print all numbers between low and high,
and for each of these numbers print whether or not the number is divisible by 3. If the number is divisible by 3,
print the word "div3" directly after the number.2 numbers, one will be low and other high.
0<=low<=high<=10000If the number is divisible by 3, print the word "div3" directly after the number.Sample input:-
1 6
Sample output:-
1 2 3 div3 4 5 6 div3, I have written this Solution Code: function test_divisors(low, high) {
// we'll store all numbers and strings within an array
// instead of printing directly to the console
const output = [];
for (let i = low; i <= high; i++) {
// simply store the current number in the output array
output.push(i);
// check if the current number is evenly divisible by 3
if (i % 3 === 0) { output.push('div3'); }
}
// return all numbers and strings
console.log(output.join(" "));
}
, 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: #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: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s.
Constraints:-
1 <= N <= 10^6
0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input
7
1 0 0 1 0 1 1
Sample Output
8
The index range for the 8 sub-arrays are:
(0, 1), (2, 3), (0, 3), (3, 4), (4, 5)
(2, 5), (0, 5), (1, 6), I have written this Solution Code: size = int(input())
givenList = list(map(int,input().split()))
hs = {}
sm = 0
ct = 0
for i in givenList:
if i == 0:
i = -1
sm = sm + i
if sm == 0:
ct += 1
if sm not in hs.keys():
hs[sm] = 1
else:
freq = hs[sm]
ct = ct +freq
hs[sm] = freq + 1
print(ct), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s.
Constraints:-
1 <= N <= 10^6
0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input
7
1 0 0 1 0 1 1
Sample Output
8
The index range for the 8 sub-arrays are:
(0, 1), (2, 3), (0, 3), (3, 4), (4, 5)
(2, 5), (0, 5), (1, 6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 1000001
int a[max1];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==0){a[i]=-1;}
}
long sum=0;
unordered_map<long,int> m;
long cnt=0;
for(int i=0;i<n;i++){
sum+=a[i];
if(sum==0){cnt++;}
cnt+=m[sum];
m[sum]++;
}
cout<<cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s.
Constraints:-
1 <= N <= 10^6
0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input
7
1 0 0 1 0 1 1
Sample Output
8
The index range for the 8 sub-arrays are:
(0, 1), (2, 3), (0, 3), (3, 4), (4, 5)
(2, 5), (0, 5), (1, 6), I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int arrSize = sc.nextInt();
long arr[] = new long[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
System.out.println(countSubarrays(arr, arrSize));
}
static long countSubarrays(long arr[], int arrSize)
{
for(int i = 0; i < arrSize; i++)
{
if(arr[i] == 0)
arr[i] = -1;
}
long ans = 0;
long sum = 0;
HashMap<Long, Integer> hash = new HashMap<>();
for(int i = 0; i < arrSize; i++)
{
sum += arr[i];
if(sum == 0)
ans++;
if(hash.containsKey(sum) == true)
{
ans += hash.get(sum);
int freq = hash.get(sum);
hash.put(sum, freq+1);
}
else hash.put(sum, 1);
}
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , I have written this Solution Code: from math import sqrt
a=int(input())
c=0
i=2
while(i*i < a):
if(a%i==0):
c=c+1
i=i+1
for i in range(int(sqrt(a)), 0, -1):
if (a % i == 0):
c=c+1
print(c+1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
long N = Long.parseLong(br.readLine());
long count = 0;
for(long i = 1; i*i <= N; i++){
if(N % i == 0){
if(i*i < N){
count += 2;
}else if(i*i == N){
count++;
}
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18.
Note:-You need to check for all the possible values of i.Input contains a single integer N.
Constraints:-
1<=N<=10^10
Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input:
16
Output:
5
Explanation:-
all disticnt numbers are - 1,2,4,8,16
Input:
3248
Output:
20 , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
long long n;
cin>>n;
long long x=sqrt(n);
unordered_map<long long ,int> m;
for(int i=1;i<=x;i++){
if(n%i==0){m[i]++;
if(n/i!=i){m[n/i]++;}}
}
cout<<m.size();
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.