Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: There are <b>N</b> COVID centres on the X- axis. Their positions are <b>X<sub>1</sub>, X<sub>2</sub>,... , X<sub>N</sub></b>. You are standing at the origin O (x = 0) with N sick people. You have to drive each of these to one of the N covid centres such that no two people reach the same centre and each centre receives exactly one patient.
You can use your car to take these people to the hospital but your car can carry only <b>K</b> patients at a time. Find the minimum distance you will have to drive in order to accomplish this task.
<b> Note: After driving all the N people to their respective COVID centres, you do not have to go back to the origin. </b>The first line contains two integers N, the number of centres and people and K, the capacity of your car.
The second line contains N integers X<sub>1</sub>, X<sub>2</sub>,... , X<sub>N</sub>. <b>It is possible that more than one COVID centres lie on the same point. </b>
Constraints:
1 <= K <= N <= 10<sup>5</sup>
-10<sup>9</sup> <= X<sub>i</sub> <= 10<sup>9</sup>Print the minimum distance you will have to drive in order to deliver the N patients to the N covid centres.Sample Input:
5 1
1 2 3 4 5
Sample Output:
25
Sample Input:
5 3
3 3 4 4 4
Sample Output:
10
Explanation Sample1:
You can drive only 1 patient at a time in your car, so here is how you can go:-
0 -> 1 -> 0 -> 2 -> 0 -> 3 -> 0 -> 4 -> 0 -> 5
You drive one by one to the four centres at x = 1, 2, 3, 4. and then you drive the 5<sup>th</sup> patient to the last centre at x = 5 and stop there.
So, the total distance becomes 2 * (1 + 2 + 3 + 4) + 5 = 25
It can be proved that their exists no shorter way of doing so., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static long negativeIndexes(int covidCentres[], int negativeIndex, int n, int k){
long totalDistance = 0;
if(negativeIndex >= 0){
negativeIndex -= (negativeIndex) % k;
while(negativeIndex >= 0){
totalDistance += 2*(Math.abs(covidCentres[negativeIndex]));
negativeIndex -= k;
}
}
return totalDistance;
}
public static long positiveIndexes(int covidCentres[], int positiveIndex, int n, int k){
long totalDistance = 0;
if(positiveIndex <= n-1){
positiveIndex += (n-1 - positiveIndex) % k;
while(positiveIndex <= n-1){
totalDistance += 2*covidCentres[positiveIndex];
positiveIndex += k;
}
}
return totalDistance;
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line[] = br.readLine().strip().split(" ");
int n = Integer.parseInt(line[0]);
int k = Integer.parseInt(line[1]);
long totalDistance = 0;
int covidCentres[] = new int[n];
line = br.readLine().strip().split(" ");
for(int i=0; i<n; i++){
covidCentres[i] = Integer.parseInt(line[i]);
}
Arrays.sort(covidCentres);
int positiveIndex = 0;
int negativeIndex;
for(int i=0; i<n; i++){
if(covidCentres[i] < 0){
positiveIndex++;
}else{
break;
}
}
negativeIndex = positiveIndex - 1;
if(Math.abs(covidCentres[0]) < Math.abs(covidCentres[n-1])){
totalDistance += negativeIndexes(covidCentres, negativeIndex, n, k);
totalDistance += positiveIndexes(covidCentres, positiveIndex, n, k);
totalDistance -= Math.abs(covidCentres[n-1]);
}else{
totalDistance += positiveIndexes(covidCentres, positiveIndex, n, k);
totalDistance += negativeIndexes(covidCentres, negativeIndex, n, k);
totalDistance -= Math.abs(covidCentres[0]);
}
System.out.println(totalDistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are <b>N</b> COVID centres on the X- axis. Their positions are <b>X<sub>1</sub>, X<sub>2</sub>,... , X<sub>N</sub></b>. You are standing at the origin O (x = 0) with N sick people. You have to drive each of these to one of the N covid centres such that no two people reach the same centre and each centre receives exactly one patient.
You can use your car to take these people to the hospital but your car can carry only <b>K</b> patients at a time. Find the minimum distance you will have to drive in order to accomplish this task.
<b> Note: After driving all the N people to their respective COVID centres, you do not have to go back to the origin. </b>The first line contains two integers N, the number of centres and people and K, the capacity of your car.
The second line contains N integers X<sub>1</sub>, X<sub>2</sub>,... , X<sub>N</sub>. <b>It is possible that more than one COVID centres lie on the same point. </b>
Constraints:
1 <= K <= N <= 10<sup>5</sup>
-10<sup>9</sup> <= X<sub>i</sub> <= 10<sup>9</sup>Print the minimum distance you will have to drive in order to deliver the N patients to the N covid centres.Sample Input:
5 1
1 2 3 4 5
Sample Output:
25
Sample Input:
5 3
3 3 4 4 4
Sample Output:
10
Explanation Sample1:
You can drive only 1 patient at a time in your car, so here is how you can go:-
0 -> 1 -> 0 -> 2 -> 0 -> 3 -> 0 -> 4 -> 0 -> 5
You drive one by one to the four centres at x = 1, 2, 3, 4. and then you drive the 5<sup>th</sup> patient to the last centre at x = 5 and stop there.
So, the total distance becomes 2 * (1 + 2 + 3 + 4) + 5 = 25
It can be proved that their exists no shorter way of doing so., 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 long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve() {
int n, k;
cin >> n >> k;
vector <int> x(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
sort(all(x));
int maxim = max(abs(x[0]), abs(x[n - 1]));
int h = 0;
ll ans = 0;
for(int i = 0; i < n; i++) {
if(x[i] > 0){
break;
}
if(h == 0){
h = k - 1;
ans += 2 * abs(x[i]);
}
else {
h--;
}
}
h = 0;
for(int i = n - 1; i >= 0; i--){
if(x[i] < 0){
break;
}
if(h == 0){
h = k - 1;
ans += 2 * x[i];
}
else{
h--;
}
}
cout << ans - maxim;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary matrix of size N x M. The task is to find the distance of nearest 1 in the matrix for each cell. The distance is calculated as |i1 β i2| + |j1 β j2|, where i1, j1 are the row number and column number of the current cell and i2, j2 are the row number and column number of the nearest cell having value 1.The first line contains two integers N and M, denoting the number of rows and columns of the matrix. Next N lines contain M integers either 0 or 1.
1 <= T <= 20
1 <= N, M <= 500
Each element of matrix is either 0 or 1
It is guaranteed that there is at least one 1 present in the input.Print N lines. Each line containing M integers denoting the distance from nearest 1.Sample Input:
3 3
1 0 0
0 1 0
0 0 0
Sample Output:
0 1 2
1 0 1
2 1 2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Pair {
int i;
int j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
}
class Main {
static boolean isValid(Pair p, int n, int m) {
int i = p.i;
int j = p.j;
if(i>=0 && i<n && j>=0 && j<m){
return true;
}
return false;
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().trim().split("\\s+");
int N = Integer.parseInt(s[0]);
int M = Integer.parseInt(s[1]);
int arr[][] = new int[N][M];
int res[][] = new int[N][M];
Queue<Pair> q = new LinkedList<>();
for(int i=0; i<N; i++) {
String[] nums = br.readLine().trim().split("\\s+");
for(int j=0; j<M; j++) {
arr[i][j] = Integer.parseInt(nums[j]);
if(arr[i][j] == 1) {
res[i][j] = 0;
q.add(new Pair(i,j));
}
else {
res[i][j] = -1;
}
}
}
while(!q.isEmpty()){
Pair p = q.remove();
Pair[] check = {
new Pair(p.i - 1, p.j - 0),
new Pair(p.i - 0, p.j - 1),
new Pair(p.i + 1, p.j + 0),
new Pair(p.i + 0, p.j + 1)
};
for(int i=0; i<4; i++) {
Pair c = check[i];
if(isValid(c, N, M) && res[c.i][c.j] == -1){
res[c.i][c.j] = res[p.i][p.j] + 1;
q.add(c);
}
}
}
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
System.out.print(res[i][j] + " ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary matrix of size N x M. The task is to find the distance of nearest 1 in the matrix for each cell. The distance is calculated as |i1 β i2| + |j1 β j2|, where i1, j1 are the row number and column number of the current cell and i2, j2 are the row number and column number of the nearest cell having value 1.The first line contains two integers N and M, denoting the number of rows and columns of the matrix. Next N lines contain M integers either 0 or 1.
1 <= T <= 20
1 <= N, M <= 500
Each element of matrix is either 0 or 1
It is guaranteed that there is at least one 1 present in the input.Print N lines. Each line containing M integers denoting the distance from nearest 1.Sample Input:
3 3
1 0 0
0 1 0
0 0 0
Sample Output:
0 1 2
1 0 1
2 1 2, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
#define ld long double
#define ll long long
#define pb push_back
#define endl '\n'
#define pi pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 500 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N][N], vis[N][N];
void solve(){
int n, m;
cin >> n >> m;
queue<pi> q;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
if(a[i][j])
q.push({i, j}), vis[i][j] = 1;
}
}
int f[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
while(!q.empty()){
pi x = q.front();
q.pop();
for(int i = 0; i < 4; i++){
int nx = x.fi + f[i][0];
int ny = x.se + f[i][1];
if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && vis[nx][ny] == 0){
vis[nx][ny] = vis[x.fi][x.se] + 1;
q.push({nx, ny});
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++)
cout << vis[i][j] - 1 << " ";
cout << endl;
}
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
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 string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: s = input("")
print (s[::-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
cout<<s;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a string your task is to reverse the given string.The first line of the input contains a string.
Constraints:-
1 <= string length <= 100
String contains only lowercase english lettersThe output should contain reverse of the input string.Sample Input
abc
Sample Output
cba, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = s.length()-1;i>=0;i--){
System.out.print(s.charAt(i));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, 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 a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
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: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
int n = Integer.parseInt(br.readLine());
int sum =0;
while(sum>9 || n>0){
if (n == 0) {
n = sum;
sum = 0;
}
sum += n%10;
n /= 10;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n>9){
int p = n;
int sum=0;
while(p>0){
sum+=p%10;
p/=10;
}
n=sum;
}
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, your task is to convert the number into a single digit by repeatedly replacing the number N with its sum of digits until the number becomes a single digit.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the single digit after performing the given operation.Sample Input:-
987
Sample Output:-
6
Explanation:-
987 - > 9 + 8 + 7 => 24 = 2 + 4 => 6
Sample Input:-
91
Sample Output:-
1, I have written this Solution Code: def singleDigit(n):
while(n>9):
p = n
sumDigit = 0
while(p>0):
sumDigit += p%10
p//=10
n = sumDigit
return sumDigit
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., 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>
#define rep(i,n) for (int i=0; i<(n); i++)
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
int ans=0;
int v=0;
for(int i=1;i<n;++i){
if(a[i]>a[i-1])
v=0;
else
++v;
ans=max(ans,v);
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., 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 num = Integer.parseInt(br.readLine());
String s= br.readLine();
int[] arr= new int[num];
String[] s1 = s.split(" ");
int ccount = 0, pcount = 0;
for(int i=0;i<(num);i++)
{
arr[i]=Integer.parseInt(s1[i]);
if(i+1 < num){
arr[i+1] = Integer.parseInt(s1[i+1]);}
if(((i+1)< num) && (arr[i]>=arr[i+1]) ){
ccount++;
}else{
if(ccount > pcount){
pcount = ccount;
}
ccount = 0;
}
}
System.out.print(pcount);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of heights of N buildings in a row. You can start from any building and jump to the <b>adjacent</b> right building till the height of the building to the right is less than or equal to the height of your current building. Find the maximum number of jumps you can make.The first line of input contains a single integer N.
The second line of input contains N integers, denoting the array height.
<b>Constraints:</b>
1 <= N <= 10<sup>5</sup>
1 <= height[i] <= 10<sup>9</sup>Print the maximum number of jumps you can make.Sample Input:-
5
5 4 1 2 1
Sample Output:-
2
<b>Explanation:</b>
We start from building with height 5 then jump right to building with height 4 then again to building with height 1 making a total of 2 jumps., I have written this Solution Code: N = int(input())
arr = iter(map(int,input().strip().split()))
jumps = []
jump = 0
temp = next(arr)
for i in arr:
if i<=temp:
jump += 1
temp = i
continue
temp = i
jumps.append(jump)
jump = 0
jumps.append(jump)
print(max(jumps)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is circular or not.
<b>Note: Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>check()</b> that takes the head node as a parameter.
<b>Note: 0 and 1 in sample input just show given LL is CLL or not. 1 denotes it is CLL, 0 denotes not</b>
Constraints:
1 <=N <= 1000
1 <= Node.data<= 1000
Return 1 if the given linked list is circular else return 0.Sample Input 1:-
3 0
1 2 3
Sample Output 1:-
0
Explanation:-
1->2->3
Sample Input 2:-
3 1
1 2 3
Sample Output 2:-
1
Explanation:-
1->2->3->1.......
, I have written this Solution Code: public static int check(Node head) {
if (head == null)
return 1;
Node node = head.next;
while (node != null && node != head)
node = node.next;
if(node==head){return 1;}
else {return 0;}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and F(N) find value of F(1), if, F(i)=(F(i-1) + F(i-1))%1000000007 and 0 <= F(1) < 1000000007.First and the only line of input contains two integers N and F(N).
Constraints:
1 <= N <= 1000000000
0 <= F(N) < 1000000007Print a single integer, F(1).Sample Input 1
2 6
Sample Output 1
3
Exlpanation: F(1) = 3, F(2)=(3+3)%1000000007 = 6.
Sample Input 2
3 6
Sample Input 2
500000005
Explanation:
F(1) = 500000005
F(2) = (500000005+500000005)%1000000007 = 3
F(3)= (3+3)%1000000007 = 6, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws NumberFormatException, IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int fn=Integer.parseInt(st.nextToken());
long ans=fn;
int P=1000000007;
long inv2n=(long)pow(pow(2,n-1,P)%P,P-2,P);
ans=((ans%P)*(inv2n%P))%P;
System.out.println((ans)%P);
}
static long pow(long x, long y,long P)
{
long res = 1l;
while (y > 0)
{
if ((y & 1) == 1)
res = (res * x)%P;
y = y >> 1;
x = (x * x)%P;
}
return res;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and F(N) find value of F(1), if, F(i)=(F(i-1) + F(i-1))%1000000007 and 0 <= F(1) < 1000000007.First and the only line of input contains two integers N and F(N).
Constraints:
1 <= N <= 1000000000
0 <= F(N) < 1000000007Print a single integer, F(1).Sample Input 1
2 6
Sample Output 1
3
Exlpanation: F(1) = 3, F(2)=(3+3)%1000000007 = 6.
Sample Input 2
3 6
Sample Input 2
500000005
Explanation:
F(1) = 500000005
F(2) = (500000005+500000005)%1000000007 = 3
F(3)= (3+3)%1000000007 = 6, I have written this Solution Code: n,f=map(int,input().strip().split())
mod=10**9+7
m1=pow(2,n-1,mod)
m=pow(m1,mod-2,mod)
print(f*m%mod), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N and F(N) find value of F(1), if, F(i)=(F(i-1) + F(i-1))%1000000007 and 0 <= F(1) < 1000000007.First and the only line of input contains two integers N and F(N).
Constraints:
1 <= N <= 1000000000
0 <= F(N) < 1000000007Print a single integer, F(1).Sample Input 1
2 6
Sample Output 1
3
Exlpanation: F(1) = 3, F(2)=(3+3)%1000000007 = 6.
Sample Input 2
3 6
Sample Input 2
500000005
Explanation:
F(1) = 500000005
F(2) = (500000005+500000005)%1000000007 = 3
F(3)= (3+3)%1000000007 = 6, 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>
/////////////
long long powerm(long long x, unsigned long long y, long long p)
{
long long res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,fn;
cin>>n>>fn;
int mo=1000000007;
cout<<(fn*powerm(powerm(2,n-1,mo),mo-2,mo))%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static boolean checkdigit(int n, int k)
{
while(n!=0)
{
int rem=n%10;
if(rem==k){
return true;
}
n=n/10;
}
return false;
}
public static int findNthNumber(int n)
{
return 0;
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int n=Integer.parseInt(line);
for(int i=n,count=1;count<n;i++)
{
if (checkdigit(i,n) || (i%n==0)){
count++;
}
if (count == n){
System.out.println(i);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: n = int(input())
ans = n*(n-1)
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find its Nth smallest non negative integer that is divisible by N.The first and the only line of input contains an integer N.
Constraints
1 <= N <= 1000Output a single integer, the Nth smallest non negative multiple of N.Sample Input
5
Sample Output
20
Explanation: The 5th smallest integer divisible by 5 is 20. The smaller integers divisible by 5 are 0, 5, 10, and 15.
Sample Input
2
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
cout<<(n*(n-1));
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
// cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, 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 message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
out.println(sumTotient(ni()/ni()));
}
public static int[] enumTotientByLpf(int n, int[] lpf)
{
int[] ret = new int[n+1];
ret[1] = 1;
for(int i = 2;i <= n;i++){
int j = i/lpf[i];
if(lpf[j] != lpf[i]){
ret[i] = ret[j] * (lpf[i]-1);
}else{
ret[i] = ret[j] * lpf[i];
}
}
return ret;
}
public static int[] enumLowestPrimeFactors(int n)
{
int tot = 0;
int[] lpf = new int[n+1];
int u = n+32;
double lu = Math.log(u);
int[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];
for(int i = 2;i <= n;i++)lpf[i] = i;
for(int p = 2;p <= n;p++){
if(lpf[p] == p)primes[tot++] = p;
int tmp;
for(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){
lpf[tmp] = primes[i];
}
}
return lpf;
}
public static long sumTotient(int n)
{
if(n == 0)return 0L;
if(n == 1)return 1L;
int s = (int)Math.sqrt(n);
long[] cacheu = new long[n/s];
long[] cachel = new long[s+1];
int X = (int)Math.pow(n, 0.66);
int[] lpf = enumLowestPrimeFactors(X);
int[] tot = enumTotientByLpf(X, lpf);
long sum = 0;
int p = cacheu.length-1;
for(int i = 1;i <= X;i++){
sum += tot[i];
if(i <= s){
cachel[i] = sum;
}else if(p > 0 && i == n/p){
cacheu[p] = sum;
p--;
}
}
for(int i = p;i >= 1;i--){
int x = n/i;
long all = (long)x*(x+1)/2;
int ls = (int)Math.sqrt(x);
for(int j = 2;x/j > ls;j++){
long lval = i*j < cacheu.length ? cacheu[i*j] : cachel[x/j];
all -= lval;
}
for(int v = ls;v >= 1;v--){
long w = x/v-x/(v+1);
all -= cachel[v]*w;
}
cacheu[(int)i] = all;
}
return cacheu[1];
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Main().run(); }
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Phoebe is a big GCD fan. Being bored, she starts counting number of pairs of integers (A, B) such that following conditions are satisfied:
<li> GCD(A, B) = X (As X is Phoebe's favourite integer)
<li> A <= B <= L
As Phoebe's performance is coming up, she needs your help to find the number of such pairs possible.
Note: GCD refers to the <a href="https://en.wikipedia.org/wiki/Greatest_common_divisor">Greatest common divisor</a>.Input contains two integers L and X.
Constraints:
1 <= L, X <= 1000000000Print a single integer denoting number of pairs possible.Sample Input
5 2
Sample Output
2
Explanation: Pairs satisfying all conditions are: (2, 2), (2, 4)
Sample Input
5 3
Sample Output
1
Explanation: Pairs satisfying all conditions are: (3, 3), I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
ull X[20000001];
ull cmp(ull N){
return N*(N+1)/2;
}
ull solve(ull N){
if(N==1)
return 1;
if(N < 20000001 && X[N] != 0)
return X[N];
ull res = 0;
ull q = floor(sqrt(N));
for(int k=2;k<N/q+1;++k){
res += solve(N/k);
}
for(int m=1;m<q;++m){
res += (N/m - N/(m+1)) * solve(m);
}
res = cmp(N) - res;
if(N < 20000001)
X[N] = res;
return res;
}
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int l,x;
cin>>l>>x;
if(l<x)
cout<<0;
else
cout<<solve(l/x);
#ifdef ANIKET_GOYAL
cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int curzeroes = 0;
StringBuilder sb = new StringBuilder();
int len = s.length();
for(int i = 0;i<len;i++){
if(s.charAt(i) == '1'){
if(curzeroes == 0){
sb.append("1");
}
else{
curzeroes--;
}
}
else{
curzeroes++;
}
}
for(int i = 0;i<curzeroes;i++){
sb.append("0");
}
if(sb.length() == 0 && curzeroes == 0){
bw.write("-1\n");
}
else{
bw.write(sb.toString()+"\n");
}
bw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: arr = input()
c = 0
res = ""
n =len(arr)
for i in range(n):
if arr[i]=='0':
c+=1
else:
if c==0:
res+='1'
else:
c-=1
for i in range(c):
res+='0'
if len(res)==0:
print(-1)
else:
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
string s; cin >> s;
stack<int> st;
for(int i = 0; i < (int)s.length(); i++){
if(!st.empty() && s[st.top()] == '0' && s[i] == '1'){
st.pop();
}
else
st.push(i);
}
string res = "";
while(!st.empty()){
res += s[st.top()];
st.pop();
}
reverse(res.begin(), res.end());
if(res == "") res = "-1";
cout << res;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, 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 M=sc.nextInt();
int N=sc.nextInt();
for(int col=0;col<N;col++){
System.out.print("*");
}
System.out.println();
for(int row=0;row<M-2;row++){
System.out.print("*");
for(int col=0;col<N-2;col++){
System.out.print(" ");
}
System.out.print("*");
System.out.println();
}
for(int col=0;col<N;col++){
System.out.print("*");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: li = list(map(int,input().strip().split()))
m=li[0]
n=li[1]
for i in range(0,n):
if i==n-1:
print("*",end="\n")
else:
print("*",end="")
for i in range(1,m-1):
print("*",end="")
for j in range(0,n-2):
print(" ",end="")
print("*",end="\n")
for i in range(0,n):
print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++){
cout<<'*';
}
cout<<endl;
m-=2;
while(m--){
cout<<'*';
for(int i=0;i<n-2;i++){
cout<<' ';
}
cout<<'*'<<endl;
}
for(int i=0;i<n;i++){
cout<<'*';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr of 4 digits, find the latest 24- hour time that can be made using each digit exactly once.
24- hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24- hour time is 00:00, and the latest is 23:59.
Return the latest 24- hour time in "HH:MM" format. If no valid time can be made, return an empty string.<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>largestTimeFromDigits()</b> that takes Integer Array "arr" as parameter.
<b>Constraints:</b>
arr.length == 4
0 ≤ arr[i] ≤ 9Return the latest 24-hour time in "HH:MM" format. If no valid time can be made, return an empty string.
Sample 1:
Input:
1 2 3 4
Output:
"23:41"
Explanation: The valid 24-hour times are "12:34", "12:43", "13:24", "13:42", "14:23", "14:32", "21:34", "21:43", "23:14", and "23:41". Of these times, "23:41" is the latest.
Sample 2:
Input:
5 5 5 5
Output:
""
Explanation: There are no valid 24-hour times as "55:55" is not valid., I have written this Solution Code:
class Solution {
public String largestTimeFromDigits(int[] A) {
String ans = "";
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
for (int k = 0; k < 4; ++k) {
if (i == j || i == k || j == k) continue; // avoid duplicate among i, j & k.
String h = "" + A[i] + A[j], m = "" + A[k] + A[6 - i - j - k], t = h + ":" + m; // hour, minutes, & time.
if (h.compareTo("24") < 0 && m.compareTo("60") < 0 && ans.compareTo(t) < 0) ans = t; // hour < 24; minute < 60; update result.
}
}
}
return ans;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: class Solution {
public static void printTriangle(){
System.out.println("*");
System.out.println("* *");
System.out.println("* * *");
System.out.println("* * * *");
System.out.println("* * * * *");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: j=1
for i in range(0,5):
for k in range(0,j):
print("*",end=" ")
if(j<=4):
print()
j=j+1, In this Programming Language: Python, 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: 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 an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: function simpleArrangement(n, arr) {
// write code here
// do not console.log
// return the output as an array
const newArr = []
// for (let i = 0; i < n; i++) {
// arr[i] += (arr[arr[i]] % n) * n;
// }
// Second Step: Divide all values by n
for (let i = 0; i < n; i++) {
newArr.push(arr[arr[i]])
}
return newArr
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: n = int(input())
a = input().split()
print(" ".join(a[int(x)] for x in a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
String[] str = s.split(" ");
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
for(int i =0;i<n;i++){
System.out.print(arr[arr[i]]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such that A[i] becomes A[A[i]].
Make sure you don't use extra memory than the array itself.The first line of the input contains a number n, the number of integers in the array.
The second line of the input contains n numbers, the elements of A.
<b>Constraints:</b>
1 <= n <= 100000
0 <= A[i] <= n-1Output the required array of n integers.Sample Input 1:
5
4 2 3 0 1
Sample Output 1:
1 3 0 4 2
Sample Input 2:
10
9 5 1 4 7 8 0 6 3 2
Sample Output 2:
2 8 5 7 6 3 9 0 4 1
<b>Explanation 1:</b>
A[0] will be A[A[0]]=A[4]=1
A[1] will be A[A[1]]=A[2]=3
A[2] will be A[A[2]]=A[3]=0
A[3] will be A[A[3]]=A[0]=4
A[4] will be A[A[4]]=A[1]=2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<a[a[i]]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n, m;
cin >> n >> m;
cout << __gcd(n, m);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: def hcf(a, b):
if(b == 0):
return a
else:
return hcf(b, a % b)
li= list(map(int,input().strip().split()))
print(hcf(li[0], li[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given 2 non-negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n. Both m and n fit in a 32 bit signed integer.
NOTE: DO NOT USE LIBRARY FUNCTIONSInput contains two space separated integers, m and n
Constraints:-
1 < = m, n < = 10^18Output the single integer denoting the gcd of the above integers.Sample Input:
6 9
Sample Output:
3
Sample Input:-
5 6
Sample Output:-
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sp = br.readLine().trim().split(" ");
long m = Long.parseLong(sp[0]);
long n = Long.parseLong(sp[1]);
System.out.println(GCDAns(m,n));
}
private static long GCDAns(long m,long n){
if(m==0)return n;
if(n==0)return m;
return GCDAns(n%m,m);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two matrices A and B of size (M x N) and (N x P) respectively, Find matrix C, the product of matrix A and B.
<a href="https://en.wikipedia.org/wiki/Matrix_multiplication">Matrix Multiplication</aThe first line contains three integers M, N, and P as mentioned in the problem statement.
Next M lines contain N integers denoting the elements of matrix A
Next N lines contain P integers denoting the elements of matrix B
<b>Constraints</b>
1 ≤ M, N, P ≤ 100
1 ≤ A[i][j], B[i][j] ≤ 100Print M lines each containing P integers denoting the elements of matrix C respectivelySample input 1:
2 2 2
1 0
0 1
2 3
1 0
Sample output 1:
2 3
1 0
<b>Explanation:</b>
[ [1 , 0] , [0 , 1] ] X [ [2 , 3] , [1 , 0] ] = [ [2 , 3] , [1 , 0] ] , I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String inp1[]=rd.readLine().split(" ");
int m=Integer.parseInt(inp1[0]);
int n=Integer.parseInt(inp1[1]);
int p=Integer.parseInt(inp1[2]);
int m1[][]=new int[m][n];
int m2[][]=new int[n][p];
for(int i=0;i<m;i++)
{
String inp[]=rd.readLine().split(" ");
for(int j=0;j<n;j++)
m1[i][j]=Integer.parseInt(inp[j]);
}
for(int i=0;i<n;i++)
{
String inp[]=rd.readLine().split(" ");
for(int j=0;j<p;j++)
m2[i][j]=Integer.parseInt(inp[j]);
}
int m3[][]=new int[m][p];
for(int i=0;i<m;i++)
{
for(int j=0;j<p;j++)
{
for(int k=0;k<n;k++){
m3[i][j]+=m1[i][k]*m2[k][j];
}
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<p;j++)
System.out.print(m3[i][j]+" ");
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two matrices A and B of size (M x N) and (N x P) respectively, Find matrix C, the product of matrix A and B.
<a href="https://en.wikipedia.org/wiki/Matrix_multiplication">Matrix Multiplication</aThe first line contains three integers M, N, and P as mentioned in the problem statement.
Next M lines contain N integers denoting the elements of matrix A
Next N lines contain P integers denoting the elements of matrix B
<b>Constraints</b>
1 ≤ M, N, P ≤ 100
1 ≤ A[i][j], B[i][j] ≤ 100Print M lines each containing P integers denoting the elements of matrix C respectivelySample input 1:
2 2 2
1 0
0 1
2 3
1 0
Sample output 1:
2 3
1 0
<b>Explanation:</b>
[ [1 , 0] , [0 , 1] ] X [ [2 , 3] , [1 , 0] ] = [ [2 , 3] , [1 , 0] ] , 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 = 1e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N][N], b[N][N], c[N][N];
void solve(){
int m, n, p;
cin >> m >> n >> p;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
cin >> a[i][j];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= p; j++)
cin >> b[i][j];
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
for(int k = 1; k <= p; k++)
c[i][k] += a[i][j]*b[j][k];
}
}
for(int i = 1; i <= m; i++){
for(int j = 1; j <= p; j++)
cout << c[i][j] << " ";
cout << 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: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: def MaximumProduct(N):
ans=N//4
if N %4 !=0:
ans=ans+1
return ans, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, find the number of minimum elements the N has to be broken into such that their product is maximum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>MaximumProduct()</b> that takes integer N as parameter.
Constraints:-
1 <= N <= 10000Return the minimum number of elements the N has to be broken intoSample Input:-
5
Sample output
2
Explanation:-
N has to be broken into 2 and 3 to get the maximum product 6.
Sample Input:-
7
Sample Output:-
2
Explanation:- 4 + 3, I have written this Solution Code: static int MaximumProduct(int N){
int ans=N/4;
if(N%4!=0){ans++;}
return ans;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int curzeroes = 0;
StringBuilder sb = new StringBuilder();
int len = s.length();
for(int i = 0;i<len;i++){
if(s.charAt(i) == '1'){
if(curzeroes == 0){
sb.append("1");
}
else{
curzeroes--;
}
}
else{
curzeroes++;
}
}
for(int i = 0;i<curzeroes;i++){
sb.append("0");
}
if(sb.length() == 0 && curzeroes == 0){
bw.write("-1\n");
}
else{
bw.write(sb.toString()+"\n");
}
bw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: arr = input()
c = 0
res = ""
n =len(arr)
for i in range(n):
if arr[i]=='0':
c+=1
else:
if c==0:
res+='1'
else:
c-=1
for i in range(c):
res+='0'
if len(res)==0:
print(-1)
else:
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
string s; cin >> s;
stack<int> st;
for(int i = 0; i < (int)s.length(); i++){
if(!st.empty() && s[st.top()] == '0' && s[i] == '1'){
st.pop();
}
else
st.push(i);
}
string res = "";
while(!st.empty()){
res += s[st.top()];
st.pop();
}
reverse(res.begin(), res.end());
if(res == "") res = "-1";
cout << res;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, 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 1001
#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(){
int n;
cin>>n;
vector<int> v(n);
FOR(i,n){
cin>>v[i];}
int q;
cin>>q;
int x;
while(q--){
cin>>x;
auto it = upper_bound(v.begin(),v.end(),x);
out(it-v.begin());
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array of N integers a[], and Q queries. For each query, you will be given a positive integer K and your task is to print the number of elements in array a[] that are smaller than or equal to K.<b>In case of Java only</b>
<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>smallerElements()</b> that takes the array a[], integer N and integer k as arguments.
<b>Custom Input</b>
The first line of input contains a single integer N.
The second line of input contains N space- separated integers depicting the values of the array.
The third line of input contains a single integer Q, the number of queries.
Each of the next Q lines of input contain a single integer, the value of K.
<b>Constraints:-</b>
1 <= N <= 10<sup>5</sup>
1 <= K, Arr[i] <= 10<sup>12</sup>
1 <= Q <= 10<sup>4</sup>Return the count of elements smaller than or equal to K.Sample Input:-
5
2 5 6 11 15
5
2
4
8
1
16
Sample Output:-
1
1
3
0
5, I have written this Solution Code: static int smallerElements(int a[], int n, int k){
int l=0;
int h=n-1;
int m;
int ans=n;
while(l<=h){
m=l+h;
m/=2;
if(a[m]<=k){
l=m+1;
}
else{
h=m-1;
ans=m;
}
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider a sequence of integers from 1 to N (1, 2, 3,. .. . N). Your task is to divide this sequence into two sets such that the absolute difference of the sum of these sets is minimum i.e if we divide the sequence in set A and B then |Sum(A) - Sum(B)| should be minimum.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the minimum absolute difference possible.Sample Input:-
5
Sample Output:-
1
Explanation:-
Set A:- 1, 2, 5
Set B:- 3. 4
Sample Input:-
8
Sample Output:-
0
Explanation:-
Set A:- 1, 2, 3, 5, 7
Set B;- 4, 6, 8, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine().trim();
long n=Integer.parseInt(str);
long sum=(n*(n+1)/2)/2;
int sum1=0,sum2=0;
for(long i=n;i>=1;i--){
if(sum-i>=0)
{
sum-=i;
sum1+=i;
}
else{
sum2+=i;
}
}
System.out.println(Math.abs(sum1-sum2));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider a sequence of integers from 1 to N (1, 2, 3,. .. . N). Your task is to divide this sequence into two sets such that the absolute difference of the sum of these sets is minimum i.e if we divide the sequence in set A and B then |Sum(A) - Sum(B)| should be minimum.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the minimum absolute difference possible.Sample Input:-
5
Sample Output:-
1
Explanation:-
Set A:- 1, 2, 5
Set B:- 3. 4
Sample Input:-
8
Sample Output:-
0
Explanation:-
Set A:- 1, 2, 3, 5, 7
Set B;- 4, 6, 8, I have written this Solution Code: n=int(input())
if(n%4==1 or n%4==2):
print(1)
else:
print(0)
'''if sum1%2==0:
print(0)
else:
print(1)''', In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Consider a sequence of integers from 1 to N (1, 2, 3,. .. . N). Your task is to divide this sequence into two sets such that the absolute difference of the sum of these sets is minimum i.e if we divide the sequence in set A and B then |Sum(A) - Sum(B)| should be minimum.The input contains a single integer N.
Constraints:-
1 <= N <= 100000Print the minimum absolute difference possible.Sample Input:-
5
Sample Output:-
1
Explanation:-
Set A:- 1, 2, 5
Set B:- 3. 4
Sample Input:-
8
Sample Output:-
0
Explanation:-
Set A:- 1, 2, 3, 5, 7
Set B;- 4, 6, 8, I have written this Solution Code: #include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if(n%4==1 || n%4==2){cout<<1;}
else {
cout<<0;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.System.out;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader reader = new FastReader();
int n = reader.nextInt();
String S = reader.next();
int ncount = 0;
int tcount = 0;
for (char c : S.toCharArray()) {
if (c == 'N') ncount++;
else tcount++;
}
if (ncount > tcount) {
out.print("Nutan\n");
} else {
out.print("Tusla\n");
}
out.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input())
s = input()
a1 = s.count('N')
a2 = s.count('T')
if(a1 > a2):
print("Nutan")
else:
print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner.
You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan.
Note: You have to print everything without quotes.The first line of the input contains a single integer L β the number of rounds (1 ≤ L ≤ 100 and L is odd).
The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input:
3
NNT
Sample Output:
Nutan
Explanation:
Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium
//Time and Date: 02:18:28 24 March 2022
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//-----------------------------------------------------------------------------------------------------------//
READV(N);
string S;
cin>>S;
ll n=0,t=0;
FORI(i,0,N)
{
if(S[i]=='N')
{
n++;
}
else if(S[i]=='T')
{
t++;
}
}
if(n>t)
{
cout<<"Nutan"<<endl;
}
else
{
cout<<"Tusla"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 β€ T β€ 100
1 β€ length of S β€ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0) {
t--;
char [] arr = br.readLine().toCharArray();
int [] hash = new int[256];
int i = 0,j=0,max=0;
while(j != arr.length) {
hash[arr[j]]++;
while (hash[arr[j]] > 1) {
hash[arr[i]]--;
i++;
}
max = Math.max(max, j-i+1);
j++;
}
System.out.println(max);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 β€ T β€ 100
1 β€ length of S β€ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code:
def longestUniqueSubsttr(string):
last_idx = {}
max_len = 0
start_idx = 0
for i in range(0, len(string)):
if string[i] in last_idx:
start_idx = max(start_idx, last_idx[string[i]] + 1)
max_len = max(max_len, i-start_idx + 1)
last_idx[string[i]] = i
return max_len
t=int(input())
while t > 0:
s=input()
print(longestUniqueSubsttr(s))
t -= 1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 β€ T β€ 100
1 β€ length of S β€ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code:
// str is input string
function longestDistinctSubstr(s) {
const mostRecent = new Map(); // Stores the most recent idx
let startIdx = 0, res = 0;
for (let i = 0; i < s.length; i++) {
if (mostRecent.has(s[i]) && mostRecent.get(s[i]) >= startIdx) {
res = Math.max(res, i - startIdx);
startIdx = mostRecent.get(s[i]) + 1;
}
mostRecent.set(s[i], i);
}
return Math.max(res, s.length - startIdx);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S, you have to find the length of the longest substring of S such that all characters are unique in the substring i.e no character is repeating within that substring.
For example, for input string S = "abcama", the output is 3 as "abc" is the longest substring with distinct characters.The first line of input contains an integer T denoting the number of test cases.
The first and the only line of each test case contains the string S.
Constraints:
1 β€ T β€ 100
1 β€ length of S β€ 1000Print length of longest substring having such that all characters are unique .
Sample Input:
2
abababcdefababcdab
gccksfvrgccks
Sample Output:
6
7, I have written this Solution Code: // C++ program to find the length of the longest substring
// without repeating characters
#include <bits/stdc++.h>
using namespace std;
int longestUniqueSubsttr(string str)
{
int n = str.size();
int res = 0; // result
// last index of all characters is initialized
// as -1
vector<int> lastIndex(256, -1);
// Initialize start of current window
int i = 0;
// Move end of current window
for (int j = 0; j < n; j++) {
// Find the last index of str[j]
// Update i (starting index of current window)
// as maximum of current value of i and last
// index plus 1
i = max(i, lastIndex[str[j]] + 1);
// Update result if we get a larger window
res = max(res, j - i + 1);
// Update last index of j.
lastIndex[str[j]] = j;
}
return res;
}
// Driver code
int main()
{
int t;
cin>>t;
while(t>0)
{ t--;
string s;
cin>>s;
int len = longestUniqueSubsttr(s);
cout<<len<<endl;
}
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 Singly linked list and an integer K. Your task is to insert the integer K at the head of the given linked list<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>addElement()</b> that takes head node and the element K as a parameter.
Constraints:
1 <=N<= 1000
1 <=K, value<= 1000Return the head of the modified linked listSample Input:-
5 2
1 2 3 4 5
Sample Output:
2 1 2 3 4 5
, I have written this Solution Code: public static Node addElement(Node head,int k) {
Node temp =new Node(k);
temp.next=head;
return temp;
}, 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:
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: 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: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: public static void For_Loop(int n){
for(int i=1;i<=n;i++){
if(i%2==1){System.out.print("odd ");}
else{
System.out.print("even ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: n = int(input())
for i in range(1, n+1):
if(i%2)==0:
print("even ",end="")
else:
print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 β€ A, B β€ 4Print a single word β the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
String[] arr=s.split(" ");
int a=Integer.parseInt(arr[0]);
int b=Integer.parseInt(arr[1]);
long ab=(long)Math.pow(a,b);
long ba=(long)Math.pow(b,a);
if(ab>ba) System.out.print("First");
else if(ab<ba) System.out.print("Second");
else System.out.print("Equal");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 β€ A, B β€ 4Print a single word β the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , I have written this Solution Code: a,b=map(int,input().split())
if a**b > b**a:
print("First")
elif a**b <b**a:
print("Second")
else :
print("Equal"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two positive integers A and B.
Print "First", if A<sup>B</sup> > B<sup>A</sup>.
Print "Second", if A<sup>B</sup> < B<sup>A</sup>.
Otherwise, print "Equal".The only line contains two space-separated integers A and B.
<b>Constraints:</b>
1 β€ A, B β€ 4Print a single word β the answer to the problem.Sample Input 1:
1 3
Sample Output 1:
Second
Sample Explanation 1:
As 1<sup>3</sup> < 3<sup>1</sup>, we print "Second".
Sample Input 2:
2 2
Sample Output 2:
Equal
Sample Explanation 2:
As 2<sup>2</sup> = 2<sup>2</sup>, we print "Equal". , I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int a,b;
cin>>a>>b;
int ans1=1;
for(int i=0;i<b;i++)
ans1*=a;
int ans2=1;
for(int i=0;i<a;i++)
ans2*=b;
if(ans1>ans2)
cout<<"First";
else if(ans1<ans2)
cout<<"Second";
else
cout<<"Equal";
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: n=int(input())
for i in range(1,n+1):
if i%3==0 and i%5==0:
print("NewtonSchool",end=" ")
elif i%3==0:
print("Newton",end=" ")
elif i%5==0:
print("School",end=" ")
else:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :-
For each multiple of 3, print "Newton" instead of the number.
For each multiple of 5, print "School" instead of the number.
For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N.
<b>Constraints</b>
1 < = N < = 1000
Print N space separated number or Newton School according to the condition.Sample Input:-
3
Sample Output:-
1 2 Newton
Sample Input:-
5
Sample Output:-
1 2 Newton 4 School, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static void NewtonSchool(int n){
for(int i=1;i<=n;i++){
if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");}
else if(i%5==0){System.out.print("School ");}
else if(i%3==0){System.out.print("Newton ");}
else{System.out.print(i+" ");}
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
NewtonSchool(x);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
arr=sorted(arr,key=int)
start=0
end=n-1
ans=0
while(start<end):
ans=max(ans,arr[end]+arr[start])
start+=1
end-=1
print (ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.