Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Complete the function <code>repeatWithDelay</code>. You will be given a single argument, <code>count</code>, a number.
This <code>count</code> argument should control the number of times the function should be executed with a 1-second delay. <strong>Use the JS inbuilt function, which repeatedly calls a function after a specific interval of time, to call the function after a 1-second delay </strong>. The function within the inbuilt function (i.e passed as callback) should print <code>"Interval has been executed " + executionCount + " time(s)"</code> to the console. The <code>executionCount</code> should increment as the function is called after every second. When the executionCount is equal to the count argument, clear the interval.
After executing the above function, use another <strong> JS inbuilt function that calls a function after a specific time</strong>. This callback function, within the inbuilt function, should print <code>"Interval execution stopped"</code> to the console. Use the built-in method, to clear the interval after the count+1 delay.
<strong>Note: </strong>You may see <code>"setTimeout was not called"</code> printed on the console. This is because you may have solved the question using loops.The function takes in a number.The function prints a string on the console.let count = 3;
repeatWithDelay(count);
// prints
Interval has been executed 1 time(s)
Interval has been executed 2 time(s)
Interval has been executed 3 time(s)
Interval execution stopped, I have written this Solution Code: function repeatWithDelay(count) {
let executionCount = 0;
let intervalId = setInterval(function() {
executionCount++;
console.log("Interval has been executed " + executionCount + " time(s)");
if (executionCount === count) {
clearInterval(intervalId);
}
}, 1000);
setTimeout(function() {
console.log("Interval execution stopped");
clearInterval(intervalId);
}, (count + 1) * 1000);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers βaβ and βmβ. The task is to find modular multiplicative inverse of βaβ under modulo βmβ.
Note: Print the smallest modular multiplicative inverse.First line of input contains a single integer T denoting number of test cases, next T lines contains two space separated integers depicting value of a and m.
Constraints :-
1 < = T < = 100
1 < = m < = 100
1 < = a < = mFor each test case, in a new line print the modular multiplicative inverse if exist else print -1.Sample Input:-
2
3 11
10 17
Sample Output:-
4
12, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine().trim());
while(t-->0){
String str[]=br.readLine().trim().split(" ");
int a=Integer.parseInt(str[0]);
int m=Integer.parseInt(str[1]);
int b;
int flag=0;
for(b=1; b<m; b++){
if(((a%m)*(b%m))%m == 1){
flag=1;
break;
}
}
if(flag==0){
System.out.println(-1);
}else{
System.out.println(b);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers βaβ and βmβ. The task is to find modular multiplicative inverse of βaβ under modulo βmβ.
Note: Print the smallest modular multiplicative inverse.First line of input contains a single integer T denoting number of test cases, next T lines contains two space separated integers depicting value of a and m.
Constraints :-
1 < = T < = 100
1 < = m < = 100
1 < = a < = mFor each test case, in a new line print the modular multiplicative inverse if exist else print -1.Sample Input:-
2
3 11
10 17
Sample Output:-
4
12, I have written this Solution Code: def modInverse(a, m):
for x in range(1, m):
if (((a%m)*(x%m) % m )== 1):
return x
return -1
t = int(input())
for i in range(t):
a ,m = map(int , input().split())
print(modInverse(a, m)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers βaβ and βmβ. The task is to find modular multiplicative inverse of βaβ under modulo βmβ.
Note: Print the smallest modular multiplicative inverse.First line of input contains a single integer T denoting number of test cases, next T lines contains two space separated integers depicting value of a and m.
Constraints :-
1 < = T < = 100
1 < = m < = 100
1 < = a < = mFor each test case, in a new line print the modular multiplicative inverse if exist else print -1.Sample Input:-
2
3 11
10 17
Sample Output:-
4
12, I have written this Solution Code:
// author-Shivam gupta
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int modInverseNaive(int a, int m) {
a %= m;
for (int x = 1; x < m; x++) {
if ((a*x) % m == 1) return x;
}
return -1;
}
signed main() {
int t;
cin >> t;
while (t-- > 0) {
int a,m;
cin >> a >> m;
cout << modInverseNaive(a, m) << '\n';
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a[] = br.readLine().split(" ");
double n = Integer.parseInt(a[0]);
double R = Integer.parseInt(a[1]);
double r = Integer.parseInt(a[2]);
R=R-r;
double count = 0;
double d = Math.asin(r/R);
count = Math.PI/d;
if(n<=count)
System.out.print("Yes");
else
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: import math
arr = list(map(int, input().split()))
n = arr[0]
R = arr[1]
r = arr[2]
if(r>R or n>1 and (R-r)*math.sin(math.acos(-1.0)/n)+1e-8<r):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has guests coming over to her house for dinner. She has a circular dining table of radius R and circular plates of radius r. Now she wonders if her table has enough space for all the guests, considering each guest takes one plate and the plate should lie completely inside the table.The input contains three space- separated integers N(Number of guests), R, and r.
Constraints:-
1 <= N <= 100
1 <= r, R <= 1000Print "Yes" if there is enough space, else print "No".Sample Input:-
4 10 4
Sample Output:-
Yes
Sample Input:-
5 10 4
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
int R,r,n;
cin>>n>>R>>r;
cout<<(r>R || n>1&& (R-r)*sin(acos(-1.0)/n)+1e-8<r ?"No":"Yes");
return 0;
}
//1340
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a marathon to be run on a circular track. There are N checkpoints on the track where energy drinks are placed. Checkpoints are numbered from 1 to N (both inclusive). For each checkpoint, you know the distance to the next checkpoint and also the energy replenished by the drink at this checkpoint.
Toros is going to take part in the marathon. For every 1 unit distance covered by him, his energy decreases by 1. He can't run further if he has 0 energy. Find the minimum index of the point where he should start so that he can visit every checkpoint at least once. Initially, he has 0 energy.The first line contains a single integer N, denoting the number of checkpoints.
The next N lines contain two space-separated integers, E[i] and D[i], denoting the energy replenished by the energy drink kept at the ith checkpoint and the distance to the next checkpoint.
<b>Constraints</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ E[i], D[i] ≤ 10<sup>9</sup>
Print a single integer containing the minimum index of the checkpoint where Toros should start so that he can complete the race.
If no such point exists, print -1Sample Input 1:
3
1 5
10 3
3 4
Sample Output 1:
2
Sample Input 2:-
3
2 4
5 4
2 7
Sample Output 2:-
-1
Sample Input 3:-
5
1 4
5 6
3 1
7 2
5 8
Sample Output 3:-
3
<b>Explanation 1:</b>
Toros starts at index 2 and drinks energy drinks. So, current energy = 10. At index 3, energy = 10 - 3 + 3 = 10. At index 1 energy = 10 - 4 + 1 = 7., I have written this Solution Code: #include<bits/stdc++.h>
//#define int long long
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N], b[N];
void solve(){
int n; cin >> n;
bool flag = 0;
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
int l = 0, r = 0;
int sum = 0, d, c = 0;
while((l + 1)%n != r && c < 2){
d = a[l] - b[l];
if(sum + d >= 0)
l++, sum += d;
else
sum = 0, l++, r = l;
if(l == n) c++;
l %= n;
}
if(c == 2) cout << -1 << endl;
else cout << r+1 << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a marathon to be run on a circular track. There are N checkpoints on the track where energy drinks are placed. Checkpoints are numbered from 1 to N (both inclusive). For each checkpoint, you know the distance to the next checkpoint and also the energy replenished by the drink at this checkpoint.
Toros is going to take part in the marathon. For every 1 unit distance covered by him, his energy decreases by 1. He can't run further if he has 0 energy. Find the minimum index of the point where he should start so that he can visit every checkpoint at least once. Initially, he has 0 energy.The first line contains a single integer N, denoting the number of checkpoints.
The next N lines contain two space-separated integers, E[i] and D[i], denoting the energy replenished by the energy drink kept at the ith checkpoint and the distance to the next checkpoint.
<b>Constraints</b>
1 ≤ N ≤ 10<sup>5</sup>
1 ≤ E[i], D[i] ≤ 10<sup>9</sup>
Print a single integer containing the minimum index of the checkpoint where Toros should start so that he can complete the race.
If no such point exists, print -1Sample Input 1:
3
1 5
10 3
3 4
Sample Output 1:
2
Sample Input 2:-
3
2 4
5 4
2 7
Sample Output 2:-
-1
Sample Input 3:-
5
1 4
5 6
3 1
7 2
5 8
Sample Output 3:-
3
<b>Explanation 1:</b>
Toros starts at index 2 and drinks energy drinks. So, current energy = 10. At index 3, energy = 10 - 3 + 3 = 10. At index 1 energy = 10 - 4 + 1 = 7., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n>10000){
System.out.print(-1);
return;
}
int[] remEnrgy = new int[n];
for(int i=0;i<n;i++) {
int e = sc.nextInt();
int d = sc.nextInt();
remEnrgy[i] = e-d;
}
for(int i=0;i<n;i++) {
if(remEnrgy[i] >= 0){
if(run(remEnrgy,i)) {
System.out.print(i+1);
return;
}
}
}
System.out.print(-1);
}
private static boolean run(int[]arr,int idx) {
long enrgy = 0;
if(idx==0){
for(int i=0;i<arr.length-1;i++) {
enrgy += arr[i];
if(enrgy<0){
return false;
}
}
return true;
}
for(int i=idx;i<arr.length;i++) {
enrgy += arr[i];
if(enrgy<0){
return false;
}
}
for(int i=0;i<idx-1;i++) {
enrgy += arr[i];
if(enrgy<0){
return false;
}
}
return true;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code: function numberOfDays(n)
{
let ans;
switch(n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans = Number(31);
break;
case 2:
ans = Number(28);
break;
default:
ans = Number(30);
break;
}
return ans;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the number of the month, your task is to calculate the number of days present in the particular month.
<b>Note:-</b>
Consider non-leap yearUser task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>numberofdays()</b> which contains M as a parameter.
<b>Constraints:-</b>
1 <= M <= 12Print the number of days in the particular month.Sample Input 1:-
1
Sample Output 1:
31
Sample Input 2:-
2
Sample Output 2:-
28, I have written this Solution Code:
static void numberofdays(int M){
if(M==4 || M ==6 || M==9 || M==11){System.out.print(30);}
else if(M==2){System.out.print(28);}
else{
System.out.print(31);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, 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().split(" ");
int N=Integer.parseInt(str[0]);
int K=Integer.parseInt(str[1]);
str=br.readLine().split(" ");
int[] arr=new int[N];
for(int i=0;i<N;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
Arrays.sort(arr);
int i=0;
boolean flag=false;
int index=binarySearch(arr,0,N-1,K-i);
while(index!=-1)
{
i++;
index=binarySearch(arr,0,index,K-i);
if(index!=-1)
{
index=binarySearch(arr,index,N-1,K+i);
}
else
flag=true;
}
if(flag)
System.out.print(K-i);
else
System.out.print(K+i);
}
public static int binarySearch(int[] arr,int start,int end,int key)
{
while(start<=end)
{
int mid=(start+end)/2;
if(arr[mid]==key)
return mid;
else if(arr[mid]>key)
end=mid-1;
else
start=mid+1;
}
return -1;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, I have written this Solution Code: size,k = map(int,input().split())
lis = list(map(int,input().split()))
l=[]
m=0
for i in lis:
if(k+m in lis and k-m in lis):
m=m+1
else:
if(k-m in lis):
print(k+m)
else:
print(k-m)
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array <b>A</b> of size <b>N</b>. You need to find the integer not present in this array that is closest to <b>K</b>. The closeness between two numbers A[i] and A[j] is defined as <b>abs(A[i] - A[j])</b>.
For Example:
For given array A = [1,2,5,6,13]
For given K = 12
Output: 12
Explanation: numbers missing 3, 4, 7,8, 9, 10, 11, 12, 14, 15....
and K = 12, so distance from each missing number is (3,9), (4,8), ....
where every pair denotes (missing number, distance) hence 12 is answer.The first line of the input contains two integers N and K.
Constraints
1 <= N <= 1000
1 <= A[i] <= 10000
1 <= K <= 10000
(The array may not contain all distinct numbers)Output the required closest number.Sample Input
5 6
4 7 10 6 5
Sample Output
8
Explanation: Closeness of 8 is 2. There is no such number that has closeness lesser than this and is not a part of array.
Sample Input
5 10
4 7 10 6 5
Sample Output
9, 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
void solve(){
int x, n; cin>>n>>x;
set<int> s;
For(i, 0, n){
int a; cin>>a;
s.insert(a);
}
int v = INF;
int cur = -INF;
For(i, -1, 20001){
if(s.find(i)!=s.end())
continue;
if(abs(i-x)<v){
cur = i;
v = abs(i-x);
}
}
cout<<cur;
}
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: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args)throws IOException {
Reader sc = new Reader();
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0;i<N;i++){
arr[i] = sc.nextInt();
}
int max=0;
if(arr[0]<arr[N-1])
System.out.print(N-1);
else{
for(int i=0;i<N-1;i++){
int j = N-1;
while(j>i){
if(arr[i]<arr[j]){
if(max<j-i){
max = j-i;
} break;
}
j--;
}
if(i==j)
break;
if(j==N-1)
break;
}
if(max==0)
System.out.print("-1");
else
System.out.print(max);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
/* For a given array arr[],
returns the maximum j β i such that
arr[j] > arr[i] */
int maxIndexDiff(int arr[], int n)
{
int maxDiff;
int i, j;
int *LMin = new int[(sizeof(int) * n)];
int *RMax = new int[(sizeof(int) * n)];
/* Construct LMin[] such that
LMin[i] stores the minimum value
from (arr[0], arr[1], ... arr[i]) */
LMin[0] = arr[0];
for (i = 1; i < n; ++i)
LMin[i] = min(arr[i], LMin[i - 1]);
/* Construct RMax[] such that
RMax[j] stores the maximum value from
(arr[j], arr[j+1], ..arr[n-1]) */
RMax[n - 1] = arr[n - 1];
for (j = n - 2; j >= 0; --j)
RMax[j] = max(arr[j], RMax[j + 1]);
/* Traverse both arrays from left to right
to find optimum j - i. This process is similar to
merge() of MergeSort */
i = 0, j = 0, maxDiff = -1;
while (j < n && i < n)
{
if (LMin[i] < RMax[j])
{
maxDiff = max(maxDiff, j - i);
j = j + 1;
}
else
i = i + 1;
}
return maxDiff;
}
// Driver Code
signed main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int maxDiff = maxIndexDiff(a, n);
cout << maxDiff;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
rightMax = [0] * n
rightMax[n - 1] = arr[n - 1]
for i in range(n - 2, -1, -1):
rightMax[i] = max(rightMax[i + 1], arr[i])
maxDist = -2**31
i = 0
j = 0
while (i < n and j < n):
if (rightMax[j] >= arr[i]):
maxDist = max(maxDist, j - i)
j += 1
else:
i += 1
if maxDist==0:
maxDist=-1
print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a queue of integers and N queries. Your the task is to perform these operations:-
enqueue:-this operation will add an element to your current queue.
dequeue:-this operation will delete the element from the starting of the queue
displayfront:-this operation will print the element presented at front
Note:-if queue is empty than dequeue operation will do nothing, and 0 will be printed as a front element of queue if it is empty.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>enqueue()</b>:- that takes the queue and the integer to be added as a parameter.
<b>dequeue</b>:- that takes the queue as parameter.
<b>displayfront</b> :- that takes the queue as parameter.
Constraints:
1 <= N(Number of queries) <= 10<sup>3</sup>You don't need to print anything else other than in displayfront() in which you require to print the element at front of your queue in a new line, if the queue is empty you just need to print 0.Sample Input:-
7
displayfront
enqueue 2
displayfront
enqueue 4
displayfront
dequeue
displayfront
Sample Output:-
0
2
2
4
Sample input:
5
enqueue 4
enqueue 5
displayfront
dequeue
displayfront
Sample output:-
4
5, I have written this Solution Code: public static void enqueue (Queue < Integer > st, int x)
{
st.add (x);
}
public static void dequeue (Queue < Integer > st)
{
if (st.isEmpty () == false)
{
int x = st.remove();
}
}
public static void displayfront(Queue < 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: Palindrome is a word, phrase, or sequence that reads the same backwards as forwards. Use recursion to check if a given string is palindrome or not.User Task:
Since this is a functional problem, you don't have to worry about the input, you just have to complete the function check_Palindrome() where you will get input string, starting index of string (which is 0) and the end index of string( which is str.length-1) as argument.
Constraints:
1 β€ T β€ 100
1 β€ N β€ 10000Return true if given string is palindrome else return falseSample Input
2
ab
aba
Sample Output
false
true, I have written this Solution Code:
static boolean check_Palindrome(String str,int s, int e)
{
// If there is only one character
if (s == e)
return true;
// If first and last
// characters do not match
if ((str.charAt(s)) != (str.charAt(e)))
return false;
// If there are more than
// two characters, check if
// middle substring is also
// palindrome or not.
if (s < e + 1)
return check_Palindrome(str, s + 1, e - 1);
return true;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, 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 a= br.readLine();
int sum=0;
int n=a.length();
int s=0;
for(int i=0; i<n; i++){
sum=sum+ (a.charAt(i) - '0');
if(i == n-1){
s= (a.charAt(i) - '0');
}
}
if(sum%3==0 && s==0){
System.out.print("Yes");
}else{
System.out.print("No");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-02-10 11:06:49
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int solve(string a) {
int n = a.size();
int sum = 0;
if (a[n - 1] != '0') {
return 0;
}
for (auto &it : a) {
sum += (it - '0');
}
debug(sum % 3);
if (sum % 3 == 0) {
return 1;
}
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
string str;
cin >> str;
int res = solve(str);
if (res) {
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: You are given a big number in form of a string A of characters from 0 to 9.
Check whether the given number is divisible by 30 .The first argument is the string A.
<b>Constraints</b>
1 ≤ |A| ≤ 10<sup>5</sup>Return "Yes" if it is divisible by 30 and "No" otherwise. Sample Input :
3033330
Sample Output:
Yes, I have written this Solution Code: A=int(input())
if A%30==0:
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args){
FastReader read = new FastReader();
int a = read.nextInt();
int b = read.nextInt();
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(){
InputStreamReader inr = new InputStreamReader(System.in);
br = new BufferedReader(inr);
}
String next(){
while(st==null || !st.hasMoreElements())
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
long nextLong(){
return Long.parseLong(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers <b>a</b> and <b>b</b>, your task is to calculate and print the following four values:-
a+b
a-b
a*b
a/bThe input contains two integers a and b separated by spaces.
<b>Constraints:</b>
1 ≤ b ≤ a ≤ 1000
<b> It is guaranteed that a will be divisible by b</b>Print the mentioned operations each in a new line.Sample Input:
15 3
Sample Output:
18
12
45
5
<b>Explanation:-</b>
First operation is a+b so 15+3 = 18
The second Operation is a-b so 15-3 = 12
Third Operation is a*b so 15*3 = 45
Fourth Operation is a/b so 15/3 = 5, I have written this Solution Code: a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array having N integers. Find the absolute difference in sums of even numbers and odd numbers in the array.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the absolute difference in sums of even numbers and odd numbers in the array.Sample Input:
5
3 4 6 9 7
Sample Output:
9, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
long evenSum = 0;
long oddSum = 0;
long temp;
for(int i=0; i<size; i++){
temp = sc.nextLong();
if((temp&1)==0){
evenSum += temp;
}else{
oddSum += temp;
}
}
System.out.println(Math.abs(evenSum-oddSum));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array having N integers. Find the absolute difference in sums of even numbers and odd numbers in the array.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the absolute difference in sums of even numbers and odd numbers in the array.Sample Input:
5
3 4 6 9 7
Sample Output:
9, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
a=list(filter(lambda x: x%2==0,arr))
b=list(filter(lambda x: x%2!=0,arr))
print(abs(sum(a)-sum(b))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array having N integers. Find the absolute difference in sums of even numbers and odd numbers in the array.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the absolute difference in sums of even numbers and odd numbers in the array.Sample Input:
5
3 4 6 9 7
Sample Output:
9, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) cin >> i;
int odd = 0, eve = 0;
for(auto &i : a){
if(i % 2) odd += i;
else eve += i;
}
cout << abs(odd - eve);
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: On an island, people only use odd numbers and avoid even numbers. A man visits the island and tells them that he used k distinct positive odd numbers to build his boat. The people ask the man to give them the number n, and they want to determine if the number n can be represented as a sum of k distinct positive odd numbers or not.The first line contains two space-separated integers n and k.
<b>Constrains:</b>
1 ≤ n≤ 10000
1 ≤ k≤ 1000
A single string "YES" or "NO".Input:
4 2
Output:
YES
Explanations:
4 can be represented as (1+3)., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
if (k*k <= n && n%2 == k%2){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){
int x = C/B;
if(C%B!=0){x++;}
int y = A/D;
if(A%D!=0){y++;}
if(x<y){return 0;}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments.
Constraints:-
1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:-
8 2 5 3
Sample Output:-
1
Explanation:-
Natsu's attack:- A = 5, B = 2, C = 5, D = 3
Dragon's attack:- A = 5, B = 2, C = 3, D =3
Natsu's attack:- A = 2, B =2, C = 3, D=3
Dragon's attack:- A = 2, B =2, C = 1, D=3
Natsu's attack:- A = -1, B =2, C = 1, D=3
Natsu's win, I have written this Solution Code:
def DragonSlayer(A,B,C,D):
x = C//B
if(C%B!=0):
x=x+1
y = A//D
if(A%D!=0):
y=y+1
if(x<y):
return 0
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y).
Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N.
Constraints:-
1 <= N <= 1000000Print the minimum number of operations required.Sample Input
5
Sample Output
3
Explanation
(1, 1) -> (2, 1) -> (2, 3) -> (2, 5)
Sample Input
1
Sample Output
0, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int x = 1;
int y = 1;
int count = 0;
while(x<n && y<n){
if(x<=y){
x = x+y;
} else{
y = x+y;
}
count++;
}
if(n<100000)
System.out.print(count);
else
System.out.print(count+1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y).
Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N.
Constraints:-
1 <= N <= 1000000Print the minimum number of operations required.Sample Input
5
Sample Output
3
Explanation
(1, 1) -> (2, 1) -> (2, 3) -> (2, 5)
Sample Input
1
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int count_gcd(int a, int b)
{
if(a==1)
return b-1;
if(a>b)
return count_gcd(b, a);
if(b%a)
return b/a + count_gcd(b%a, a);
else
return 1e9;
}
int n;
int32_t main()
{
IOS;
cin>>n;
if(n==1)
{
cout<<"0";
return 0;
}
int ans=1e9;
for(int i=1;i<n;i++)
ans=min(ans, count_gcd(i, n));
cout<<ans;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Edward is playing the slots. The result of a spin is represented by three uppercase English letters
C<sub>1</sub>, C<sub>2</sub>, and C<sub>3</sub>. It is considered a win when all of them are the same letter.
Determine whether Edward will win or not.The input consists of a string S.
<b>Constraints</b>
S consists of 3 characters all of which are uppercase English letters.If the result is a win, print Won; otherwise, print Lost.<b>Sample Input 1</b>
SSS
<b>Sample Output 1</b>
Won
<b>Sample Input 2</b>
WVW
<b>Sample Output 2</b>
Lost, I have written this Solution Code: #include <stdio.h>
int main(){
char s[9];
scanf("%s",s);
if(s[0]==s[1]&&s[1]==s[2]){
printf("Won");
}else{
printf("Lost");
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code: def solve(a):
maxi = 0
mini = 1e7+1
for i in a:
if(i < mini):
mini = i
if(i > maxi):
maxi = i
return mini,maxi, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[ ] of size N containing positive integers, find maximum and minimum elements from the array.The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers denoting the elements of the array.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^7For each testcase you need to print the maximum and minimum element found separated by space.Sample Input:
2
5
7 3 4 5 6
4
1 2 3 4
Sample Output:
7 3
4 1
, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
findMinMax(arr, n);
System.out.println();
}
}
public static void findMinMax(int arr[], int n)
{
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++)
{
min = Math.min(arr[i], min);
max = Math.max(arr[i], max);
}
System.out.print(max + " " + min);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException
{
InputStreamReader pk = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(pk);
String[] strNums;
int num[] = new int[4];
strNums = in.readLine().split(" ");
for (int i = 0; i < strNums.length; i++) {
num[i] = Integer.parseInt(strNums[i]);
}
if((num[0]<(num[1]+num[2])) || (num[0]<(num[1]*num[3])))
System.out.println("1");
else
System.out.println("0");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: a = []
a = list(map(int, input().split()))
if a[1]+a[2] > a[0] or a[1]*a[3] > a[0]:
defeat = 1
else:
defeat = 0
print(defeat), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are fighting against a monster.
The monster has health M while you have initial health Y.
To defeat him, you need health strictly greater than the monster's health.
You have access to two types of pills, red and green. Eating a red pill adds R to your health while eating a green pill multiplies your health by G.
Determine if it is possible to defeat the monster by eating at most one pill of any kind.Input contains four integers M (0 <= M <= 10<sup>4</sup>), Y (0 <= Y <= 10<sup>4</sup>), R (0 <= R <= 10<sup>4</sup>) and G (1 <= G <= 10<sup>4</sup>).Print 1 if it is possible to defeat the monster and 0 if it is impossible to defeat it.Sample Input 1:
10 2 2 2
Sample Output 1:
0
Sample Input 2:
8 7 2 1
Sample Output 2:
1
Explanation for Sample 2:
You can eat a red pill to make your health : 7 + 2 = 9 > 8., I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll M, Y, R, G;
cin >> M >> Y >> R >> G;
ll maxm = Y;
maxm = max(maxm, Y+R);
maxm = max(maxm, Y*G);
cout << (M < maxm) << "\n";
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: N = int(input())
Nums = list(map(int,input().split()))
f = False
for n in Nums:
if n < 0:
f = True
break
if (f):
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
bool win=false;
for(int i=0;i<n;i++){
cin>>a;
if(a<0){win=true;}}
if(win){
cout<<"Yes";
}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
if(a[i]<0){System.out.print("Yes");return;}
}
System.out.print("No");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: def getMissingNo(arr, n):
total = (n+1)*(n)//2
sum_of_A = sum(arr)
return total - sum_of_A
N = int(input())
arr = list(map(int,input().split()))
one = getMissingNo(arr,N)
print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n-1];
for(int i=0;i<n-1;i++){
a[i]=sc.nextInt();
}
boolean present = false;
for(int i=1;i<=n;i++){
present=false;
for(int j=0;j<n-1;j++){
if(a[j]==i){present=true;}
}
if(present==false){
System.out.print(i);
return;
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array.
Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers.
<b>Constraints:-</b>
1 ≤ N ≤ 1000
1 ≤ elements ≤ NPrint the missing elementSample Input:-
3
3 1
Sample Output:
2
Sample Input:-
5
1 4 5 2
Sample Output:-
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
cin>>a[i];
}
sort(a,a+n-1);
for(int i=1;i<n;i++){
if(i!=a[i-1]){cout<<i<<endl;return 0;}
}
cout<<n;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: static void simpleSum(int a, int b, int c){
System.out.println(a+b+c);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: void simpleSum(int a, int b, int c){
cout<<a+b+c;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C.
Constraints:-
1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input
1 2 3
Sample Output:-
6
Sample Input:-
5 4 2
Sample Output:-
11, I have written this Solution Code: x = input()
a, b, c = x.split()
a = int(a)
b = int(b)
c = int(c)
print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?<b>User Task:</b>
Complete the function <b>Time()</b> that takes integers A, B, and S as parameters.
<b>Constraints:-</b>
1 <= A, B, V <= 1000
<b>Note:-</b>
It is guaranteed that the calculated distance will always be divisible by V.Return the Time taken in seconds by Kazama to reach Shin-chan.
<b>Note:-</b>
Remember Distance can not be negativeSample Input:-
A = 5, B = 2, S = 3
Sample Output:-
1
Sample Input:-
A = 9, B = 1, S = 2
Sample Output:-
4
<b>Explanation 1:-</b>
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
System.out.print(Time(n,m,k));
}
static int Time(int A, int B, int S){
if(B>A){
return (B-A)/S;
}
return (A-B)/S;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?<b>User Task:</b>
Complete the function <b>Time()</b> that takes integers A, B, and S as parameters.
<b>Constraints:-</b>
1 <= A, B, V <= 1000
<b>Note:-</b>
It is guaranteed that the calculated distance will always be divisible by V.Return the Time taken in seconds by Kazama to reach Shin-chan.
<b>Note:-</b>
Remember Distance can not be negativeSample Input:-
A = 5, B = 2, S = 3
Sample Output:-
1
Sample Input:-
A = 9, B = 1, S = 2
Sample Output:-
4
<b>Explanation 1:-</b>
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
int Time(int a, int b, int s) {
return (abs(a - b) / s);
}
int main() {
int n, m, k;
cin >> n >> m >> k;
cout << Time(n, m, k) << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?<b>User Task:</b>
Complete the function <b>Time()</b> that takes integers A, B, and S as parameters.
<b>Constraints:-</b>
1 <= A, B, V <= 1000
<b>Note:-</b>
It is guaranteed that the calculated distance will always be divisible by V.Return the Time taken in seconds by Kazama to reach Shin-chan.
<b>Note:-</b>
Remember Distance can not be negativeSample Input:-
A = 5, B = 2, S = 3
Sample Output:-
1
Sample Input:-
A = 9, B = 1, S = 2
Sample Output:-
4
<b>Explanation 1:-</b>
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
, I have written this Solution Code: #include <stdio.h>
int Time(int a, int b, int s) {
return (abs(a - b) / s);
}
int main() {
int n, m, k;
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &k);
printf("%d\n", Time(n, m, k));
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Shinchan and Kazama are standing in a horizontal line, Shinchan is standing at point A and Kazama is standing at point B. Kazama is very intelligent and recently he learned how to calculate the speed if the distance and time are given and now he wants to check if the formula he learned is correct or not So he starts running at a speed of S unit/s towards Shinhan and noted the time he reaches to Shinhan. Since Kazama is disturbed by Shinchan, can you calculate the time for him?<b>User Task:</b>
Complete the function <b>Time()</b> that takes integers A, B, and S as parameters.
<b>Constraints:-</b>
1 <= A, B, V <= 1000
<b>Note:-</b>
It is guaranteed that the calculated distance will always be divisible by V.Return the Time taken in seconds by Kazama to reach Shin-chan.
<b>Note:-</b>
Remember Distance can not be negativeSample Input:-
A = 5, B = 2, S = 3
Sample Output:-
1
Sample Input:-
A = 9, B = 1, S = 2
Sample Output:-
4
<b>Explanation 1:-</b>
Distance = 5-2 = 3, Speed = 3
Time = Distance/Speed
, I have written this Solution Code: def Time(a,b,s):
if b>a:
return (b-a)//s
return (a-b)//s
if __name__ == "__main__":
n,m,k = map(int,input().split())
print(Time(n,m,k)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
for i in range(0,n-2):
if li[i]==li[i+1] and li[i+1]==li[i+2]:
print("Yes",end="")
exit()
print("No",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(n);
bool fl = false;
For(i, 0, n){
cin>>a[i];
if(i>=2){
if(a[i]==a[i-1] && a[i]==a[i-2]){
fl = true;
}
}
}
if(fl){
cout<<"Yes";
}
else
cout<<"No";
}
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: Given an array A of N integers, find whether there exists three consecutive same integers in the array.The first line of the input contains an integer N.
The second line contains N space separated integers of the array A.
Constraints
3 <= N <= 1000
1 <= A[i] <= 100Output "Yes" if there exists three consecutive equal integers in the array, else output "No" (without quotes).Sample Input
5
1 2 2 2 4
Sample Output
Yes
Explanation: The segment [2, 2, 2] follows the criterion.
Sample Input
5
1 2 2 3 4
Sample Output
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n-2;i++){
if(a[i]==a[i+1] && a[i+1]==a[i+2]){
System.out.print("Yes");
return;
}
}
System.out.print("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code:
import sys
from collections import defaultdict
from heapq import heappush, heappop
n, m = map(int, input().split())
d = defaultdict(list)
dist = [sys.maxsize]*n
dist[0] = 0
for _ in range(m):
start, dest, wt = map(int, input().split())
d[start-1].append((dest-1, wt))
d[dest-1].append((start-1, wt))
heap = [(0, 0, 0)]
while heap:
count, cost, u= heappop(heap)
for vertex, weight in d[u]:
if dist[vertex] > cost + weight*(count+1):
dist[vertex] = cost + weight*(count+1)
heappush(heap, (count+1, dist[vertex], vertex))
for d in dist:
if d == sys.maxsize:
print(-1)
else:
print(d), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF =1e18;
vector<tuple<int, int, int>> adj;
void solve()
{
int n, m;
cin>>n>>m;
// assert(1<=n && n<=3000);
// assert(0<=m && m<=10000);
adj.resize(n);
for(int i = 0;i<m;i++)
{
int x, y, w;
cin>>x>>y>>w;
x--;
y--;
// assert(0<=x && x<n);
// assert(0<=y && y<n);
// assert(1<=w && w<=1e9);
adj.push_back({x, y, w});
adj.push_back({y, x, w});
}
vector<int> dp_old(n, INF);
vector<int> dp_new(n, INF);
dp_old[0] = 0;
for(int i = 1;i<=n;i++)
{
fill(dp_new.begin(), dp_new.end(), INF);
for(auto [x, y,w]:adj)
{
dp_new[y]= min({dp_new[y], dp_old[x] + i * w});
}
for(int j = 0;j<n;j++)
dp_new[j] = min(dp_new[j], dp_old[j]);
swap(dp_new, dp_old);
}
for(int i = 0;i<n;i++)
{
if(dp_old[i] == INF)
dp_old[i] = -1;
cout<<dp_old[i]<<"\n";
}
}
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);
}
#endif
solve();
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it.
Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>.
Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j.
Find the minimum distance from city 1 to all the cities i (1 β€ i β€ n). If there exists no way to go from city 1 to city i, print -1.
<b>Note: </b>
All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively.
The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w.
<b>Constraints:</b>
1 β€ n β€ 3000
0 β€ m β€ 10000
1 β€ x, y β€ n
1 β€ w β€ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input
6 5
2 4 3
2 3 4
2 1 2
2 5 6
1 5 2
Sample Output
0
2
10
8
2
-1
Explanation:
Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10
Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2
There doesn't exist any path from 1 to 6 so print -1
, I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java.
util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*;
import static java.lang.System.*;
public class Main
{
public void tq()throws Exception
{
st=new StringTokenizer(bq.readLine());
int tq=1;
sb=new StringBuilder(2000000);
o:
while(tq-->0)
{
int n=i();
int m=i();
LinkedList<int[]> l[]=new LinkedList[n];
for(int x=0;x<n;x++)l[x]=new LinkedList<>();
for(int x=0;x<m;x++)
{
int a=i()-1;
int b=i()-1;
int c=i();
l[a].add(new int[]{b,c});
l[b].add(new int[]{a,c});
}
long d[]=new long[n];
for(int x=0;x<n;x++)d[x]=maxl;
d[0]=0l;
PriorityQueue<long[]> p=new PriorityQueue<>(5000,(a,b)->a[2]-b[2]<1l?-1:1);
p.add(new long[]{0l,0,0});
while(p.size()>0)
{
long r[]=p.poll();
long di=r[0];
int no=(int)r[1];
long mu=r[2];
for(int e[]:l[no])
{
int node=e[0];
int w=e[1];
long de=di+w*(mu+1);
if(d[node]>de)
{
d[node]=de;
p.add(new long[]{de,node,mu+1});
}
}
}
for(long x:d)
{
sl(x==maxl?-1:x);
}
}
p(sb);
}
int di[][]={{-1,0},{1,0},{0,-1},{0,1}};
int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}};
long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long.
MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st;
StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[])
{Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;
x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++)
r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;}
char[] so(char ar[]) {Character
r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)
ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb.
append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl
(String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb
.append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s)
;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);}
long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a)
{return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b)
{while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!=
s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1]
=true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n;
y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1)
r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException
{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String
s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();}
double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double.
parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p)
{out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void
p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p)
{out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out.
println(p);}void pl(boolean p)
{out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a)
{sb.append(e);sb.append(' ');}sb.append("\n");}
void s(long a[])
{for(long e:a){sb.append(e);sb.append(' ')
;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append
("\n");}}
void s(char a[])
{for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][])
{for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws
IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;
x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws
IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl
(int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine())
;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws
IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new
StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;}
String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard
(int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer
(bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard
(int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens())
st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());}
return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new
StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][]
arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine();
for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[])
{StringBuilder sb=new StringBuilder
(2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder
(2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);}
void p(long ar[][])
{StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa);
sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1;
StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);}
void p(double ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a);
sb.append(' ');}out.println(sb);}void p
(double ar[][]){StringBuilder sb=new StringBuilder(2*
ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n")
;}p(sb);}void p(char ar[])
{StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa);
sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0]
.length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:-
T<sup>Β°F</sup> = T<sup>Β°C</sup> Γ 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter.
<b>Constraints</b>
-10^3 <= C <= 10^3
<b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input :
25
Sample Output:
77
Sample Input:-
-40
Sample Output:-
-40, I have written this Solution Code: def CelsiusToFahrenheit(C):
F = int((C * 1.8) + 32)
return F
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:-
T<sup>Β°F</sup> = T<sup>Β°C</sup> Γ 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter.
<b>Constraints</b>
-10^3 <= C <= 10^3
<b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input :
25
Sample Output:
77
Sample Input:-
-40
Sample Output:-
-40, I have written this Solution Code: static int CelsiusToFahrenheit(int c){
return 9*(c/5) + 32;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a*b*c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 β€ n β€ 10^5
1 β€ a, b, c β€ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code: n,a,b,c = map(int, input().split())
m = 1000000007
result = 0
while n > 3:
result = (a%m + b%m + c%m)%m
a = b
b = c
c = result
n -= 1
print(result), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 β€ n β€ 10^5
1 β€ a, b, c β€ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code:
import java.io.*;
import java.util.*;
class Main
{
static int mod = 1000000007;
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
//int t = Integer.parseInt(read.readLine());
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
long a =Long.parseLong(str[1]);
long b = Long.parseLong(str[2]);
long c = Long.parseLong(str[3]);
long dp[] = new long[n];
dp[0] = a;
dp[1] = b;
dp[2] = c;
for(int i = 3; i < n; i++)
{
dp[i] = (dp[i-1]%mod + dp[i-2]%mod + dp[i-3]%mod)%mod;
}
System.out.println(dp[n-1]);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A Tribonacci number T(n) is the sum of the preceding three elements in a series.
Calculate the value of the nth Tribonacci number modulo 1000000007. The initial three numbers of this series will be a, b and c i.e., T(1)=a, T(2)=b, T(3)=c.The only line of input contains 4 integers n, a, b, c.
Constraints
4 β€ n β€ 10^5
1 β€ a, b, c β€ 1000000000Print the result containing one integer i.e., T(n) modulo 1000000007.Input1:
5 1 2 3
Output1:
11
Input2:
4 1 1 1
Output2:
3
Explanation(might now be the optimal solution):
Input 1:
Follow the below steps:-
T(1) = 1
T(2) = 2
T(3) = 3
T(4) = 6
T(5) = 11, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e3+ 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 9;
void solve(){
int n, a, b, c;
cin >> n >> a >> b >> c;
for(int i = 4; i <= n; i++){
int x = (a + b + c) % mod;
a = b;
b = c;
c = x;
}
cout << c << endl;
}
void testcases(){
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(Β°c) = (T(Β°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(Β°c) = (T(Β°f) - 32)*5/9
T(Β°c) = (77-32)*5/9
T(Β°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
int[] arr=new int[5];
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
String[] s=rd.readLine().split(" ");
int sum=0;
for(int i=0;i<5;i++){
arr[i]=Integer.parseInt(s[i]);
sum+=arr[i];
}
int i=0,j=arr.length-1;
boolean isEmergency=false;
while(i<=j)
{
int temp=arr[i];
sum-=arr[i];
if(arr[i]>= sum)
{
isEmergency=true;
break;
}
sum+=temp;
i++;
}
if(isEmergency==false)
{
System.out.println("Stable");
}
else
{
System.out.println("SPD Emergency");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: arr = list(map(int,input().split()))
m = sum(arr)
f=[]
for i in range(len(arr)):
s = sum(arr[:i]+arr[i+1:])
if(arr[i]<s):
f.append(1)
else:
f.append(0)
if(all(f)):
print("Stable")
else:
print("SPD Emergency"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Our five power rangers have powers P1, P2, P3, P4, and P5.
To ensure the proper distribution of power, the power of every power ranger must remain <b>less</b> than the sum of powers of other power rangers.
If the above condition is not met, there's an emergency. Can you let us know if there's an emergency?The first and the only line of input contains 5 integers P1, P2, P3, P4, and P5.
Constraints
0 <= P1, P2, P3, P4, P5 <= 100Output "SPD Emergency" (without quotes) if there's an emergency, else output "Stable".Sample Input
1 2 3 4 5
Sample Output
Stable
Explanation
The power of every power ranger is less than the sum of powers of other power rangers.
Sample Input
1 2 3 4 100
Sample Output
SPD Emergency
Explanation
The power of the 5th power ranger (100) is not less than the sum of powers of other power rangers (1+2+3+4=10)., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> vect(5);
int tot = 0;
for(int i=0; i<5; i++){
cin>>vect[i];
tot += vect[i];
}
sort(all(vect));
tot -= vect[4];
if(vect[4] >= tot){
cout<<"SPD Emergency";
}
else{
cout<<"Stable";
}
}
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 buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: n=int(input())
a=map(int,input().split())
b=[]
mx=-200000
cnt=0
for i in a:
if i>mx:
cnt+=1
mx=i
print(cnt), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: function numberOfRoofs(arr)
{
let count=1;
let max = arr[0];
for(let i=1;i<arrSize;i++)
{
if(arr[i] > max)
{
count++;
max = arr[i];
}
}
return count;
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are standing on the left side of the first building .From this position you can see the roof of a building <b>i</b> if no building to the left of the i<sup>th</sup> building has a height greater than or equal to the height of the i<sup>th</sup> building.
You are asked to find the number of buildings whose roofs you can see.The first line contains N denoting number of buildings.
The next line contains N space seperated integers denoting heights of the buildings from left to right.
Constraints
1 <= N <= 100000
1 <= H[i] <= 1000000000000000The output should contain one integer which is the number of buildings whose roofs you can see.Sample input:
5
1 2 2 4 3
Sample output:
3
Explanation:-
the building at index 3 will hide before building at index 2 and building at index 5 will hide before building at index 4
Sample input:
5
1 2 3 4 5
Sample output:
5
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=s.nextInt();
}
int count=1;
int max = a[0];
for(int i=1;i<n;i++)
{
if(a[i] > max)
{
count++;
max = a[i];
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
static long mod = 1000000007;
public static void main(String[] args) throws IOException {
FastScanner s=new FastScanner();
int t1 =1;
while(t1-->0){
long a = s.nextLong();
long o = s.nextLong();
if(a==0 || o==0) System.out.println(0);
else System.out.println(a*(long)o%mod);
}
}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, I have written this Solution Code: a,b =map(int, input().split())
print((a*b)%1000000007), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono has gathered all the FRIENDS for a grand chapo event. For winning the chapo, she has asked the FRIENDS for the solution to a simple problem.
Our magical Tono has A apple candies and O orange candies. In one turn, she chooses an apple or an orange candy with equal probability, and turns it into the other type. Now, she asks the FRIENDS the expected number of turns she will follow this process until either the number of apple or the orange candies become 0.The first and the only line of input contains two integers A and O.
Constraints
1 <= A, O <= 10<sup>9</sup>Output the single line corresponding to the expected number of turns Tono needs to complete the process.
The answer is of the form p/q. Print it as (p*r)%1000000007 where r is modulo inverse of q with respect to 1000000007.Sample Input
1 2
Sample Output
2
Sample Input
0 5
Sample Output
0, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
template<class C> void mini(C&a4, C b4){a4=min(a4,b4);}
typedef unsigned long long ull;
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define mod 1000000007ll
#define pii pair<int,int>
/////////////
signed main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int mo=1000000007;
int a,b;
cin>>a>>b;
cout<<(a*b)%mo;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
long z=0,x=0,y=0;
int choice;
Scanner in = new Scanner(System.in);
choice = in.nextInt();
String s="";
int f = 1;
while(f<=choice){
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
System.out.println((long)(Math.max((z-x),(z-y))));
f++;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: n = int(input())
for i in range(n):
l = list(map(int,input().split()))
print(l[2]-min(l)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int power (int a, int b = mod - 2)
{
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
signed main()
{
read(t);
assert(1 <= t && t <= ll(1e4));
while (t--)
{
readc(x, y, z);
assert(1 <= x && x <= ll(1e15));
assert(1 <= y && y <= ll(1e15));
assert(max(x, y) < z && z <= ll(1e15));
int r = 2*z - x - y - 1;
int l = z - max(x, y);
print(r - l + 1);
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The universe contains a magic number <b>z</b>. Thor's power is known to <b>x</b> and Loki's power to be <b>y</b>.
One's strength is defined to be <b>z - a</b>, if his power is <b>a</b>. Your task is to find out who among Thor and Loki has the highest strength, and print that strength.
<b>Note:</b> The input and answer may not fit in a 32-bit integer type. In particular, if you are using C++ consider using <em>long long int</em> over <em>int</em>.The first line contains one integer t β the number of test cases.
Each test case consists of one line containing three space-separated integers x, y and z.
<b> Constraints: </b>
1 β€ t β€ 10<sup>4</sup>
1 β€ x, y β€ 10<sup>15</sup>
max(x, y) < z β€ 10<sup>15</sup>For each test case, print a single value - the largest strength among Thor and Loki.Sample Input
2
2 3 4
1 1 5
Sample Output
2
4, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int t;
cin>>t;
while(t--)
{
int x, y, z;
cin>>x>>y>>z;
cout<<max(z - y, z- x)<<endl;
}
}
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);
}
#endif
solve();
}, 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 3N integers and you have to find a subsequence of length 2N of that array such that the ((sum of first N elements of that subsequence) - (sum of last N elements of that subsequence)) is maximum possible. Find that maximum value.First Line of input contains single integer N
Second line of input contains 3N space separated integers denoting the Array
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Output a single integer which is the maximum value of ((sum of first N elements of that subsequence) - (sum of last N elements of that subsequence))Sample Input 1
2
3 1 4 1 5 9
Sample Output 1
1
Explaination 1
sequece selected : 3 4 1 5
Sample Input 2
1
1 2 3
Sample Output 2
-1
Explaination 2
sequece selected : 1 2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
FastReader sc = new FastReader();
int n = sc.nextInt();
int al = 3*n;
int arr[] = new int[al];
long leftArr[] = new long[al];
long rightArr[] = new long[al];
for(int i = 0; i < arr.length; i++)
arr[i] = sc.nextInt();
long leftSum = 0;
long rightSum = 0;
PriorityQueue<Integer> leftPq = new PriorityQueue<>();
PriorityQueue<Integer> rightPq = new PriorityQueue<>(Collections.reverseOrder());
for (int i = 0; i < n; i++) {
leftSum += arr[i];
leftPq.add(arr[i]);
}
for (int i = al-1; i >= 2*n; i--) {
rightSum += arr[i];
rightPq.add(arr[i]);
}
leftArr[n-1] = leftSum;
for (int i = n; i < 2*n; i++) {
leftPq.add(arr[i]);
leftSum += arr[i];
leftSum -= leftPq.poll();
leftArr[i] = leftSum;
}
rightArr[2*n]= rightSum;
for (int i = 2*n-1; i >= n; i--) {
rightPq.add(arr[i]);
rightSum += arr[i];
rightSum -= rightPq.poll();
rightArr[i] = rightSum;
}
long ans = Integer.MIN_VALUE;
for (int i = n-1; i <= 2*n-1 ; i++) {
ans = Math.max(ans,leftArr[i]-rightArr[i+1]);
}
System.out.println(ans);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of 3N integers and you have to find a subsequence of length 2N of that array such that the ((sum of first N elements of that subsequence) - (sum of last N elements of that subsequence)) is maximum possible. Find that maximum value.First Line of input contains single integer N
Second line of input contains 3N space separated integers denoting the Array
Constraints
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Output a single integer which is the maximum value of ((sum of first N elements of that subsequence) - (sum of last N elements of that subsequence))Sample Input 1
2
3 1 4 1 5 9
Sample Output 1
1
Explaination 1
sequece selected : 3 4 1 5
Sample Input 2
1
1 2 3
Sample Output 2
-1
Explaination 2
sequece selected : 1 2, I have written this Solution Code: #include<iostream>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<long int, long int>
int main(){
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin >> n;
long int a[3*n];
rep(i, 3 * n) cin >> a[i];
priority_queue<P, vector<P>, greater<P> > q1;
priority_queue<P> q2;
priority_queue<P, vector<P>, greater<P> > q3;
long int c[3*n];
fill(c, c + 3 * n, 1);
long int sm1 = 0, sm2 = 0;
for (int i = 0; i < n; i++){
q1.push(P(a[i], i));
sm1 += a[i];
}
for (int i = n; i < 3 * n; i++){
q2.push(P(a[i], i));
sm2 += a[i];
}
for (int i = 0; i < n; i++){
P p = q2.top();
q2.pop();
sm2 -= p.first;
c[p.second] = 0;
q3.push(p);
}
long int ans = sm1 - sm2;
for (int i = n; i < 2 * n; i++){
if (c[i] == 1){
sm2 -= a[i];
P p2 = q3.top();
q3.pop();
while(p2.second <= i){
p2 = q3.top();
q3.pop();
}
sm2 += p2.first;
c[p2.second] = 1;
}
q1.push(P(a[i], i));
sm1 += a[i];
c[i] = 1;
P p1 = q1.top();
q1.pop();
sm1 -= p1.first;
c[p1.second] = 0;
ans = max(ans, sm1 - sm2);
}
cout << ans << endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: n=int(input())
x,y=0,0
for i in range(4*n+1):
a1,b1=map(int,input().split())
x=x^a1
y=y^b1
print(x,y), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
n = n*4+1;
int x = 0;
int y = 0;
For(i, 0, n){
int a, b; cin>>a>>b;
x^=a;
y^=b;
}
cout<<x<<" "<<y<<"\n";
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <i> Why Geometry?? ? </i>
You are given 4*N+1 distinct points on the cartesian plane. Out of these points, 4*N points represent the end points of N rectangles (<b>with axis parallel to co-ordinate axis</b>), while one point does not belong to any of the rectangles. Report the coordinates of the point that does not belong to any of the N rectangles.The first line of the input contains an integer N.
The next 4*N+1 lines contain two integers X and Y, the coordinates of the given points.
Constraints
1 <= N <= 100000
0 <= X, Y <= 1000000
The given points always represent N rectangles and an extra pointOutput space separated X and Y coordinates of the extra point.Samle Input
1
1 3
1 1
3 1
1 4
3 3
Sample Output
1 4
Explanation: (1, 1), (1, 3), (3, 1), and (3, 3) represent the end of a rectangle, while (1, 4) is the extra point., I have written this Solution Code: import java.io.*;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static long mod = 1000000007 ;
public static double epsilon=0.00000000008854;
public static InputReader sc = new InputReader(System.in);
public static PrintWriter pw = new PrintWriter(System.out);
public static long pow(long x,long y,long mod){
long ans=1;
x%=mod;
while(y>0){
if((y&1)==1){
ans=(ans*x)%mod;
}
y=y>>1;
x=(x*x)%mod;
}
return ans;
}
public static void main(String[] args) throws Exception {
int n=sc.nextInt();
n=4*n+1;
int x=0,y=0;
for(int i=0;i<n;i++){
int a=sc.nextInt();
x^=a;
int b=sc.nextInt();
y^=b;
}
pw.println(x+" "+y);
pw.flush();
pw.close();
}
public static Comparator<Integer[]> MOquery(int block){
return
new Comparator<Integer[]>(){
@Override
public int compare(Integer a[],Integer b[]){
int a1=a[0]/block;
int b1=b[0]/block;
if(a1==b1){
if((a1&1)==1)
return a[1].compareTo(b[1]);
else{
return b[1].compareTo(a[1]);
}
}
return a1-b1;
}
};
}
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[]> column(){
return
new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
long a1=o1[0];
long a2=o2[1];
long b1=o2[0];
long b2=o1[1];
int ans=0;
if(a1*a2>b1*b2){
ans=1;
}
else ans=-1;
return ans;
}
};
}
public static Comparator<Integer[]> col(int i){
return
new Comparator<Integer[]>() {
@Override
public int compare(Integer[] o1, Integer[] o2) {
if(o1[i]-o2[i]!=0)
return o1[i].compareTo(o2[i]);
return o1[i+1].compareTo(o2[i+1]);
}
};
}
public static Comparator<Integer> des(){
return
new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
};
}
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 an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.