Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc= new FastReader();
String str= sc.nextLine();
String a="Apple";
if(a.equals(str)){
System.out.println("Gravity");
}
else{
System.out.println("Space");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
//-----------------------------------------------------------------------------------------------------------//
string S;
cin>>S;
if(S=="Apple")
{
cout<<"Gravity"<<endl;
}
else
{
cout<<"Space"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''.
Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 ≤ length of S ≤ 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1:
Apple
Sample Output 1:
Gravity
Sample Input 2:
Mango
Sample Output 2:
Space
Sample Input 3:
AppLE
Sample Output 3:
Space, I have written this Solution Code: n=input()
if n=='Apple':print('Gravity')
else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: Given four positive integers A, B, C, and D, can a rectangle have these integers as its sides?The input consists of a single line containing four space-separated integers A, B, C and D.
<b> Constraints: </b>
1 ≤ A, B, C, D ≤ 1000Output "Yes" if a rectangle is possible; otherwise, "No" (without quotes).Sample Input 1:
3 4 4 3
Sample Output 1:
Yes
Sample Explanation 1:
A rectangle is possible with 3, 4, 3, and 4 as sides in clockwise order.
Sample Input 2:
3 4 3 5
Sample Output 2:
No
Sample Explanation 2:
No rectangle can be made with these side lengths., I have written this Solution Code: #include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==c) &&(b==d)){
cout << "Yes\n";
}else if((a==b) && (c==d)){
cout << "Yes\n";
}else if((a==d) && (b==c)){
cout << "Yes\n";
}else{
cout << "No\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code: t=int(input())
while t>0:
n=int(input())
a=map(int,input().split())
m=0
c=0
for i in a:
c+=i
if c>m:m=c
elif c<0:c=0
print(m)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static long Sum(int a[], int size)
{
long max_so_far = -1000000007, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
while(t-->0){
int n = Integer.parseInt(br.readLine().trim());
int arr[] = new int[n];
String inputLine[] = br.readLine().trim().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(inputLine[i]);
}
System.out.println(Sum(arr,n));
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array, A of length N, find the contiguous subarray within A which has the largest sum.First line of each test case contain the number of test cases.
The first line of each test case contains an integer n, the length of the array A
and the next line contains n integers.
Constraints:
1<=T<=100
1 <= N <= 10^5
-10^6 <= A[i] <= 10^6Output an integer representing the maximum possible sum of the contiguous subarray.Input:
1
5
1 2 3 4 -10
Output:
10
Explanation:-
1+2+3+4=10, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
long long Sum(long long a[], int size)
{
long long max_so_far = INT_MIN, max_ending_here = 0;
for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<Sum(a,n)<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b. Your task is to find the sum of all the even divisors of each number from a to b inclusive.The input contains two integers a and b.
<b>Constraints:-</b>
1 ≤ a ≤ b ≤ 10<sup>8</sup>Print the sum of even divisors.Sample Input 1:-
1 10
Sample Output 1:-
42
Sample Input 2:-
1 20
Sample Output 2:-
174
<b>Explanation:</b>
Even divisors for 1:- NIL
Even divisors for 2:- 2
Even divisors for 3:- NIL
Even divisors for 4:- 2, 4
Even divisors for 5:- NIL
Even divisors for 6:- 2,6
Even divisors for 7:- NIL
Even divisors for 8:- 2, 4, 8
Even divisors for 9:- NIL
Even divisors for 10:- 2,10
Total :- 2+2+4+2+6+2+4+8+2+10 = 42, I have written this Solution Code: import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
assert a>=1&&a<=100000000 : "Input not valid";
assert b>=a&&b<=100000000 : "Input not valid";
long ans=0;
for(int i=2;i<=b;i+=2){
int t=b/i;
t-=(a-1)/i;
ans+=t*i;
}
System.out.print(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 find the sum of all the even divisors of each number from a to b inclusive.The input contains two integers a and b.
<b>Constraints:-</b>
1 ≤ a ≤ b ≤ 10<sup>8</sup>Print the sum of even divisors.Sample Input 1:-
1 10
Sample Output 1:-
42
Sample Input 2:-
1 20
Sample Output 2:-
174
<b>Explanation:</b>
Even divisors for 1:- NIL
Even divisors for 2:- 2
Even divisors for 3:- NIL
Even divisors for 4:- 2, 4
Even divisors for 5:- NIL
Even divisors for 6:- 2,6
Even divisors for 7:- NIL
Even divisors for 8:- 2, 4, 8
Even divisors for 9:- NIL
Even divisors for 10:- 2,10
Total :- 2+2+4+2+6+2+4+8+2+10 = 42, I have written this Solution Code: // #include <bits/stdc++.h>
// using namespace std;
// long long int mod=1e9+7;
// #define inf INT_MAX
// #define f first
// #define s second
// #define psb push_back
// #define ppb pop_back
// #define psf push_front
// #define ppf pop_front
// #define umap unordered_map
// #define uset unordered_set
// typedef long long int ll;
// typedef long double ld;
// typedef pair<int,int> pi;
// typedef pair<long long int,long long int> pll;
// typedef vector<pair<int,int>> vpi;
// typedef vector<pair<long long int,long long int>> vpll;
// typedef vector<int> vi;
// typedef vector<vector<int>> vvi;
// typedef vector<vector<pair<int,int>>> vvpi;
// typedef vector<long long int> vll;
// typedef vector<string> vs;
// typedef vector<vector<long long int>> vvll;
// typedef vector<vector<vector<int>>> vvvi;
// typedef vector<vector<vector<long long int>>> vvvll;
// typedef vector<vector<pair<long long int,long long int>>> vvpll;
// typedef unsigned int ui;
// typedef unsigned long long int ull;
// ll long_max=((unsigned ll)1<<63)-1;
// int int_max=INT_MAX;
// ll powm(ll x,ll y){
// if(x==1||x==0) return x;
// if(y==0) return 1;
// if(y==1) return x;
// ll ans=powm(x,y/2);
// ans=(ans*ans)%mod;
// if(y%2==1){
// ans=(ans*x)%mod;
// }
// return ans;
// }
// vvll matmul(vvll &x,vvll &y){
// int n=x.size();
// vvll ans=x;
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// ans[i][j]=0;
// for(int k=0;k<n;k++){
// ans[i][j]+=x[i][k]*y[k][j];
// ans[i][j]%=mod;
// }
// }
// }
// return ans;
// }
// vvll matexp(vvll &x,ll y){
// // if(x==1||x==0) return x;
// // if(y==0) return 1;
// if(y==1) return x;
// vvll ans=matexp(x,y/2);
// ans=matmul(ans,ans);
// if(y%2==1){
// ans=matmul(ans,x);
// }
// return ans;
// }
// // in O(sqrt(n));
// vll factors(ll a){
// vll ans;
// ll i=1;
// while(i*i<=a){
// if(a%i==0){
// ans.psb(i);
// if(a/i!=i){
// ans.psb(a/i);
// }
// }
// i++;
// }
// sort(ans.begin(),ans.end());
// return ans;
// }
// // enable fac and invfac in main function to use
// // factorial and inverse factorial vectors;
// vll fc,invfc,inv;
// void fac(int n){
// fc.resize(n);
// fc[0]=1;
// for(int i=1;i<n;i++){
// fc[i]=(fc[i-1]*i)%mod;
// }
// }
// void invfac(int n){
// inv.resize(n);
// for(int i=0;i<n;i++){
// inv[i]=powm(i,mod-2);
// }
// invfc.resize(n);
// invfc[0]=1;
// invfc[1]=1;
// for(int i=2;i<n;i++){
// invfc[i]=(invfc[i-1]*inv[i])%mod;
// }
// }
// // enable fac() and invfac() in main function to use c;
// ll ncr(int n,int r){
// if(r>n) return 0;
// return (((fc[n]*invfc[r])%mod)*invfc[n-r])%mod;
// }
// ll npr(int n,int r){
// if(r>n) return 0;
// return ((fc[n]*invfc[n-r])%mod)%mod;
// }
// // enable siv() in main to use vector isprime;
// vi isprime;
// vi prime;
// void siv(int n){
// isprime.assign(n,1);
// isprime[1]=0;
// for(int i=2;i<n;i++){
// if(isprime[i]==0)continue;
// prime.psb(i);
// int j=i;
// while(i*(ll)j<n){
// isprime[i*j]=0;
// j++;
// }
// }
// }
// vi fps;
// void fp_sieve(int n){
// fps.assign(n,0);
// fps[1]=1;
// for(int i=2;i<n;i++){
// if(fps[i]==0){
// fps[i]=i;
// int j=i;
// while(i*(ll)j<n){
// if(fps[i*j]==0)
// fps[i*j]=i;
// j++;
// }
// }
// }
// }
// // enable fp_sieve to use this function and fps vector;
// // prime factorization in O(log(n));
// vpi pmfactors(int t){
// vpi ans;
// // vector using fps vector;
// while(t!=1){
// if(ans.size()==0||ans.back().f!=fps[t]) ans.psb({fps[t],1});
// else ans.back().s++;
// t/=fps[t];
// }
// reverse(ans.begin(),ans.end());
// return ans;
// }
// // prime factorization in O(sqrt(n));
// vpi abs_pmfactors(int t){
// vpi ans;
// int i=2;
// while(i*i<=t){
// if(t%i==0){
// ans.psb({i,0});
// while(t%i==0){
// t/=i;
// ans.back().s++;
// }
// }
// i++;
// }
// if(t!=1) ans.psb({t,1});
// sort(ans.begin(),ans.end());
// return ans;
// }
// ll mystoll(string &a){
// ll ans=0,t=1;
// while(a.size()>0){
// ans=(a.back()-'0')*t+ans;
// t*=10;
// a.pop_back();
// }
// return ans;
// }
// string itos(ll a){
// if(a==0) return "0";
// string ans="";
// bool vd=0;
// if(a<0){
// vd=1;
// a*=-1;
// }
// while(a>0){
// ans=(char)(a%10+'0')+ans;
// a/=10;
// }
// if(vd) ans="-"+ans;
// return ans;
// }
// bool ispal(string &a,int si,int ei){
// // int n=a.size();
// // int si=0,ei=n-1;
// while(si<ei&&a[si]==a[ei]) si++,ei--;
// if(si<ei) return 0;
// return 1;
// }
// ll absncr(ll n,ll k){
// if(k>n) return 0;
// ld ans=1;
// for(int i=1;i<=k;i++){
// ans=ans*(n-k+i)/i;
// ans=floor(ans+0.01);
// ll fns=ans;
// fns%=mod;
// ans=fns;
// }
// return floor(ans+0.01);
// }
// struct llnode{
// int val;
// llnode* next;
// llnode(int val){
// this->val=val;
// next=0;
// }
// ~llnode(){
// delete this->next;
// }
// };
// struct node{
// ll f,s,v;
// node(){};
// node(ll x,ll y,ll t):f(x),s(y),v(t){}
// };
// // vpi a;
// // struct mncomp{
// // bool operator()(const int &x,const int &y) const{
// // if(a[x].s>a[y].s) return 1;
// // else if(a[x].s<a[y].s) return 0;
// // else return a[x].f<a[y].f;
// // }
// // };
// // struct mxcomp{
// // bool operator()(const int &x,const int &y) const{
// // if(a[x][1]<a[y][1]) return 1;
// // else if(a[x][1]>a[y][1]) return 0;
// // else return a[x][2]>a[y][2];
// // }
// // };
// struct bstcomp{
// bool operator()(const pll &x,const pll &y) const{
// if(x.f<y.f) return 1;
// if(x.f>y.f) return 0;
// return x.s<y.s;
// // return 0;
// }
// };
// struct comp{
// bool operator()(const pll &x,const pll &y) const{
// if(x.f<y.f) return 1;
// // if(x.f<y.f) return 0;
// // return x.s<y.s;
// return 0;
// }
// };
// // // int n,m;
// vvi ed,up;
// vi vd;
// // // vi x,pt,rs;
// // // vll val,vd,ct,sum,pt,dt;
// // // vpi dpg,dpb;
// void dfs(int curr,int pnt){
// // up[curr][0]=pnt;
// // int i=1;
// // while(up[curr][i-1]!=-1){
// // up[curr][i]=up[up[curr][i-1]][i-1];
// // i++;
// // if(i>up[0].size())break;
// // }
// // dt[curr]=dpt;
// for(int i=0;i<ed[curr].size();i++){
// int cd=ed[curr][i];
// int vl=up[curr][i];
// if(cd==pnt) continue;
// if(vl==0){
// vd.psb(cd);
// }
// // cout<<"ff";
// dfs(cd,curr);
// }
// }
// /******************** code starts from here ***************************/
// void solve(){
// }
// // C:\Users\my\AppData\Roaming\Sublime Text 3\Packages\User
// int main(){
// // #ifndef ONLINE_JUDGE
// // // for getting input from input.txt
// // freopen("input.txt", "r", stdin);
// // // for writing output to output.txt
// // freopen("output.txt", "w", stdout);
// // #endif
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// // fac(1e6+1);
// // invfac(1e6+1);
// // siv(1e5+1);
// // fp_sieve(2e5+1);
// // for(int i=1;i<=3000;i++){
// // string x;
// // ll f=fun(i,x);
// // mp[i][x]=f;
// // }
// int t=1;
// cin>>t;
// int ct=1;
// while(t--){
// // cout<<"Case #"<<ct++<<": ";
// solve();
// }
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
#define int long long
int solve(int a,int b){
int ans=0;
for(int i=2;i<=b;i+=2){
int t=b/i;
t-=(a-1)/i;
ans+=t*i;
}
return ans;
}
signed main(){
int t;
t=1;
while(t--){
int a,b;
cin>>a>>b;
int ans = solve(a,b);
cout<<ans<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: def partition(array, low, high):
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
(array[i + 1], array[high]) = (array[high], array[i + 1])
return i + 1
def quick_sort(array, low, high):
if low < high:
pi = partition(array, low, high)
quick_sort(array, low, pi - 1)
quick_sort(array, pi + 1, high)
t=int(input())
for i in range(t):
n=int(input())
a=input().strip().split()
a=[int(i) for i in a]
quick_sort(a, 0, n - 1)
for i in a:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code:
public static int[] quickSort(int arr[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(arr, low, high);
// Recursively sort elements before
// partition and after partition
quickSort(arr, low, pi-1);
quickSort(arr, pi+1, high);
}
return arr;
}
public static int partition(int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low-1); // index of smaller element
for (int j=low; j<high; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++;
// swap arr[i] and arr[j]
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
int temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: function quickSort(arr, low, high)
{
if(low < high)
{
let pi = partition(arr, low, high);
quickSort(arr, low, pi-1);
quickSort(arr, pi+1, high);
}
return arr;
}
function partition(arr, low, high)
{
let pivot = arr[high];
let i = (low-1); // index of smaller element
for (let j=low; j<high; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++;
// swap arr[i] and arr[j]
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
let temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}, In this Programming Language: JavaScript, 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: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int curzeroes = 0;
StringBuilder sb = new StringBuilder();
int len = s.length();
for(int i = 0;i<len;i++){
if(s.charAt(i) == '1'){
if(curzeroes == 0){
sb.append("1");
}
else{
curzeroes--;
}
}
else{
curzeroes++;
}
}
for(int i = 0;i<curzeroes;i++){
sb.append("0");
}
if(sb.length() == 0 && curzeroes == 0){
bw.write("-1\n");
}
else{
bw.write(sb.toString()+"\n");
}
bw.flush();
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: arr = input()
c = 0
res = ""
n =len(arr)
for i in range(n):
if arr[i]=='0':
c+=1
else:
if c==0:
res+='1'
else:
c-=1
for i in range(c):
res+='0'
if len(res)==0:
print(-1)
else:
print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 0s and 1s are super cool.
You are given a binary string (string consisting of only zeros and ones). We need to modify the string such that no 0 is followed by a 1. For achieving this, we will find the leftmost occurrence of "01" substring in the string and remove it from the string. We will repeat this operation until there is no substring of the form "01" in the string.
For example, if the initial string is "011010", it will transform in the following manner:
<b>01</b>1010 -> 1<b>01</b>0 -> 10
Find the final remaining string. If the length of remaining string is 0, print -1 instead.The first and the only line of input contains the initial string, S.
Constraints
1 <= |S| <= 300000Output the remaining string. If the length of remaining string is 0, output -1.Sample Input
011010
Sample Output
10
Explanation: Available in the question text.
Sample Input
001101
Sample Output
-1
, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
string s; cin >> s;
stack<int> st;
for(int i = 0; i < (int)s.length(); i++){
if(!st.empty() && s[st.top()] == '0' && s[i] == '1'){
st.pop();
}
else
st.push(i);
}
string res = "";
while(!st.empty()){
res += s[st.top()];
st.pop();
}
reverse(res.begin(), res.end());
if(res == "") res = "-1";
cout << res;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: static int LastDigit(int N){
return N%10;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: int LastDigit(int N){
return N%10;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N print the last digit of the given integer.<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>LastDigit()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return the last digit of the given integer.Sample Input:-
123
Sample Output:-
3
Sample Input:-
6
Sample Output:-
6, I have written this Solution Code: def LastDigit(N):
return N%10, 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: 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: Given an array of N elements, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader inputMachine = new BufferedReader(new InputStreamReader(System.in));
int length = Integer.parseInt(inputMachine.readLine());
String[] arrText = inputMachine.readLine().trim().split(" ");
int[] nums = new int[length];
for (int i = 0; i < nums.length; i++) {
nums[i] = Integer.parseInt(arrText[i]);
}
Arrays.sort(nums);
int i = 0;
int j = length - 1;
long sum = 0;
while (i < j) {
sum += nums[j] - nums[i];
i++;
j--;
}
System.out.println(sum);
}
}, 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, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: n = int(input())
arr = list(map(int,input().split()))
arr.sort()
s = 0
for i in range(n//2):
s += arr[n-i-1]-arr[i]
print(s), 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, N is an even positive number. You have to make N/2 pairs among them such that each element is in exactly one pair. Score of a pair is the absolute difference between there values. Find the maximum sum of score of N/2 pairs.First Line of input contains N.
Second line of input contains N space seperated integers, denoting Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000
N will be evenPrint a single integer which is the maximum sum of score of N/2 pairs.Sample Input 1
2
1 2
Sample Output 1
1
Sample Input 2
4
1 4 2 4
Sample Output 2
5
Explanation: (1, 4) (2, 4) are the optimal pairs, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
sort(a,a+n);
int ans=0;
for(int i=0;i<n/2;++i){
ans+=abs(a[i]-a[n-i-1]);
}
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: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code: n = int(input())
if (n%4==0 and n%100!=0 or n%400==0):
print("YES")
elif n==0:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not.
Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b>
Complete the function <b>LeapYear()</b> that takes integer n as a parameter.
<b>Constraint:</b>
1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input:
2000
Sample Output:
YES
Sample Input:
2003
Sample Output:
NO
Sample Input:
1900
Sample Output:
NO, I have written this Solution Code:
import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int n = scanner.nextInt();
LeapYear(n);
}
static void LeapYear(int year){
if(year%400==0 || (year%100 != 0 && year%4==0)){System.out.println("YES");}
else {
System.out.println("NO");}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int ans = 0;
For(i, 0, n){
int a; cin>>a;
ans += a;
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code: n = int(input())
chocolates = list(map(int, input().strip().split(" ")))
count = 0
for val in chocolates:
count += val
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: It's Solo's 1st birthday and everyone is gifting her chocolates. There are N guests invited, and the i<sup>th</sup> guest gives Solo C<sub>i</sub> chocolates.
Find the total number of chocolates that Solo receives.The first line of the input contains an integer N, the number of guests.
The second line of the input contains N integers C<sub>1</sub>, C<sub>2</sub>, ....C<sub>N</sub>
Constraints
1 <= N <= 100
1 <= C<sub>i</sub> <= 100Output a single integer, the total number of chocolates that Solo receives.Sample Input
5
1 2 4 3 2
Sample Output
12
Explanation: Solo receives a total of 1+2+4+3+2 = 12 chocolates.
Sample Input
1
2
Sample Output
2, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int A[] = new int[n];
for(int i=0;i<n;i++){
A[i]=sc.nextInt();
}
int Total=0;
for(int i=0;i<n;i++){
Total+=A[i];
}
System.out.print(Total);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: function Charity(n,m) {
// write code here
// do no console.log the answer
// return the output using return keyword
const per = Math.floor(m / n)
return per > 1 ? per : -1
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: static int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: def Charity(N,M):
x = M//N
if x<=1:
return -1
return x
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a charity which has N people. Penny wants to donate some of her clothes to the charity in such a way that all people receive equal clothes and each individual receives <b> more than 1 </b>. If she has M clothes with her what is the maximum number of clothes one individual can get?<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>Charity()</b> that takes integers N, and M as arguments.
Constraints:-
1 <= M, N <= 1000Return the maximum number of clothes one individual can get if it is impossible to distribute clothes return -1.Sample Input
6 20
Sample Output
3
Sample Input
8 5
Sample Output
-1, I have written this Solution Code: int Charity(int n, int m){
int x= m/n;
if(x<=1){return -1;}
return x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: static void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
System.out.print(x+4*j+" ");
}
System.out.println();
x+=6;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: def Pattern(N):
x=0
for i in range (0,N):
for j in range (0,N):
print(x+4*j,end=' ')
print()
x = x+6
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara loves patterns, today she encounters an interesting pattern and wants to write a code that can print the pattern of a given height N. As Sara is weak in programming help her to code it.
The pattern for height 6:-
0 4 8 12 16 20
6 10 14 18 22 26
12 16 20 24 28 32
18 22 26 30 34 38
24 28 32 36 40 44
30 34 38 42 46 50<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 an argument.
Constraints:-
1 <= N <= 100Print the given pattern.Sample Input:-
3
Sample Output:-
0 4 8
6 10 14
12 16 20
Sample Input:-
5
Sample Output:-
0 4 8 12 16
6 10 14 18 22
12 16 20 24 28
18 22 26 30 34
24 28 32 36 40, I have written this Solution Code: void Pattern(int N){
int x=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
printf("%d ",x+4*j);
}
printf("\n");
x+=6;
}
}, In this Programming Language: C++, 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: Nobita likes a number if it is stored in an integer while Doraemon likes it when it is stored in a String. Your task is to write a code so that they can easily convert an integer to a string or a string to an integer whenever they want.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the following functions:-
<b>StringToInt()</b> that takes String S as parameter.
<b>IntToString()</b> that takes the integer N as parameter.
Constraints:-
1 <= (Given Number) <= 100Return an integer in <b>StringToInt()</b> while return a integer integer in <b>IntToString()</b>. The driver code will print "<b>Nice Job</b>" if your code is correct otherwise "<b>Wrong answer</b>".Sample Input:-
5
Sample Output:-
Nice Job
Sample Input:-
12
Sample Output:-
Nice Job, I have written this Solution Code: def StringToInt(a):
return int(a)
def IntToString(a):
return str(a)
if __name__ == "__main__":
n = input()
s = StringToInt(n)
if n == str(s):
a=1
# print("Nice Job")
else:
print("Wrong answer")
quit()
p = IntToString(s)
if s == int(p):
print("Nice Job")
else:
print("Wrong answer"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita likes a number if it is stored in an integer while Doraemon likes it when it is stored in a String. Your task is to write a code so that they can easily convert an integer to a string or a string to an integer whenever they want.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the following functions:-
<b>StringToInt()</b> that takes String S as parameter.
<b>IntToString()</b> that takes the integer N as parameter.
Constraints:-
1 <= (Given Number) <= 100Return an integer in <b>StringToInt()</b> while return a integer integer in <b>IntToString()</b>. The driver code will print "<b>Nice Job</b>" if your code is correct otherwise "<b>Wrong answer</b>".Sample Input:-
5
Sample Output:-
Nice Job
Sample Input:-
12
Sample Output:-
Nice Job, I have written this Solution Code: static int StringToInt(String S)
{
return Integer.parseInt(S);
}
static String IntToString(int N){
return String.valueOf(N);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code:
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log(x*y*z);
};
};
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a*b*c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Complete the "mul" function which will properly return the answer by performing multiplication when invoked as below syntax.
Ex:- mul(2)*(3)*(4) - > 24Three integers will be given as input
<b>Constarints</b>
1≤ a,b,c ≤1000The number resulting after the multiplication of 3 input numbersSample input:-
1 5 2
Sample output:-
10
<b>Explanation:-</b>
1*5*2 = 10, I have written this Solution Code: x,y,z= map(int,input().split())
print(x*y*z), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input 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>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(read.readLine());
StringTokenizer st = new StringTokenizer(read.readLine());
int[] arr = new int[N];
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
StringBuilder res = new StringBuilder();
for(int i=0; i<N-1; i+=2) {
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
res.append(arr[i] + " ");
res.append(arr[i+1] + " ");
}
if(N % 2 != 0) {
res.append(arr[N-1]);
}
System.out.print(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input 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>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: n = int(input())
a = list(map(int,input().strip().split()))
a.sort()
for i in range(0,n-1,2):
print("{} ".format(a[i+1]),end="")
print("{} ".format(a[i]),end="")
if n&1:
print("{} ".format(a[n-1])), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an N-size array of unique integers, your task is to print the array in a waveform, i. e a1 >= a2 <= a3 >= a4 <= a5.. . print the lexicographically smallest array possible.The first line of input 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>9</sup>Print the array in wave form as mentioned.Sample Input :-
5
2 1 3 5 4
Sample Output:-
2 1 4 3 5
Sample Input:-
3
1 2 3
Sample Output:-
2 1 3, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n,m;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n-1;i+=2){
cout<<a[i+1]<<" ";
cout<<a[i]<<" ";
}
if(n&1){
cout<<a[n-1]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String args[]) throws IOException {
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().trim().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
int d = Integer.parseInt(str[3]);
int e = Integer.parseInt(str[4]);
System.out.println(grades(a, b, c, d, e));
}
static char grades(int a, int b, int c, int d, int e)
{
int sum = a+b+c+d+e;
int per = sum/5;
if(per >= 80)
return 'A';
else if(per >= 60)
return 'B';
else if(per >= 40)
return 'C';
else
return 'D';
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: li = list(map(int,input().strip().split()))
avg=0
for i in li:
avg+=i
avg=avg/5
if(avg>=80):
print("A")
elif(avg>=60 and avg<80):
print("B")
elif(avg>=40 and avg<60):
print("C")
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, 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 str[]=br.readLine().split(" ");
int a[]=new int[str.length];
int sum=0;
for(int i=0;i<str.length;i++)
{
a[i]=Integer.parseInt(str[i]);
sum=sum+a[i];
}
System.out.println(sum/4);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Ram is studying in Class V and has four subjects, each subject carry 100 marks. He passed with flying colors in his exam, but when his neighbour asked how much percentage did he got in exam, he got stuck in calculation. Ram is a good student but he forgot how to calculate percentage. Help Ram to get him out of this problem.
Given four numbers a , b , c and d denoting the marks in four subjects . Calculate the overall percentage (floor value ) Ram got in exam .First line contains four variables a, b, c and d.
<b>Constraints</b>
1<= a, b, c, d <= 100
Print single line containing the percentage.Sample Input 1:
25 25 25 25
Sample Output 1:
25
Sample Input 2:
75 25 75 25
Sample Output 2:
50, I have written this Solution Code: a,b,c,d = map(int,input().split())
print((a+b+c+d)*100//400), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Main {
static final int MOD = 1000000007;
public static void main(String args[]) throws IOException {
BufferedReader br
= new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().trim().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int c = Integer.parseInt(str[2]);
int d = Integer.parseInt(str[3]);
int e = Integer.parseInt(str[4]);
System.out.println(grades(a, b, c, d, e));
}
static char grades(int a, int b, int c, int d, int e)
{
int sum = a+b+c+d+e;
int per = sum/5;
if(per >= 80)
return 'A';
else if(per >= 60)
return 'B';
else if(per >= 40)
return 'C';
else
return 'D';
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows:
If the percentage is >= 80 then print Grade ‘A’
If the percentage is <80 and >=60 then print Grade ‘B’
If the percentage is <60 and >=40 then print Grade ‘C’
else print Grade ‘D’The input contains 5 integers separated by spaces.
<b>Constraints:</b>
1 ≤ marks ≤ 100You need to print the grade obtained by a student.Sample Input:
75 70 80 90 100
Sample Output:
A
<b>Explanation</b>
((75+70+80+90+100)/5)*100=83%
A grade.
, I have written this Solution Code: li = list(map(int,input().strip().split()))
avg=0
for i in li:
avg+=i
avg=avg/5
if(avg>=80):
print("A")
elif(avg>=60 and avg<80):
print("B")
elif(avg>=40 and avg<60):
print("C")
else:
print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
A consecutive set of integers is a consecutive elements sequence.
See sample for better understandingFirst line contains integer N number of elements of the array. Next line contains N space separated integers which are elements of array.
Constraints
1<= N <=100000
1<= A[i] <=100000Output the longest consecutive sequence in the array.Sample Input
7
100 4 200 1 3 2 2
Sample Output
4
Explanation
The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
Set<Integer> set=new TreeSet<>();
String nums[]=br.readLine().split("\\s+");
try
{
for(int i=0;i<n;++i)
{
set.add(Integer.parseInt(nums[i]));
}
}catch(NumberFormatException e)
{}
int max=0;
int prev=0;
int count=1;
for(Integer i:set)
{
if(prev==0)
{
prev=i;
continue;
}
if(prev+1==i)
{
++count;
}
else
{
if(count>max) max=count;
count=1;
}
prev=i;
}
if(count>max) max=count;
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 unsorted array of integers, find the length of the longest consecutive elements sequence.
A consecutive set of integers is a consecutive elements sequence.
See sample for better understandingFirst line contains integer N number of elements of the array. Next line contains N space separated integers which are elements of array.
Constraints
1<= N <=100000
1<= A[i] <=100000Output the longest consecutive sequence in the array.Sample Input
7
100 4 200 1 3 2 2
Sample Output
4
Explanation
The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4., I have written this Solution Code: N = int(input())
A = [int(x) for x in input().split()]
numSet = set(A)
longest = 0
for n in A:
if (n - 1) not in numSet:
length = 0
while (n + length) in numSet:
length += 1
longest = max(length, longest)
print(longest), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
A consecutive set of integers is a consecutive elements sequence.
See sample for better understandingFirst line contains integer N number of elements of the array. Next line contains N space separated integers which are elements of array.
Constraints
1<= N <=100000
1<= A[i] <=100000Output the longest consecutive sequence in the array.Sample Input
7
100 4 200 1 3 2 2
Sample Output
4
Explanation
The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int longestConsecutive(vector<int>& nums)
{ int ans=0,cnt=0;
for(int i=0;i<nums.size();i++)
{
if(i==0 || nums[i-1]+1==nums[i])
{
cnt++;
}else cnt=1;
ans=max(ans,cnt);
}
return ans;
}
int main()
{
int n; cin>>n;
int a[n];
set<int>ss;
for(int i=0; i<n; i++)
{ cin>>a[i];
ss.insert(a[i]);
}
vector<int> v;
for(auto it:ss)
v. push_back(it);
cout<<longestConsecutive(v)<<endl;
return 0;
}, In this Programming Language: C++, 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: You are given N line segments on the number line. Each segment is denoted by two integers L and R (L <= R), denoting the start and end points of the segment.
You need to find the maximum number of segments overlapping at a point. More clearly, if you find the number of segments passing the point for all points on the number line, you need to report the maximum value obtained in the process.
Note: Even if segments overlap at the end points, it is considered an overlap.
See sample for better understanding.The first line of the input contains an integer N, the number of segments.
The next N line contain two space separated integers L and R, the end points of the i<sup>th</sup> segment.
Constraints
1 <= N <= 200000
0 <= L <= R <= 200000Output a single integer, the maximum number of segments overlapping at a point.Sample Input
3
1 3
2 4
3 5
Sample Output
3
Explanation: All the segments overlap at the point 3.
Sample Input
2
1 5
7 11
Sample Output
1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int Q = Integer.parseInt(br.readLine());
int[] arr = new int[200002];
while(Q-->0){
String[] inLine = br.readLine().split(" ");
arr[Integer.parseInt(inLine[0])]++;
arr[Integer.parseInt(inLine[1])+1]--;
}
int maxseg = 0;
int sum = 0;
for (int i=0;i< arr.length;++i){
sum += arr[i];
if (sum>maxseg){
maxseg = sum;
}
}
System.out.println(maxseg);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N line segments on the number line. Each segment is denoted by two integers L and R (L <= R), denoting the start and end points of the segment.
You need to find the maximum number of segments overlapping at a point. More clearly, if you find the number of segments passing the point for all points on the number line, you need to report the maximum value obtained in the process.
Note: Even if segments overlap at the end points, it is considered an overlap.
See sample for better understanding.The first line of the input contains an integer N, the number of segments.
The next N line contain two space separated integers L and R, the end points of the i<sup>th</sup> segment.
Constraints
1 <= N <= 200000
0 <= L <= R <= 200000Output a single integer, the maximum number of segments overlapping at a point.Sample Input
3
1 3
2 4
3 5
Sample Output
3
Explanation: All the segments overlap at the point 3.
Sample Input
2
1 5
7 11
Sample Output
1, I have written this Solution Code: n = int(input())
arr = [0]*21000000
for _ in range(n):
l,r = map(int,input().split())
arr[l] += 1
arr[r+1] -= 1
i = 1
for i in range(1,200005):
arr[i] += arr[i-1]
print(max(arr))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given N line segments on the number line. Each segment is denoted by two integers L and R (L <= R), denoting the start and end points of the segment.
You need to find the maximum number of segments overlapping at a point. More clearly, if you find the number of segments passing the point for all points on the number line, you need to report the maximum value obtained in the process.
Note: Even if segments overlap at the end points, it is considered an overlap.
See sample for better understanding.The first line of the input contains an integer N, the number of segments.
The next N line contain two space separated integers L and R, the end points of the i<sup>th</sup> segment.
Constraints
1 <= N <= 200000
0 <= L <= R <= 200000Output a single integer, the maximum number of segments overlapping at a point.Sample Input
3
1 3
2 4
3 5
Sample Output
3
Explanation: All the segments overlap at the point 3.
Sample Input
2
1 5
7 11
Sample Output
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
vector<int> cur(200002, 0);
int n; cin>>n;
For(i, 0, n){
int l, r; cin>>l>>r;
cur[l]++;
cur[r+1]--;
}
int ans = cur[0];
For(i, 1, sz(cur)){
cur[i]+=cur[i-1];
ans = max(ans, cur[i]);
}
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: t=int(input())
while t!=0:
m,n=input().split()
m,n=int(m),int(n)
for i in range(m):
arr=input().strip()
if '1' in arr:
arr='1 '*n
else:
arr='0 '*n
print(arr)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
int a[N][N];
// Driver code
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
bool b[n];
for(int i=0;i<n;i++){
b[i]=false;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
if(a[i][j]==1){
b[i]=true;
}
}
}
for(int i=0;i<n;i++){
if(b[i]){
for(int j=0;j<m;j++){
cout<<1<<" ";
}}
else{
for(int j=0;j<m;j++){
cout<<0<<" ";
}
}
cout<<endl;
}
}}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1.
Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow.
The first line of each test case contains m and n denotes the number of rows and a number of columns.
Then next m lines contain n elements denoting the elements of the matrix.
Constraints:
1 ≤ T ≤ 20
1 ≤ m, n ≤ 700
Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input:
1
5 4
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Output:
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1
Explanation:
Rows = 5 and columns = 4
The given matrix is
1 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too.
The final matrix is
1 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
1 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(isr);
int t = Integer.parseInt(bf.readLine());
while (t-- > 0){
String inputs[] = bf.readLine().split(" ");
int m = Integer.parseInt(inputs[0]);
int n = Integer.parseInt(inputs[1]);
String[] matrix = new String[m];
for(int i=0; i<m; i++){
matrix[i] = bf.readLine();
}
StringBuffer ones = new StringBuffer("");
StringBuffer zeros = new StringBuffer("");
for(int i=0; i<n; i++){
ones.append("1 ");
zeros.append("0 ");
}
for(int i=0; i<m; i++){
if(matrix[i].contains("1")){
System.out.println(ones);
}else{
System.out.println(zeros);
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements.
Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:-
1 3 5 4
Sample output:-
9
Explanation-
1+3+5=9, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int odd_ball( ArrayList<Integer> myNumbers){
int res=0;
for (int i : myNumbers){
if(i%2!=0){
res+=i;
}
}
return res;
}
public static void main (String[] args) {
Scanner sc= new Scanner(System.in);
ArrayList<Integer> myNumbers = new ArrayList<Integer>();
while (sc.hasNextInt()) {
int i = sc.nextInt();
myNumbers.add(i);
}
System.out.print( odd_ball(myNumbers));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements.
Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:-
1 3 5 4
Sample output:-
9
Explanation-
1+3+5=9, I have written this Solution Code:
arr=list(map(int,input().split()))
Sum=0
for i in range(len(arr)):
if arr[i]%2!=0:
Sum+=arr[i]
print(Sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a function called oddball_sum which takes in a list of numbers and returns the sum of all the odd elements.
Try to solve with and without reduce function.An array containing numbersSum of all the odd numbers in that arraySample Input:-
1 3 5 4
Sample output:-
9
Explanation-
1+3+5=9, I have written this Solution Code: function oddball_sum(nums) {
// final count of all odd numbers added up
let final_count = 0;
// loop through entire list
for (let i = 0; i < nums.length; i++) {
// we divide by 2, and if there is a remainder then
// the number must be odd so we add it to final_count
if (nums[i] % 2 === 1) {
final_count += nums[i]
}
}
console.log(final_count);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a String <b>S</b>, you need to typecast this String to Long. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains S as a parameter.
<b>Constraints:-</b>
1 <= |S| <= 15
The string will contain only numeric digits(1-9)You need to return the typecasted Long value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".
<b>Note:-</b> We are not converting this string to int here because the size of the number exceeds the int limits.Sample Input 1:-
43
Sample Output 1:-
Nice Job
Sample Input 2:-
2584563259874
Sample Output 2:-
Nice Job, I have written this Solution Code: def checkConevrtion(a):
return int(a)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a String <b>S</b>, you need to typecast this String to Long. If the typecasting is done successfully then we will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".User task:
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>checkConvertion()</b>, which contains S as a parameter.
<b>Constraints:-</b>
1 <= |S| <= 15
The string will contain only numeric digits(1-9)You need to return the typecasted Long value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".
<b>Note:-</b> We are not converting this string to int here because the size of the number exceeds the int limits.Sample Input 1:-
43
Sample Output 1:-
Nice Job
Sample Input 2:-
2584563259874
Sample Output 2:-
Nice Job, I have written this Solution Code: static long checkConevrtion(String S)
{
return Long.parseLong(S);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: N = int(input())
Nums = list(map(int,input().split()))
f = False
for n in Nums:
if n < 0:
f = True
break
if (f):
print("Yes")
else:
print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
bool win=false;
for(int i=0;i<n;i++){
cin>>a;
if(a<0){win=true;}}
if(win){
cout<<"Yes";
}
else{
cout<<"No";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, check if it contains any negative integer.First line of input contains a single integer N. The next line contains the N space separated integers.
Constraints:-
1 < = N < = 1000
-10000 < = Arr[i] < = 10000Print "Yes" if the array contains any negative integer else print "No".Sample Input:-
4
1 2 3 -3
Sample Output:-
Yes
Sample Input:-
3
1 2 3
Sample Output:-
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
if(a[i]<0){System.out.print("Yes");return;}
}
System.out.print("No");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number.
If the number is greater than 3 then print "great".
If the number is greater than 5 then print "awesome".
If the number is not greater than 3 or 5, print "bad".A single integer x.
<b>Constraints</b>
-10<sup>8</sup> <= x <= 10<sup>8</sup>Output a single string denoting the required answer.Sample Input 1:
3
Sample Output 1:
bad
Sample Input 2:
4
Sample Output 2:
great
Sample Input 3:
6
Sample Output 3:
awesome, 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());
if(n>5)out.print("awesome");
else if(n>3)out.print("great");
else out.print("bad");
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 a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: void farhenheitToCelsius(int n){
n-=32;
n/=9;
n*=5;
cout<<n;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: Fahrenheit= int(input())
Celsius = int(((Fahrenheit-32)*5)/9 )
print(Celsius), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a temperature F in Farenheit, your task is to convert it into Celsius using the following equation:-
T(°c) = (T(°f) - 32)*5/9You don't have to worry about the input, you just have to complete the function <b>fahrenheitToCelsius</b>
Constraints:-
-10^3 <= F <= 10^3
<b>Note:-</b> It is guaranteed that F - 32 will be a multiple of 9.Print an integer containing converted temperature in Fahrenheit.Sample Input 1:
77
Sample Output 1:
25
Sample Input 2:-
-40
Sample Output 2:-
-40
<b>Explanation 1</b>:
T(°c) = (T(°f) - 32)*5/9
T(°c) = (77-32)*5/9
T(°c) =25, I have written this Solution Code: static void farhrenheitToCelsius(int farhrenheit)
{
int celsius = ((farhrenheit-32)*5)/9;
System.out.println(celsius);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.