Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
int powmod(int a, int b, int c = MOD){
int ans = 1;
while(b){
if(b&1){
ans = (ans*a)%c;
}
a = (a*a)%c;
b >>= 1;
}
return ans;
}
void solve(){
int a, b, c, d; cin>>a>>b>>c>>d;
int x = pow(c, d);
int y = powmod(b, x, MOD-1);
int ans = powmod(a, y, MOD);
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: There are n piles of stones, where the i- th pile has a<sub>i</sub> stones. Two people play a game, where they take alternating turns removing stones.
In a move, a player may remove a positive number of stones from the first non- empty pile (the pile with the minimal index, that has at least one stone). The first player who cannot make a move (because all piles are empty) loses the game. If both players play optimally, determine the winner of the game.The first line of the input contains a single integer n denoting the number of piles. The second line of each test case contains n integers a<sub>1</sub>, …, a<sub>n</sub> where a<sub>i</sub> is equal to the number of stones in the i- th pile.
<b>Constraints</b>
1 ≤ n ≤ 10<sup>3</sup>
1 ≤ a<sub>i</sub> ≤ 10<sup>9</sup>If the player who makes the first move will win, output "First". Otherwise, output "Second".<b>Sample Input 1</b>
3
2 5 4
<b>Sample Output 1</b>
First
<b>Sample Input 1</b>
8
1 1 1 1 1 1 1 1
<b>Sample Output 1</b>
Second, I have written this Solution Code: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<ctime>
#define db double
#define N 100100
using namespace std;
int T,n,num[N];
int main()
{
int i,j,t;
// cin>>T;
T=1;
while(T--)
{
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&num[i]);
for(i=1;i<n&&num[i]==1;i++);
if(i&1) puts("First");
else puts("Second");
}
}, 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 are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
int n=Integer.parseInt(bu.readLine());
String s[]=bu.readLine().split(" ");
int a[]=new int[n],i;
PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if(o1[0]<o2[0]) return 1;
else return -1;
}});
for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);
int k=Integer.parseInt(bu.readLine());
for(i=0;i<k;i++) pq.add(new int[]{a[i],i});
sb.append(pq.peek()[0]+" ");
for(i=k;i<n;i++)
{
pq.add(new int[]{a[i],i});
while(!pq.isEmpty() && pq.peek()[1]<=i-k) pq.poll();
sb.append(pq.peek()[0]+" ");
}
System.out.println(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: N = int(input())
A = [int(x) for x in input().split()]
K = int(input())
def print_max(a, n, k):
max_upto = [0 for i in range(n)]
s = []
s.append(0)
for i in range(1, n):
while (len(s) > 0 and a[s[-1]] < a[i]):
max_upto[s[-1]] = i - 1
del s[-1]
s.append(i)
while (len(s) > 0):
max_upto[s[-1]] = n - 1
del s[-1]
j = 0
for i in range(n - k + 1):
while (j < i or max_upto[j] < i + k - 1):
j += 1
print(a[j], end=" ")
print()
print_max(A, N, K), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array A of size N. You have to print the maximum in every <b>K-sized subarray</b> from the left to the right in the array A.
More formally, you have to print N - K + 1 integers X<sub>1</sub>, X<sub>2</sub>, ..., X<sub>N-K+1</sub> such that X<sub>i</sub> (1 <= i <= N - K + 1) is the maximum element in the subarray A<sub>i</sub>, A<sub>i+1</sub>, ..., A<sub>i+K-1</sub>.1. The first line contains an integer N, denoting the size of the array.
2. The second line has N space-separated integers of the array A.
3. The third line contains integer K, denoting the size of the sliding window
<b>Constraints :</b>
1 ≤ N ≤ 10<sup>5</sup>
-10<sup>4</sup> ≤ A[i] ≤ 10<sup>4</sup>
1 ≤ K ≤ NPrint the max of K numbers for each position of sliding windowSample Input:-
8
1 3 -1 -3 5 3 6 7
3
Sample Output:-
3 3 5 5 6 7
Explanation:-
Window position Max
- - - -
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Sample Input:-
1
1
1
Sample Output:-
1 , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
vector<int> maxSwindow(vector<int>& arr, int k) {
vector<int> result;
deque<int> Q(k); // store the indices
// process the first window
for(int i = 0; i < k; i++) {
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
Q.push_back(i);
}
// process the remaining elements
for(int i = k; i < arr.size(); i++) {
// add the max of the current window
result.push_back(arr[Q.front()]);
// remove the elements going out of the window
while(!Q.empty() and Q.front() <= i - k)
Q.pop_front();
// remove the useless elements
while(!Q.empty() and arr[i] >= arr[Q.back()])
Q.pop_back();
// add the current element in the deque
Q.push_back(i);
}
result.push_back(arr[Q.front()]);
return result;
}
int main()
{
int k, n, m;
cin >> n;
vector<int> nums, res;
for(int i =0; i < n; i++){
cin >> m;
nums.push_back(m);
}
cin >> k;
res = maxSwindow(nums,k);
for(auto i = res.begin(); i!=res.end(); i++)
cout << *i << " ";
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: 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: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix.
Constraints:-
1 <= M, N <= 100
1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:-
3 3
1 2 3
4 5 6
7 8 9
Sample Output:-
18
Explanation:-
1 + 4 + 7 = 12
2 + 5 + 8 = 15
3 + 6 + 9 = 18
maximum = 18
Sample Input:-
3 2
1 4
9 6
9 1
Sample Output:-
19, I have written this Solution Code: m,n=map(int ,input().split())
matrix=[]
for i in range(m):
l1=[eval(x) for x in input().split()]
matrix.append(l1)
l2=[]
for coloumn in range(n):
sum1=0
for row in range(m):
sum1+= matrix[row][coloumn]
l2.append(sum1)
print(max(l2))
'''for row in range(n):
sum2=0
for col in range(m):
sum2 += matrix[row][col]
print(sum2)''', In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix.
Constraints:-
1 <= M, N <= 100
1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:-
3 3
1 2 3
4 5 6
7 8 9
Sample Output:-
18
Explanation:-
1 + 4 + 7 = 12
2 + 5 + 8 = 15
3 + 6 + 9 = 18
maximum = 18
Sample Input:-
3 2
1 4
9 6
9 1
Sample Output:-
19, I have written this Solution Code: // mat is the matrix/ 2d array
// the dimensions of array are:- a rows, b columns
function colMaxSum(mat,a,b) {
// write code here
// do not console.log
// return the answer as a number
let idx = -1;
// Variable to store max sum
let maxSum = Number.MIN_VALUE;
// Traverse matrix column wise
for (let i = 0; i < b; i++) {
let sum = 0;
// calculate sum of column
for (let j = 0; j < a; j++) {
sum += mat[j][i];
}
// Update maxSum if it is
// less than current sum
if (sum > maxSum) {
maxSum = sum;
// store index
idx = i;
}
}
let res;
res = [idx, maxSum];
// return result
return maxSum;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix.
Constraints:-
1 <= M, N <= 100
1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:-
3 3
1 2 3
4 5 6
7 8 9
Sample Output:-
18
Explanation:-
1 + 4 + 7 = 12
2 + 5 + 8 = 15
3 + 6 + 9 = 18
maximum = 18
Sample Input:-
3 2
1 4
9 6
9 1
Sample Output:-
19, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n,m;
cin>>n>>m;
int a[m];
for(int i=0;i<m;i++){
a[i]=0;
}
int x;
int sum=0;
FOR(i,n){
FOR(j,m){
cin>>x;
a[j]+=x;
sum=max(sum,a[j]);
}
}
out(sum);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size M*N, your task is to find the column having the maximum sum and print the sum.The first line of input contains two space-separated integers M and N. The following M lines of input contain N space-separated integers each depicting the values of the matrix.
Constraints:-
1 <= M, N <= 100
1 <= Matrix[][] <= 100000Print the maximum sum.Sample Input:-
3 3
1 2 3
4 5 6
7 8 9
Sample Output:-
18
Explanation:-
1 + 4 + 7 = 12
2 + 5 + 8 = 15
3 + 6 + 9 = 18
maximum = 18
Sample Input:-
3 2
1 4
9 6
9 1
Sample Output:-
19, 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 m = sc.nextInt();
int n = sc.nextInt();
int a[][] = new int[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
a[i][j]=sc.nextInt();
}
}
int sum=0;
int ans=0;
for(int i=0;i<n;i++){
sum=0;
for(int j=0;j<m;j++){
sum+=a[j][i];
}
if(sum>ans){ans=sum;}
}
System.out.print(ans);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int BS(int arr[],int x,int start,int end){
if( start > end) return start-1;
int mid = start + (end - start)/2;
if(arr[mid]==x) return mid;
if(arr[mid]>x) return BS(arr,x,start,mid-1);
return BS(arr,x,mid+1,end);
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
String[] s;
for(;t>0;t--){
s = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int x = Integer.parseInt(s[1]);
s = br.readLine().split(" ");
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = Integer.parseInt(s[i]);
int res = BS(arr,x,0,arr.length-1);
System.out.println(res);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: def bsearch(arr,e,l,r):
if(r>=l):
mid = l + (r - l)//2
if (arr[mid] == e):
return mid
elif arr[mid] > e:
return bsearch(arr, e,l, mid-1)
else:
return bsearch(arr,e, mid + 1, r)
else:
return r
t=int(input())
for i in range(t):
ip=list(map(int,input().split()))
l=list(map(int,input().split()))
le=ip[0]
e=ip[1]
print(bsearch(sorted(l),e,0,le-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x.
Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.
<b>Constraints:</b>
1 ≤ T ≤ 100
1 ≤ N ≤ 10^5
1 ≤ arr[i] ≤ 10^18
0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput:
3
7 0
1 2 8 10 11 12 19
7 5
1 2 8 10 11 12 19
7 10
1 2 8 10 11 12 19
Output:
-1
1
3
Explanation:
Testcase 1: No element less than or equal to 0 is found. So output is "-1".
Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing).
Testcase 3: Number less than or equal to 10 is 10 and its index is 3., 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, x; cin >> n >> x;
for(int i = 0; i < n; i++)
cin >> a[i];
int l = -1, h = n;
while(l+1 < h){
int m = (l + h) >> 1;
if(a[m] <= x)
l = m;
else
h = m;
}
cout << l << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, I have written this Solution Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = -1 , b = 0, c= 0, d = 0;
for(int i = 0 ; i < s.length() ; i++){
if(s.charAt(i) == 'a')
a++;
else if(s.charAt(i) == 'b')
b++;
else if(s.charAt(i) == 'c')
c++;
else if(s.charAt(i) == 'd')
d++;
}
if(a==-1)
System.out.print(0);
else
System.out.print(findmin(a,b,c,d));
}
static int findmin(int a, int b, int c , int d){
int f , s ;
f = Math.min(a,b); s = Math.min(c, d);
return Math.min(f,s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, I have written this Solution Code: arr=input()
a=0
b=0
c=0
d=0
for i in range(0,len(arr)):
if(arr[i]=='a'):
a+=1
elif (arr[i]=='b'):
b+=1
elif (arr[i]=='c'):
c+=1
elif (arr[i]=='d'):
d+=1
ans=(min(int(a/2),b,c,d))
ans1=min(a-1,b,c,d)
print (max(ans,ans1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, 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]={};
for(auto r:s){
c[r-'a']++;
}
int ans=min(min(c[0]-1,c[1]),min(c[2],c[3]));
if(ans<0)
ans=0;
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 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 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: There are three sticks with integer lengths l<sub>1</sub>, l<sub>2</sub> and l<sub>3</sub>. You are asked to break exactly one of them into two pieces in such a way that:
- both pieces have positive (strictly greater than 0) integer length;
- the total length of the pieces is equal to the original length of the stick;
- it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides. A square is also considered a rectangle.
Determine if it's possible to do that.The input consists of 3 space- separated integers l<sub>1</sub>, l<sub>2</sub> and l<sub>3</sub>.
<b>Constraints</b>
1 ≤ l<sub>i</sub> ≤ 10<sup>8</sup>Print "Yes" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "No".<b>Sample Input 1</b>
6 1 5
<b>Sample Output 1</b>
Yes
<b>Sample Input 2</b>
2 5 2
<b>Sample Output 2</b>
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt=1;
// cin >> tt;
while (tt--) {
int a, b, c;
cin >> a >> b >> c;
if (a == b + c || b == c + a || c == a + b) {
cout << "Yes" << '\n';
} else {
if ((a == b && c % 2 == 0) || (a == c && b % 2 == 0) || (b == c && a % 2 == 0)) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a Binary Tree, your task is to compute the sum of all leaf nodes in the tree.
Note :- All the nodes in the tree are distinct .<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>sumOfLeaf()</b> that takes "root" node as parameter.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= node values <= 10^5
Sum of "N" over all test cases does not exceed 2*10^5
For <b>Custom Input:</b>
First line of input should contains the number of test cases T. For each test case, there will be two lines of input.
First line contains number of nodes N and the required sum X. Second line will be a string representing the tree as described below:
The values in the string are in the order of level order traversal of the tree where, numbers denote node values, and a character “N” denotes NULL child.
<b>Note:</b> If a node has been declared Null using 'N', no information about its children will be given further in the array.Return the sum of all the leaf nodes of the binary tree.Sample Input:
2
3
10 8 34
2
48 36
Sample Output:
42
36, I have written this Solution Code:
static class Res
{
int sum = 0;
}
public static int sumOfLeaf(Node root)
{
Res r = new Res();
leafSum(root, r);
return r.sum;
}
public static void leafSum(Node root, Res r)
{
if(root == null)
return;
if(root.left == null && root.right == null)
r.sum += root.data;
leafSum(root.left, r);
leafSum(root.right, r);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output.
<b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10000
-10000 ≤ A[i] ≤ 10000
The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput:
1
5
-7 -2 3 4 6
Output:
4 9 16 36 49, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
arr = sortedSquares(arr);
for(int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
}
public static int[] sortedSquares(int[] A) {
int[] nums = new int[A.length];
int k=A.length-1;
int i=0, j=A.length-1;
while(i<=j){
if(Math.abs(A[i]) <= Math.abs(A[j])){
nums[k--] = A[j]*A[j];
j--;
}
else{
nums[k--] = A[i]*A[i];
i++;
}
}
return nums;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output.
<b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10000
-10000 ≤ A[i] ≤ 10000
The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput:
1
5
-7 -2 3 4 6
Output:
4 9 16 36 49, I have written this Solution Code: t = int(input())
for i in range(t):
n = int(input())
for i in sorted(map(lambda j:int(j)**2,input().split())):
print(i,end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b><em>Enumeration in Java</em></b>
Write a Java program to print name of month of year using Enumeration in java.
1->January
2->February
3->March
4->April
5->May
6->Jun
7->July
8->August
9->September
10->October
11->November
12->DecemberThere is an integer n is given as input.
1 <= n <=12print day of month name using Enumeration in java.Sample Output:
5
Sample Output:
May, I have written this Solution Code: import java.util.Scanner;
// A simple enum example where enum is declared
// outside any class (Note enum keyword instead of
// class keyword)
enum Month {
January,
February,
March,
April,
May,
Jun,
July,
August,
September,
October,
November,
December
}
public class Main {
// Driver method
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
switch (n) {
case 1:
System.out.println(Month.January);
break;
case 2:
System.out.println(Month.February);
break;
case 3:
System.out.println(Month.March);
break;
case 4:
System.out.println(Month.April);
break;
case 5:
System.out.println(Month.May);
break;
case 6:
System.out.println(Month.Jun);
break;
case 7:
System.out.println(Month.July);
break;
case 8:
System.out.println(Month.August);
break;
case 9:
System.out.println(Month.September);
break;
case 10:
System.out.println(Month.October);
break;
case 11:
System.out.println(Month.November);
break;
case 12:
System.out.println(Month.December);
break;
default:
System.out.println("Please give a valid number");
break;
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's call a positive integer powerful if it has only one non- zero digits. For example, 5000, 4, 1, 10, and 200 are powerful integers whereas 42, 13, 666, 77, and 101 are not.
You are given an integer n. You have to calculate the number of powerful integers x such that 1 ≤ x ≤ n.The input consists of an integer n.
<b>Constraints</b>
1 ≤ n ≤ 999999Print one integer denoting the number of extremely round integers x such that 1 ≤ x ≤ n.<b>Sample Input 1</b>
9
<b>Sample Output 1</b>
9
<b>Sample Input 2</b>
42
<b>Sample Output 2</b>
13, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t=1;
// cin >> t;
for (int i = 0; i < t; i++){
int n;
cin >> n;
int ans = 0;
for (int j = 1; j <= 9; j++){
int x = j;
while (x <= n){
ans++;
x *= 10;
}
}
cout << ans << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b><em>Array List In Java</em></b>
There is a list, having n integers that may have duplicates, is given. Write a Java program to print all unique elements and their frequencies. Elements must be in sorted order.There is an integer n is given in first line of input.
In Second line, n space separated integers are given.
<b>Constraints</b>
1 <= n <= 10<sup>4</sup>Print all unique elements and their frequencies. Elements must be in sorted order.Sample Input:
7
1 2 4 3 5 4 3
Sample Output:
1 1
2 1
3 2
4 2
5 1, I have written this Solution Code: import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
public static void main(String[] args) {
Map<Integer,Integer> mp = new HashMap<>();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
if (mp.get(a)!=null) {
mp.put(a, mp.get(a) + 1);
} else
mp.put(a, 1);
}
for (Map.Entry<Integer, Integer> entry : mp.entrySet()) {
System.out.print(entry.getKey());
System.out.print(" ");
System.out.println(entry.getValue());
}
return;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer Q representing the number of queries and an integer K. There are two types of queries:
(i) 1 x : Add the number x to the stream
(ii) 2 : Print the sum of last K numbers of the stream. If there are less than K numbers in the stream, print the sum of current stream.
Process all the queries.First line contains two integers Q and K.
Next Q lines contains the queries.
Constraints
1 <= Q <= 10^5
1 <= x <= 10^5
1 <= K <= Q
There is atleast one query of 2nd type. For each query of type 2, print the sum of last K numbers of the stream on a new line.Sample Input 1:
5 2
1 4
2
1 1
1 3
2
Output
4
4
Explanation:
Initial Stream = {}
Add 4. Stream = {4}
Sum of last two elements = 4
Add 1. Stream = {4, 1}
Add 3. Stream = {4, 1, 3}
Sum of last two elements = 4
Sample Input 2:
3 1
1 1
2
2
Output
1
1
Explanation
Initial Stream = {}
Add 1. Stream = {1}
Sum of last element = 1
Sum of last element = 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n,k;
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
n=Integer.parseInt(strs[0]);
k=Integer.parseInt(strs[1]);
Long sum=0L;
Queue<Integer>x=new LinkedList<Integer>();
while(n>0){
n--;
line = br.readLine();
strs = line.trim().split("\\s+");
int y=Integer.parseInt(strs[0]);
if(y==1){
y=Integer.parseInt(strs[1]);
x.add(y);
sum += y;
if (x.size() > k) {
sum -= x.peek();
x.remove();
}
}
else{
System.out.print(sum+"\n");
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer Q representing the number of queries and an integer K. There are two types of queries:
(i) 1 x : Add the number x to the stream
(ii) 2 : Print the sum of last K numbers of the stream. If there are less than K numbers in the stream, print the sum of current stream.
Process all the queries.First line contains two integers Q and K.
Next Q lines contains the queries.
Constraints
1 <= Q <= 10^5
1 <= x <= 10^5
1 <= K <= Q
There is atleast one query of 2nd type. For each query of type 2, print the sum of last K numbers of the stream on a new line.Sample Input 1:
5 2
1 4
2
1 1
1 3
2
Output
4
4
Explanation:
Initial Stream = {}
Add 4. Stream = {4}
Sum of last two elements = 4
Add 1. Stream = {4, 1}
Add 3. Stream = {4, 1, 3}
Sum of last two elements = 4
Sample Input 2:
3 1
1 1
2
2
Output
1
1
Explanation
Initial Stream = {}
Add 1. Stream = {1}
Sum of last element = 1
Sum of last element = 1, I have written this Solution Code: /**
* author: tourist1256
* created: 2022-06-14 14:26:47
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
int32_t main() {
int Q, K;
cin >> Q >> K;
deque<int> st;
int sum = 0;
while (Q--) {
int x;
cin >> x;
if (x == 1) {
int y;
cin >> y;
if (st.size() == K) {
sum -= st.back();
st.pop_back();
st.push_front(y);
sum += y;
} else {
st.push_front(y);
sum += y;
}
} else {
cout << sum << "\n";
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A[] of size N. For any subarray size i (1 <= i <= N), you have to do the following:
<ul><li>Write all subarrays of size i from array A on a piece of paper.</li><li>Now, replace each of these subarrays with their minimum element.</li><li>Now, find the maximum value among all these minimums.</li>
Print this maximum value for all subarray sizes k (1 <= k <= N).The first line contains an integer N denoting the size of the array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.
Constraint:-
1 <= N <= 10^5
1 <= A[i] <= 10^6Print the array of numbers of size N for each of the considered window size 1, 2, ..., N respectively.Sample Input:
7
10 20 30 50 10 70 30
Sample Output:
70 30 20 10 10 10 10
Explanation:
Testcase 1:
First element in output indicates maximum of minimums of all windows of size 1. Minimums of windows of size 1 are {10}, {20}, {30}, {50}, {10}, {70} and {30}. Maximum of these minimums is 70.
Second element in output indicates maximum of minimums of all windows of size 2. Minimums of windows of size 2 are {10}, {20}, {30}, {10}, {10}, and {30}. Maximum of these minimums is 30.
Third element in output indicates maximum of minimums of all windows of size 3. Minimums of windows of size 3 are {10}, {20}, {10}, {10} and {10}. Maximum of these minimums is 20.
Similarly other elements of output are computed., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
int n = Integer.parseInt(br.readLine());
String s= br.readLine();
String[] str = s.split(" ");
int arr[] = new int[n];
for(int i=0 ; i<n ; i++){
arr[i]=Integer.parseInt(str[i]) ;
}
printMaxOfMin(n,arr);
}
static void printMaxOfMin(int n,int[] arr)
{
Stack<Integer> s = new Stack<>();
int left[] = new int[n+1];
int right[] = new int[n+1];
for (int i=0; i<n; i++)
{
left[i] = -1;
right[i] = n;
}
for (int i=0; i<n; i++)
{
while (!s.empty() && arr[s.peek()] >= arr[i])
s.pop();
if (!s.empty())
left[i] = s.peek();
s.push(i);
}
while (!s.empty())
s.pop();
for (int i = n-1 ; i>=0 ; i-- )
{
while (!s.empty() && arr[s.peek()] >= arr[i])
s.pop();
if(!s.empty())
right[i] = s.peek();
s.push(i);
}
int ans[] = new int[n+1];
for (int i=0; i<=n; i++)
ans[i] = 0;
for (int i=0; i<n; i++)
{
int len = right[i] - left[i] - 1;
ans[len] = Math.max(ans[len], arr[i]);
}
for (int i=n-1; i>=1; i--)
ans[i] = Math.max(ans[i], ans[i+1]);
for (int i=1; i<=n; i++)
System.out.print(ans[i] + " ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A[] of size N. For any subarray size i (1 <= i <= N), you have to do the following:
<ul><li>Write all subarrays of size i from array A on a piece of paper.</li><li>Now, replace each of these subarrays with their minimum element.</li><li>Now, find the maximum value among all these minimums.</li>
Print this maximum value for all subarray sizes k (1 <= k <= N).The first line contains an integer N denoting the size of the array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.
Constraint:-
1 <= N <= 10^5
1 <= A[i] <= 10^6Print the array of numbers of size N for each of the considered window size 1, 2, ..., N respectively.Sample Input:
7
10 20 30 50 10 70 30
Sample Output:
70 30 20 10 10 10 10
Explanation:
Testcase 1:
First element in output indicates maximum of minimums of all windows of size 1. Minimums of windows of size 1 are {10}, {20}, {30}, {50}, {10}, {70} and {30}. Maximum of these minimums is 70.
Second element in output indicates maximum of minimums of all windows of size 2. Minimums of windows of size 2 are {10}, {20}, {30}, {10}, {10}, and {30}. Maximum of these minimums is 30.
Third element in output indicates maximum of minimums of all windows of size 3. Minimums of windows of size 3 are {10}, {20}, {10}, {10} and {10}. Maximum of these minimums is 20.
Similarly other elements of output are computed., 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 l[N], r[N], ans[N], a[N];
signed main() {
IOS;
int n; cin >> n;
stack<int> s;
a[0] = a[n+1] = -inf;
s.push(0);
for(int i = 1; i <= n; i++){
cin >> a[i];
while(!s.empty() && a[s.top()] >= a[i])
s.pop();
l[i] = s.top();
s.push(i);
}
while(!s.empty())
s.pop();
s.push(n+1);
for(int i = n; i >= 1; i--){
while(!s.empty() && a[s.top()] >= a[i])
s.pop();
r[i] = s.top();
s.push(i);
}
for(int i = 1; i <= n; i++){
int len = r[i] - l[i] - 1;
ans[len] = max(ans[len], a[i]);
}
for(int i = n-1; i >= 1; i--)
ans[i] = max(ans[i], ans[i+1]);
for(int i = 1; i <= n; i++)
cout << ans[i] << " ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void sieve(boolean prime[], int n) {
int i,j;
for(i = 0; i <= n; i++)
prime[i] = true;
for(i = 2; i*i <= n; i++)
if(prime[i])
for(j = i*i; j<=n; j+=i)
prime[j] = false;
}
public static void main (String[] args) throws IOException {
int num = 10000005;
boolean prime[] = new boolean[num+1];
sieve(prime, num);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T --> 0) {
int n = Integer.parseInt(br.readLine().trim());
int count = 0;
for(int i=(n/2)+1; i<=n; i++)
if(prime[i])
count++;
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
bool a[max1];
long b[max1];
void pre(){
b[0]=0;b[1]=0;
for(int i=0;i<max1;i++){
a[i]=false;
}
long cnt=0;
for(int i=2;i<max1;i++){
if(a[i]==false){
cnt++;
for(int j=i+i;j<=max1;j=j+i){a[j]=true;}
}
b[i]=cnt;
}
}
int main(){
pre();
int t;
cin>>t;
while(t--){
long n;
cin>>n;
cout<<(b[n]-b[(n)/2])<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Another array B is defined as:
B[i] = A[j] such that j > i and A[j] < A[i]. If there does not exist any index j satisfying the above conditions then B[i] = -1.
Find the array B.The first line contains an integer N.
The next line contains N space-separated integers denoting elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ Ai ≤ 10<sup>5</sup>Print N space separated integers denoting the elements of array B.Sample Input 1:
4
10 2 5 3
Output
2 -1 3 -1
Explanation:
Next element smaller than 10 is 2.
There are no elements after 2 that are less than 2.
Next element smaller than 5 is 3.
There are no elements after 3.
Sample Input 2:
2
1 2
Output
-1 -1
Explanation:
There are no elements after 1 which is less than 1 and there are no elements after 2. , I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
void printNSE(vector<int> &arr, int n) {
int next, i, j;
vector<int> b;
for (i = 0; i < n; i++) {
next = -1;
for (j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) {
next = arr[j];
break;
}
}
b.push_back(next);
}
for (int i = 0; i < n; i++) {
cout << b[i] << " ";
}
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
printNSE(arr, n);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Another array B is defined as:
B[i] = A[j] such that j > i and A[j] < A[i]. If there does not exist any index j satisfying the above conditions then B[i] = -1.
Find the array B.The first line contains an integer N.
The next line contains N space-separated integers denoting elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ Ai ≤ 10<sup>5</sup>Print N space separated integers denoting the elements of array B.Sample Input 1:
4
10 2 5 3
Output
2 -1 3 -1
Explanation:
Next element smaller than 10 is 2.
There are no elements after 2 that are less than 2.
Next element smaller than 5 is 3.
There are no elements after 3.
Sample Input 2:
2
1 2
Output
-1 -1
Explanation:
There are no elements after 1 which is less than 1 and there are no elements after 2. , I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
long res[]=new long[n];
Arrays.fill(res,-1);
Stack<Integer> stack=new Stack<>();
stack.push(0);
for(int i=1;i<n;i++){
while(!stack.isEmpty() && a[i] < a[stack.peek()]){
res[stack.pop()]=a[i];
}
stack.push(i);
}
for(int k=0;k<n;k++){
System.out.print(res[k]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
def checkSpecial_M_Visor(N,M) :
# Final result of summation of divisors
i=2;
count=0
while i<=N :
if(N%i==0):
count=count+1
i=i+2
if(count == M):
return "Yes"
return "No"
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
static String checkSpecial_M_Visor(int N, int M)
{
int temp=0;
for(int i = 2; i <=N; i+=2)
{
if(N%i==0)
temp++;
}
if(temp==M)
return "Yes";
else return "No";
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
string checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
if(count==M){return "Yes";}
return "No";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
char* ans;
if(count==M){return "Yes";}
return "No";
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 0., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader bd=new BufferedReader(new InputStreamReader(System.in));
String st1=bd.readLine();
int n=Integer.parseInt(st1);
int arr[]=new int[n];
String[] st2=bd.readLine().split(" ");
for(int i=0; i<n; i++){
arr[i]=Integer.parseInt(st2[i]);
}
long sum_till_here_forward = 0;
long max_sum_forward = 0;
long sum_till_here_backward = 0;
long max_sum_backward = 0;
long sum_forward[] = new long[n+1];
long sum_backward[] = new long[n+1];
long maximum=0;
if(n==2){
maximum=Math.max(arr[0],arr[1]);
}
else{
for(int i=0; i<n; i++){
sum_till_here_forward += arr[i];
if(sum_till_here_forward > max_sum_forward){
max_sum_forward = sum_till_here_forward;
}
if(sum_till_here_forward < 0){
sum_till_here_forward = 0;
}
sum_forward[i+1] = max_sum_forward;
}
for(int i=n-1; i>=0; i--){
sum_till_here_backward += arr[i];
if(sum_till_here_backward > max_sum_backward){
max_sum_backward = sum_till_here_backward;
}
if(sum_till_here_backward < 0){
sum_till_here_backward=0;
}
sum_backward[i+1] = max_sum_backward;
}
for(int i=1; i<n; i++){
maximum=Math.max(maximum,(sum_forward[i-1]+sum_backward[i+1]));
}
}
System.out.print(maximum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 0., I have written this Solution Code: n=int(input())
l=list(map(int,input().split()))
left=[]
for i in range(n):
left.append(0)
curr_max=l[0]
max_so_far=l[0]
for i in range(1,n):
left[i]=max_so_far
curr_max = max(l[i], curr_max+l[i])
max_so_far = max(max_so_far, curr_max)
right=[]
for i in range(n):
right.append(0)
curr_max=l[n-1]
max_so_far=l[n-1]
for i in range(n-2,-1,-1):
right[i]=max_so_far
curr_max = max(l[i], curr_max+l[i])
max_so_far = max(max_so_far, curr_max)
ans=0
for i in range(n):
ans=max(ans,left[i]+right[i])
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: After sitting idle in home for around 2 months, Jiraya has finally come up with a super interesting problem on arrays (or maybe!).
You are given an array A of N integers. You need to choose an index i from 1 to N (inclusive) and divide this array into 2 parts, then find the maximum sum of contiguous subarray in both the parts of arrays and add the obtained values from the two arrays.
What is the maximum sum that you can obtain?
Note: The element at index i is not a part of any of the generated arrays, choosing an empty subarray is allowed, one of the generated array is empty if i=1 or i=N (its maximum subarray sum will be 0).
See sample for better understanding.The first line of input contains a single integer N.
The second line of input contains N integers A[1], A[2],. , A[N]
Constraints
2 <= N <= 200000
-1000000 <= A[i] <= 1000000Output a single integer, the answer to the above problem.
(The answer may not fit into integer data type)Sample Input
6
-5 -1 4 -3 5 -4
Sample Output
9
Explanation: We choose i = 4. The two arrays are [-5, -1, 4] and [5, -4]. The maximum sum of contiguous subarrays are 4 and 5 respectively. Therefore, the answer is 4 + 5 = 9.
Sample Input
5
-1 -1 -1 -1 -1
Sample Output
0
Explanation: We choose i = 3. The two arrays are [-1, -1] and [-1, -1]. The maximum sum of contiguous subarrays are 0 and 0 respectively (empty subarrays). Therefore, the answer is 0 + 0 = 0., 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 ld 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
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 200005;
// 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
vector<int> a;
int n;
vector<int> kadane(){
int cur = 0;
int mx = 0;
vector<int> vect(n);
for(int i=0; i<n; i++){
cur += a[i];
mx = max(mx, cur);
if(cur < 0)
cur = 0;
vect[i]=mx;
}
return vect;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n;
for(int i=0; i<n; i++){
int x; cin>>x;
a.pb(x);
}
vector<int> v1 = kadane();
reverse(all(a));
vector<int> v2 = kadane();
reverse(all(v2));
int ans = 0;
For(i, 0, n){
if(i>0 && i<n-1)
ans = max(ans, v1[i-1]+v2[i+1]);
else if(i==0)
ans = max(ans, v2[i+1]);
else
ans = max(ans, v1[i-1]);
}
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two elements A and B, your task is to swap the given two elements.<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>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:-
5 7
Sample Output:-
7 5
Sample Input:-
3 6
Sample Output:-
6 3, I have written this Solution Code: class Solution {
public static void Swap(int A, int B){
int C = A;
A = B;
B = C;
System.out.println(A + " " + B);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two elements A and B, your task is to swap the given two elements.<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>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:-
5 7
Sample Output:-
7 5
Sample Input:-
3 6
Sample Output:-
6 3, I have written this Solution Code: # Python program to swap two variables
li= list(map(int,input().strip().split()))
x=li[0]
y=li[1]
# create a temporary variable and swap the values
temp = x
x = y
y = temp
print(x,end=" ")
print(y,end="")
, 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: 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: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array.
Constraints:-
1 <= N <= 10000
1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:-
3
1 2 3 4 5 6
Sample Output:-
1 4 2 5 3 6
Sample Input:-
2
2 4 6 8
Sample Output:-
2 6 4 8, I have written this Solution Code: a=input()
a=int(a)
arr=input().split()
i=0
j=int(len(arr)/2)
while(i<len(arr)/2):
print (arr[i], arr[j], end=' ')
i+=1
j+=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array.
Constraints:-
1 <= N <= 10000
1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:-
3
1 2 3 4 5 6
Sample Output:-
1 4 2 5 3 6
Sample Input:-
2
2 4 6 8
Sample Output:-
2 6 4 8, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 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);
}
signed main()
{
int n;
cin>>n;
int a[2*n];
FOR(i,2*n){
cin>>a[i];}
FOR(i,n){
cout<<a[i]<<" "<<a[n+i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array.
Constraints:-
1 <= N <= 10000
1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:-
3
1 2 3 4 5 6
Sample Output:-
1 4 2 5 3 6
Sample Input:-
2
2 4 6 8
Sample Output:-
2 6 4 8, 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[2*n];
int j=0;
for(int i=0;i<2*n;i++){
a[j]=sc.nextInt();
j+=2;
if(j>=2*n){
j=1;
}
}
for(int i=0;i<2*n;i++){
System.out.print(a[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t= Integer.parseInt(br.readLine());
if(t%2==0)
System.out.println("Even");
else
System.out.println("Odd");
}
catch (Exception e){
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: n = int(input())
if n % 2 == 0:
print("Even")
else:
print("Odd"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch(num % 2)
{
case 0:
printf("Even");
break;
/* Else if n%2 == 1 */
case 1:
printf("Odd");
break;
}
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. <b>Value</b> of an element A<sub>i</sub> is defined as the sum of the absolute difference of all elements of the array with A<sub>i</sub>. More formally, the value of an element at index i is the sum of |A<sub>i</sub> - A<sub>j</sub>| over all j (1 <= j <= N). Find the maximum such value over all i (1 <= i <= N) in the array.
<b>Note</b>: Given array is 1-based indexThe first line of the input contains a single integer N.
The second line of the input contains N space-separated integers.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ A<sub>i</sub> ≤ 10<sup>9</sup>Print the maximum such value over all i (1 <= i <= N) in the array.Sample Input:
6
1 1 5 5 8 9
Sample Output:
25
<b>Explanation:</b>
For, i = 6,
|A<sub>1</sub> - A<sub>6</sub>| = 8
|A<sub>2</sub> - A<sub>6</sub>| = 8
|A<sub>3</sub> - A<sub>6</sub>| = 4
|A<sub>4</sub> - A<sub>6</sub>| = 4
|A<sub>5</sub> - A<sub>6</sub>| = 1
Value = 8 + 8 + 4 + 4 + 1 = 25
For all other i, give values less than 25., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long double ld;
const int mod = 1e9 + 7;
const int INF = 2e9;
void solve(){
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<int> pre(n + 1);
for(int i = 1; i <= n; i++){
pre[i] = pre[i - 1] + a[i];
}
int ans = 0;
for(int i = 1; i <= n; i++){
ans = max(ans, (pre[n] - pre[i]) - ((n - i) * (a[i])) + ((i-1)* a[i]) - pre[i - 1]);
}
cout << ans;
}
signed main(){
fast
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
if(i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String [] str=br.readLine().trim().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
int size=a[n-1]+1;
int c[]=new int[size];
for(int i=0;i<size;i++) c[i]=0;
for(int i=0;i<n;i++) c[a[i]]++;
int max=0,freq=c[1];
for(int i=2;i<size;i++){
if(freq<=c[i]){
freq=c[i];
max=i;
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: n = int(input())
a = [int(x) for x in input().split()]
freq = {}
for x in a:
if x not in freq:
freq[x] = 1
else:
freq[x] += 1
mx = max(freq.values())
rf = sorted(freq)
for i in range(len(rf) - 1, -1, -1):
if freq[rf[i]] == mx:
print(rf[i])
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, 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 n; cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
int mx = 0, id = -1;
for(int i = 1; i <= 100; i++){
if(a[i] >= mx)
mx = a[i], id = i;
}
cout << id;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are A Bacterias.
Each time Jerry shouts, the bacterias multiply by K times.
In order to have B or more slimes, at least how many times does Jerry need to shout?Input is given from Standard Input in the following format:
A B K
<b>Constraints</b>
1≤A≤B≤10^9
2≤K≤10^9
All values in input are integers.Print the answer.<b>Sample Input 1</b>
1 4 2
<b>Sample Output 1</b>
2
<b>Sample Input 2</b>
7 7 10
<b>Sample Output 2</b>
0
<b>Sample Input 3</b>
31 415926 5
<b>Sample Output 3</b>
6
(In first case, after the first shout Jerry will have 2 bacteria and after the second shout, he will have 4(2*2) bacteria., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define subnb true
#define Lnb true
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, k;
cin >> a >> b >> k;
int res = 0;
while(a < b) {
a *= k;
res++;
}
cout << res << '\n';
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 ≤ T ≤ 10
0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("").append(String.valueOf(object));
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) throws Exception{
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
int testCases=in.nextInt();
while(testCases-- > 0) {
int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
while ((a>0&&b>0)||(a>0&&c>0)||(b>0&&c>0)) {
if (a >= b && a >= c) {
a--;
if (b >= c) {
b--;
}
else{
c--;
}
}
else if (b >= a && b >= c) {
b--;
if (a >= c) {
a--;
}
else{
c--;
}
}
else{
c--;
if (a >= b) {
a--;
}
else{
b--;
}
}
}
if (a==0&&b==0&&c==0){
out.println("Yes");
}
else{
out.println("No");
}
}
out.close();
} catch (Exception e) {
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 ≤ T ≤ 10
0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: t=int(input())
for i in range(t):
arr=list(map(int,input().split()))
a,b,c=sorted(arr)
if((a+b+c)%2):
print("No")
elif ((a+b)>=c):
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them.
If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases.
Each of the next T lines contains 3 space separated integers A, B and C respectively.
<b> Constraints: </b>
1 ≤ T ≤ 10
0 ≤ A, B, C ≤ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1:
2
3 4 2
2 2 2
Sample Output 1:
No
Yes
Sample Explanation 1:
For the first test case, there is no possible way to make all the elements zero.
For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long powm(long long a, long long b,long long mod) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a %mod;
a = a * a %mod;
b >>= 1;
}
return res;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if(fopen("input.txt","r"))
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
#endif
int t;
cin>>t;
while(t--)
{
int a,b,c;
cin>>a>>b>>c;
if(a>b+c||b>a+c||c>a+b)
cout<<"No\n";
else
{
int sum=a+b+c;
if(sum%2)
cout<<"No\n";
else
cout<<"Yes\n";
}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Bob loves to play with numbers. He has an integer N. Find the number of digits that N has in base K.The input contains two space-separated integers in the following format:
N K
<b>Constraints</b>
All values in the input are integers.
1 ≤ N ≤ 10<sup>9</sup>
2 ≤ K ≤ 10Print the number of digits that N has in base K.<b>Sample Input 1</b>
11 2
<b>Sample Output 1</b>
4
<b>Sample Input 2</b>
1010101 10
<b>Sample Output 2</b>
7
<b>Sample Input 3</b>
314159265 3
<b>Sample Output 3</b>
18, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=1000000007,MAX=200005,INF=1<<30;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;cin>>N>>K;
int cnt=0;
while(N){
N-=N%K;
N/=K;
cnt++;
}
cout<<cnt<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void sieve(boolean prime[], int n) {
int i,j;
for(i = 0; i <= n; i++)
prime[i] = true;
for(i = 2; i*i <= n; i++)
if(prime[i])
for(j = i*i; j<=n; j+=i)
prime[j] = false;
}
public static void main (String[] args) throws IOException {
int num = 10000005;
boolean prime[] = new boolean[num+1];
sieve(prime, num);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T --> 0) {
int n = Integer.parseInt(br.readLine().trim());
int count = 0;
for(int i=(n/2)+1; i<=n; i++)
if(prime[i])
count++;
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
bool a[max1];
long b[max1];
void pre(){
b[0]=0;b[1]=0;
for(int i=0;i<max1;i++){
a[i]=false;
}
long cnt=0;
for(int i=2;i<max1;i++){
if(a[i]==false){
cnt++;
for(int j=i+i;j<=max1;j=j+i){a[j]=true;}
}
b[i]=cnt;
}
}
int main(){
pre();
int t;
cin>>t;
while(t--){
long n;
cin>>n;
cout<<(b[n]-b[(n)/2])<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
static int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code:
int commonFactors(int A,int B,int C){
int cnt=0;
for(int i=1;i<=A;i++){
if(A%i==0){
if(B%i==0 || C%i==0){cnt++;}
}
}
for(int i=1;i<=B;i++){
if(B%i==0){
if(A%i!=0 && C%i==0){cnt++;}
}
}
return cnt;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B and C. Your task is to calculate the number of integers which are factors of atleast two given numbers.<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>CommonFactors()</b> that takes the integers A, B and C as parameters.
<b>Constraints:</b>
1 <= A, B, C <= 100000Return the count of common factors.Sample Input:-
3 6 12
Sample Output:-
4
Explanation:- 1, 2, 3, 6 are the required factors
Sample Input:-
1 2 3
Sample Output:-
1, I have written this Solution Code: def CommonFactors(A,B,C):
cnt=0
for i in range (1,A+1):
if(A%i==0):
if(B%i==0) or (C%i==0):
cnt=cnt+1
for i in range (1,B+1):
if(B%i==0):
if(A%i!=0) and (C%i==0):
cnt = cnt +1
return cnt
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, I have written this Solution Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int a = -1 , b = 0, c= 0, d = 0;
for(int i = 0 ; i < s.length() ; i++){
if(s.charAt(i) == 'a')
a++;
else if(s.charAt(i) == 'b')
b++;
else if(s.charAt(i) == 'c')
c++;
else if(s.charAt(i) == 'd')
d++;
}
if(a==-1)
System.out.print(0);
else
System.out.print(findmin(a,b,c,d));
}
static int findmin(int a, int b, int c , int d){
int f , s ;
f = Math.min(a,b); s = Math.min(c, d);
return Math.min(f,s);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, I have written this Solution Code: arr=input()
a=0
b=0
c=0
d=0
for i in range(0,len(arr)):
if(arr[i]=='a'):
a+=1
elif (arr[i]=='b'):
b+=1
elif (arr[i]=='c'):
c+=1
elif (arr[i]=='d'):
d+=1
ans=(min(int(a/2),b,c,d))
ans1=min(a-1,b,c,d)
print (max(ans,ans1)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. You can rearrange its letters in any way you want. You have to the find the maximum number of substrings in S which are equal to "abcda" after rearrangement.First line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
String contains lowercase english letters.Output a single integer which is the maximum number of substrings in S which are equal to "abcda" after rearrangement.Sample Input
cbdaaabcda
Sample Output
2
Explanation : we can rearrange the given string as abcdaabcda, 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]={};
for(auto r:s){
c[r-'a']++;
}
int ans=min(min(c[0]-1,c[1]),min(c[2],c[3]));
if(ans<0)
ans=0;
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: 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: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code:
#include <iostream>
using namespace std;
int Dishes(int N, int T){
return T-N;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
printf("%d",Dishes(n,k));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K and an array height[] of size N, where height[i] denotes the height of the ith tree in a forest. The task is to make a cut of height X from the ground such that at max K units wood is collected. Find the minimum value of X
<b>If you make a cut of height X from the ground then every tree with a height greater than X will be reduced to X and the remaining part of the wood can be collected</b>The first line contains two integers N and K.
The next line contains N integers denoting the elements of the array height[]
<b>Constraints</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ arr[i] ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>7</sup>Print a single integer with the value of X.Sample Input:
4 2
1 2 1 2
Sample Output:
1
<b>Explanation:</b>
Make a cut at height 1, the updated array will be {1, 1, 1, 1} and
the collected wood will be {0, 1, 0, 1} i. e. 0 + 1 + 0 + 1 = 2., I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++)
arr[i] = sc.nextInt();
System.out.println(minValue(arr, n, k));
}
static int minValue(int arr[], int N, int k)
{
int l = 0, h = N;
while(l+1 < h){
int m = (l + h) >> 1;
if(f(arr, m, N) <= k)
h = m;
else
l = m;
}
return h;
}
static int f(int a[], int x, int n)
{
int sum = 0;
for(int i = 0; i < n; i++)
sum += Math.max(a[i]-x, 0);
return sum;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K and an array height[] of size N, where height[i] denotes the height of the ith tree in a forest. The task is to make a cut of height X from the ground such that at max K units wood is collected. Find the minimum value of X
<b>If you make a cut of height X from the ground then every tree with a height greater than X will be reduced to X and the remaining part of the wood can be collected</b>The first line contains two integers N and K.
The next line contains N integers denoting the elements of the array height[]
<b>Constraints</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ arr[i] ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>7</sup>Print a single integer with the value of X.Sample Input:
4 2
1 2 1 2
Sample Output:
1
<b>Explanation:</b>
Make a cut at height 1, the updated array will be {1, 1, 1, 1} and
the collected wood will be {0, 1, 0, 1} i. e. 0 + 1 + 0 + 1 = 2., I have written this Solution Code: def minCut(arr,k):
mini = 1
maxi = k
mid = 0
while mini<=maxi:
mid = mini + int((maxi - mini)/2)
wood = 0
for j in range(n):
if(arr[j]-mid>=0):
wood += arr[j] - mid
if wood == k:
break;
elif wood > k:
mini = mid+1
else:
maxi = mid-1
print(mini)
n,k = list(map(int, input().split()))
arr = list(map(int, input().split()))
minCut(arr,k), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer K and an array height[] of size N, where height[i] denotes the height of the ith tree in a forest. The task is to make a cut of height X from the ground such that at max K units wood is collected. Find the minimum value of X
<b>If you make a cut of height X from the ground then every tree with a height greater than X will be reduced to X and the remaining part of the wood can be collected</b>The first line contains two integers N and K.
The next line contains N integers denoting the elements of the array height[]
<b>Constraints</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ arr[i] ≤ 10<sup>5</sup>
1 ≤ K ≤ 10<sup>7</sup>Print a single integer with the value of X.Sample Input:
4 2
1 2 1 2
Sample Output:
1
<b>Explanation:</b>
Make a cut at height 1, the updated array will be {1, 1, 1, 1} and
the collected wood will be {0, 1, 0, 1} i. e. 0 + 1 + 0 + 1 = 2., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define ll 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;
int a[N], n, k;
int f(int x){
int sum = 0;
for(int i = 1; i <= n; i++)
sum += max(a[i]-x, 0);
return sum;
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, h = N;
while(l+1 < h){
int m = (l + h) >> 1;
if(f(m) <= k)
h = m;
else
l = m;
}
cout << h;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
testcases();
return 0;
} , 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 N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices.
<b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements
The second line contains N different integers separated by spaces
<b>constraints:-</b>
1 <= N <= 35
1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places.
Sample Input 1:
6
1 2 3 4 5 6
Sample Output 1:
9 48
Sample Input 2:
3
1 2 3
Sample Output 2:
2 3
<b>Explanation 1:-</b>
After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1
Hence the sum of the numbers at even indices: 5+3+1=9
product of the numbers at odd indices: 6*4*2=48
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long x=1,y=0;
if(n&1){
for(int i=0;i<n;i++){
if(i%2==0){
x*=a[i];
}
else{
y+=a[i];
}
}
}
else{
for(int i=0;i<n;i++){
if(i%2==0){
y+=a[i];
}
else{
x*=a[i];
}
}
}
cout<<y<<" "<<x;
}
, 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 N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices.
<b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements
The second line contains N different integers separated by spaces
<b>constraints:-</b>
1 <= N <= 35
1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places.
Sample Input 1:
6
1 2 3 4 5 6
Sample Output 1:
9 48
Sample Input 2:
3
1 2 3
Sample Output 2:
2 3
<b>Explanation 1:-</b>
After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1
Hence the sum of the numbers at even indices: 5+3+1=9
product of the numbers at odd indices: 6*4*2=48
, I have written this Solution Code: n = int(input())
lst = list(map(int, input().strip().split()))[:n]
lst.reverse()
lst_1 = 0
for i in range(1, n, 2):
lst_1 += lst[i]
lst_2 = 1
for i in range(0, n, 2):
lst_2 *= lst[i]
print(lst_1,lst_2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices.
<b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements
The second line contains N different integers separated by spaces
<b>constraints:-</b>
1 <= N <= 35
1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places.
Sample Input 1:
6
1 2 3 4 5 6
Sample Output 1:
9 48
Sample Input 2:
3
1 2 3
Sample Output 2:
2 3
<b>Explanation 1:-</b>
After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1
Hence the sum of the numbers at even indices: 5+3+1=9
product of the numbers at odd indices: 6*4*2=48
, 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 Arr[] = new int[n];
for(int i=0;i<n;i++){
Arr[i] = sc.nextInt();
}
if(n%2==1){
long sum=0;
long product=1;
for(int i=0;i<n;i++){
if(i%2==0){
product*=Arr[i];
}
else{
sum+=Arr[i];
}
}
System.out.print(sum+" "+product);
}
else{
long sum=0;
long product=1;
for(int i=0;i<n;i++){
if(i%2==1){
product*=Arr[i];
}
else{
sum+=Arr[i];
}
}
System.out.print(sum+" "+product);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves triangles. Whenever she sees three points she connects them by straight lines to form a triangle. In triangles, her favorite one is a right-angled triangle. If the triangle is not right-angled but it can be converted into one by moving one of the points exactly by distance 1 so, that all the coordinates remain integer, she calls such triangles "Special".
Given three points A, B, and C your task is to check if the formed triangle is "Right", "Special" or "Simple".The first line of input contains the position of A(Ax, Ay). The second line of input contains the position of B(Bx, By). The third line of input contains the position of C(Cx, Cy).
Constraints:-
|X|, |Y| <= 10^9Print "Right" if the triangle is right- angled, print "Special" if the triangle can be formed into a right- angled by moving one of the points exactly by distance 1, else print "Simple".Sample Input:-
0 0
2 0
0 1
Sample Output:-
Right
Sample Input:-
-1 0
2 0
0 1
Sample Output:-
Special
Sample Input:-
-1 0
2 0
10 10
Sample Output:-
Simple, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int dx[] = { -1, 0, 1, 0 };
static int dy[] = { 0, 1, 0, -1 };
static boolean ifRight(int x1, int y1, int x2, int y2, int x3, int y3) {
int a = ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));
int b = ((x1 - x3) * (x1 - x3)) + ((y1 - y3) * (y1 - y3));
int c = ((x2 - x3) * (x2 - x3)) + ((y2 - y3) * (y2 - y3));
if ((a == (b + c) && a != 0 && b != 0 && c != 0) ||
(b == (a + c) && a != 0 && b != 0 && c != 0) ||
(c == (a + b) && a != 0 && b != 0 && c != 0)) {
return true;
}
return false;
}
static void isValidCombination(int x1, int y1, int x2, int y2, int x3, int y3) {
int x, y;
boolean possible = false;
if (ifRight(x1, y1, x2, y2, x3, y3)) {
System.out.print("Right");
return;
}
else {
for (int i = 0; i < 4; i++)
{
x = dx[i] + x1;
y = dy[i] + y1;
if(ifRight(x, y, x2, y2, x3, y3))
{
System.out.print("Special");
return;
}
x = dx[i] + x2;
y = dy[i] + y2;
if(ifRight(x1, y1, x, y, x3, y3)) {
System.out.print("Special");
return;
}
x = dx[i] + x3;
y = dy[i] + y3;
if(ifRight(x1, y1, x2, y2, x, y)) {
System.out.print("Special");
return;
}
}
}
if (!possible) {
System.out.println("Simple");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x1, y1, x2, y2, x3, y3;
x1 = sc.nextInt();
y1 = sc.nextInt();
x2 = sc.nextInt();
y2 = sc.nextInt();
x3 = sc.nextInt();
y3 = sc.nextInt();
isValidCombination(x1, y1, x2, y2, x3, y3);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves triangles. Whenever she sees three points she connects them by straight lines to form a triangle. In triangles, her favorite one is a right-angled triangle. If the triangle is not right-angled but it can be converted into one by moving one of the points exactly by distance 1 so, that all the coordinates remain integer, she calls such triangles "Special".
Given three points A, B, and C your task is to check if the formed triangle is "Right", "Special" or "Simple".The first line of input contains the position of A(Ax, Ay). The second line of input contains the position of B(Bx, By). The third line of input contains the position of C(Cx, Cy).
Constraints:-
|X|, |Y| <= 10^9Print "Right" if the triangle is right- angled, print "Special" if the triangle can be formed into a right- angled by moving one of the points exactly by distance 1, else print "Simple".Sample Input:-
0 0
2 0
0 1
Sample Output:-
Right
Sample Input:-
-1 0
2 0
0 1
Sample Output:-
Special
Sample Input:-
-1 0
2 0
10 10
Sample Output:-
Simple, I have written this Solution Code: def check(s):
a=pow((d[0]-d[2]),2)+pow((d[1]-d[3]),2)
b=pow((d[0]-d[4]),2)+pow((d[1]-d[5]),2)
c=pow((d[2]-d[4]),2)+pow((d[3]-d[5]),2)
if ((a and b and c)==0):
return
if (a+b==c or a+c==b or b+c==a):
print(s)
exit(0)
d = list()
for i in range(0,3):
val = list(map(int,input().strip().split()))
d.append(val[0])
d.append(val[1])
check("Right\n")
for i in range(0,6):
d[i]=d[i]-1
check("Special\n")
d[i]=d[i]+2
check("Special\n")
d[i]=d[i]-1
print("Simple"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves triangles. Whenever she sees three points she connects them by straight lines to form a triangle. In triangles, her favorite one is a right-angled triangle. If the triangle is not right-angled but it can be converted into one by moving one of the points exactly by distance 1 so, that all the coordinates remain integer, she calls such triangles "Special".
Given three points A, B, and C your task is to check if the formed triangle is "Right", "Special" or "Simple".The first line of input contains the position of A(Ax, Ay). The second line of input contains the position of B(Bx, By). The third line of input contains the position of C(Cx, Cy).
Constraints:-
|X|, |Y| <= 10^9Print "Right" if the triangle is right- angled, print "Special" if the triangle can be formed into a right- angled by moving one of the points exactly by distance 1, else print "Simple".Sample Input:-
0 0
2 0
0 1
Sample Output:-
Right
Sample Input:-
-1 0
2 0
0 1
Sample Output:-
Special
Sample Input:-
-1 0
2 0
10 10
Sample Output:-
Simple, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int d[6];
int sq(int n)
{
return n*n;
}
void check(char *s)
{
int a,b,c;
a=sq(d[0]-d[2])+sq(d[1]-d[3]);
b=sq(d[0]-d[4])+sq(d[1]-d[5]);
c=sq(d[2]-d[4])+sq(d[3]-d[5]);
if ((a&&b&&c)==0)
return;
if (a+b==c||a+c==b||b+c==a)
{
cout << s;
exit(0);
}
}
int main()
{
int i;
for (i=0;i<6;i++)
cin >> d[i];
check("Right\n");
for (i=0;i<6;i++)
{
d[i]--;
check("Special\n");
d[i]+=2;
check("Special\n");
d[i]--;
}
cout << "Simple";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a stack of integers and N queries. Your task is to perform these operations:-
<b>push:-</b>this operation will add an element to your current stack.
<b>pop:-</b>remove the element that is on top
<b>top:-</b>print the element which is currently on top of stack
<b>Note:-</b>if the stack is already empty then the pop operation will do nothing and 0 will be printed as a top element of the stack if it is empty.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>push()</b>:- that takes the stack and the integer to be added as a parameter.
<b>pop()</b>:- that takes the stack as parameter.
<b>top()</b> :- that takes the stack as parameter.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>3</sup>You don't need to print anything else other than in <b>top</b> function in which you require to print the topmost element of your stack in a new line, if the stack is empty you just need to print 0.Input:
7
push 1
push 2
top
pop
top
pop
top
Output:
2
1
0
, I have written this Solution Code:
public static void push (Stack < Integer > st, int x)
{
st.push (x);
}
// Function to pop element from stack
public static void pop (Stack < Integer > st)
{
if (st.isEmpty () == false)
{
int x = st.pop ();
}
}
// Function to return top of stack
public static void top(Stack < Integer > st)
{
int x = 0;
if (st.isEmpty () == false)
{
x = st.peek ();
}
System.out.println (x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: static int LikesBoth(int N, int A, int B){
return (A+B-N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: def LikesBoth(N,A,B):
return (A+B-N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: int LikesBoth(int N,int A, int B){
return (A+B-N);
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: N people are standing in a queue in which A of them like apple and B of them like oranges. How many people like both apple and oranges.
<b>Note</b>:- It is guaranteed that each and every person likes at least one of the given two.<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>LikesBoth()</b> that takes integers N, A, and B as arguments.
Constraints:-
1 <= N <= 10000
1 <= A <= N
1 <= B <= NReturn the number of people that like both of the fruit.Sample Input:-
5 3 4
Sample Output:-
2
Sample Input:-
5 5 5
Sample Output:-
5, I have written this Solution Code: int LikesBoth(int N,int A, int B){
return (A+B-N);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's the sale season and Ankit bought items worth a total of X rupees. The sale season offer is as follows: <ul><li>if X ≤ 100, no discount. </li><li>if 100 < X ≤ 1000, discount is 25 rupees. </li><li>if 1000 < X ≤ 5000, discount is 100 rupees. </li><li>if X > 5000, discount is 500 rupees. </li></ul>Find the final amount Ankit needs to pay for his shopping.The first line of input will contain a single integer T, denoting the number of test cases. Each test case consists of single line of input containing an integer X.
<b>Constraints</b>
1 ≤ T ≤ 100
1 ≤ X ≤ 10000For each test case, output on a new line the final amount Ankit needs to pay for his shopping.Sample Input :
4
15
70
250
1000
Sample Output :
15
70
225
975
Explanation :
<ul><li>Since X ≤ 100, there is no discount. </li><li>Here, X = 250. Since 100 < 250 ≤ 1000, discount is of 25 rupees. Therefore, Ankit needs to pay 250 − 25 = 225 rupees., I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define INF 1e9+7
using namespace std;
void solve(){
int x;
cin>>x;
if (x > 100 and x <= 1000)
x -= 25;
else if (x > 1000 and x <= 5000)
x -= 100;
else if (x > 5000)
x -= 500;
cout<<x<<"\n";
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
for(int i=1;i<=t;++i)
{
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array A of size N and value K. The elements of the array A contains positive integers. You have to print all the elements which are greater than K in the array in sorted order (including K as well if present in the array A), and print all the elements which are smaller than K in sorted order both of them in separate lines. If the elements greater than or equal to K are not present in the array then print "-1". Similarly, in the case of smaller elements print -1 if elements smaller than K doesn’t exist. If a number appears more than once print number more than once.First line of input contains number of testcases T. For each testcase, there are two lines, first of which contains N and K separated by space, next line contains N space separated integers.
Constraints:
1 <= T <= 100
1 <= N <= 100000
1 <= K <= 1000000
1 <= A[i] <= 1000000
Sum of N over all test cases do not exceed 100000For each testcase, print the required elements(if any), else print "-1" (without quotes)Input:
1
5 1
2 1 5 7 6
Output:
1 2 5 6 7
-1
Explanation:
Testcase 1 : Since, 1, 2, 5, 6, 7 are greater or equal to given K. Also, no element less than K is present in the array., I have written this Solution Code: import java.io.*;
import java.util.*;
class Reader{
BufferedReader reader;
Reader(){
this.reader = new BufferedReader(new InputStreamReader(System.in));
}
public String read() throws IOException {
return reader.readLine();
}
public int readInt() throws IOException {
return Integer.parseInt(reader.readLine());
}
public long readLong() throws IOException {
return Long.parseLong(reader.readLine());
}
public String[] readArray() throws IOException {
return reader.readLine().split(" ");
}
public int[] readIntegerArray() throws IOException {
String[] str = reader.readLine().split(" ");
int[] arr = new int[str.length];
for(int i=0;i<str.length;i++) arr[i] = Integer.parseInt(str[i]);
return arr;
}
public long[] readLongArray() throws IOException {
String[] str = reader.readLine().split(" ");
long[] arr = new long[str.length];
for(int i=0;i<str.length;i++) arr[i] = Long.parseLong(str[i]);
return arr;
}
}
public class Main {
public static void main(String[] args) throws IOException {
Reader rdr = new Reader();
int t = rdr.readInt();
while(t-- > 0){
int[] str = rdr.readIntegerArray();
int n = str[0];
int k = str[1];
int[] arr = rdr.readIntegerArray();
Arrays.sort(arr);
int c=0;
for(int i=0;i<n;i++){
if(arr[i]>=k){
System.out.print(arr[i]+" ");
c++;
}
}
if(c==0) System.out.print(-1);
System.out.println();
if(c==n) System.out.print(-1);
else for(int i=0;i<n-c;i++) System.out.print(arr[i]+" ");
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.