Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares.
Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix.
<b>Constraints:-</b>
1 ≤ N ≤ 800
1 ≤ Matrix[i][j] ≤ 100000
Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1:
3
1 2 3
4 5 6
7 8 9
Output 1:
25
20
Sample Input 2:
4
1 2 3 4
6 8 9 10
11 12 13 14
15 16 17 18
Sample Output 2:
80
79
<b>Explanation 1</b>
The black square contains 1, 3, 5, 7, 9; sum = 25
The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input())
bSum=0
wSum=0
for i in range(n):
c=(input().split())
for j in range(len(c)):
if(i%2==0):
if(j%2==0):
bSum+=int(c[j])
else:
wSum+=int(c[j])
else:
if(j%2==0):
wSum+=int(c[j])
else:
bSum+=int(c[j])
print(bSum)
print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares.
Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix.
<b>Constraints:-</b>
1 ≤ N ≤ 800
1 ≤ Matrix[i][j] ≤ 100000
Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1:
3
1 2 3
4 5 6
7 8 9
Output 1:
25
20
Sample Input 2:
4
1 2 3 4
6 8 9 10
11 12 13 14
15 16 17 18
Sample Output 2:
80
79
<b>Explanation 1</b>
The black square contains 1, 3, 5, 7, 9; sum = 25
The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int mat[][] = new int[N][N];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
mat[i][j] = sc.nextInt();
}
alternate_Matrix_Sum(mat,N);
}
static void alternate_Matrix_Sum(int mat[][], int N)
{
long sum =0, sum1 = 0;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if((i+j)%2 == 0)
sum += mat[i][j];
else sum1 += mat[i][j];
}
}
System.out.println(sum);
System.out.print(sum1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of numbers. Use appropriate array methods to find all numbers that are greater than 5. Complete the function <code>getNumbersGreaterThan5</code> that accepts an array of integers <code>nums</code> and returns an array of numbers that are greater than 5.An array <code>nums</code> of numbersAn array of the numbers greater than 5 that are present in <code>nums</code>const inputArr = [1,2,3,9,10,7,5,4,3]
const ans = getNumbersGreaterThan5(inputArr)
console.log(ans) // prints [9, 10, 7], I have written this Solution Code: function getNumbersGreaterThan5(nums) {
return nums.filter((num) => num > 5);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N integers arranged in a circular fashion. Your task is to find the maximum contiguous subarray sum containing at least 1 element.The first line of input contains a single integer T which denotes the number of test cases. The first line of each test case contains a single integer N which denotes the total number of elements. The second line of each test case contains N space-separated integers denoting the elements of the array.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^5
-10^6 <= Arr[i] <= 10^6
The Sum of N over all test cases is less than equal to 10^6.For each test case print the maximum sum obtained by adding the consecutive elements.<b>Input:</b>
4
7
8 -8 9 -9 10 -11 12
8
10 -3 -4 7 6 5 -4 -1
8
-1 40 -14 7 6 5 -4 -1
4
-1 -2 -3 -4
<b>Output:</b>
22
23
52
-1
Explanation:
Testcase 1: Starting from the last element of the array, i.e, 12, and moving in a circular fashion, we have max subarray as 12, 8, -8, 9, -9, 10, which gives the maximum sum as 22., I have written this Solution Code: import java.io.*;
import java.util.*;
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 long maxSubarraySumCircular(long[] array) {
long currentSum = 0, maxSum = Long.MIN_VALUE;
for(int i = 0; i < array.length; i++) {
currentSum = Math.max(currentSum + array[i], array[i]);
maxSum = Math.max(maxSum, currentSum);
}
if(maxSum < 0) return maxSum;
currentSum = 0;
long minSum = Long.MAX_VALUE;
for(int i = 0; i < array.length; i++) {
currentSum = Math.min(currentSum + array[i], array[i]);
minSum = Math.min(minSum, currentSum);
}
long totalSum = 0;
for(long element : array) totalSum += element;
return Math.max(maxSum, totalSum - minSum);
}
public static void main (String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
long a[] = new long[n];
long sum = 0l;
for(int i=0;i<n;i++){
a[i] = sc.nextLong();
}
System.out.println(maxSubarraySumCircular(a));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N integers arranged in a circular fashion. Your task is to find the maximum contiguous subarray sum containing at least 1 element.The first line of input contains a single integer T which denotes the number of test cases. The first line of each test case contains a single integer N which denotes the total number of elements. The second line of each test case contains N space-separated integers denoting the elements of the array.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^5
-10^6 <= Arr[i] <= 10^6
The Sum of N over all test cases is less than equal to 10^6.For each test case print the maximum sum obtained by adding the consecutive elements.<b>Input:</b>
4
7
8 -8 9 -9 10 -11 12
8
10 -3 -4 7 6 5 -4 -1
8
-1 40 -14 7 6 5 -4 -1
4
-1 -2 -3 -4
<b>Output:</b>
22
23
52
-1
Explanation:
Testcase 1: Starting from the last element of the array, i.e, 12, and moving in a circular fashion, we have max subarray as 12, 8, -8, 9, -9, 10, which gives the maximum sum as 22., I have written this Solution Code: def kadane(a):
Max = a[0]
temp = Max
for i in range(1,len(a)):
temp += a[i]
if temp < a[i]:
temp = a[i]
Max = max(Max,temp)
return Max
def maxCircularSum(a):
n = len(a)
max_kadane = kadane(a)
neg_a = [-1*x for x in a]
max_neg_kadane = kadane(neg_a)
max_wrap = -(sum(neg_a)-max_neg_kadane)
res = max(max_wrap,max_kadane)
return res if res != 0 else max_kadane
for _ in range(int(input())):
s=int(input())
a=list(map(int,input().split()))
print(maxCircularSum(a)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of N integers arranged in a circular fashion. Your task is to find the maximum contiguous subarray sum containing at least 1 element.The first line of input contains a single integer T which denotes the number of test cases. The first line of each test case contains a single integer N which denotes the total number of elements. The second line of each test case contains N space-separated integers denoting the elements of the array.
<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^5
-10^6 <= Arr[i] <= 10^6
The Sum of N over all test cases is less than equal to 10^6.For each test case print the maximum sum obtained by adding the consecutive elements.<b>Input:</b>
4
7
8 -8 9 -9 10 -11 12
8
10 -3 -4 7 6 5 -4 -1
8
-1 40 -14 7 6 5 -4 -1
4
-1 -2 -3 -4
<b>Output:</b>
22
23
52
-1
Explanation:
Testcase 1: Starting from the last element of the array, i.e, 12, and moving in a circular fashion, we have max subarray as 12, 8, -8, 9, -9, 10, which gives the maximum sum as 22., I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 10001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int INF = 4557430888798830399ll;
signed main()
{
fast();
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> A(n);
FOR(i,n){
cin>>A[i];
}
int maxTillNow = -INF;
int maxEndingHere = -INF;
int start = 0;
while (start < A.size()) {
maxEndingHere = max(maxEndingHere + A[start], (int)A[start]);
maxTillNow = max(maxTillNow, maxEndingHere);
start++;
}
vector<int> prefix(n, 0), suffix(n, 0), maxSuffTill(n, 0);
for (int i = 0; i < n; ++i) {
prefix[i] = A[i];
if (i != 0) prefix[i] += prefix[i - 1];
}
for (int i = n - 1; i >= 0; --i) {
suffix[i] = A[i];
maxSuffTill[i] = max(A[i],(int) 0);
if (i != n - 1) {
suffix[i] += suffix[i + 1];
maxSuffTill[i] = max(suffix[i], maxSuffTill[i + 1]);
}
}
for (int i = 0; i < n; ++i) {
int sum = prefix[i];
if (i != n - 1) sum += maxSuffTill[i + 1];
maxTillNow = max(maxTillNow, sum);
}
out(maxTillNow);
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){
int x=N;
while(D-->0){
x-=x/2;
x*=3;
}
System.out.println(x);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
cout << x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<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>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D):
ans = N
while D > 0:
ans = ans - ans//2
ans = ans*3
D = D-1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String[] nab = rd.readLine().split(" ");
long n = Long.parseLong(nab[0]);
long girl = Long.parseLong(nab[1]);
long boy = Long.parseLong(nab[2]);
long total = 0;
if(n>1 && girl>1 && boy>1){
long temp = n/(girl+boy);
total = (girl*temp);
if(n%(girl+boy)<girl)
total+=n%(girl+boy);
else
total+=girl;
System.out.print(total);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: n,a,b=map(int,input().split())
if n%(a+b)== 0:
print(n//(a+b)*a)
else:
k=n-(n//(a+b))*(a+b)
if k >= a:
print((n//(a+b))*a+a)
else:
print((n//(a+b))*a+k), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ready for a super simple challenge!
You are given two integers A and B. You will create a line of boys and girls in the following manner:
First A girls, then B boys, then A girls, then B boys, and so on.
You will also be given an integer N. Find the number of girls in the first N people of the row.The first and the only line of input contains 3 integers N, A, B.
Constraints
1 < N, A, B <= 10^18 (1000000000000000000)
A+B <= 10^18Output a singer integer, the number of girls in the first N people in the queue.Sample Input
8 3 4
Sample Output
4
Explanation
The arrangement will look like GGGBBBBG, where G represents girl and B represents boy., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// it's swapnil07 ;)
#ifdef SWAPNIL07
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define end_routine()
#endif
signed main()
{
fast
int n, a, b; cin>>n>>a>>b;
int x = a+b;
int y = (n/x);
n -= (y*x);
int ans = y*a;
if(n > a)
ans += a;
else
ans += n;
cout<<ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers. You can do an operation on the array:
In one operation, you can select exactly 4 elements from the array, and add the second smallest element of those 4 to your happiness. For example: if you select W, X, Y, Z where W <= X <= Y <= Z, you get X amount of happiness. Remove the 4 elements from the array.
Find the maximum amount of happiness you can get from the array, if you can perform the operations as many times as the constraints permit.
Note: You cannot choose elements if the remaining array size is less than 4.First line of input contains a single integer N.
Second line of input contains N integers, denoting array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N is always divisible by 4.Output the maximum amount of happiness you can get.Sample Input 1
4
2 1 2 4
Sample Output 1
2
Explanation: We select the values 1 2 2 4 and get second highest happiness which is 2.
Sample Input 2
8
7 3 5 5 2 1 1 7
Sample Output 2
7, 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 n=sc.nextInt();
int arr[]=new int[n];
for(int i=0; i<n; i++){
arr[i]=sc.nextInt();
}
int j=0;
long maxHappiness=0;
Arrays.sort(arr);
int x=n/4;
int i=1;
while(x>0){
maxHappiness+=arr[n-i*3];
i++;
x--;
}
System.out.print(maxHappiness);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N integers. You can do an operation on the array:
In one operation, you can select exactly 4 elements from the array, and add the second smallest element of those 4 to your happiness. For example: if you select W, X, Y, Z where W <= X <= Y <= Z, you get X amount of happiness. Remove the 4 elements from the array.
Find the maximum amount of happiness you can get from the array, if you can perform the operations as many times as the constraints permit.
Note: You cannot choose elements if the remaining array size is less than 4.First line of input contains a single integer N.
Second line of input contains N integers, denoting array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N is always divisible by 4.Output the maximum amount of happiness you can get.Sample Input 1
4
2 1 2 4
Sample Output 1
2
Explanation: We select the values 1 2 2 4 and get second highest happiness which is 2.
Sample Input 2
8
7 3 5 5 2 1 1 7
Sample Output 2
7, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
} sort(a,a+n);
int ans=0;
for(int i=1;i<=n/4;++i){
ans+=a[n-i*3];
}
cout<<ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given an array of several arrays that each contain integers and your goal is to write a function that
will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your
program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:-
[[3, 2], [1], [4, 12]]
Sample output:-
22
Explanation:-
3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) {
// store our final answer
var sum = 0;
// loop through entire array
for (var i = 0; i < arr.length; i++) {
// loop through each inner array
for (var j = 0; j < arr[i].length; j++) {
// add this number to the current final sum
sum += arr[i][j];
}
}
console.log(sum);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two binary trees, your task is to check if their exist a pair of nodes one from each tree such that their sum is equal to a specified target.<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>pairsum()</b> that takes root nodes of both trees and the target value as parameters.
Constraints:
1 < = Nodes < = 10000
1 < = Node.data < = 10000
1 < = target < = 20000Return true if their exist a pair of nodes one from each tree such that their sum is equal to a specified target else return false.Sample Input:-
1 5
/ \ \
2 3 6
target = 8
Sample Output:-
1
Explanation:
take 2 from first tree and 6 from second tree.
sum = 2 + 6 = 8 = target , I have written this Solution Code:
int m[20001];
void solve(struct Node* root){
m[root->data]++;
if(root->left!=NULL){
solve(root->left);
}
if(root->right!=NULL){
solve(root->right);
}
}
bool check(struct Node* root,int target){
if((target-root->data)>0 && m[target-root->data]>0){return true;}
bool ch1=false,ch2=false;
if(root->left!=NULL){
ch1=check(root->left,target);
}
if(root->right!=NULL){
ch2=check(root->right,target);
}
if(ch1 || ch2){return true;}
return false;
}
bool pairsum(struct Node* root1, struct Node* root2, int target){
solve(root1);
return check(root2,target);
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two binary trees, your task is to check if their exist a pair of nodes one from each tree such that their sum is equal to a specified target.<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>pairsum()</b> that takes root nodes of both trees and the target value as parameters.
Constraints:
1 < = Nodes < = 10000
1 < = Node.data < = 10000
1 < = target < = 20000Return true if their exist a pair of nodes one from each tree such that their sum is equal to a specified target else return false.Sample Input:-
1 5
/ \ \
2 3 6
target = 8
Sample Output:-
1
Explanation:
take 2 from first tree and 6 from second tree.
sum = 2 + 6 = 8 = target , I have written this Solution Code:
unordered_map<int,int> m;
void solve(Node* root){
m[root->data]++;
if(root->left!=nullptr){
solve(root->left);
}
if(root->right!=nullptr){
solve(root->right);
}
}
bool check(Node* root,int target){
if(m.find(target-root->data)!=m.end()){return true;}
bool ch1=false,ch2=false;
if(root->left!=nullptr){
ch1=check(root->left,target);
}
if(root->right!=nullptr){
ch2=check(root->right,target);
}
if(ch1 || ch2){return true;}
return false;
}
bool pairsum(Node* root1, Node* root2, int target){
solve(root1);
return check(root2,target);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two binary trees, your task is to check if their exist a pair of nodes one from each tree such that their sum is equal to a specified target.<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>pairsum()</b> that takes root nodes of both trees and the target value as parameters.
Constraints:
1 < = Nodes < = 10000
1 < = Node.data < = 10000
1 < = target < = 20000Return true if their exist a pair of nodes one from each tree such that their sum is equal to a specified target else return false.Sample Input:-
1 5
/ \ \
2 3 6
target = 8
Sample Output:-
1
Explanation:
take 2 from first tree and 6 from second tree.
sum = 2 + 6 = 8 = target , I have written this Solution Code: static int m[] = new int[20001];
static void solve(Node root){
m[root.data]++;
if(root.left!=null){
solve(root.left);
}
if(root.right!=null){
solve(root.right);
}
}
static boolean check(Node root,int target){
if((target-root.data)>=0 && m[target-root.data]>0){return true;}
boolean ch1=false,ch2=false;
if(root.left!=null){
ch1=check(root.left,target);
}
if(root.right!=null){
ch2=check(root.right,target);
}
if(ch1 || ch2){return true;}
return false;
}
static boolean pairsum(Node root1, Node root2, int target){
solve(root1);
return check(root2,target);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Print a right angled triangle of stars of given height N as shown in example.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 10Print the Right angled triangle of height N.Sample Input:-
3
Sample Output:-
*
**
***
Sample Input:-
4
Sample Output:-
*
**
***
****, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
for(int i =1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*") ;
}
System.out.println();
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Print a right angled triangle of stars of given height N as shown in example.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 10Print the Right angled triangle of height N.Sample Input:-
3
Sample Output:-
*
**
***
Sample Input:-
4
Sample Output:-
*
**
***
****, I have written this Solution Code: x=int(input(""))
for i in range(x):
for j in range(i+1):
print("*",end='')
print(""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Print a right angled triangle of stars of given height N as shown in example.The input contains a single integer N.
<b>Constraints:-</b>
1 ≤ N ≤ 10Print the Right angled triangle of height N.Sample Input:-
3
Sample Output:-
*
**
***
Sample Input:-
4
Sample Output:-
*
**
***
****, I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<i+1;j++){
cout<<'*';}
cout<<endl;
}}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), 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 t = Integer.parseInt(br.readLine());
for(int i=0;i<t;i++){
int n = Integer.parseInt(br.readLine());
System.out.println(Ways(n,1));
}
}
static int Ways(int x, int num)
{
int val =(x - num);
if (val == 0)
return 1;
if (val < 0)
return 0;
return Ways(val, num + 1) + Ways(x, num + 1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long cnt=0;
int j;
void sum(int X,int j) {
if(X==0){cnt++;}
if(X<0)
{return;}
else {
for(int i=j;i<=(X);i++){
X=X-i;
sum(X,i+1);
X=X+i;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n<1){cout<<0<<endl;continue;}
sum(n,1);
cout<<cnt<<endl;
cnt=0;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: // ignore number of testcases
// n is the number as provided in input
function numberOfWays(n) {
// write code here
// do not console.log the answer
// return answer as a number
if(n < 1) return 0;
let cnt = 0;
let j;
function sum(X, j) {
if (X == 0) { cnt++; }
if (X < 0) { return; }
else {
for (let i = j; i <= X; i++) {
X = X - i;
sum(X, i + 1);
X = X + i;
}
}
}
sum(n,1);
return cnt
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find number of ways an integer N can be represented as a sum of unique natural numbers.First line contain an integer T denoting number of test cases. Each test case contains a single integer N.
Constraint:-
1 <= T <= 100
0 <= N <= 120Print a single integer containing number of ways.Sample input
4
6
1
4
2
Sample output:-
4
1
2
1
Explanation:-
TestCase1:-
6 can be represented as (1, 2, 3), (1, 5), (2, 4), (6), I have written this Solution Code: for _ in range(int(input())):
x = int(input())
n = 1
dp = [1] + [0] * x
for i in range(1, x + 1):
u = i ** n
for j in range(x, u - 1, -1):
dp[j] += dp[j - u]
if x==0:
print(0)
else:
print(dp[-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], of size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], of size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function bubbleSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], of size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., 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 t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int temp;
for(int i=1;i<n;i++){
if(a[i]<a[i-1]){
for(int j=i;j>0;j--){
if(a[j]<a[j-1]){
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
else{
break;
}
}
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[], of size N containing positive integers. You need to print the elements of an array in increasing order.The first line of the input denotes the number of test cases 'T'. The first line of the test case is the size of the array and the second line consists of array elements.
For Python Users just complete the given function.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ A[i] ≤ 1000For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
<b>Explanation:</b>
Testcase 1: 1 3 4 7 9 are in sorted form.
Testcase 2: For the given input, 1 2 3 4 5 6 7 8 9 10 are in sorted form., I have written this Solution Code: def bubbleSort(arr):
arr.sort()
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements
function replaceArray(arr, n) {
// write code here
// do not console.log
// return the new array
const newArr = []
newArr[0] = arr[0] * arr[1]
newArr[n-1] = arr[n-1] * arr[n-2]
for(let i= 1;i<n-1;i++){
newArr[i] = arr[i-1] * arr[i+1]
}
return newArr
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code: n = int(input())
X = [int(x) for x in input().split()]
lst = []
for i in range(len(X)):
if i == 0:
lst.append(X[i]*X[i+1])
elif i == (len(X) - 1):
lst.append(X[i-1]*X[i])
else:
lst.append(X[i-1]*X[i+1])
for i in lst:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long b[n],a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<n-1;i++){
b[i]=a[i-1]*a[i+1];
}
b[0]=a[0]*a[1];
b[n-1]=a[n-1]*a[n-2];
for(int i=0;i<n;i++){
cout<<b[i]<<" ";}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
System.out.print(a[0]*a[1]+" ");
for(int i=1;i<n-1;i++){
System.out.print(a[i-1]*a[i+1]+" ");
}
System.out.print(a[n-1]*a[n-2]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code:
int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: static int mythOrFact(int N){
int prime =1;
int cnt = N+1;
for(int i=2;i<N;i++){
if(N%i==0){cnt+=i;prime=0;}
}
int p = 3*N;
p/=2;
if((cnt<=p && prime==1) || (cnt>p && prime==0) ){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a saying in Sara's village that "A number is called prime if the sum of all the factors of N is less than or equal to (3*N)/2 ". Given the number N, your task is to check if it is a myth or a fact for the number given.<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>mythOrFact()</b> that takes integer N as argument.
Constraints:-
2 <= N <= 1000Return 1 if it is a fact else return 0.Sample Input:-
2
Sample Output:-
1
Explanation:-
Sum = 2 + 1 = 3
3*(2) / 2 = 3
Sample Input:-
9
Sample Output:-
0, I have written this Solution Code: def mythOrFact(N):
prime=1
cnt=N+1
for i in range (2,N):
if N%i==0:
prime=0
cnt=cnt+i
x = 3*N
x=x//2
if(cnt <= x and prime==1) or (cnt>x and prime==0):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String[] str1 = str.split(" ");
int[] arr = new int[n];
HashMap<Integer,Integer> map = new HashMap<>();
List<Integer> list = new ArrayList<>();
for(int i = 0; i < n; ++i) {
arr[i] = Integer.parseInt(str1[i]);
}
arr = frequencySort(arr);
for(int i : arr) {
System.out.print(i+" ");
}
}
static Map<Integer,Integer>map;
public static int[] frequencySort(int[] nums)
{
map=new HashMap<Integer,Integer>();
for(int i:nums){
if(map.containsKey(i)){
map.put(i,1+map.get(i));
}else{
map.put(i,1);
}
}
Integer[]arr=new Integer[nums.length];
int k=0;
for(int i:nums){
arr[k++]=i;
}
Arrays.sort(arr,new Comp());
k=0;
for(int i:arr){
nums[k++]=i;
}
return nums;
}
}
class Comp implements Comparator<Integer>{
Map<Integer,Integer>map=Main.map;
public int compare(Integer a,Integer b){
if(map.get(a)>map.get(b))return 1;
else if(map.get(b)>map.get(a))return -1;
else{
if(a>b)return -1;
else if(a<b)return 1;
return 0;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: import numpy as np
from collections import defaultdict
d=defaultdict(list)
d_f=defaultdict (int)
n=int(input())
a=np.array([input().strip().split()],int).flatten()
for i in a:
d_f[i]+=1
for i in d_f:
d[d_f[i]].append(i)
d=sorted(d.items())
for i in d:
i[1].sort(reverse=True)
for i in d:
for j in i[1]:
for _ in range(i[0]):
print(j,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.The first line of the input contains n ( length of num )
The second line contains the array num.
<b>Constraints</b>
1 ≤ nums. length ≤ 100
-100 ≤ nums[i] ≤ 100Print the sorted arraySample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation: '
3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3., I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-10 12:51:16
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
bool static comparator(pair<int, int> m, pair<int, int> n) {
if (m.second == n.second)
return m.first > n.first; // m>n can also be written it will return the same
else
return m.second < n.second;
}
vector<int> frequencySort(vector<int>& nums) {
unordered_map<int, int> mp;
for (auto k : nums)
mp[k]++;
vector<pair<int, int>> v1;
for (auto k : mp)
v1.push_back(k);
sort(v1.begin(), v1.end(), comparator);
vector<int> v;
for (auto k : v1) {
while (k.second != 0) {
v.push_back(k.first);
k.second--;
}
}
return v;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> res = frequencySort(a);
for (auto& it : res) {
cout << it << " ";
}
cout << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of size n consisting of unique integers and an integer k. A function f is defined as follows:
f(i) = Minimum j such that subarray a<sub>i</sub>, a<sub>i+1</sub>, ., a<sub>j</sub> have k elements strictly greater than a<sub>i</sub>
and -1 (if no such j exists)
Your task is to calculate f(i) for all 1 ≤ i ≤ n.The first line contains an integer t (1 <= T <= 10<sup>5</sup>) - the number of test cases.
The first line of each test case contains two integers n and k (1 <= n <= 10<sup>5</sup>, 1 <= k <= n).
The second line of each test case contains n integers a<sub>1</sub>, a<sub>2</sub>, …a<sub>n</sub> (−10<sup>9</sup> <= a<sub>i</sub> <= 10<sup>9</sup>).
It is guaranteed that elements in a given array are unique.
It is guaranteed that the sum of n over all test cases does not exceed 2 * 10<sup>5</sup>.For each test case, print a separate line containing space-separated n integers f(1), f(2),. , f(n).Sample Input 1:
1
3 1
2 1 3
Sample Output 1:
2 2 -1
Explanation:
For index 0, the element at index 2 is the first element greater than 2.
For index 1, the element at index 2 is the first element greater than 1.
For index 2, no such index exists.
, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(),k = sc.nextInt();
FenwickTree tree = new FenwickTree(n+1);
int arr[] = sc.readArray(n);
compress(arr);
ArrayList<Pair> q = new ArrayList<Main.Pair>();
for(int i = 1; i<=n; i++)q.add(new Pair(arr[i-1], i));
Collections.sort(q);
int[] res = new int[n];
for(int i = 1; i<=n; i++) {
Pair curr = q.get(i-1);
int l = curr.y,r = n;
int ans = -1;
while(l<=r) {
int mid = (l+r)/2;
int len = (mid-curr.y+1);
len-=tree.find(curr.y,mid);
if(len > k) {
ans = mid-1;
r = mid-1;
}
else {
l = mid+1;
}
}
res[curr.y-1] = ans;
tree.add(curr.y, 1);
}
for(int e : res)out.print(e+" ");
out.println();
}
static class FenwickTree
{
public int[] tree;
public int size;
public FenwickTree(int size)
{
this.size = size;
tree = new int[size+5];
}
public void add(int i, int v)
{
while(i <= size)
{
tree[i] += v;
i += i&-i;
}
}
public int find(int i)
{
int res = 0;
while(i >= 1)
{
res += tree[i];
i -= i&-i;
}
return res;
}
public int find(int l, int r)
{
return find(r)-find(l-1);
}
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 2_000_00;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of size n consisting of unique integers and an integer k. A function f is defined as follows:
f(i) = Minimum j such that subarray a<sub>i</sub>, a<sub>i+1</sub>, ., a<sub>j</sub> have k elements strictly greater than a<sub>i</sub>
and -1 (if no such j exists)
Your task is to calculate f(i) for all 1 ≤ i ≤ n.The first line contains an integer t (1 <= T <= 10<sup>5</sup>) - the number of test cases.
The first line of each test case contains two integers n and k (1 <= n <= 10<sup>5</sup>, 1 <= k <= n).
The second line of each test case contains n integers a<sub>1</sub>, a<sub>2</sub>, …a<sub>n</sub> (−10<sup>9</sup> <= a<sub>i</sub> <= 10<sup>9</sup>).
It is guaranteed that elements in a given array are unique.
It is guaranteed that the sum of n over all test cases does not exceed 2 * 10<sup>5</sup>.For each test case, print a separate line containing space-separated n integers f(1), f(2),. , f(n).Sample Input 1:
1
3 1
2 1 3
Sample Output 1:
2 2 -1
Explanation:
For index 0, the element at index 2 is the first element greater than 2.
For index 1, the element at index 2 is the first element greater than 1.
For index 2, no such index exists.
, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define sz(x) ((ll)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x = min(x,y)
#define maxi(x,y) x = max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);
// DEBUG FUNCTIONS START
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void deb() {cerr << "\n";}
template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);}
// DEBUG FUNCTIONS END
const int N = 2e5 + 5;
void solve(){
int n, k;
cin >> n >> k;
vi a(n);
rep(i,0,n){
cin >> a[i];
}
vi b = a;
sort(all(b));
vi pos(n);
ordered_set<int> s;
rep(i,0,n){
a[i] = lb(all(b), a[i]) - b.begin();
pos[a[i]] = i;
s.insert(i);
}
vi res(n, -1);
rep(i,0,n){
int position = pos[i];
int idx = s.order_of_key(position);
if(sz(s) > idx + k){
res[position] = *s.find_by_order(idx + k);
}
s.erase(position);
}
rep(i,0,n){
cout << res[i] << " ";
}
cout << endl;
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cout << fixed << setprecision(15);
//freopen ("03.txt","r",stdin);
//freopen ("3.txt","w",stdout);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
int powm(int a, int b){
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S.
Constraints:
1 <= |S| <= 1000000
String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input
ababa
Sample Output
10
Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: import java.io.*;
import java.io.IOException;
import java.util.*;
class Main {
public static long mod = (long)Math.pow(10,9)+7 ;
public static double epsilon=0.00000000008854;
public static InputReader sc = new InputReader(System.in);
public static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
String s=sc.nextLine();
int n=s.length();
int hnum[]=new int[26];
int hpast[]=new int[26];
Arrays.fill(hpast,-1);
long hsum[]=new long[26];
long ans=0;
for(int i=0;i<n;i++){
int k=s.charAt(i)-'a';
if(hpast[k]!=-1)
hsum[k]=hsum[k]+(i-hpast[k])*hnum[k];
ans+=hsum[k];
hnum[k]++;
hpast[k]=i;
}
pw.println(ans);
pw.flush();
pw.close();
}
public static Comparator<Long[]> column(int i){
return
new Comparator<Long[]>() {
@Override
public int compare(Long[] o1, Long[] o2) {
return o1[i].compareTo(o2[i]);
}
};
}
public static Comparator<Integer[]> col(int i){
return
new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
return o1[i].compareTo(o2[i]);
}
};
}
public static String reverseString(String s){
StringBuilder input1 = new StringBuilder();
input1.append(s);
input1 = input1.reverse();
return input1.toString();
}
public static int[] scanArray(int n){
int a[]=new int [n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
return a;
}
public static long[] scanLongArray(int n){
long a[]=new long [n];
for(int i=0;i<n;i++)
a[i]=sc.nextLong();
return a;
}
public static String [] scanStrings(int n){
String a[]=new String [n];
for(int i=0;i<n;i++)
a[i]=sc.nextLine();
return a;
}
public static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S.
Constraints:
1 <= |S| <= 1000000
String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input
ababa
Sample Output
10
Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: def findS(s):
visited= [ 0 for i in range(256)];
distance =[0 for i in range (256)];
for i in range(256):
visited[i]=0;
distance[i]=0;
sum=0;
for i in range(len(s)):
sum+=visited[ord(s[i])] * i - distance[ord(s[i])];
visited[ord(s[i])] +=1;
distance[ord(s[i])] +=i;
return sum;
if __name__ == '__main__':
s=input("");
print(findS(s));, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S.
Constraints:
1 <= |S| <= 1000000
String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input
ababa
Sample Output
10
Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: #pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int c[26]={};
int f[26]={};
int ans=0;
int n=s.length();
for(int i=0;i<n;++i){
ans+=f[s[i]-'a']*i-c[s[i]-'a'];
f[s[i]-'a']++;
c[s[i]-'a']+=i;
}
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: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, 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 x = sc.nextInt();
int y = sc.nextInt();
x--;
y++;
System.out.print(x);
System.out.print(" ");
System.out.print(y);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You must be familiar with various types of operators. One of the most commonly used operators in any language are increment and decrement operators. Given two numbers X and Y. Your task is to print the value of X decremented by 1 and value of Y after incremented by 1.The first line of the input contains two integers X and Y.
<b>Constraints:</b>
1 ≤ X, Y ≤ 10000You need to perform the task as mentioned in the question, and finally, print the result separated by a space.Sample Input 1:
4 5
Sample Output 1:
3 6
Sample Input 2:
5 6
Sample Output 2:
4 7, I have written this Solution Code: def incremental_decremental(x, y):
x -= 1
y += 1
print(x, y, end =' ')
def main():
input1 = input().split()
x = int(input1[0])
y = int(input1[1])
#z = int(input1[2])
incremental_decremental(x, y)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void compress(String str, int l){
for (int i = 0; i < l; i++) {
int count = 1;
while (i < l - 1 && str.charAt(i) == str.charAt(i + 1)) {
count++;
i++;
}
System.out.print(str.charAt(i));
System.out.print(count);
}
System.out.println();
}
public static void main (String[] args) throws IOException{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(rd.readLine());
while(test-->0){
String s = rd.readLine();
int len = s.length();
compress(s,len);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, I have written this Solution Code:
def compress(st):
n = len(st)
i = 0
while i < n:
count = 1
while (i < n-1 and st[i] == st[i + 1]):
count += 1
i += 1
i += 1
print(st[i-1] +str(count),end="")
t=int(input())
for i in range(t):
s=input()
compress(s)
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, 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 = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
string s; cin >> s;
int c = 1;
char p = 0;
int n = s.length();
for(int i = 1; i < n; i++){
if(s[i] != s[i-1]){
cout << s[i-1] << c;
c = 1;
}
else
c++;
}
cout << s[n-1] << c << 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: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: int ludo(int N){
return (N==1||N==6);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: def ludo(N):
if N==1 or N==6:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code:
int ludo(int N){
return (N==1||N==6);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: static int ludo(int N){
if(N==1 || N==6){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a sequence P, which is represented by the following recurrence
P(N) = P(N-2) + P(N-3)
P(0) = P(1) = P(2) = 1
Now given a number N your task is to find the Nth number in this sequence.
Note: Since the output could be very long, take mod 1000000007. And try to give the most optimum solution as you can.The input line contains T, denoting the number of testcases. Each testcase contains single line containing an integer N.
Constraints:
1 <= T <= 15
1 <= N <=100For each testcase, print the nth number of the P sequence in a newline.Sample Input:
2
12
10
Sample Output:
21
12
Explanation:
Testcase 1:
As per the recurrence relation given in the question, we are basically adding last second and last third numbers of the sequence in bottom up manner. Let's see this case
P(3) = P(1) + P(0) = 2
P(4) = P(2) + P(1) = 2
P(5) = P(3) + P(2) = 3
P(6) = P(4) + P(3) = 4
P(7) = P(5) + P(4) = 5
P(8) = P(6) + P(5) = 7
P(9) = P(7) + P(6) = 9
P(10) = P(8) + P(7) = 12
P(11) = P(9) + P(8) = 16
P(12) = P(10) + P(9) = 21
, 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());
long[] dp = new long[101];
Arrays.fill(dp,-1);
while(t-- > 0) {
int n = Integer.parseInt(br.readLine());
if(dp[n] != -1) {
System.out.println(dp[n]);
} else {
System.out.println(solve(n,dp));
}
}
}
static long solve(int n,long[] dp) {
int mod = 1000000007;
if(n < 3) return 1;
if(dp[n] != -1) return dp[n];
return dp[n] = (solve(n-3,dp)%mod+solve(n-2,dp)%mod)%mod;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a sequence P, which is represented by the following recurrence
P(N) = P(N-2) + P(N-3)
P(0) = P(1) = P(2) = 1
Now given a number N your task is to find the Nth number in this sequence.
Note: Since the output could be very long, take mod 1000000007. And try to give the most optimum solution as you can.The input line contains T, denoting the number of testcases. Each testcase contains single line containing an integer N.
Constraints:
1 <= T <= 15
1 <= N <=100For each testcase, print the nth number of the P sequence in a newline.Sample Input:
2
12
10
Sample Output:
21
12
Explanation:
Testcase 1:
As per the recurrence relation given in the question, we are basically adding last second and last third numbers of the sequence in bottom up manner. Let's see this case
P(3) = P(1) + P(0) = 2
P(4) = P(2) + P(1) = 2
P(5) = P(3) + P(2) = 3
P(6) = P(4) + P(3) = 4
P(7) = P(5) + P(4) = 5
P(8) = P(6) + P(5) = 7
P(9) = P(7) + P(6) = 9
P(10) = P(8) + P(7) = 12
P(11) = P(9) + P(8) = 16
P(12) = P(10) + P(9) = 21
, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const int N = 3e5+5;
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int li;
typedef unsigned long int uli;
typedef long long int ll;
typedef unsigned long long int ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
using vl = vector<ll>;
bool isPowerOfTwo (int x)
{
/* First x in the below expression is
for the case when x is 0 */
return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
int Tot;
long long a[100010];
map <long long,int> mp;
void dfs(int now,int ee,int les)
{
if (les==0||now+1==ee)
{
Tot++;
return;
}
for (int i=0;i<=les;i++)
dfs(now+1,ee,les-i);
}
void dfs2(int now,long long num,int les)
{
if (now==0) num+=les*a[0];
if (les==0||now==0)
{
mp[num]--;
if (mp[num]==0) mp.erase(num);
return;
}
for (int i=0;i<=les;i++)
dfs2(now-1,num+i*a[now],les-i);
}
ll solve(ll x, ll y){
int a[50],b[50];
FOR(i,50){
a[i]=b[i]=0;}
int i=0;
while(x>0){
a[i]=x%2;
x/=2;
i++;
}
i=0;
while(y>0){
b[i]=y%2;
y=y/2;
i++;
}
int ans=0;
FOR(i,50){
if(a[i]!=b[i]){ans++;}
}
return ans;
}
int main()
{
ll a[101];
a[0]=a[1]=a[2]=1;
for(int i =3;i<=100;i++){
a[i]=a[i-2]+a[i-3];
a[i]=a[i]%MOD;
}
int t;
cin>>t;
while(t--){
int n;
cin>>n;
out(a[n]);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a grid of dimensions N*N. When you blast a bomb at cell (i, j) all the cells of row i and column j get damaged. You have 5 bombs. Find the number of ways you can choose 5 cells to place these bombs in so that the maximum number of cells gets damaged.Input contains a single integer N.
Constraints
5 <= N <= 100Output a single integer which is the number of ways you can choose 5 cells to place the bombs in so that maximum number of cells get damaged.Sample Input 1
5
Sample output 1
120
Sample Input 2
6
Sample Output 2
4320
Explanation:-
For test1:-
for maximum blast:-
their are 5 ways to place bomb 1
their are 4 ways to place bomb 2
their are 3 ways to place bomb 3
their are 2 ways to place bomb 4
their is 1 way to place bomb 5
so total number of ways will be= 5*4*3*2*1 =120, I have written this Solution Code: import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
long n;
long r=5;
n=sc.nextLong();
long p = 1, k = 1;
if (n - r < r) {
r = n - r;
}
if (r != 0) {
while (r > 0) {
p *= n;
k *= r;
long m = gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
}
else
{
p = 1;
}
long ans=p*p*120;
System.out.println(ans);
}
static long gcd(long n1, long n2)
{
long gcd = 1;
for (int i = 1; i <= n1 && i <= n2; ++i)
{
if (n1 % i == 0 && n2 % i == 0)
{
gcd = i;
}
}
return gcd;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a grid of dimensions N*N. When you blast a bomb at cell (i, j) all the cells of row i and column j get damaged. You have 5 bombs. Find the number of ways you can choose 5 cells to place these bombs in so that the maximum number of cells gets damaged.Input contains a single integer N.
Constraints
5 <= N <= 100Output a single integer which is the number of ways you can choose 5 cells to place the bombs in so that maximum number of cells get damaged.Sample Input 1
5
Sample output 1
120
Sample Input 2
6
Sample Output 2
4320
Explanation:-
For test1:-
for maximum blast:-
their are 5 ways to place bomb 1
their are 4 ways to place bomb 2
their are 3 ways to place bomb 3
their are 2 ways to place bomb 4
their is 1 way to place bomb 5
so total number of ways will be= 5*4*3*2*1 =120, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int N;
cin>>N;
int pick = ((N) * (N - 1) * (N - 2) * (N - 3) * (N - 4)) / 120;
cout<<(pick * pick * 120);
#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: For Christmas decoration, Jerry has set up N christmas lights in a row. The brightness of the i<sup>th</sup> light from the left is B[i]. A light at position i is powerful if its brightness is greater than or equal to the sum of brightness of all the lights to its left. Now, Tom wants the number of powerful lights to be maximum so he wants to rearrange the lights so that maximum number of lights are powerful. Find the maximum number of powerful lights, and make Tom and Jerry happy this Christmas.The first line of the input contains a single integer N.
The next line contain N integers denoting array B.
Constraints
1 <= N <= 100000
1 <= B[i] <= 10<sup>15</sup>Print a single integer denoting maximum number of powerful lights after rearrangement.Sample Input 1
5
10 1 3 23 3
Sample Output 1
4
Explanation: we can rearrange the lights as 1 3 10 23 3. In this lights at index 1, 2, 3 and 4 are powerful.
Sample Input 2
5
1 1 1 1 1
Sample Output 2
2, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve(int TC) throws Exception {
int n = ni();
long[] a = new long[n];
for(int i=0;i<n;i++) {
a[i] = nl();
}
long sum = 0, ans = 0;
Arrays.sort(a);
for(long i: a) {
if(i >= sum) {
++ ans;
sum += i;
}
}
pn(ans);
}
boolean TestCases = false;
public static void main(String[] args) throws Exception { new Main().run(); }
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
int T = TestCases ? ni() : 1;
for(int t=1;t<=T;t++) solve(t);
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
void p(Object o) { out.print(o); }
void pn(Object o) { out.println(o); }
void pni(Object o) { out.println(o);out.flush(); }
int ni() {
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
long nl() {
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-') {
minus = true;
b = readByte();
}
while(true) {
if(b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
double nd() { return Double.parseDouble(ns()); }
char nc() { return (char)skip(); }
int BUF_SIZE = 1024 * 8;
byte[] inbuf = new byte[BUF_SIZE];
int lenbuf = 0, ptrbuf = 0;
int readByte() {
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
} return inbuf[ptrbuf++];
}
boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))) {
sb.appendCodePoint(b); b = readByte();
} return sb.toString();
}
char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
} return n == p ? buf : Arrays.copyOf(buf, p);
}
void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For Christmas decoration, Jerry has set up N christmas lights in a row. The brightness of the i<sup>th</sup> light from the left is B[i]. A light at position i is powerful if its brightness is greater than or equal to the sum of brightness of all the lights to its left. Now, Tom wants the number of powerful lights to be maximum so he wants to rearrange the lights so that maximum number of lights are powerful. Find the maximum number of powerful lights, and make Tom and Jerry happy this Christmas.The first line of the input contains a single integer N.
The next line contain N integers denoting array B.
Constraints
1 <= N <= 100000
1 <= B[i] <= 10<sup>15</sup>Print a single integer denoting maximum number of powerful lights after rearrangement.Sample Input 1
5
10 1 3 23 3
Sample Output 1
4
Explanation: we can rearrange the lights as 1 3 10 23 3. In this lights at index 1, 2, 3 and 4 are powerful.
Sample Input 2
5
1 1 1 1 1
Sample Output 2
2, I have written this Solution Code: def lights(x):
sum = 0
count = 0
for i in x:
if i >= sum:
count += 1
sum += i
return count
if __name__ == '__main__':
n = int(input())
x = input().split()
for i in range(len(x)):
x[i] = int(x[i])
x.sort()
print(lights(x)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For Christmas decoration, Jerry has set up N christmas lights in a row. The brightness of the i<sup>th</sup> light from the left is B[i]. A light at position i is powerful if its brightness is greater than or equal to the sum of brightness of all the lights to its left. Now, Tom wants the number of powerful lights to be maximum so he wants to rearrange the lights so that maximum number of lights are powerful. Find the maximum number of powerful lights, and make Tom and Jerry happy this Christmas.The first line of the input contains a single integer N.
The next line contain N integers denoting array B.
Constraints
1 <= N <= 100000
1 <= B[i] <= 10<sup>15</sup>Print a single integer denoting maximum number of powerful lights after rearrangement.Sample Input 1
5
10 1 3 23 3
Sample Output 1
4
Explanation: we can rearrange the lights as 1 3 10 23 3. In this lights at index 1, 2, 3 and 4 are powerful.
Sample Input 2
5
1 1 1 1 1
Sample Output 2
2, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main(){
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ans=0;
int v=0;
for(int i=0;i<n;++i){
if(a[i]>=v){
++ans;
v+=a[i];
}
}
cout<<ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String st = br.readLine();
int len = 0;
int c=0;
for(int i=0;i<st.length();i++){
if(st.charAt(i)=='A'){
c++;
len = Math.max(len,c);
}else{
c=0;
}
}
System.out.println(len);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, I have written this Solution Code: S=input()
max=0
flag=0
for i in range(0,len(S)):
if(S[i]=='A' or S[i]=='B'):
if(S[i]=='A'):
flag+=1
if(flag>max):
max=flag
else:
flag=0
print(max), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S.
Constraints
1 <= |S| <= 100000
S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input
ABAAABBBAA
Sample Output
3
Explanation: Substring from character 3-5 is the longest consisting of As only.
Sample Input
AAAA
Sample Output
4, 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(){
string s; cin>>s;
int ct = 0;
int ans = 0;
for(char c: s){
if(c == 'A')
ct++;
else
ct=0;
ans = max(ans, ct);
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of N integers. A subarray is good if the sum of elements of that subarray is greater than or equal to K. Print the length of good subarray of minimum length.First line of input contains N and K.
Second line of input contains N integers representing the elements of the array Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000
1 <= K <= 1000000000000Print the length of good subarray of minimum length.Sample input
5 12
2 3 2 5 5
Sample output
3
Explanation :
Subarray from index 3 to 5 has sum 12 and is therefore good and its length(3) is minimum among all possible good subarray., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int k;
cin>>k;
int a[n+1];
int to=0;
for(int i=1;i<=n;++i)
{
cin>>a[i];
}
int j=1;
int s=0;
int ans=n;
for(int i=1;i<=n;++i)
{
while(s<k&&j<=n)
{
s+=a[j];
++j;
}
if(s>=k)
{
ans=min(ans,j-i);
}
s-=a[i];
}
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: You are given an array Arr of N integers. A subarray is good if the sum of elements of that subarray is greater than or equal to K. Print the length of good subarray of minimum length.First line of input contains N and K.
Second line of input contains N integers representing the elements of the array Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000
1 <= K <= 1000000000000Print the length of good subarray of minimum length.Sample input
5 12
2 3 2 5 5
Sample output
3
Explanation :
Subarray from index 3 to 5 has sum 12 and is therefore good and its length(3) is minimum among all possible good subarray., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s[]=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
long k=Long.parseLong(s[1]);
int a[]=new int[n];
s=br.readLine().split(" ");
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
int length=Integer.MAX_VALUE,i=0,j=0;
long currSum=0;
for(j=0;j<n;j++)
{
currSum+=a[j];
while(currSum>=k)
{
length=Math.min(length,j-i+1);
currSum-=a[i];
i++;
}
}
System.out.println(length);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array Arr of N integers. A subarray is good if the sum of elements of that subarray is greater than or equal to K. Print the length of good subarray of minimum length.First line of input contains N and K.
Second line of input contains N integers representing the elements of the array Arr.
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 100000
1 <= K <= 1000000000000Print the length of good subarray of minimum length.Sample input
5 12
2 3 2 5 5
Sample output
3
Explanation :
Subarray from index 3 to 5 has sum 12 and is therefore good and its length(3) is minimum among all possible good subarray., I have written this Solution Code: def result(arr,n,k):
minnumber = n + 1
start = 0
end = 0
curr_sum = 0
while(end < n):
while(curr_sum < k and end < n):
curr_sum += arr[end]
end += 1
while( curr_sum >= k and start < n):
if (end - start < minnumber):
minnumber = end - start
curr_sum -= arr[start]
start += 1
return minnumber
n = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(result(arr, n[0], n[1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
bool EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
int main(){
int n1,n2,v1,v2;
cin>>n1>>n2>>v1>>v2;
if(EqualOrNot(n1,n2,v1,v2)){
cout<<"Yes";}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: def EqualOrNot(h1,h2,v1,v2):
if (v2>v1 and (h1-h2)%(v2-v1)==0):
return True
else:
return False
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Gian and Suneo want their heights to be equal so they asked Doraemon's help. Doraemon gave a big light to both of them but the both big lights have different speed of magnifying. Let's assume the big light given to Gian can increase height of a person by v1 m/s and that of Suneo's big light is v2 m/s.
At the end of each second Doraemon check if their heights are equal or not.
Given initial height of Gian and Suneo, your task is to check whether the height of Gian and Suneo will become equal at some point or not, assuming they both started at the same time.First line takes the input of integer h1(height of gian), h2(height of suneo), v1(speed of Gian's big light) and v2(speed of Suneo's big light) as parameter.
<b>Constraints:-</b>
1 <b>≤</b> h2 < h1<b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v1 <b>≤</b> 10<sup>4</sup>
1 <b>≤</b> v2 <b>≤</b> 10<sup>4</sup>complete the function EqualOrNot and return a boolean True if their height will become equal at some point (as seen by Doraemon) else print False
Sample input:-
4 2 2 4
Sample output:-
Yes
Explanation:-
height of Gian goes as- 4 6 8 10. .
height of Suneo goes as:- 2 6 10..
at the end of 1 second their height will become equal.
Sample Input:-
5 4 1 6
Sample Output:
No, I have written this Solution Code: static boolean EqualOrNot(int h1, int h2, int v1,int v2){
if (v2>v1&&(h1-h2)%(v2-v1)==0){
return true;
}
return false;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 1, I have written this Solution Code: n=int(input())
x=n/3
if n%3==2:
x+=1
print(int(x)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int ans = n/3;
if(n%3==2){ans++;}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x=n/3;
if(n%3==2){
x++;}
cout<<x;}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two arrays A and B, both of size N. Let S = { S<sub>1</sub>,S<sub>2</sub>,S<sub>3</sub>,..., S<sub>m</sub> } be any subset of integers from the set { 1, 2, 3,..., N }. We define:
L(S) = lcm(A<sub>S<sub>1</sub></sub>, A<sub>S<sub>2</sub></sub>, ..., A<sub>S<sub>m</sub></sub>)
V(S) = B<sub>S<sub>1</sub></sub> + B<sub>S<sub>2</sub></sub> + ... + B<sub>S<sub>m</sub></sub>
Finally, we define f(k) as the minimum possible value of V(S) over all subsets S such that L(S) = k; if no such S exists then f(k) is defined to be 0.
Return the bitwise-xor of f(k) for all k from 1 to 10<sup>6</sup>.The first line of the input consists of a single integer N (1 ≤ N ≤ 10<sup>6</sup>).
The second line contains N space-separated integers A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub> (1 ≤ A<sub>i</sub> ≤ 10<sup>6</sup>).
The third line contains N space-separated integers B<sub>1</sub>, B<sub>2</sub>, ... B<sub>N</sub> (1 ≤ B<sub>i</sub> ≤ 10<sup>6</sup>).Print a single integer denoting the required answer.Sample Input 1:
2
6 1
2 3
Sample Output 1:
1
Sample Explanation 1:
The value of f(1) = 3, f(6) = 2. For all other k, f(k) =0, so answer = 3⊕2 = 1.
Sample Input 2:
3
2 8 6
92 15 80
Sample Output 2:
92, I have written this Solution Code: #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define aint(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const int inf = 1e9;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 1e6;
vi lpf(N + 1), lpfull(N + 1);
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
read(n);
readarr(a, n);
readarr(b, n);
vi best(N + 1, inf);
FOR (i, 1, n) best[a[i]] = min(best[a[i]], b[i]);
vvi dp(N + 1, vi(0));
FOR (i, 2, N)
{
if (!lpf[i])
for (int j = i; j <= N; j += i) lpf[j] = i;
int x = lpf[i];
if (lpf[i/x] == x) lpfull[i] = lpfull[i/x]*x;
else lpfull[i] = x;
}
int first_zero_bit[1001] = {};
FOR (i, 1, 1000)
{
FOR (j, 0, 30)
if (!((i >> j) & 1)) {first_zero_bit[i] = j; break;}
}
dp[1].pb(inf);
int ans = 0;
if (best[1] < inf) ans = best[1];
FOR (i, 2, N)
{
vi v;
int temp = i;
while (temp > 1)
{
v.pb(lpf[temp]);
temp /= lpfull[temp];
}
temp = 1 << sz(v);
dp[i].assign(temp, inf);
FORD (j, temp - 2, 0)
{
int augment = (1 << first_zero_bit[j]) + j;
int new_i = i/v[first_zero_bit[j]], new_j = j;
if (new_i % v[first_zero_bit[j]])
{
if (first_zero_bit[j]) new_j = j - (j >> first_zero_bit[j])*(1 << (first_zero_bit[j] - 1));
else new_j = j/2;
}
dp[i][j] = min({dp[i][augment], dp[new_i][new_j], best[new_i]});
}
FOR (j, 0, temp/2 - 1)
best[i] = min(best[i], dp[i][j] + dp[i][temp - j - 1]);
if (best[i] < inf) ans ^= best[i];
}
print(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three distinct positive integers, A, B and C, in the input. Your task is to find their median.
The median of a set of integers is the number at the middle position if they are arranged in ascending order.The input consists of a single line containing three integers A, B and C.
<b> Constraints: </b>
1 ≤ A, B, C ≤ 10<sup>9</sup>
A, B, C are pairwise distinct.
Print a single integer, the median of the given numbers.Sample Input 1:
5 1 3
Sample Output 1:
3
Sample Input 2:
1 2 3
Sample Output 2:
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
String a = in.readLine();
String[] nums = a.split(" ");
long[] l = new long[3];
for(int i=0; i<3; i++){
l[i] = Long.parseLong(nums[i]);
}
Arrays.sort(l);
System.out.print(l[1]);
}
catch(Exception e){
System.out.println(e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three distinct positive integers, A, B and C, in the input. Your task is to find their median.
The median of a set of integers is the number at the middle position if they are arranged in ascending order.The input consists of a single line containing three integers A, B and C.
<b> Constraints: </b>
1 ≤ A, B, C ≤ 10<sup>9</sup>
A, B, C are pairwise distinct.
Print a single integer, the median of the given numbers.Sample Input 1:
5 1 3
Sample Output 1:
3
Sample Input 2:
1 2 3
Sample Output 2:
2, I have written this Solution Code:
//#define ASC
//#define DBG_LOCAL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#define int long long
// #define int __int128
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define endl '\n'
#define fi first
#define se second
// const int mod = 1e9 + 7;
const int mod=998'244'353;
const long long INF = 2e18 + 10;
// const int INF=1e9+10;
#define readv(x, n) \
vector<int> x(n); \
for (auto &i : x) \
cin >> i;
template <typename T>
using v = vector<T>;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vector<vector<T>>>;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;
typedef pair<int, int> pii;
int multiply(int a, int b, int in_mod) { return (int)(1LL * a * b % in_mod); }
int mult_identity(int a) { return 1; }
const double PI = acosl(-1);
auto power(auto a, auto b, const int in_mod)
{
auto prod = mult_identity(a);
auto mult = a % 2;
while (b != 0)
{
if (b % 2)
{
prod = multiply(prod, mult, in_mod);
}
if(b/2)
mult = multiply(mult, mult, in_mod);
b /= 2;
}
return prod;
}
auto mod_inv(auto q, const int in_mod)
{
return power(q, in_mod - 2, in_mod);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define stp cout << fixed << setprecision(20);
void solv()
{
int A ,B, C;
cin>>A>>B>>C;
vector<int> values;
values.push_back(A);
values.push_back(B);
values.push_back(C);
sort(all(values));
cout<<values[1]<<endl;
}
void solve()
{
int t = 1;
// cin>>t;
for(int i = 1;i<=t;i++)
{
// cout<<"Case #"<<i<<": ";
solv();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#else
#ifdef ASC
namespace fs = std::filesystem;
std::string path = "./";
string filename;
for (const auto & entry : fs::directory_iterator(path)){
if( entry.path().extension().string() == ".in"){
filename = entry.path().filename().stem().string();
}
}
if(filename != ""){
string input_file = filename +".in";
string output_file = filename +".out";
if (fopen(input_file.c_str(), "r"))
{
freopen(input_file.c_str(), "r", stdin);
freopen(output_file.c_str(), "w", stdout);
}
}
#endif
#endif
// auto clk = clock();
// -------------------------------------Code starts here---------------------------------------------------------------------
signed t = 1;
// cin >> t;
for (signed test = 1; test <= t; test++)
{
// cout<<"Case #"<<test<<": ";
// cout<<endl;
solve();
}
// -------------------------------------Code ends here------------------------------------------------------------------
// clk = clock() - clk;
#ifndef ONLINE_JUDGE
// cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
#endif
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given three distinct positive integers, A, B and C, in the input. Your task is to find their median.
The median of a set of integers is the number at the middle position if they are arranged in ascending order.The input consists of a single line containing three integers A, B and C.
<b> Constraints: </b>
1 ≤ A, B, C ≤ 10<sup>9</sup>
A, B, C are pairwise distinct.
Print a single integer, the median of the given numbers.Sample Input 1:
5 1 3
Sample Output 1:
3
Sample Input 2:
1 2 3
Sample Output 2:
2, I have written this Solution Code: lst = list(map(int, input().split()))
lst.sort()
print(lst[1]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: void magicTrick(int a, int b){
cout<<a+b/2;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: static void magicTrick(int a, int b){
System.out.println(a + b/2);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
<b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b>
<b>Constraints</b>:-
1 <= A, B <= 1000Print the resulting amountSample Input:-
3 4
Sample Output:-
5
Sample Input:-
8 4
Sample Output:-
10, I have written this Solution Code: A,B = map(int,input().split(' '))
C = A+B//2
print(C)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
String code[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",
".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };
Scanner sc =new Scanner(System.in);
String morseCode =sc.nextLine();
morseToWords(code,morseCode);
}
static void morseToWords(String[] code,String morseCode ){
HashMap<String,Character> hs =new HashMap<>();
for(int i=0; i<26; i++)
hs.put(code[i],(char)('A'+i));
String [] array = morseCode.split(" ");
for(int i=0; i< array.length; i++)
System.out.print(hs.get(array[i]));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code:
dict = dict1 = {".-":"A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N", "---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"}
def word(s):
print(''.join(dict.get(i) for i in s.split()))
if __name__ == "__main__":
word(input()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-18 01:39:40
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
float calculateSD(vector<float> a, int n) {
float sum = 0.0, mean, SD = 0.0;
for (int i = 0; i < n; ++i) {
sum += a[i];
}
mean = sum / n;
for (int i = 0; i < n; ++i) {
SD += pow(a[i] - mean, 2);
}
return sqrt(SD / n);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// Morse Code
{
char str[100000];
cin.getline(str, sizeof(str), '\n');
string temp = "";
vector<string> words;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == ' ') {
if (temp.length() > 0) {
words.push_back(temp);
}
temp = "";
} else {
temp += str[i];
}
}
if (temp.length() > 0) {
words.push_back(temp);
}
// debug(words);
map<string, string> dict = {
{".-", "A"},
{"-...", "B"},
{"-.-.", "C"},
{"-..", "D"},
{".", "E"},
{"..-.", "F"},
{"--.", "G"},
{"....", "H"},
{"..", "I"},
{".---", "J"},
{"-.-", "K"},
{".-..", "L"},
{"--", "M"},
{"-.", "N"},
{"---", "O"},
{".--.", "P"},
{"--.-", "Q"},
{".-.", "R"},
{"...", "S"},
{"-", "T"},
{"..-", "U"},
{"...-", "V"},
{".--", "W"},
{"-..-", "X"},
{"-.--", "Y"},
{"--..", "Z"}};
for (auto &it : words) {
cout << dict[it];
}
cout << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void cal(int arr[], int n){
int countZ = 0;
for(int i = 0; i < n; i++) {
if(arr[i] == 0) {
countZ++;
}
}
for(int i = 1; i <= countZ; i++) {
System.out.print("0 ");
}
for(int i = 1; i <= n - countZ; i++) {
System.out.print("1 ");
}
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nD = br.readLine();
String nDArr[] = nD.split(" ");
int n = Integer.parseInt(nDArr[0]);
int arr[]= new int[n];
String input = br.readLine();
String sar[] = input.split(" ");
for(int i = 0; i < n; i++){
arr[i] = Integer.parseInt(sar[i]);
}
cal(arr, n);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 1, I have written this Solution Code: n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
for i in l:
print(i, end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 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; cin >> n;
int a[2] = {0};
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
for(int i = 0; i <= 1; i++)
for(int j = 0; j < a[i]; j++)
cout << i << " ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int i=str.length()-1;
if(i==0){
int number=Integer.parseInt(str);
System.out.println(number);
}else{
while(str.charAt(i)=='0'){
i--;
}
for(int j=i;j>=0;j--){
System.out.print(str.charAt(j));
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: n=int(input())
def reverse(n):
return int(str(n)[::-1])
print(reverse(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
int I;
for( I=0;I<s.length();I++){
if(s[I]!='0'){break;}
}
if(I==s.length()){cout<<0;return 0;}
for(int j=I;j<s.length();j++){
cout<<s[j];}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Everyone has heard of palindromes, right! A palindrome is a string that remains the same if reversed.
Let's define a new term, Dalindrome.
A Dalindrome is a string whose atleast one of the substrings is a palindrome.
Given a string, find whether it's a Dalindrome.The only line of input contains a string to be checked.
Constraints
1 <= length of string <= 100Output "Yes" if string is a Dalindrome, else output "No".Sample Input
cbabcc
Sample Output
Yes
Explanation: "bab" is one of the substrings of the string that is a palindrome. There may be other substrings that are palindrome as well like "cc", or "cbabc". The question requires atleast one., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
System.out.println("Yes");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Everyone has heard of palindromes, right! A palindrome is a string that remains the same if reversed.
Let's define a new term, Dalindrome.
A Dalindrome is a string whose atleast one of the substrings is a palindrome.
Given a string, find whether it's a Dalindrome.The only line of input contains a string to be checked.
Constraints
1 <= length of string <= 100Output "Yes" if string is a Dalindrome, else output "No".Sample Input
cbabcc
Sample Output
Yes
Explanation: "bab" is one of the substrings of the string that is a palindrome. There may be other substrings that are palindrome as well like "cc", or "cbabc". The question requires atleast one., I have written this Solution Code: string = str(input())
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Everyone has heard of palindromes, right! A palindrome is a string that remains the same if reversed.
Let's define a new term, Dalindrome.
A Dalindrome is a string whose atleast one of the substrings is a palindrome.
Given a string, find whether it's a Dalindrome.The only line of input contains a string to be checked.
Constraints
1 <= length of string <= 100Output "Yes" if string is a Dalindrome, else output "No".Sample Input
cbabcc
Sample Output
Yes
Explanation: "bab" is one of the substrings of the string that is a palindrome. There may be other substrings that are palindrome as well like "cc", or "cbabc". The question requires atleast one., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// 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
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
string s; cin>>s;
cout<<"Yes";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, I have written this Solution Code: n = int(input())
all_no = input().split(' ')
i = 0
joined_str = ''
while(i < n-1):
if(i == 0):
joined_str = str(int(all_no[i]) + int(all_no[i+1]))
else:
joined_str = joined_str + ' ' + str(int(all_no[i]) + int(all_no[i+1]))
i = i + 2
print(joined_str), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int t;
for(int i=0;i<n;i+=2){
System.out.print(a[i]+a[i+1]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number represents the pair-wise sum of consecutive elements of the array A.
In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).The first line of the input contains the number of test cases T.
For each test case, the first line of the input contains an integer N(even number) denoting the number of elements in the array. The next line contains N (white-space separated) integers.
Constraints
1 <= N <= 100
1 <= A[I] <= 1000000000For each test case, output N/2 elements representing the pairwise sum of adjacent elements in the array.Input:-1
4
1 2 6 4
output-1
3 10
input-2
10
1 2 3 4 5 6 0 7 8 9
output-2
3 7 11 7 17
Explanation(might now be the optimal solution):
Testcase 1:
Follow the below steps:-
Step 1: [1 2 6 4]
Step 2: (1 2) and (6 4)
Step 3: 3 10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i+=2){
cout<<a[i]+a[i+1]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function isArray which takes an input which can be any data type and returns true
if it's an array else false.Could be any datatype string number object or an arraytrue or falseSample Input:-
1
[2, 3]
Sample Output
false
true, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
String str= s.next();
if(str.charAt(0)== '['){
System.out.println("true");
}
else{
System.out.println("false");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the function isArray which takes an input which can be any data type and returns true
if it's an array else false.Could be any datatype string number object or an arraytrue or falseSample Input:-
1
[2, 3]
Sample Output
false
true, I have written this Solution Code: function isArray(input){
if(Array.isArray(input)) {
console.log(true)
}else{
console.log(false)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements
function replaceArray(arr, n) {
// write code here
// do not console.log
// return the new array
const newArr = []
newArr[0] = arr[0] * arr[1]
newArr[n-1] = arr[n-1] * arr[n-2]
for(let i= 1;i<n-1;i++){
newArr[i] = arr[i-1] * arr[i+1]
}
return newArr
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:-
a) First element is replaced by multiplication of first and second.
b) Last element is replaced by multiplication of last and second last.
See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array.
Constraints:-
2 < = N < = 100000
1 < = arr[i] < = 100000Print the modified arraySample Input :-
5
2 3 4 5 6
Sample Output:-
6 8 15 24 30
Explanation:-
{2*3, 2*4, 3*5, 4*6, 5*6}
Sample Input:-
2
3 4
Sample Output:-
12 12, I have written this Solution Code: n = int(input())
X = [int(x) for x in input().split()]
lst = []
for i in range(len(X)):
if i == 0:
lst.append(X[i]*X[i+1])
elif i == (len(X) - 1):
lst.append(X[i-1]*X[i])
else:
lst.append(X[i-1]*X[i+1])
for i in lst:
print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |