Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s.
Constraints:-
1 <= N <= 10^6
0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input
7
1 0 0 1 0 1 1
Sample Output
8
The index range for the 8 sub-arrays are:
(0, 1), (2, 3), (0, 3), (3, 4), (4, 5)
(2, 5), (0, 5), (1, 6), I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 1000001
int a[max1];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==0){a[i]=-1;}
}
long sum=0;
unordered_map<long,int> m;
long cnt=0;
for(int i=0;i<n;i++){
sum+=a[i];
if(sum==0){cnt++;}
cnt+=m[sum];
m[sum]++;
}
cout<<cnt;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array arr[] of size N containing 0s and 1s only. The task is to count the subarrays having an equal number of 0s and 1s.The first line of the input contains an integer N denoting the size of the array and the second line contains N space-separated 0s and 1s.
Constraints:-
1 <= N <= 10^6
0 <= A[i] <= 1For each test case, print the count of required sub-arrays in new line.Sample Input
7
1 0 0 1 0 1 1
Sample Output
8
The index range for the 8 sub-arrays are:
(0, 1), (2, 3), (0, 3), (3, 4), (4, 5)
(2, 5), (0, 5), (1, 6), I have written this Solution Code: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner sc = new Scanner(System.in);
int arrSize = sc.nextInt();
long arr[] = new long[arrSize];
for(int i = 0; i < arrSize; i++)
arr[i] = sc.nextInt();
System.out.println(countSubarrays(arr, arrSize));
}
static long countSubarrays(long arr[], int arrSize)
{
for(int i = 0; i < arrSize; i++)
{
if(arr[i] == 0)
arr[i] = -1;
}
long ans = 0;
long sum = 0;
HashMap<Long, Integer> hash = new HashMap<>();
for(int i = 0; i < arrSize; i++)
{
sum += arr[i];
if(sum == 0)
ans++;
if(hash.containsKey(sum) == true)
{
ans += hash.get(sum);
int freq = hash.get(sum);
hash.put(sum, freq+1);
}
else hash.put(sum, 1);
}
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code: def Average(A,B,C):
return (A+B+C)//3
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
static int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Mohit has three integers A, B, and C with him he wants to find the average of these three integers however he is weak in maths, so help him to find the average. You need to report the floor of the average value.<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>Average()</b> that takes integers A, B, and C as arguments.
Constraints:-
1 <= A, B, and C <= 10000Return the floor of average of these numbers.Sample Input:-
3 4 5
Sample Output:-
4
Sample Input:-
3 4 4
Sample Output:-
3, I have written this Solution Code:
int Average(int A,int B, int C){
return (A+B+C)/3;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static long mod =1000000007;
public static boolean isPrime(long m){
if (m <2)
return false;
for(int i =2 ;i*i<=m;i++)
{
if (m%i == 0)
return false;
}
return true;
}
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s [] =br.readLine().trim().split(" ");
long x = Long.parseLong(s[0]);
long n = Long.parseLong(s[1]);
long ans = 1;
for(int i = 2; i*i <= x; i++){
if(x%i != 0) continue;
ans = (ans*f(n, i)) % mod;
while(x%i == 0)
x /= i;
}
if(x > 1)
ans = (ans*f(n, x)) % mod;
System.out.println(ans);
}
static long f(long n, long p){
long ans = 1;
long cur = 1;
while(cur <= n/p){
cur = cur*p;
long z = power(p, n/cur);
ans = (ans*z) % mod;
}
return ans;
}
public static long power(long no,long pow){
long p = 1000000007;
long result = 1;
while(pow > 0)
{
if ( (pow & 1) == 1)
result = ((result%p) * (no%p))%p;
no = ((no%p) * (no%p))%p;
pow >>= 1;
}
return result;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: import math
mod = 1000000007
def modExpo(x, n):
if n <= 0:
return 1
if n % 2 == 0:
return modExpo((x * x) % mod, n // 2)
return (x * modExpo((x * x) % mod, (n - 1) // 2)) % mod
def calc(n, p):
prod = 1
pPow = 1
while pPow <= (n // p):
pPow *= p
add = 0
while pPow != 1:
quo = n // pPow
quo -= add
power = modExpo(pPow, quo)
prod = (prod * power) % mod
add += quo
pPow //= p
return prod
x, n = map(int, input().split())
res = 1
i = 2
while (i * i) <= x:
if x % i == 0:
res = (res * calc(n, i)) % mod
while x % i == 0:
x //= i
i += 1
if x > 1:
res = (res * calc(n, x)) % mod
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Let's assume some functional definitions for this problem.
We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.
Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.
(Here a**b means a raised to the power b or pow(a, b))
For example:
f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),
f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).
Let g(x,y) be the product of f(y,p) for all p in prime(x).
For example:
g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,
g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.
You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).
(Read modulo exponentiation before attempting this problem)The only line contains integers x and n — the numbers used in formula.
Constraints
2 ≤ x ≤ 1000000000
1 ≤ n ≤ 1000000000000000000Print the answer corresponding to the input.Sample Input 1
10 2
Sample Output 1
2
Sample Input 2
20190929 1605
Sample Output 2
363165664
Explanation
In the first example, g(10,1)=f(1,2)⋅f(1,5)=1, g(10,2)=f(2,2)⋅f(2,5)=2., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int power(int a, int b){
int ans = 1;
b %= (mod-1);
while(b){
if(b&1)
ans = (ans*a) % mod;
b >>= 1;
a = (a*a) % mod;
}
return ans;
}
int f(int n, int p){
int ans = 1;
int cur = 1;
while(cur <= n/p){
cur = cur*p;
int z = power(p, n/cur);
ans = (ans*z) % mod;
}
return ans;
}
signed main() {
IOS;
int x, n, ans = 1;
cin >> x >> n;
for(int i = 2; i*i <= x; i++){
if(x%i != 0) continue;
ans = (ans*f(n, i)) % mod;
while(x%i == 0)
x /= i;
}
if(x > 1)
ans = (ans*f(n, x)) % mod;
cout << ans;
return 0;
}, 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 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 an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcase = Integer.parseInt(br.readLine());
for(int t=0;t<testcase;t++){
int num = Integer.parseInt(br.readLine().trim());
if(num==1)
System.out.println("No");
else if(num<=3)
System.out.println("Yes");
else{
if((num%2==0)||(num%3==0))
System.out.println("No");
else{
int flag=0;
for(int i=5;i*i<=num;i+=6){
if(((num%i)==0)||(num%(i+2)==0)){
System.out.println("No");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Yes");
}
}
}
}catch (Exception e) {
System.out.println("I caught: " + e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: t=int(input())
for i in range(t):
number = int(input())
if number > 1:
i=2
while i*i<=number:
if (number % i) == 0:
print("No")
break
i+=1
else:
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 integer, print whether that integer is a prime number or not.First line of input contains an integer T, showing the number of test cases. Every test case is a single integer A.
Constraints
1 <= T <= 100
1 <= A <= 10^8If the given integer is prime, print 'Yes', else print 'No'.Sample Input
3
5
9
13
Output
Yes
No
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,k;
cin>>n;
long x=sqrt(n);
int cnt=0;
vector<int> v;
for(long long i=2;i<=x;i++){
if(n%i==0){
cout<<"No"<<endl;
goto f;
}}
cout<<"Yes"<<endl;
f:;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, return the number of trailing zeroes in N!.
Where N!=N*(N-1)*(N-2)....1Input contains a single integer N.
Constraints:-
1<= N <=1000000000000000Print the number of zeros in factorial(N)Sample Input
5
Sample Output
1
Explanation:-
5! = 120
number of zeroes = 1
Sample Input;
11
Sample output:
2, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static long findTrailingZeros(long n)
{
long count = 0;
for (long i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}
static long fact(long num)
{
long sum=1;
for(int i=1;i<num;i++)
{
sum+=sum*i;
}
return sum;
}
public static void main (String[] args)throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
long num=Long.parseLong(bf.readLine());
System.out.println(findTrailingZeros(num));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, return the number of trailing zeroes in N!.
Where N!=N*(N-1)*(N-2)....1Input contains a single integer N.
Constraints:-
1<= N <=1000000000000000Print the number of zeros in factorial(N)Sample Input
5
Sample Output
1
Explanation:-
5! = 120
number of zeroes = 1
Sample Input;
11
Sample output:
2, I have written this Solution Code: n=int(input())
divisible5count=0
while(n>0):
divisible5count=divisible5count+n//5
n=n//5
print(divisible5count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, return the number of trailing zeroes in N!.
Where N!=N*(N-1)*(N-2)....1Input contains a single integer N.
Constraints:-
1<= N <=1000000000000000Print the number of zeros in factorial(N)Sample Input
5
Sample Output
1
Explanation:-
5! = 120
number of zeroes = 1
Sample Input;
11
Sample output:
2, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
long long fd(long long n)
{
// Initialize result
long long count = 0;
// Keep dividing n by powers of
// 5 and update count
for (long long i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}
// Driver code
int main()
{
int t;
t=1;
while(t--){
long long n;
cin>>n;
cout<<fd(n)<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this question, you need to create a class <b>Student</b> which has 4 parameters:-
<b>name ( String )</b>
<b>eng (int) </b>
<b>maths (int) </b>
<b>hindi (int) </b>
Also, you need to complete the given three functions:-
<b>createStudentArray</b>:- In which you need to create an array of students and take input
<b>engAverage</b>:- In which you need to create an average of marks in English.
<b>avgPercentageOfClass</b>:- In which you need to calculate the average percentage of the class.
Note:- Scanner is already defined in this question. Use "sc" for scanner.You need to take the input in <b>createStudentArray()</b> only in which you have already provided the number of students N you just have to create an array of size N and take input respectively.
Constraints:-
1 <= N <= 1000Return the Student array in <b>createStudentArray()</b>, Return the floor of average marks in english in <b>engAverage</b>, and return the floor of average percentage of the class in <b.avgPercentageOfClas</b>.
Note:- In <b>avgPercentageOfClas</b> you first need to create the average of individual then find the average of all the students.Sample Input:-
3
Shiv 65 47 78
Negi 55 40 56
Gargi 43 56 40
Sample Output:-
54
53
Explanation:-
Average marks in eng = (65 + 55 + 43)/3 = 163/3 = 54
Average percentage of class =>
shiv = (65 + 47 + 78)/3 = 190/3 = 63
Negi = (55 + 40 + 56)/3 = 151/3 = 50
Gargi = (43 + 56 + 40)/3 = 139/3 = 46
avg = (63 + 50 + 46 )/3 = 159 = 53, I have written this Solution Code:
class Student:
def __init__(self, name, eng, maths, hindi):
self.name=name
self.eng=eng
self.maths=maths
self.hindi=hindi
def createStudentArray(n):
stulist=[]
for i in range(n):
Name,Eng,Maths,Hindi=input().split()
s=Student(Name,int(Eng),int(Maths),int(Hindi))
stulist.append(s)
return stulist
def engAverage(arr):
total=0
for i in arr:
total+=i.eng
return int(total/len(arr))
def avgPercentageOfClass(arr):
subtotal=0
total=0
for i in arr:
subtotal=(i.eng+i.maths+i.hindi)//3
total+=subtotal
return int(total/len(arr))
N=int(input())
arr=createStudentArray(N)
print(engAverage(arr))
print(avgPercentageOfClass(arr)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this question, you need to create a class <b>Student</b> which has 4 parameters:-
<b>name ( String )</b>
<b>eng (int) </b>
<b>maths (int) </b>
<b>hindi (int) </b>
Also, you need to complete the given three functions:-
<b>createStudentArray</b>:- In which you need to create an array of students and take input
<b>engAverage</b>:- In which you need to create an average of marks in English.
<b>avgPercentageOfClass</b>:- In which you need to calculate the average percentage of the class.
Note:- Scanner is already defined in this question. Use "sc" for scanner.You need to take the input in <b>createStudentArray()</b> only in which you have already provided the number of students N you just have to create an array of size N and take input respectively.
Constraints:-
1 <= N <= 1000Return the Student array in <b>createStudentArray()</b>, Return the floor of average marks in english in <b>engAverage</b>, and return the floor of average percentage of the class in <b.avgPercentageOfClas</b>.
Note:- In <b>avgPercentageOfClas</b> you first need to create the average of individual then find the average of all the students.Sample Input:-
3
Shiv 65 47 78
Negi 55 40 56
Gargi 43 56 40
Sample Output:-
54
53
Explanation:-
Average marks in eng = (65 + 55 + 43)/3 = 163/3 = 54
Average percentage of class =>
shiv = (65 + 47 + 78)/3 = 190/3 = 63
Negi = (55 + 40 + 56)/3 = 151/3 = 50
Gargi = (43 + 56 + 40)/3 = 139/3 = 46
avg = (63 + 50 + 46 )/3 = 159 = 53, I have written this Solution Code:
static class Student
{
String name;
int eng, maths, hindi;
}
static Student[] createStudentArray(int n)
{
Student st[] = new Student[n];
for(int i = 0; i < n; i++)
{
st[i] = new Student();
st[i].name = sc.next();
st[i].eng = sc.nextInt();
st[i].hindi = sc.nextInt();
st[i].maths = sc.nextInt();
}
return st;
}
static int engAverage(Student st[], int n)
{
int sum = 0;
for(int i = 0; i < n; i++)
{
sum += st[i].eng;
}
return sum/n;
}
static int avgPercentageOfClass(Student st[], int n)
{
int sum = 0; int avg = 0;
for(int i = 0; i < n; i++)
{
sum = 0;
sum += st[i].eng + st[i].maths + st[i].hindi;
avg += sum/3;
}
return avg/(n);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int[] arr = new int[27];
int total_sum = s.length();
for(int i = 0;i<s.length();i++){
arr[(int)(s.charAt(i))-97]++;
}
int count = 0;
int diff = 0;
for(int i = 0;i<27;i++){
diff = total_sum - arr[i];
if(arr[i] != 0 && diff>= arr[i]){
count+= arr[i];
}
else if( arr[i] != 0 && diff < arr[i]){
count+=diff;
}
}
System.out.println(count);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: s=input()
si=len(s)
d={}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
l=list(d.values())
k = list(d.keys())
a=max(l)
if(si>=(2*a)):
print(si)
else:
ans=si-a
print(2*ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string S. Find a string R which is an anagram of S and the hamming distance between S and R is maximum.
An anagram of a string is another string that contains the same characters, only the order of characters can be different.
Hamming distance between two strings of equal length is the number of positions at which the corresponding character is different.The first and the only line of input contains a single string S.
Constraints:
1 <= |S| <= 100000
S contains only lowercase letters of the English alphabet.Print the maximum hamming distance between S and R.Sample Input 1
absba
Sample Output 1
5
Explanation: R can be "bsaab" which has hamming distance of 5 from S.
Sample Input 2
aaa
Sample Output 2
0
Explanation: R can be "aaa" which has hamming distance of 0 from S., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
string s;
cin>>s;
int n=s.length();
int f[26]={};
int ma=0;
for(auto r:s){
f[r-'a']++;
ma=max(ma,f[r-'a']);
}
sort(s.begin(),s.end());
string r=s;
for(int i=0;i<n;++i)
r[i]=s[(i+ma)%n];
int ans=0;
for(int i=0;i<n;++i)
if(s[i]!=r[i])
++ans;
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have a string of lowercase characters. A character is called major character if it occurs most number of times in the string. If two or more characters have the most number of occurrence then they all are major character(s).
Print the last occurrence of the major character(s). Indexing starts from 0.First line contains a single integer N denoting the size of the string.
Second line contains the string S.
<b>constraints</b>
1 <= N <= 10<sup>5</sup>
S contains only lowercase English letters.A single integer denoting the last occurrence of the major character(s).Sample Input:
10
occurrense
Output:
9
Explanation:
c, r and e are the major characters.
last occurrence of major character 'e' is at index 9., I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int n=Integer.parseInt(in.next());
String s=in.next();
int count[] = new int[26];
Arrays.fill(count,0);
for(int i=0;i<n;i++){
count[s.charAt(i) - 'a']++;
}
int major=0;
for(int i=0;i<26;i++){
if(count[i] > major){
major=count[i];
}
}
int last=0;
for(int i=0;i<n;i++){
int j=s.charAt(i) - 'a';
if(count[j] == major)last=i;
}
out.print(last);
out.close();
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: static void printInteger(int N){
System.out.println(N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: void printInteger(int x){
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: void printIntger(int n)
{
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b>
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>9</sup>Print the integer N.Sample Input:-
3
Sample Output:
3
Sample Input:
56
Sample Output:
56, I have written this Solution Code: n=int(input())
print (n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args)throws IOException {
Reader sc = new Reader();
int N = sc.nextInt();
int[] arr = new int[N];
for(int i=0;i<N;i++){
arr[i] = sc.nextInt();
}
int max=0;
if(arr[0]<arr[N-1])
System.out.print(N-1);
else{
for(int i=0;i<N-1;i++){
int j = N-1;
while(j>i){
if(arr[i]<arr[j]){
if(max<j-i){
max = j-i;
} break;
}
j--;
}
if(i==j)
break;
if(j==N-1)
break;
}
if(max==0)
System.out.print("-1");
else
System.out.print(max);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
/* For a given array arr[],
returns the maximum j – i such that
arr[j] > arr[i] */
int maxIndexDiff(int arr[], int n)
{
int maxDiff;
int i, j;
int *LMin = new int[(sizeof(int) * n)];
int *RMax = new int[(sizeof(int) * n)];
/* Construct LMin[] such that
LMin[i] stores the minimum value
from (arr[0], arr[1], ... arr[i]) */
LMin[0] = arr[0];
for (i = 1; i < n; ++i)
LMin[i] = min(arr[i], LMin[i - 1]);
/* Construct RMax[] such that
RMax[j] stores the maximum value from
(arr[j], arr[j+1], ..arr[n-1]) */
RMax[n - 1] = arr[n - 1];
for (j = n - 2; j >= 0; --j)
RMax[j] = max(arr[j], RMax[j + 1]);
/* Traverse both arrays from left to right
to find optimum j - i. This process is similar to
merge() of MergeSort */
i = 0, j = 0, maxDiff = -1;
while (j < n && i < n)
{
if (LMin[i] < RMax[j])
{
maxDiff = max(maxDiff, j - i);
j = j + 1;
}
else
i = i + 1;
}
return maxDiff;
}
// Driver Code
signed main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int maxDiff = maxIndexDiff(a, n);
cout << maxDiff;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of integers of size N, your task is to find the maximum parity index of this array.
<b>Parity Index is the maximum difference between two indices i and j (1 <= i < j <= N) of an array A such that A<sub>i</sub> < A<sub>j</sub>.</b>The first line contains a single integer N, next line contains N space-separated integers depicting the values of the array.
<b>Constraints:-</b>
1 < = N < = 10<sup>5</sup>
1 < = Arr[i] < = 10<sup>5</sup>Print the maximum value of <b>j- i</b> under the given condition, if no pair satisfies the condition print -1.Sample Input 1:-
5
1 2 3 4 5
Sample Output 1:-
4
Sample Input 2:-
5
5 4 3 2 1
Sample Output 2:-
-1
<b>Explanation 1:</b>
The maximum difference of j<sub>th</sub> - i<sub>th</sub> index is 4:(4<sub>th</sub> - 0<sub>th</sub>), also arr[4] > arr[0]
, I have written this Solution Code: n=int(input())
arr=list(map(int,input().split()))
rightMax = [0] * n
rightMax[n - 1] = arr[n - 1]
for i in range(n - 2, -1, -1):
rightMax[i] = max(rightMax[i + 1], arr[i])
maxDist = -2**31
i = 0
j = 0
while (i < n and j < n):
if (rightMax[j] >= arr[i]):
maxDist = max(maxDist, j - i)
j += 1
else:
i += 1
if maxDist==0:
maxDist=-1
print(maxDist), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
System.out.print("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some messages. Here, we will start with the famous <b>"Hello World"</b> message. Now, here you are given a function to complete. <i>Don't worry about the ins and outs of functions, <b>just add the printing command to print "Hello World", </b></i>.your task is to just print "Hello World", without the quotes.Hello WorldHello World must be printed., I have written this Solution Code: def print_fun():
print ("Hello World")
def main():
print_fun()
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: def QueenAttack(X, Y, P, Q):
if X==P or Y==Q or abs(X-P)==abs(Y-Q):
return 1
return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) .
Your task is to check whether the queen can attack the king in one move or not.
The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments.
Constraints:-
1 <= X, Y, P, Q <= 8
Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:-
1 1 5 5
Sample Output:-
1
Sample Input:-
3 4 6 6
Sample Output:-
0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){
if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){
return 1;
}
return 0;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: def Print_Digit(n):
dc = {1: "one", 2: "two", 3: "three", 4: "four",
5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"}
final_list = []
while (n > 0):
final_list.append(dc[int(n%10)])
n = int(n / 10)
for val in final_list[::-1]:
print(val, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a natural number N, your task is to print all the digits of the number in English words. The words have to separate by space and in lowercase English letters.<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>Print_Digit()</b> that takes integer N as a parameter.
<b>Constraints:-</b>
1 ≤ N ≤ 10<sup>7</sup>Print the digits of the number as shown in the example.
<b>Note:-</b>
Print all digits in lowercase English lettersSample Input:-
1024
Sample Output:-
one zero two four
Sample Input:-
2
Sample Output:-
two, I have written this Solution Code: class Solution {
public static void Print_Digits(int N){
if(N==0){return;}
Print_Digits(N/10);
int x=N%10;
if(x==1){System.out.print("one ");}
else if(x==2){System.out.print("two ");}
else if(x==3){System.out.print("three ");}
else if(x==4){System.out.print("four ");}
else if(x==5){System.out.print("five ");}
else if(x==6){System.out.print("six ");}
else if(x==7){System.out.print("seven ");}
else if(x==8){System.out.print("eight ");}
else if(x==9){System.out.print("nine ");}
else if(x==0){System.out.print("zero ");}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
function LeapYear(year){
// write code here
// return the output using return keyword
// do not use console.log here
if ((0 != year % 4) || ((0 == year % 100) && (0 != year % 400))) {
return 0;
} else {
return 1
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: year = int(input())
if year % 4 == 0 and not year % 100 == 0 or year % 400 == 0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.The input contains a single integer N
<b>Constraint:</b>
1 <= n <= 10<sup>4</sup>Print "YES" if the year is a leap year else print "NO".Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
int area = LeapYear(side);
if(area==1){
System.out.println("YES");}
else{
System.out.println("NO");}
}
static int LeapYear(int year){
if(year%400==0){return 1;}
if(year%100 != 0 && year%4==0){return 1;}
else {
return 0;}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: public static void For_Loop(int n){
for(int i=1;i<=n;i++){
if(i%2==1){System.out.print("odd ");}
else{
System.out.print("even ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, For each i (1<=i<=n) if i is even print "<b>even</b>" else print "<b>odd</b>".<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that take the integer n as a parameter.
</b>Constraints:</b>
1 ≤ n ≤ 100Print even or odd for each i, separated by white spaces.Sample Input:
5
Sample Output:
odd even odd even odd
Sample Input:
2
Sample Output:
odd even, I have written this Solution Code: n = int(input())
for i in range(1, n+1):
if(i%2)==0:
print("even ",end="")
else:
print("odd ",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c
<b>Constraint:</b>
1<=integers<=10000Print the maximum integer among the given integers.Sample Input:-
2 6 3
Sample Output:-
6
Sample Input:-
48 100 100
Sample Output:
100, I have written this Solution Code: a,b,c=[int(a) for a in input().split()]
print(max(a,b,c)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given three integers your task is to calculate the maximum integer among the given integers.The input contains three integers a, b, and c
<b>Constraint:</b>
1<=integers<=10000Print the maximum integer among the given integers.Sample Input:-
2 6 3
Sample Output:-
6
Sample Input:-
48 100 100
Sample Output:
100, 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 p = scanner.nextInt();
int tm = scanner.nextInt();
int r = scanner.nextInt();
int intrst = MaxInteger(p,tm,r);
System.out.println(intrst);
}
static int MaxInteger(int a ,int b, int c){
if(a>=b && a>=c){return a;}
if(b>=a && b>=c){return b;}
return c;}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int[]sort(int n, int a[]){
int i,key;
for(int j=1;j<n;j++){
key=a[j];
i=j-1;
while(i>=0 && a[i]>key){
a[i+1]=a[i];
i=i-1;
}
a[i+1]=key;
}
return a;
}
public static void main (String[] args) throws IOException {
InputStreamReader io = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
int n = Integer.parseInt(br.readLine());
String str = br.readLine();
String stra[] = str.trim().split(" ");
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = Integer.parseInt(stra[i]);
}
a=sort(n,a);
int max=0;
for(int i=0;i<n;i++)
{
if(a[i]+a[n-i-1]>max)
{
max=a[i]+a[n-i-1];
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements where N is even. You have to pair up the elements into N/2 pairs such that each element is in exactly 1 pair. You need to find minimum possible X such that there exists a way to pair the N elements and for no pair sum of its elements is greater than X.First line contains N.
Second line contains N space separated integers, denoting array.
Constraints:
1 <= N <= 100000
1 <= elements of the array <= 1000000000Print a single integer, minimum possible X.Sample Input
4
3 1 1 4
Sample Output
5
Explanation: we can pair (1, 3) and (1, 4) so all pairs have sum less than or equal to 5., I have written this Solution Code: n=int(input())
arr=input().split()
for i in range(0,n):
arr[i]=int(arr[i])
arr=sorted(arr,key=int)
start=0
end=n-1
ans=0
while(start<end):
ans=max(ans,arr[end]+arr[start])
start+=1
end-=1
print (ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
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: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ma=0;
for(int i=0;i<n;++i){
ma=max(ma,a[i]+a[n-i-1]);
}
cout<<ma;
#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: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: a=int(input())
for i in range(a):
n, m = map(int,input().split())
k=[]
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=sum(l)
k.append(l)
if(a==9):
print("NO")
elif(k[n-1][m-1]!=k[0][0]):
print("NO")
elif((n+m-1)*k[0][0]==s):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, 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 mod = 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;
}
int n, m;
vvi a, down, rt;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin >> n >> m;
a.clear();
down.clear();
rt.clear();
a.resize(n + 2, vi(m + 2));
down.resize(n + 2, vi(m + 2));
rt.resize(n + 2, vi(m + 2));
FOR (i, 1, n)
FOR (j, 1, m)
cin >> a[i][j];
FOR (i, 1, n)
{
if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1];
FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j];
}
bool flag=true;
FOR (i, 1, n)
{
if(flag==0)
break;
FOR (j, 1, m)
{
if (rt[i][j] < 0 || down[i][j] < 0 )
{
flag=false;
break;
}
if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j]))
{
flag=false;
break;
}
if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j]))
{
flag=false;
break;
}
}
}
if(flag)
cout << "YES\n";
else
cout<<"NO\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nutan was given a grid of size N×M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero):
He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells.
You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 ≤ T ≤ 10) — the number of test cases. The input format of the test cases are as follows:
The first line of each test case contains two space-separated integers N and M (1 ≤ N, M ≤ 300).
Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 ≤ A<sub>ij</sub> ≤ 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input:
3
1 1
10000
2 2
3 2
1 3
1 2
1 2
Sample Output:
YES
YES
NO, I have written this Solution Code: import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static void process() throws IOException {
int n = sc.nextInt(), m = sc.nextInt();
int arr[][] = new int[n][m];
int mat[][] = new int[n][m];
for(int i = 0; i<n; i++)arr[i] = sc.readArray(m);
mat[0][0] = arr[0][0];
int i = 0, j = 0;
while(i<n && j<n) {
if(arr[i][j] != mat[i][j]) {
System.out.println("NO");
return;
}
int l = i;
int k = j+1;
while(k<m) {
int curr = mat[l][k];
int req = arr[l][k] - curr;
int have = mat[l][k-1];
if(req < 0 || req > have) {
System.out.println("NO");
return;
}
have-=req;
mat[l][k-1] = have;
mat[l][k] = arr[l][k];
k++;
}
if(i+1>=n)break;
for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k];
i++;
}
System.out.println("YES");
}
private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
private static int N = 0;
private static void google(int tt) {
System.out.print("Case #" + (tt) + ": ");
}
static FastScanner sc;
static FastWriter out;
public static void main(String[] args) throws IOException {
boolean oj = true;
if (oj) {
sc = new FastScanner();
out = new FastWriter(System.out);
} else {
sc = new FastScanner("input.txt");
out = new FastWriter("output.txt");
}
long s = System.currentTimeMillis();
int t = 1;
t = sc.nextInt();
int TTT = 1;
while (t-- > 0) {
process();
}
out.flush();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.err.println(Arrays.deepToString(o));
}
static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.x, o.x);
}
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long sqrt(long z) {
long sqz = (long) Math.sqrt(z);
while (sqz * 1L * sqz < z) {
sqz++;
}
while (sqz * 1L * sqz > z) {
sqz--;
}
return sqz;
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
public static long gcd(long a, long b) {
if (a > b)
a = (a + b) - (b = a);
if (a == 0L)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
public static int lower_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > x) {
high = mid - 1;
} else {
ans = mid;
low = mid + 1;
}
}
return ans;
}
public static int upper_bound(int[] arr, int x) {
int low = 0, high = arr.length - 1, mid = -1;
int ans = arr.length;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void reverseArray(int[] a) {
int n = a.length;
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
static void reverseArray(long[] a) {
int n = a.length;
long arr[] = new long[n];
for (int i = 0; i < n; i++)
arr[i] = a[n - i - 1];
for (int i = 0; i < n; i++)
a[i] = arr[i];
}
public static void push(TreeMap<Integer, Integer> map, int k, int v) {
if (!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k) + v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v) {
int lol = map.get(k);
if (lol == v)
map.remove(k);
else
map.put(k, lol - v);
}
public static int[] compress(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1;
for (int x : ls)
if (!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for (int i = 0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
static class FastScanner {
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1)
return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] readArray(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] readArrayLong(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public int[][] readArrayMatrix(int N, int M, int Index) {
if (Index == 0) {
int[][] res = new int[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
int[][] res = new int[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = (int) nextLong();
}
return res;
}
public long[][] readArrayMatrixLong(int N, int M, int Index) {
if (Index == 0) {
long[][] res = new long[N][M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
res[i][j] = nextLong();
}
return res;
}
long[][] res = new long[N][M];
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++)
res[i][j] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC)
c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-')
neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] readArrayDouble(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32)
c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32)
return true;
while (true) {
c = getChar();
if (c == NC)
return false;
else if (c > 32)
return true;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter.
Constraints:
1 <= P <= 10^3
1 <= Tm <= 20
1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input:
42 15 8
Output:
50
Explanation:
Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: import math
p,t,r = [int(x) for x in input().split()]
res=p*t*r
print(math.floor(res/100)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to find the simple interest for given principal amount P, time Tm(in years) and rate R.<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>SimpleInterest()</b> that takes the principal amount P, rate R, and time Tm as a parameter.
Constraints:
1 <= P <= 10^3
1 <= Tm <= 20
1 <= R <= 20Return the floor value of the simple interest i.e. interest in integer format.Input:
42 15 8
Output:
50
Explanation:
Testcase 1: Simple interest of given principal amount 42, in 8 years at a 15% rate of interest is 50., I have written this Solution Code: static int SimpleInterest(int P, int R, int Tm){
return (P*Tm*R)/100;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A circular array is called good if, for every index i (0 to N-1), there exists an index j such that i != j and sum of all the numbers in the clockwise direction from i to j is equal to the sum of all numbers in the anticlockwise direction from i to j.
You are given an circular array of size N, Your task is to check whether the given array is good or not.First line of input contains a single integer N, the next line of input contains N space separated integes depicting values of the array.
Constraints:-
1 <= N <= 100000
1 <= Arr[i] <= 1000000Print "Yes" if array is good else print "No"Sample Input:-
4
1 4 1 4
Sample Output:-
Yes
Explanation:-
for index 1, j will be 3, then sum of elements from index 1 to 3 in clockwise direction will be 1 + 4 + 1 = 6 and the sum of elements from index 1 to 3 in anticlockwise direction will be 1 + 4 + 1 = 6.
For index 2, j will be 4
For index 3, j will be 1
For index 4, j will be 2
Sample Input:-
4
1 2 3 4
Sample Output:-
No, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 10001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int INF = 4557430888798830399ll;
signed main()
{
fast();
int n;
cin>>n;
int a[n];
FOR(i,n){
cin>>a[i];}
if(n&1){out("No");return 0;}
FOR(i,n/2){
if(a[i]!=a[n/2+i]){out("No");return 0;}
}
out("Yes");
}
, In this Programming Language: Unknown, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given first term A and the common ratio R of a GP (Geometric Progression) and an integer N, your task is to calculate its Nth term.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function
<b>NthGP()</b> that takes the integer A, R and N as parameter.
<b>Constraints</b>
1 <= A, R <= 100
1 <= N <= 10
Return the Nth term of the given GP.
<b>Note:</b> It is guaranteed that the Nth term of this GP will always fit in 10^9.Sample Input:
3 2
5
Sample Output:-
48
Sample Input:-
2 2
10
Sample Output:
1024
<b>Explanation:-</b>
For Test Case 1:- 3 6 12 24 48 96., I have written this Solution Code:
static int NthGP(int l, int b, int h){
int ans=l;
h--;
while(h-->0){
ans*=b;
}
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has an array A of length N consisting of integers. The elements of the array may be positive, negative or zero. Further, Alice has a special integer K and she can choose any subarray of A and make all its elements equal to K. In other words, Alice can choose two integers i and j such that 1 ≤ i ≤ j ≤ N, and make A[i] = A[i + 1] = ... = A[j] = K.
Note that Alice can do this operation at most once, and possibly not do it at all. Find the maximum possible sum of the array.The first line consists of two space-separated integers N and K.
The second line consists of N space-separated integers – A[1], A[2], ... A[N].
<b>Constraints:</b>
1 ≤ N ≤ 1000
-1000 ≤ K ≤ 1000
-1000 ≤ A[i] ≤ 1000Print a single integer denoting the maximum possible sum of the array after the operation.Sample Input 1:
3 1
-1 5 -2
Sample Output 1:
5
Sample Explanation 1:
It is optimal to assign the subarray [3, 3]. The sum then becomes -1 + 5 + 1 = 5.
Sample Input 2:
3 0
-1 -2 3
Sample Output 2:
3
Sample Explanation 2:
It is optimal to assign the subarray [1, 2]. The sum then becomes 0 + 0 + 3 = 3.
Sample Input 3:
2 0
2 4
Sample Output 3:
6
Sample Explanation 3:
It is optimal to not assign any subarrays., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] tokens = br.readLine().split(" ");
int n = Integer.parseInt(tokens[0]), k = Integer.parseInt(tokens[1]);
int[] arr = new int[n];
tokens = br.readLine().split(" ");
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(tokens[i]);
int[] sums = new int[n];
sums[0] = arr[0];
for (int i = 1; i < n; i++)
sums[i] = arr[i] + sums[i - 1];
int maxSum = sums[n - 1];
for (int i = 0; i < n; i++) {
int sum = sums[n - 1] - sums[i] + k * (i + 1);
if (sum > maxSum)
maxSum = sum;
}
for (int i = 1; i < n; i++) {
for (int j = i; j < n; j++) {
int sum = sums[n - 1] - (sums[j] - sums[i - 1]) + k * (j - i + 1);
if (sum > maxSum)
maxSum = sum;
}
}
System.out.println(maxSum);
} catch (Exception e) {
System.out.println("Exception caught");
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has an array A of length N consisting of integers. The elements of the array may be positive, negative or zero. Further, Alice has a special integer K and she can choose any subarray of A and make all its elements equal to K. In other words, Alice can choose two integers i and j such that 1 ≤ i ≤ j ≤ N, and make A[i] = A[i + 1] = ... = A[j] = K.
Note that Alice can do this operation at most once, and possibly not do it at all. Find the maximum possible sum of the array.The first line consists of two space-separated integers N and K.
The second line consists of N space-separated integers – A[1], A[2], ... A[N].
<b>Constraints:</b>
1 ≤ N ≤ 1000
-1000 ≤ K ≤ 1000
-1000 ≤ A[i] ≤ 1000Print a single integer denoting the maximum possible sum of the array after the operation.Sample Input 1:
3 1
-1 5 -2
Sample Output 1:
5
Sample Explanation 1:
It is optimal to assign the subarray [3, 3]. The sum then becomes -1 + 5 + 1 = 5.
Sample Input 2:
3 0
-1 -2 3
Sample Output 2:
3
Sample Explanation 2:
It is optimal to assign the subarray [1, 2]. The sum then becomes 0 + 0 + 3 = 3.
Sample Input 3:
2 0
2 4
Sample Output 3:
6
Sample Explanation 3:
It is optimal to not assign any subarrays., I have written this Solution Code: N, K = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
initialsum = sum(arr)
maxtamp = 0
temp = 0
for i in range(N):
temp += (K - arr[i])
maxtamp = max(maxtamp, temp)
if temp < 0:
temp = 0
print(initialsum + maxtamp), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice has an array A of length N consisting of integers. The elements of the array may be positive, negative or zero. Further, Alice has a special integer K and she can choose any subarray of A and make all its elements equal to K. In other words, Alice can choose two integers i and j such that 1 ≤ i ≤ j ≤ N, and make A[i] = A[i + 1] = ... = A[j] = K.
Note that Alice can do this operation at most once, and possibly not do it at all. Find the maximum possible sum of the array.The first line consists of two space-separated integers N and K.
The second line consists of N space-separated integers – A[1], A[2], ... A[N].
<b>Constraints:</b>
1 ≤ N ≤ 1000
-1000 ≤ K ≤ 1000
-1000 ≤ A[i] ≤ 1000Print a single integer denoting the maximum possible sum of the array after the operation.Sample Input 1:
3 1
-1 5 -2
Sample Output 1:
5
Sample Explanation 1:
It is optimal to assign the subarray [3, 3]. The sum then becomes -1 + 5 + 1 = 5.
Sample Input 2:
3 0
-1 -2 3
Sample Output 2:
3
Sample Explanation 2:
It is optimal to assign the subarray [1, 2]. The sum then becomes 0 + 0 + 3 = 3.
Sample Input 3:
2 0
2 4
Sample Output 3:
6
Sample Explanation 3:
It is optimal to not assign any subarrays., I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int n, x;
cin >> n >> x;
int a[n + 1] = {}, pre[n + 1] = {};
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
int ans = pre[n];
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
ans = max(ans, pre[i - 1] + (pre[n] - pre[j]) + x*(j - i + 1));
cout << ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code:
int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: static int Phone(int n, int k, int m){
if(n*k<m){
return -1;
}
int x = m/k;
if(m%k!=0){x++;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments.
Constraints:-
1 <= N <= 1000
1 <= K <= 100
0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:-
10 3 10
Sample Output:-
4
Sample Input:-
10 3 40
Sample Output:-
-1, I have written this Solution Code: def Phone(N,K,M):
if N*K < M :
return -1
x = M//K
if M%K!=0:
x=x+1
return x, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: class Solution {
public static void printTriangle(){
System.out.println("*");
System.out.println("* *");
System.out.println("* * *");
System.out.println("* * * *");
System.out.println("* * * * *");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle.
See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>.
In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input:
No Input
Sample Output:-
*
* *
* * *
* * * *
* * * * *, I have written this Solution Code: j=1
for i in range(0,5):
for k in range(0,j):
print("*",end=" ")
if(j<=4):
print()
j=j+1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int cost(int n){
if(n == 0) return 0;
int g = (n-1)/3 + 1;
return g*g + cost(n-g);
}
signed main() {
IOS;
clock_t start = clock();
int q; cin >> q;
while(q--){
int n;
cin >> n;
cout << cost(n) << endl;
}
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: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., 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)
);
long q = Long.parseLong(br.readLine());
while(q-->0)
{
long N = Long.parseLong(br.readLine());
System.out.println(candyCrush(N,0,0));
}
}
static long candyCrush(long N, long cost,long group)
{
if(N==0)
{
return cost;
}
if(N%3==0)
{
group = N/3;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
else
{
group = (N/3)+1;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
}
}, 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: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Cf cf = new Cf();
cf.solve();
}
static class Cf {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int mod = (int)1e9+7;
public void solve() {
int t = in.readInt();
if(t>=6) {
out.printLine("No");
}else {
out.printLine("Yes");
}
}
public long findPower(long x,long n) {
long ans = 1;
long nn = n;
while(nn>0) {
if(nn%2==1) {
ans = (ans*x) % mod;
nn-=1;
}else {
x = (x*x)%mod;
nn/=2;
}
}
return ans%mod;
}
public static int log2(int x) {
return (int) (Math.log(x) / Math.log(2));
}
private static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * Math.pow(10, readInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
private static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
writer.flush();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
writer.flush();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, 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 n;
cin>>n;
if(n<6)
cout<<"Yes";
else
cout<<"No";
#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: Hi, it's Monica!
Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle.
Constraints
1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input
3
Sample Output
Yes
Sample Input
10
Sample Output
No, I have written this Solution Code: n=int(input())
if(n>=6):
print("No")
else:
print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: def patternPrinting(n):
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end=' ')
print()
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given length l, width b and height h of a cuboid. The task is to find the total surface area and volume of cuboid.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:-
<b>Surface_Area()</b> that takes the integer l, b and h as parameter.
<b>Volume()</b> that takes the integer l, b and h as parameter.
<b>Constraints:</b>
1 <= l, b, h <= 10^2Return the surface area of cuboid in function Surface_Area() and return Volume of cuboid in function Volume().Sample Input:
1 2 3
Sample Output:
22 6
Explanation:
Test Case 1: The total surface area for the given cuboid is 22 and its volume 6., I have written this Solution Code: static int Surface_Area(int l, int b, int h){
return 2*(l*b + b*h + h*l);
}
static int Volume(int l, int b, int h){
return l*b*h;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: str1 = input()
str2 = ''
for i in range(len(str1)):
if(i % 2 == 0):
str2 = str2 + str1[i]+" "
print(str2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
for(int i = 0;i<s.length();i++){
if(i%2==0){
System.out.print(s.charAt(i)+" ");
}
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: // str is input
function oddChars(str) {
// write code here
// do not console.log
// return the output as a string
return str.split('').filter((v,idx)=> idx % 2 === 0).join(' ')
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string(1-indexed). Print all the characters of the string at odd positions.The first line of the input contains a string S. String contains only lowercase english letters.
Constraints:-
1 <= |S| <= 100
The output should contain the character's at odd positions seperated by space.Sample Input
abcde
Sample Output
a c e
Sample Input
abcd
Sample Output
a c
Explanation:
index => 1 2 3 4
chars => a b c d
a and c are at odd index., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(!(i&1)){cout<<s[i]<<" ";}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of size N. You will now be asked Q queries. In each query, you will be given two pairs of integers (A, B) and (C, D). To answer this query, you must take all values in the subarray [A, B] and sort them. Similarly, take all values in the subarray [C, D] and sort them. You need to print "Yes" if these two subarrays after sorting differ in atmost one position, otherwise print "No".The first line contains a single integer T – the number of test cases.
The first line of each test case contains two space-separated integers, N and Q.
The second line contains N space-separated integers A<sub>1</sub>, A<sub>2</sub> ... A<sub>N</sub>.
Then Q lines follow, each line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 ≤ T ≤ 10
1 ≤ N, Q ≤ 10<sup>5</sup>
1 ≤ A<sub>i</sub> ≤ 10<sup>5</sup>
B - A = D - COutput Q lines for each test case, each line containing either "Yes" or "No" denoting the answer to that query. Note that the <b>output is case-sensitive</b>.Sample Input 1:
3
3 3
1 2 3
1 2 2 3
1 3 1 3
1 1 3 3
6 3
1 2 3 1 2 3
1 3 4 6
1 4 2 5
1 5 2 6
3 3
1 1 1
1 2 2 3
1 1 2 2
1 3 1 3
Sample Output 1:
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes, I have written this Solution Code: #include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define ll long long
//#define Neutral Shimokitazawa
#define Tp template<class T>
#ifdef Neutral
const int End=1e6;
char buf[End],*p1=buf,*p2=buf;
#define g() (p1==p2&&(p2=(p1=buf)+fread(buf,1,End,stdin),p1==p2)?EOF:*p1++)
#else
#define g() getchar()
#endif
#define pc(x) putchar(x)
#define isd(x) (x>=48&&x<=57)
namespace SlowIO{
Tp inline void rd(T &x) {
x=0; char i=g(); bool f=1;
while(!isd(i)) f&=(i!='-'),i=g();
while(isd(i)) x=(x<<3)+(x<<1)+(i^48),i=g();
x*=((f<<1)-1);
}
const int OUT=1e6;
static char outp[OUT]; int out;
Tp inline void op(T x){
out=0; x<0&&(x=-x,pc('-'));
if(!x){ pc(48); return; }
while(x) outp[++out]=x%10+48,x/=10;
while(out) pc(outp[out--]);
}
Tp inline void writeln(T x){ op(x);pc('\n'); }
Tp inline void writesp(T x){ op(x); pc(' '); }
Tp inline void write(T x,char c=0){ op(x); c&&pc(c); }
}; using namespace SlowIO;
#define Seed chrono::steady_clock::now().time_since_epoch().count()
mt19937 rnd(Seed);
const int mod=19260817; //随机后的hash值区间[1,19260817]
#define pii pair<int,int>
#define rp register pii
#define fir(x) x.first
#define sec(x) x.second
#define N 100001
int n,q,a[N];
int fash[N]; //fash[i]:值i对应的hash 由于hash和STL冲了所以以后都用fash(
struct __tree{
struct seg{
int lc,rc;
ll val; int cnt;
}tr[N*80]; int tot;
#define lef(u) tr[u].lc
#define rig(u) tr[u].rc
#define Val(u) tr[u].val
#define Cnt(u) tr[u].cnt
inline void change(int &u,int lst,int l,int r,int x){
tr[u=++tot]=tr[lst];
Val(u)+=fash[x],++Cnt(u);
if(l==r) return; ri mid=l+r>>1;
if(x<=mid) change(lef(u),lef(lst),l,mid,x);
else change(rig(u),rig(lst),mid+1,r,x);
}
inline pii qfirst(int u,int lst1,int v,int lst2,int l,int r){
if(l==r) return {Cnt(u)-Cnt(lst1)-(Cnt(v)-Cnt(lst2)),l}; //由于不一定就是一个有而另一个无,可能是数量不同,所以需要记录数量差
ri mid=l+r>>1; bool t=Val(lef(u))-Val(lef(lst1))==Val(lef(v))-Val(lef(lst2));
if(t) return qfirst(rig(u),rig(lst1),rig(v),rig(lst2),mid+1,r);
else return qfirst(lef(u),lef(lst1),lef(v),lef(lst2),l,mid);
} //直接在主席树上二分少只log
inline pii qlast(int u,int lst1,int v,int lst2,int l,int r){
if(l==r) return {Cnt(u)-Cnt(lst1)-(Cnt(v)-Cnt(lst2)),l};
ri mid=l+r>>1; bool t=Val(rig(u))-Val(rig(lst1))==Val(rig(v))-Val(rig(lst2));
if(t) return qlast(lef(u),lef(lst1),lef(v),lef(lst2),l,mid);
else return qlast(rig(u),rig(lst1),rig(v),rig(lst2),mid+1,r);
} //first:最小的不相同数 last:最大的不相同数
inline int quecnt(int u,int lst,int l,int r,int L,int R){
if(l>=L&&r<=R) return Cnt(u)-Cnt(lst);
ri mid=l+r>>1,ret=0;
if(L<=mid) ret=quecnt(lef(u),lef(lst),l,mid,L,R);
if(R>mid) ret+=quecnt(rig(u),rig(lst),mid+1,r,L,R);
return ret;
}
inline ll queval(int u,int lst,int l,int r,int L,int R){
if(l>=L&&r<=R) return Val(u)-Val(lst);
ri mid=l+r>>1; ll ret=0;
if(L<=mid) ret=queval(lef(u),lef(lst),l,mid,L,R);
if(R>mid) ret+=queval(rig(u),rig(lst),mid+1,r,L,R);
return ret;
}
}tr; int root[N];
const int lim=1e5;
inline bool query(int a,int b,int c,int d){
if(tr.queval(root[b],root[a-1],1,lim,1,lim)
==tr.queval(root[d],root[c-1],1,lim,1,lim)) return true; //哈希值相同
rp l=tr.qfirst(root[b],root[a-1],root[d],root[c-1],1,lim),
r=tr.qlast(root[b],root[a-1],root[d],root[c-1],1,lim);
//if(sec(l)==sec(r)) return true; //上下界相同 这里不返回则下面上下界都不同
if(fir(l)*fir(r)>0) return false; //两个区间内都是同一棵树更多
if(abs(fir(l))>=2||abs(fir(r))>=2) return false; //有任意一个边界存在一棵树比另一棵树多(>=2)个
return tr.quecnt(root[b],root[a-1],1,lim,sec(l)+1,sec(r)-1)==0&&
tr.quecnt(root[d],root[c-1],1,lim,sec(l)+1,sec(r)-1)==0; //在上下界中间不存在其他数
}
inline void Episode(){
//play an episode for queries!
if(!n) return;
tr.tot=0,fill(fash+1,fash+lim+1,0);
}
#define readf(name) freopen(name".in","r",stdin)
#define writf(name) freopen(name".out","w",stdout)
int main()
{
//readf("input3"),writf("mine");
int T; rd(T);
while(T--){
tr.tot=0; //Episode();
rd(n),rd(q);
for(ri i=1;i<=n;++i){
rd(a[i]);
if(!fash[a[i]])
fash[a[i]]=rnd()%mod+1;
tr.change(root[i],root[i-1],1,lim,a[i]);
} while(q--){
int a,b,c,d;
rd(a),rd(b),rd(c),rd(d);
assert(d -c == b - a);
if(a==c&&b==d){puts("Yes"); continue;}
puts(query(a,b,c,d)?"Yes":"No");
}
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: static void pattern(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j + " ");
}
System.out.println();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code:
void patternPrinting(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
printf("\n");
}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to print a right-angle triangle pattern of consecutive numbers of height N.
See the example for a better understanding.<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>pattern()</b> that takes integer n as a parameter.
Constraint:
1 <= N <= 100Print a right angle triangle of numbers of height N.Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Sample Input:
2
Sample Output:
1
1 2, I have written this Solution Code: function pattern(n) {
// write code herenum
for(let i = 1;i<=n;i++){
let str = ''
for(let k = 1; k <= i;k++){
if(k === 1) {
str += `${k}`
}else{
str += ` ${k}`
}
}
console.log(str)
}
}, In this Programming Language: JavaScript, 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.