Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n][n];
FOR(i,n){
FOR(j,n){
cin>>a[i][j];}}
int sum=0,sum1=0;;
FOR(i,n){
sum+=a[i][i];
sum1+=a[n-i-1][i];
}
out1(sum);out(sum1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String args[])throws Exception {
InputStreamReader inr= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(inr);
String str=br.readLine();
int row = Integer.parseInt(str);
int col=row;
int [][] arr=new int [row][col];
for(int i=0;i<row;i++){
String line =br.readLine();
String[] elements = line.split(" ");
for(int j=0;j<col;j++){
arr[i][j]= Integer.parseInt(elements[j]);
}
}
int sumPrimary=0;
int sumSecondary=0;
for(int i=0;i<row;i++){
sumPrimary=sumPrimary + arr[i][i];
sumSecondary= sumSecondary + arr[i][row-1-i];
}
System.out.println(sumPrimary+ " " +sumSecondary);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: // mat is the matrix/ 2d array
// the dimensions of array are n * n
function diagonalSum(mat, n) {
// write code here
// console.log the answer as in example
let principal = 0, secondary = 0;
for (let i = 0; i < n; i++) {
principal += mat[i][i];
secondary += mat[i][n - i - 1];
}
console.log(`${principal} ${secondary}`);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: n = int(input())
sum1 = 0
sum2 = 0
for i in range(n):
a = [int(j) for j in input().split()]
sum1 = sum1+a[i]
sum2 = sum2+a[n-1-i]
print(sum1,sum2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Design a system that takes big URLs like βhttp://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from1-to-n/β and converts them into a short 6 character URL. It is given that URLs are stored in database and every URL has an associated integer id. So your program should take an integer id and generate a 6 character long URL.
A URL character can be one of the following
A lower case alphabet [βaβ to βzβ], total 26 characters
An upper case alphabet [βAβ to βZβ], total 26 characters
A digit [β0β² to β9β], total 10 characters
There are total 26 + 26 + 10 = 62 possible characters.
So the task is to convert an integer (database id) to a base 62 number where digits of 62 base are "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"The first line contains T denoting the number of test cases.
The next T lines contain a single integer N.
1 <= T <= 100000
1 <= N <= 1000000000For each test case, in a new line, print the shortened string.Sample Input:
1
12345
Sample Output:
dnh
Explanation:
Try to convert 12345 in base-62, replace the integer with the corresponding character, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static StringBuffer URL(int n)
{
StringBuffer c =new StringBuffer("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
StringBuffer url = new StringBuffer();
while (n > 0)
{
url.append(c.charAt(n % 62));
n = n / 62;
}
return url.reverse();
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int l= Integer.parseInt(br.readLine());
for(int i=0;i<l;i++){
int n = Integer.parseInt(br.readLine());
System.out.println(URL(n));
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Design a system that takes big URLs like βhttp://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from1-to-n/β and converts them into a short 6 character URL. It is given that URLs are stored in database and every URL has an associated integer id. So your program should take an integer id and generate a 6 character long URL.
A URL character can be one of the following
A lower case alphabet [βaβ to βzβ], total 26 characters
An upper case alphabet [βAβ to βZβ], total 26 characters
A digit [β0β² to β9β], total 10 characters
There are total 26 + 26 + 10 = 62 possible characters.
So the task is to convert an integer (database id) to a base 62 number where digits of 62 base are "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"The first line contains T denoting the number of test cases.
The next T lines contain a single integer N.
1 <= T <= 100000
1 <= N <= 1000000000For each test case, in a new line, print the shortened string.Sample Input:
1
12345
Sample Output:
dnh
Explanation:
Try to convert 12345 in base-62, replace the integer with the corresponding character, I have written this Solution Code: t=int(input())
a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
while(t>0):
s=""
n=int(input())
while(n>0):
r=n%62
s=a[r]+s
n=n//62
print(s)
t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Design a system that takes big URLs like βhttp://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from1-to-n/β and converts them into a short 6 character URL. It is given that URLs are stored in database and every URL has an associated integer id. So your program should take an integer id and generate a 6 character long URL.
A URL character can be one of the following
A lower case alphabet [βaβ to βzβ], total 26 characters
An upper case alphabet [βAβ to βZβ], total 26 characters
A digit [β0β² to β9β], total 10 characters
There are total 26 + 26 + 10 = 62 possible characters.
So the task is to convert an integer (database id) to a base 62 number where digits of 62 base are "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"The first line contains T denoting the number of test cases.
The next T lines contain a single integer N.
1 <= T <= 100000
1 <= N <= 1000000000For each test case, in a new line, print the shortened string.Sample Input:
1
12345
Sample Output:
dnh
Explanation:
Try to convert 12345 in base-62, replace the integer with the corresponding character, I have written this Solution Code: #include<bits/stdc++.h>
#define int long long
#define ld long double
#define ll long long
#define pb push_back
#define endl '\n'
#define pi pair<int,int>
#define vi vector<int>
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
void solve(){
int n; cin >> n;
string t = "";
while(n){
int c = n%62;
t += s[c];
n /= 62;
}
reverse(t.begin(), t.end());
cout << t << endl;
}
void testcases(){
int tt = 1;
cin >> tt;
while(tt--){
solve();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: static void Icecreams (int N, int D){
int x=N;
while(D-->0){
x-=x/2;
x*=3;
}
System.out.println(x);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
cout << x;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: void Icecreams (int N, int D){
int x=N;
while(D--){
x-=x/2;
x*=3;
}
printf("%d", x);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is fond of ice cream initially she had N ice creams with her. If Sara eats exactly half of the ice cream she has in a day and the remaining icecreams get tripled each night. How many ice creams does Sara have at the end of D-days?
<b>Note:- </b>
Take the floor value while dividing by 2.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Icecreams()</b> that takes integers N and D as parameters.
<b>Constraints:-</b>
1 <= N <= 100
1 <= D <= 20Print a single integer denoting the number of ice creams at the end of D days.Sample Input 1:-
5 1
Sample Output 1:-
9
</b>Explanation:-</b>
Sara will eat 2 ice creams and the remaining 3 will be tripled i. e 9.
Sample Input 2:-
5 3
Sample Output 2:-
24
<b>Explanation:-</b>
Day 1:- N=5, eaten = 2, rem = 3 => remaining = 3*3 = 9
Day 2:- N=9, eaten = 4, rem = 5 => remaining = 5*3 = 15
Day 3:- N=15, eaten = 7, rem = 8 => remaining = 8*3 = 24, I have written this Solution Code: def Icecreams(N,D):
ans = N
while D > 0:
ans = ans - ans//2
ans = ans*3
D = D-1
return ans
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter.
Constraints:
1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:-
5
Sample Output:-
15
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code:
static void sum(int N){
long x=N;
x=x*(x+1);
x=x/2;
System.out.print(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the first 2 terms A and B of an Arithmetic Series, tell the Nth term of the series.<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>NthAP()</b> that takes the integer A, B, and N as a parameter.
<b>Constraints:</b>
-10<sup>3</sup> ≤ A ≤ 10<sup>3</sup>
-10<sup>3</sup> ≤ B ≤ 10<sup>3</sup>
1 ≤ N ≤ 10<sup>4</sup>Return the Nth term of AP series.Sample Input 1:
2 3 4
Sample Output 1:
5
Sample Input 2:
1 2 10
Sample output 2:
10, I have written this Solution Code: class Solution {
public static int NthAP(int a, int b, int n){
return a+(n-1)*(b-a);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix of characters. The matrix has N rows and M columns. Given a string s, you have to tell if it is possible to generate that string from given matrix.
Rules for generating string from matrix are:
You have to pick first character of string from row 1, second character from row 2 and so on. The (N+1)th character of string is to be picked from row 1, that is, you can traverse the rows in a cyclic manner (row 1 comes after row N).
If an occurrence of a character is picked from a row, you cannot pick the same occurrence again from that row.
You have to print Yes if given string can be generated from matrix using the given rules, else print No.First line consists of two integers N and M, denoting the matrix dimensions.
Next N lines consist of M characters each.
Last line consists of a string s.
Constraints:
1 ≤ N, M ≤ 200
1 ≤ S.length() ≤ 4*10<sup>4</sup>
S contains only lowercase English letters .
Print "Yes" if string can be generated else print "No". Answer for each test case should come in a new line.
Sample Input 1:
3 3
aba
xyz
bdr
axbaydb
Sample Output 1:
Yes
Explanation
We pick "a" from row 1. Now, we can only pick one more "a" from row 1 as one "a" is already used.
Similarly, "x" from row 2, "b" from row 3.
Now, we again go back to row 1.
We pick "a" from row 1, "y" from row 2 and so on., I have written this Solution Code: N,M = map(int,input().split())
words=[]
for i in range(N):
words.append(list(input().strip()))
test_word=list(input().strip())
ans="Yes"
for i in range(len(test_word)):
if test_word[i] not in words[i%N]:
ans="No"
break
else:
words[i%N].remove(test_word[i])
print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a matrix of characters. The matrix has N rows and M columns. Given a string s, you have to tell if it is possible to generate that string from given matrix.
Rules for generating string from matrix are:
You have to pick first character of string from row 1, second character from row 2 and so on. The (N+1)th character of string is to be picked from row 1, that is, you can traverse the rows in a cyclic manner (row 1 comes after row N).
If an occurrence of a character is picked from a row, you cannot pick the same occurrence again from that row.
You have to print Yes if given string can be generated from matrix using the given rules, else print No.First line consists of two integers N and M, denoting the matrix dimensions.
Next N lines consist of M characters each.
Last line consists of a string s.
Constraints:
1 ≤ N, M ≤ 200
1 ≤ S.length() ≤ 4*10<sup>4</sup>
S contains only lowercase English letters .
Print "Yes" if string can be generated else print "No". Answer for each test case should come in a new line.
Sample Input 1:
3 3
aba
xyz
bdr
axbaydb
Sample Output 1:
Yes
Explanation
We pick "a" from row 1. Now, we can only pick one more "a" from row 1 as one "a" is already used.
Similarly, "x" from row 2, "b" from row 3.
Now, we again go back to row 1.
We pick "a" from row 1, "y" from row 2 and so on., I have written this Solution Code: import java.util.*;
import java.util.stream.*;
class Main {
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int i = 0; i < T; i++)
{
int n = sc.nextInt();
int m = sc.nextInt();
String[][] arr = new String[n][1];
for (int j = 0; j < n; j++)
{
arr[j][0] = sc.next();
}
//System.out.println(Arrays.toString(arr[1])); o/p: [x, y, z]
//System.out.println(arr[1]); o/p: xyz
//System.out.println(arr[1].getClass().getSimpleName()); o/p:char[]
String s1 = sc.next();
int l = 0;
boolean ans = true;
while (s1.length() != l)
{
//String ls = Arrays.toString(arr[l%n]);
if (arr[l%n][0].contains(String.valueOf(s1.charAt(l))))
{
ans = true;
arr[l%n][0] = arr[l%n][0].replaceFirst(String.valueOf(s1.charAt(l)),"");
//arr[l%n][0] = ls;
}
else
{
ans = false;
break;
}
l+=1;
}
if (ans == true)
{
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: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube.
<b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter.
<b>Constraints:</b>
1 <= N <= 6Return the number on the opposite side.Sample Input:-
2
Sample Output:-
5
Sample Input:-
1
Sample Output:-
6, I have written this Solution Code: def DiceProblem(N):
return (7-N)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube.
<b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter.
<b>Constraints:</b>
1 <= N <= 6Return the number on the opposite side.Sample Input:-
2
Sample Output:-
5
Sample Input:-
1
Sample Output:-
6, I have written this Solution Code:
int diceProblem(int N){
return (7-N);
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube.
<b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter.
<b>Constraints:</b>
1 <= N <= 6Return the number on the opposite side.Sample Input:-
2
Sample Output:-
5
Sample Input:-
1
Sample Output:-
6, I have written this Solution Code:
static int diceProblem(int N){
return (7-N);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a cubic dice with 6 faces. All the individual faces have numbers printed on them. The numbers are in the range of 1 to 6, like any <b>ordinary dice</b>. You will be provided with a face of this cube, your task is to find the number on the opposite face of the cube.
<b>Note</b>:- The sum of numbers on all opposite faces of the die is constant<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>DiceProblem()</b> that takes the integer N(face) as parameter.
<b>Constraints:</b>
1 <= N <= 6Return the number on the opposite side.Sample Input:-
2
Sample Output:-
5
Sample Input:-
1
Sample Output:-
6, I have written this Solution Code:
int diceProblem(int N){
return (7-N);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output.
<b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10000
-10000 ≤ A[i] ≤ 10000
The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput:
1
5
-7 -2 3 4 6
Output:
4 9 16 36 49, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main
{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int n = Integer.parseInt(read.readLine());
int[] arr = new int[n];
String str[] = read.readLine().trim().split(" ");
for(int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
arr = sortedSquares(arr);
for(int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
}
public static int[] sortedSquares(int[] A) {
int[] nums = new int[A.length];
int k=A.length-1;
int i=0, j=A.length-1;
while(i<=j){
if(Math.abs(A[i]) <= Math.abs(A[j])){
nums[k--] = A[j]*A[j];
j--;
}
else{
nums[k--] = A[i]*A[i];
i++;
}
}
return nums;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an sorted array <b>Arr[]</b> of size <b>N</b>, containing both <b>negative</b> and <b>positive</b> integers, you need to print the squared sorted output.
<b>Note</b> Try using two pointer approachThe first line of input contains T, denoting the number of test cases. Each testcase contains 2 lines. The first line contains the N size of the array. The second line contains elements of an array separated by space.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 10000
-10000 ≤ A[i] ≤ 10000
The Sum of N over all test cases does not exceed 10^6For each test case you need to print the sorted squared output in new lineInput:
1
5
-7 -2 3 4 6
Output:
4 9 16 36 49, I have written this Solution Code: t = int(input())
for i in range(t):
n = int(input())
for i in sorted(map(lambda j:int(j)**2,input().split())):
print(i,end=' ')
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
if(s==null){
System.exit(0);
}
StringTokenizer st = new StringTokenizer(s, " ");
int power = Integer.parseInt(st.nextToken());
int multiple = Integer.parseInt(st.nextToken());
int res = power;
for(int i = 1;i<=multiple;i++){
res = res*2;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int x, n;
cin >> x >> n;
cout << x*(1 << n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: x,n = map(int,input().split())
print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is very confused after knowing all about Sirius. To lighten Harry's mood Sirius asks a fun problem to him. Sirius puts K talking skulls equally spaced on the circumference of a circle. Now he enumerates them from 1 to K in clockwise order. Now given skull X and skull Z, he asks Harry to find number of possible Y such that angle XYZ is obtuse(more than 90 degrees).
Note:- X Y and Z must be different.The first line of the input contains single integer T, denoting number of test cases.
Each test case contains three integers K, X and Z.
Constraints
1 <= T <= 10
1 <= K <= 1000000000
1 <= X, Y <= KFor each testcase print number of possible Y in a new line.Sample Input
2
6 1 3
10 1 5
Sample Output
1
3
Explanation:
For first case, 2 is the suitable skull.
For second case, 2, 3 and 4 are the suitable skulls., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
while(t-- > 0){
String str[] = in.readLine().trim().split(" ");
int k = Integer.parseInt(str[0]);
int x = Integer.parseInt(str[1]);
int z = Integer.parseInt(str[2]);
int cnt = Math.abs(x-z);
int rem = k - cnt;
if(cnt < rem){
if(cnt != 0){
System.out.println(cnt-1);
}
else{
System.out.println(0);
}
}
else if(rem < cnt){
if(rem != 0){
System.out.println(rem-1);
}
else{
System.out.println(0);
}
}
else{
System.out.println(0);
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is very confused after knowing all about Sirius. To lighten Harry's mood Sirius asks a fun problem to him. Sirius puts K talking skulls equally spaced on the circumference of a circle. Now he enumerates them from 1 to K in clockwise order. Now given skull X and skull Z, he asks Harry to find number of possible Y such that angle XYZ is obtuse(more than 90 degrees).
Note:- X Y and Z must be different.The first line of the input contains single integer T, denoting number of test cases.
Each test case contains three integers K, X and Z.
Constraints
1 <= T <= 10
1 <= K <= 1000000000
1 <= X, Y <= KFor each testcase print number of possible Y in a new line.Sample Input
2
6 1 3
10 1 5
Sample Output
1
3
Explanation:
For first case, 2 is the suitable skull.
For second case, 2, 3 and 4 are the suitable skulls., I have written this Solution Code: k = int(input())
for i in range(k):
z = 0
a = input().split()
a = [int(i) for i in a]
rad = 360/a[0]
dia = abs(a[2]-a[1])
ang = rad*dia
if(ang/2 > 90):
z = a[0]- dia - 1
elif(ang/2 < 90):
z = dia - 1
else:
z = 0
print(z)
a.clear(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry is very confused after knowing all about Sirius. To lighten Harry's mood Sirius asks a fun problem to him. Sirius puts K talking skulls equally spaced on the circumference of a circle. Now he enumerates them from 1 to K in clockwise order. Now given skull X and skull Z, he asks Harry to find number of possible Y such that angle XYZ is obtuse(more than 90 degrees).
Note:- X Y and Z must be different.The first line of the input contains single integer T, denoting number of test cases.
Each test case contains three integers K, X and Z.
Constraints
1 <= T <= 10
1 <= K <= 1000000000
1 <= X, Y <= KFor each testcase print number of possible Y in a new line.Sample Input
2
6 1 3
10 1 5
Sample Output
1
3
Explanation:
For first case, 2 is the suitable skull.
For second case, 2, 3 and 4 are the suitable skulls., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int t,k,r,s,a,b;
cin>>t;
while(t--)
{
cin>>k>>r>>s;
b=max(r,s);
a=min(r,s);
if(k%2==0&&(b-a)==k/2)
cout<<0;
else
if((k%2!=0&&(b-a)<=k/2)||(k%2==0&&(b-a)<k/2))
cout<<b-a-1;
else if((b-a)>k/2)
cout<<k-(b-a)-1;
cout<<endl;
}
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
String[] line = br.readLine().split(" ");
int minIndex = 0;
long minVal = Long.MAX_VALUE;
for (int i=0;i<line.length;++i){
long el = Long.parseLong(line[i]);
if (minVal>el){
minVal = el;
minIndex = i;
}
}
StringBuilder sb = new StringBuilder();
for (int i = minIndex;i< line.length;++i){
sb.append(line[i]+" ");
}
for (int i=0;i<minIndex;++i){
sb.append(line[i]+" ");
}
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: N = int(input())
arr = list(map(int, input().split()))
mi = arr.index(min(arr))
ans = arr[mi:] + arr[:mi]
for e in ans:
print(e, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
int mi=0;
for(int i=0;i<n;++i)
if(a[i]<a[mi])
mi=i;
for(int i=0;i<n;++i)
cout<<a[(i+mi)%n]<<" ";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 0- indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.
In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1' and '1' to '0'.
Return the minimum number of operations needed to make s equal to target.There will be a string target will be given in the first line of Input.
<b>Constraints</b>
n == target. length
1 <= n <= 10^5
target[i] is either '0' or '1'.Return the minimum number of operations needed to make s equal to target.Sample Input:
10111
Sample Output:
3
Explanation: Initially, s = "00000".
Choose index i = 2: "00000" - > "00111"
Choose index i = 0: "00111" - > "11000"
Choose index i = 1: "11000" - > "10111"
We need at least 3 flip operations to form target., I have written this Solution Code: k=input()
l=len(k)
a,i=0,0
while(i<l):
if k[i]=='0':
a+=1
while i<l and k[i] == '0':
i+=1
else:
a+=1
while i<l and k[i]=='1':
i+=1
if k[0]=='0':
a-=1
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a 0- indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.
In one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1' and '1' to '0'.
Return the minimum number of operations needed to make s equal to target.There will be a string target will be given in the first line of Input.
<b>Constraints</b>
n == target. length
1 <= n <= 10^5
target[i] is either '0' or '1'.Return the minimum number of operations needed to make s equal to target.Sample Input:
10111
Sample Output:
3
Explanation: Initially, s = "00000".
Choose index i = 2: "00000" - > "00111"
Choose index i = 0: "00111" - > "11000"
Choose index i = 1: "11000" - > "10111"
We need at least 3 flip operations to form target., I have written this Solution Code: import java.util.*;
public class Main{
public int minFlips(String target) {
int ans=0;
for(int i=0;i<target.length();i++){
if(target.charAt(i)=='1'&&ans%2==0)ans++;
else if(target.charAt(i)=='0'&&ans%2!=0)ans++;
}
return ans;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s;
s = sc.next();
Main obj = new Main();
int ans = obj.minFlips(s);
System.out.println(ans);
return;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to print all the even integer from 1 to N.<b>User task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>For_Loop()</b> that takes the integer n as a parameter.
</b>Constraints:</b>
1 <= N <= 100
<b>Note:</b>
<i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Print all the even numbers from 1 to n.Sample Input:-
5
Sample Output:-
2 4
Sample Input:-
6
Sample Output:-
2 4 6, I have written this Solution Code: public static void For_Loop(int n){
for(int i=2;i<=n;i+=2){
System.out.print(i+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, 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 month=sc.nextInt();
switch(month)
{
case 1:
System.out.println("31");
break;
case 2:
System.out.println("28");
break;
case 3:
System.out.println("31");
break;
case 4:
System.out.println("30");
break;
case 5:
System.out.println("31");
break;
case 6:
System.out.println("30");
break;
case 7:
System.out.println("31");
break;
case 8:
System.out.println("31");
break;
case 9:
System.out.println("30");
break;
case 10:
System.out.println("31");
break;
case 11:
System.out.println("30");
break;
case 12:
System.out.println("31");
break;
default:
System.out.println("invalid month");
break;
} }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, I have written this Solution Code: def MonthDays(N):
if N==1 or N==3 or N==5 or N==7 or N==8 or N==10 or N==12:
print(31)
elif N==4 or N==6 or N==9 or N==11:
print(30)
elif N==2:
print(28)
else:
print("Months out of range")
N = int(input())
MonthDays(N), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program print total number of days in a month using switch case.First line of the input contains Month Number
<b>Constraints</b>
1 <= Month <= 12Print total number of days in a month (in general).Sample Input :
3
Sample Output :
31, I have written this Solution Code: #include <stdio.h>
int main()
{
int month;
scanf("%d", &month);
switch(month)
{
case 1:
printf("31");
break;
case 2:
printf("28");
break;
case 3:
printf("31");
break;
case 4:
printf("30");
break;
case 5:
printf("31");
break;
case 6:
printf("30");
break;
case 7:
printf("31");
break;
case 8:
printf("31");
break;
case 9:
printf("30");
break;
case 10:
printf("31");
break;
case 11:
printf("30");
break;
case 12:
printf("31");
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of n numbers, sorted in non-decreasing order, and k queries. For each query, print the minimum index of an array element not less than the given one.
Note: if the query value is greater than all the elements in the array return n+1.The first line of the input contains n and k.
The second line contains n elements of the array, sorted in non- decreasing order.
The third line contains k queries. All array elements and queries are integers, each of which does not exceed 2.10<sup>9</sup>.
<b>Constraints</b>
0 ≤ n, k ≤ 10<sup>5</sup>For each of the k queries, print the minimum index of an array element not less than the given one. If there are none, print n+1.Sample Input
5 5
3 3 5 8 9
2 4 8 1 10
Sample Output
1
3
4
1
6, I have written this Solution Code: #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
#define int long long
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(int l = LLONG_MIN, int r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
double Solve() {
int n, k;
cin >> n >> k;
vector<double> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double l = 0, r = 1e9;
auto check = [&](double x) -> bool {
int piece = 0;
for (int i = 0; i < n; i++) {
piece += a[i] / x;
}
if (piece >= k) {
return true;
}
return false;
};
while (r - l > 0.000001) {
double mid = l + (r - l) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
return l;
}
double Actual() {
int n, k;
cin >> n >> k;
vector<double> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double l = 0, r = 1e9;
auto check = [&](double x) -> bool {
int piece = 0;
for (int i = 0; i < n; i++) {
piece += a[i] / x;
}
if (piece >= k) {
return true;
}
return false;
};
while (r - l > 0.000001) {
double mid = l + (r - l) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
return l;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
auto start = std::chrono::high_resolution_clock::now();
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
while (q--) {
int x;
cin >> x;
int l = 0, r = n - 1;
while (l <= r) {
int mid = l + (r - l) / 2;
if (a[mid] <= x) {
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << l << "\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 Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
String[] line = br.readLine().split(" ");
int minIndex = 0;
long minVal = Long.MAX_VALUE;
for (int i=0;i<line.length;++i){
long el = Long.parseLong(line[i]);
if (minVal>el){
minVal = el;
minIndex = i;
}
}
StringBuilder sb = new StringBuilder();
for (int i = minIndex;i< line.length;++i){
sb.append(line[i]+" ");
}
for (int i=0;i<minIndex;++i){
sb.append(line[i]+" ");
}
System.out.print(sb);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: N = int(input())
arr = list(map(int, input().split()))
mi = arr.index(min(arr))
ans = arr[mi:] + arr[:mi]
for e in ans:
print(e, end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of length N. Print the lexographically minimum rotation of the array Arr.
All the elements of the array are distinct.First line of input contains a single integer N.
Second line of input contains N integers denoting the array Arr.
Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 1000000000Print the lexographically minimum rotation of the array Arr.Sample Input
5
2 3 1 4 10
Sample Output
1 4 10 2 3, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int a[n];
for(int i=0;i<n;++i){
cin>>a[i];
}
int mi=0;
for(int i=0;i<n;++i)
if(a[i]<a[mi])
mi=i;
for(int i=0;i<n;++i)
cout<<a[(i+mi)%n]<<" ";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares.
Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix.
<b>Constraints:-</b>
1 ≤ N ≤ 800
1 ≤ Matrix[i][j] ≤ 100000
Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1:
3
1 2 3
4 5 6
7 8 9
Output 1:
25
20
Sample Input 2:
4
1 2 3 4
6 8 9 10
11 12 13 14
15 16 17 18
Sample Output 2:
80
79
<b>Explanation 1</b>
The black square contains 1, 3, 5, 7, 9; sum = 25
The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input())
bSum=0
wSum=0
for i in range(n):
c=(input().split())
for j in range(len(c)):
if(i%2==0):
if(j%2==0):
bSum+=int(c[j])
else:
wSum+=int(c[j])
else:
if(j%2==0):
wSum+=int(c[j])
else:
bSum+=int(c[j])
print(bSum)
print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares.
Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix.
<b>Constraints:-</b>
1 ≤ N ≤ 800
1 ≤ Matrix[i][j] ≤ 100000
Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1:
3
1 2 3
4 5 6
7 8 9
Output 1:
25
20
Sample Input 2:
4
1 2 3 4
6 8 9 10
11 12 13 14
15 16 17 18
Sample Output 2:
80
79
<b>Explanation 1</b>
The black square contains 1, 3, 5, 7, 9; sum = 25
The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main (String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int mat[][] = new int[N][N];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
mat[i][j] = sc.nextInt();
}
alternate_Matrix_Sum(mat,N);
}
static void alternate_Matrix_Sum(int mat[][], int N)
{
long sum =0, sum1 = 0;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if((i+j)%2 == 0)
sum += mat[i][j];
else sum1 += mat[i][j];
}
}
System.out.println(sum);
System.out.print(sum1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at time 0, the second participant starts at time x, the third β at time 2β
x, and so on. The duration of the contest is t minutes for each participant, so the first participant finishes the contest at time t, the second β at time t+x, and so on. When a participant finishes the contest, their dissatisfaction equals the number of participants that started the game (or starting it now) but haven't yet finished it.
Determine the sum of dissatisfaction of all participants.The input consists of three space separated integers n, t and x β the number of participants, the start interval and the contest duration.
<b>Constraints</b>
1 ≤ n, x, t ≤ 2β
10<sup>9</sup>Print the total dissatisfaction of participants.<b>Sample Input 1</b>
4 2 5
<b>Sample Output 1</b>
5
<b>Sample Input 2</b>
3 1 2
<b>Sample Output 2</b>
3, I have written this Solution Code: #include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
void fastio() {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
const int mod = 1000000007;
/*
-----------------------------------------------
Author : Abhas
-----------------------------------------------
*/
#define int long long int
#define cint(n) int n;cin>>n;
#define PI 3.141592653589793238
#define ailoop(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b) for(int i=a;i<b;i++)
#define swapf(dt) void swap(dt &a,dt &b) {dt temp=a;a=b;b=temp;}
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a,a+n)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define precise(digits) fixed<<setprecision(digits)
#define debug(func) cerr<<#func<<" : "<<func<<endl;
#define endl "\n"
#define spc " "
// int power(int a, int b) {
// if(b==0) return 1;
// if(b&1) return a*pow(a,b-1);
// else return pow(a*a,b/2);
// }
// bool issquare(int n) {
// int temp = sqrt(n);
// return temp*temp==n;
// }
void solution() {
int n,x,t;
cin>>n>>x>>t;
int count=0;
int m,p,o;
m = min(n-1,t/x);
if(m==0){
cout<<0<<endl;
}
else{
count = m*(m-1)/2 + m*(n-m);
cout<<count<<endl;
}
}
int32_t main() {
auto start=chrono::system_clock::now();
{
fastio();
int t = 1;
// cin>>t;cin.ignore();
for(int caseno=1;caseno<=t;caseno++) {
// cout<<"Case #"<<caseno<<": ";
solution();
}
}
auto end=chrono::system_clock::now();
// chrono::duration<double> elapsed=end-start;cout<<"Time taken: "<<elapsed.count()<<" sec";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to play Holi with his friends. So he wants to buy three colors for which he needs some money from his father. For buying all three colors he needs at least 75 rupees. For buying 2 colors he needs at least 50 rupees. For buying at least 1 color he needs 25 rupees.
You have to check how many colors did Newton buy. If he buys all three colors print "Newton is very happy", if he buys only two colors print "Newton is happy", if he buys only one color print "Newton is sad" otherwise print "Newton won't play Holi".The first line contains the integer n denoting the amount of money Newton receives from his father.
<b>Constraints</b>
0 ≤ n ≤ 1000Print the output based on the suitable condition.Sample input:
60
Sample output:
Newton is happy
<b>Explanation</b>
Newton will get only two colors as he gets only 60 ruppes from his father., I have written this Solution Code: import java.util.Scanner;
class Solution {
public void num(int money){
if (money < 25) {
System.out.println("Newton won't play Holi");
}
else if (money < 50) {
System.out.println("Newton is sad");
}
else if (money < 75) {
System.out.println("Newton is happy");
}
else {
System.out.println("Newton is very happy");
}
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int money= scanner.nextInt();
Solution obj = new Solution();
obj.num(money);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader sc= new BufferedReader(new InputStreamReader(System.in));
int a=0, b=0, c=0, d=0;
long z=0;
String[] str;
str = sc.readLine().split(" ");
a= Integer.parseInt(str[0]);
b= Integer.parseInt(str[1]);
c= Integer.parseInt(str[2]);
d= Integer.parseInt(str[3]);
BigInteger m = new BigInteger("1000000007");
BigInteger n = new BigInteger("1000000006");
BigInteger zero = new BigInteger("0");
BigInteger ans, y;
if(d==0){
z =1;
}else{
z = (long)Math.pow(c, d);
}
if(b==0){
y= zero;
}else{
y = (BigInteger.valueOf(b)).modPow((BigInteger.valueOf(z)), n);
}
if(y == zero){
System.out.println("1");
}else if(a==0){
System.out.println("0");
}else{
ans = (BigInteger.valueOf(a)).modPow(y, m);
System.out.println(ans);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given four integers a, b, c, and d. Find the value of a<sup>(b<sup>(c<sup>d</sup>)</sup>)</sup> modulo 1000000007.
(Fact: 0<sup>0</sup> = 1)The first and the only line of input contains 4 integers a, b, c, and d.
Constraints
1 <= a, b, c, d <= 12Output a single integer, the answer modulo 1000000007.Sample Input
2 2 2 2
Sample Output
65536
Explanation
2^(2^(2^2)) = 2^(2^4) = 2^16 = 65536.
Sample Input
0 7 11 1
Sample Output
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
int powmod(int a, int b, int c = MOD){
int ans = 1;
while(b){
if(b&1){
ans = (ans*a)%c;
}
a = (a*a)%c;
b >>= 1;
}
return ans;
}
void solve(){
int a, b, c, d; cin>>a>>b>>c>>d;
int x = pow(c, d);
int y = powmod(b, x, MOD-1);
int ans = powmod(a, y, MOD);
cout<<ans;
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: static void verticalFive(){
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
System.out.println("*");
}
static void horizontalFive(){
System.out.print("* * * * *");
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to print Five stars ('*') <b><i>vertically</i></b> and 5 <b><i>horizontally</i></b>
There will be two functions:
<ul>
<li>verticalFive(): Print stars in vertical order</li>
<li>horizontalFive(): Print stars in horizontal order</l>
</ul><b>User Task:</b>
Your task is to complete the functions <b>verticalFive()</b> and <b>horizontalFive()</b>.
Print 5 vertical stars in <b> verticalFive</b> and 5 horizontal stars(separated by whitespace) in <b>horizontalFive</b> function.
<b>Note</b>: You don't need to print the extra blank line it will be printed by the driver codeNo Sample Input:
Sample Output:
*
*
*
*
*
* * * * *, I have written this Solution Code: def vertical5():
for i in range(0,5):
print("*",end="\n")
#print()
def horizontal5():
for i in range(0,5):
print("*",end=" ")
vertical5()
print(end="\n")
horizontal5(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 β€ N β€ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
String num = br.readLine();
int N = Integer.parseInt(num);
String result = "";
if(N < 1000 && N > 0 && N == 1){
result = "AC";
} else {
result = "WA";
}
System.out.println(result);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 β€ N β€ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: N=int(input())
if N==1:
print("AC")
else:
print("WA"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts?
Given an integer N, print "AC" if N is 1. Otherwise, print "WA".
Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N.
<b> Constraints: </b>
0 β€ N β€ 1000Print the required answer.Sample Input 1
1
Sample Output 1
AC
Sample Input 2
0
Sample Output 2
WA
, I have written this Solution Code: //Author: Xzirium
//Time and Date: 03:04:29 27 December 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
if(N==1)
{
cout<<"AC"<<endl;
}
else
{
cout<<"WA"<<endl;
}
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the first 2 terms A and B of an Arithmetic Series, tell the Nth term of the series.<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>NthAP()</b> that takes the integer A, B, and N as a parameter.
<b>Constraints:</b>
-10<sup>3</sup> ≤ A ≤ 10<sup>3</sup>
-10<sup>3</sup> ≤ B ≤ 10<sup>3</sup>
1 ≤ N ≤ 10<sup>4</sup>Return the Nth term of AP series.Sample Input 1:
2 3 4
Sample Output 1:
5
Sample Input 2:
1 2 10
Sample output 2:
10, I have written this Solution Code: class Solution {
public static int NthAP(int a, int b, int n){
return a+(n-1)*(b-a);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void sieve(boolean prime[], int n) {
int i,j;
for(i = 0; i <= n; i++)
prime[i] = true;
for(i = 2; i*i <= n; i++)
if(prime[i])
for(j = i*i; j<=n; j+=i)
prime[j] = false;
}
public static void main (String[] args) throws IOException {
int num = 10000005;
boolean prime[] = new boolean[num+1];
sieve(prime, num);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T --> 0) {
int n = Integer.parseInt(br.readLine().trim());
int count = 0;
for(int i=(n/2)+1; i<=n; i++)
if(prime[i])
count++;
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
bool a[max1];
long b[max1];
void pre(){
b[0]=0;b[1]=0;
for(int i=0;i<max1;i++){
a[i]=false;
}
long cnt=0;
for(int i=2;i<max1;i++){
if(a[i]==false){
cnt++;
for(int j=i+i;j<=max1;j=j+i){a[j]=true;}
}
b[i]=cnt;
}
}
int main(){
pre();
int t;
cin>>t;
while(t--){
long n;
cin>>n;
cout<<(b[n]-b[(n)/2])<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: n = 1000
arr = [True for i in range(n+1)]
i = 2
while i*i <= n:
if arr[i] == True:
for j in range(i*2, n+1, i):
arr[j] = False
i +=1
arr2 = [0] * (n+1)
for i in range(2,n+1):
if arr[i]:
arr2[i] = arr2[i-1] + 1
else:
arr2[i] = arr2[i-1]
x = int(input())
for i in range(x):
y = int(input())
print(arr2[y]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<bool> sieve(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
return is_prime;
}
int main() {
vector<bool> prime = sieve(1e5 + 1);
vector<int> prefix(1e5 + 1, 0);
for (int i = 1; i <= 1e5; i++) {
if (prime[i]) {
prefix[i] = prefix[i - 1] + 1;
} else {
prefix[i] = prefix[i - 1];
}
}
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << prefix[n] << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You will be given an array of several arrays that each contain integers and your goal is to write a function that
will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your
program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:-
[[3, 2], [1], [4, 12]]
Sample output:-
22
Explanation:-
3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) {
// store our final answer
var sum = 0;
// loop through entire array
for (var i = 0; i < arr.length; i++) {
// loop through each inner array
for (var j = 0; j < arr[i].length; j++) {
// add this number to the current final sum
sum += arr[i][j];
}
}
console.log(sum);
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, 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());
long fact=1;
for(int i=1; i<=n;i++){
fact*=i;
}
System.out.print(fact);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, I have written this Solution Code: def fact(n):
if( n==0 or n==1):
return 1
return n*fact(n-1);
n=int(input())
print(fact(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Find factorial of a given number where n! = n * n-1 * n-2 .....* 1First line consists of a single integer denoting n
Constraints:-
0 <= n <= 20Output is a single line containing factorial(n)Sample Input
5
Sample Output
120
Explanation:-
5!= 5 * 4 * 3 * 2 * 1 = 120
Sample Input
10
Sample Output
3628800, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
int main(){
int t;
t=1;
while(t--){
int n;
cin>>n;
unsigned long long sum=1;
for(int i=1;i<=n;i++){
sum*=i;
}
cout<<sum<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array and Q queries. Your task is to perform these operations:-
enqueue: this operation will add an element to your current queue.
dequeue: this operation will delete the element from the starting of the queue
displayfront: this operation will print the element presented at the frontUser task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions:
<b>enqueue()</b>:- that takes the integer to be added and the maximum size of array as parameter.
<b>dequeue()</b>:- that takes the queue as parameter.
<b>displayfront()</b> :- that takes the queue as parameter.
Constraints:
1 <= Q(Number of queries) <= 10<sup>3</sup>
<b> Custom Input:</b>
First line of input should contains two integer number of queries Q and the size of the array N. Next Q lines contains any of the given three operations:-
enqueue x
dequeue
displayfrontDuring a dequeue operation if queue is empty you need to print "Queue is empty", during enqueue operation if the maximum size of array is reached you need to print "Queue is full" and during displayfront operation you need to print the element which is at the front and if the queue is empty you need to print "Queue is empty".
Note:-Each msg or element is to be printed on a new line
Sample Input:-
8 2
displayfront
enqueue 2
displayfront
enqueue 4
displayfront
dequeue
displayfront
enqueue 5
Sample Output:-
Queue is empty
2
2
4
Queue is full
Explanation:-here size of given array is 2 so when last enqueue operation perfomed the array was already full so we display the msg "Queue is full".
Sample input:
5 5
enqueue 4
enqueue 5
displayfront
dequeue
displayfront
Sample output:-
4
5, I have written this Solution Code: public static void enqueue(int x,int k)
{
if (rear >= k) {
System.out.println("Queue is full");
}
else {
a[rear] = x;
rear++;
}
}
public static void dequeue()
{
if (rear <= front) {
System.out.println("Queue is empty");
}
else {
front++;
}
}
public static void displayfront()
{
if (rear<=front) {
System.out.println("Queue is empty");
}
else {
int x = a[front];
System.out.println(x);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: def Race(A,B,C):
if abs(C-A) ==abs(C-B):
return 'D'
if abs(C-A)>abs(C-B):
return 'S'
return 'N'
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<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>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: static char Race(int A,int B,int C){
if(Math.abs(C-A)==Math.abs(C-B)){return 'D';}
if(Math.abs(C-A)>Math.abs(C-B)){return 'S';}
else{
return 'N';}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an undirected graph of N nodes and E edges. Edges are given in the form of x y if there is an edge between x and y. Print 1 if graph is connected else print 0.Two integers denoting N and E.
Then E lines follow, in each line two integers u, v denoting there is an edge between them.
Constraints
1<= N <=100000
0<= M <=100000
1<= u, v <=N
Print 1 if graph is connected else print 0.Input :
4 6
1 2
2 3
3 4
4 2
1 3
2 4
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));
String[] line = br.readLine().trim().split(" ");
int n = Integer.parseInt(line[0]);
int m = Integer.parseInt(line[1]);
Set<Integer> set = new HashSet<>();
while(m-->0){
String[] str = br.readLine().trim().split(" ");
set.add(Integer.parseInt(str[0]));
set.add(Integer.parseInt(str[1]));
}
if(set.size()==n){
System.out.println("1");
}else{
System.out.println("0");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an undirected graph of N nodes and E edges. Edges are given in the form of x y if there is an edge between x and y. Print 1 if graph is connected else print 0.Two integers denoting N and E.
Then E lines follow, in each line two integers u, v denoting there is an edge between them.
Constraints
1<= N <=100000
0<= M <=100000
1<= u, v <=N
Print 1 if graph is connected else print 0.Input :
4 6
1 2
2 3
3 4
4 2
1 3
2 4
Output:
1, I have written this Solution Code: from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(list)
for _ in range(M):
u, v = map(int, input().split())
d[u].append(v)
vertex = set()
flag = False
for i in d.keys():
vertex.add(i)
vertex.update(d[i])
if(len(vertex) == N):
flag = True
break
if(flag):
print(1)
else:
print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an undirected graph of N nodes and E edges. Edges are given in the form of x y if there is an edge between x and y. Print 1 if graph is connected else print 0.Two integers denoting N and E.
Then E lines follow, in each line two integers u, v denoting there is an edge between them.
Constraints
1<= N <=100000
0<= M <=100000
1<= u, v <=N
Print 1 if graph is connected else print 0.Input :
4 6
1 2
2 3
3 4
4 2
1 3
2 4
Output:
1, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#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 sz 200000
int dist[sz];
int vis[sz];
int cnt=0;
vector<int> NEB[sz];
void dfs(int s)
{
vis[s]=1;
cnt++;
for(auto it:NEB[s])
{
if(vis[it]==0)
{
dfs(it);
}
}
}
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
NEB[a].pu(b);
NEB[b].pu(a);
}
dfs(1);
if(cnt==n) cout<<1<<endl;
else cout<<0<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given side A of the equilateral triangle, compute its area. The area of an equilateral triangle is given as.
<b>Note:</b> Round off the answer to 2 decimals.The input line contains a single float value.
<b>Constraints</b>
1 <= A <= 50Print the output, containing the area of an equilateral triangle.Input:
3
Output:
3.90
<b>Explanation</b>
The area of the triangle will be (1.73/4)*3*3 = 3.897, which rounded off to 2 digits gives 3.90 as the answer., I have written this Solution Code: import math
A = float(input())
print('%.2f' % ((math.sqrt(3)/4)*A*A)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
if(s==null){
System.exit(0);
}
StringTokenizer st = new StringTokenizer(s, " ");
int power = Integer.parseInt(st.nextToken());
int multiple = Integer.parseInt(st.nextToken());
int res = power;
for(int i = 1;i<=multiple;i++){
res = res*2;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int x, n;
cin >> x >> n;
cout << x*(1 << n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 β€ X β€ 1000
1 β€ N β€ 10Print a single integer β the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: x,n = map(int,input().split())
print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b>
Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter.
Constraints:
1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:-
5
Sample Output:-
15
Sample Input:-
3
Sample Output:-
6, I have written this Solution Code:
static void sum(int N){
long x=N;
x=x*(x+1);
x=x/2;
System.out.print(x);
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tom has been given an integer array A of size N. Now, he needs to find the number of increasing sub-sequences of this array with length β₯1 and GCD=1. A sub-sequence of an array is obtained by deleting some (or none) elements and maintaining the relative order of the rest of the elements. As the answer may be large, print it Modulo (10^9)+7.The first line contains a single integer N denoting the size of array A. The next line contains N space-separated integers denoting the elements of array A.
Constraints:
1 β€ N β€ 500
1 β€ A[i] β€ 100Print the required answer Modulo 10^9+7.Sample Input
3
1 2 3
Sample Output
5, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static int gcd(int a, int b) {
if(b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long cal(int arr[], int n){
long dp[][] = new long[n][101];
for(int i = 0; i < n; i++) {
dp[i][arr[i]] = 1;
for(int j = i - 1; j >= 0; j--){
if (arr[j] < arr[i]){
for(int k = 0; k <= 100; k++) {
int GCD = gcd(arr[i], k);
dp[i][GCD] = dp[i][GCD] + dp[j][k];
}
}
}
}
long sum = 0;
int MOD = 1000000007;
for(int i = 0; i < n; i++) {
sum = (sum + dp[i][1]) % MOD;
}
return sum;
}
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nD = br.readLine();
String nDArr[] = nD.split(" ");
int n = Integer.parseInt(nDArr[0]);
int arr[]= new int[n];
String input = br.readLine();
String sar[] = input.split(" ");
for(int i = 0; i < n; i++){
arr[i] = Integer.parseInt(sar[i]);
}
System.out.println(cal(arr, n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tom has been given an integer array A of size N. Now, he needs to find the number of increasing sub-sequences of this array with length β₯1 and GCD=1. A sub-sequence of an array is obtained by deleting some (or none) elements and maintaining the relative order of the rest of the elements. As the answer may be large, print it Modulo (10^9)+7.The first line contains a single integer N denoting the size of array A. The next line contains N space-separated integers denoting the elements of array A.
Constraints:
1 β€ N β€ 500
1 β€ A[i] β€ 100Print the required answer Modulo 10^9+7.Sample Input
3
1 2 3
Sample Output
5, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define scn(a) scanf("%lld",&a)
#define nl printf("\n")
#define scns(a,b) scanf("%lld %lld",&a,&b)
#define print(a) printf("%lld",a)
#define tc ll t; scn(t); while(t--)
#define vec vector<ll>
#define pb push_back
#define pairs pair<ll,ll>
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define srt(v) sort(v.rbegin(),v.rend())
#define mem(a,b) memset(a,b,sizeof(a))
#define inf LLONG_MAX
#define zer LLONG_MIN
#define mp make_pair
#define maxx 200005
const int MOD = 1e9+7;
const int MAXN = 502;
ll dp[MAXN][MAXN];
int a[MAXN];
int main()
{
int n; scanf("%d", &n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
dp[i][a[i]]=1;
for(int j=i-1;j>=1;j--)
{
if(a[j]<a[i])
{
for(int k=1;k<=100;k++)
{
int g=__gcd(k,a[i]);
dp[i][g]=(dp[i][g]%MOD + dp[j][k]%MOD)%MOD;
}
}
}
}
ll ans=0;
for(int i=1;i<=n;i++)
ans=(ans%MOD + dp[i][1]%MOD)%MOD;
cout<<ans<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given string S representing a non- negative integer number, and an integer K, return the smallest possible integer after removing k digits from S.
Example:
Input: num = "1432219", k = 3
Output: "1219"
Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.First contains the string S. Second line contains the integer K.
Constraints:
1 <= K <= S.size() <= 10^5
S contains only digits.
S does not start with 0.Print the required answer.Sample Input:
1432219
3
Sample Output:
1219
Sample Input:
2020
2
Sample Output:
0, 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);
String s = in.next();
int k =Integer.parseInt(in.next());
Stack<Integer> st = new Stack<Integer>();
for(int i=0;i<s.length();i++){
int d=s.charAt(i)-'0';
while(k>0 && !st.empty() && st.peek() > d ){
st.pop();
k--;
}
st.push(d);
}
while(k>0){
st.pop();
k--;
}
int n=st.size();
char arr[] = new char[n];
for(int i=n-1;i>=0;i--){
arr[i]=(char)(48+st.peek());
st.pop();
}
String ans=String.valueOf(arr);
int i=0;
while(i<n && ans.charAt(i)=='0')i++;
if(i==n){
out.print("0");
}
else{
out.print(ans.substring(i));
}
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: You are given an array A of size N. Find the number of pairs of indices (i, j) in the array A such that i < j and A<sub>i</sub> - i = A<sub>j</sub> - j.The first line of the input contains a single integer N.
The second line of the input contains N space seperated integers.
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= A<sub>i</sub> <= 10<sup>5</sup>Print the number of pairs of indices (i, j) in the given array A such that i < j and A<sub>i</sub> - i = A<sub>j</sub> - j.Sample Input:
4
1 3 3 4
Sample Output:
3
Explaination:
The three pairs of indices are:
(1, 3) -> A[1] - 1 = A[3] - 3 -> 1 - 1 = 3 - 3 -> 0 = 0
(1, 4) -> A[1] - 1 = A[4] - 4 -> 1 - 1 = 4 - 4 -> 0 = 0
(3, 4) -> A[3] - 3 = A[4] - 4 -> 3 - 3 = 4 - 4 -> 0 = 0, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n;
cin >> n;
map<int, int> mp;
int ans = 0;
for(int i = 1; i <= n; ++i){
int x;
cin >> x;
mp[x - i]++;
}
for(auto i:mp)
ans += i.second * (i.second - 1)/2;
cout << ans;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
int p=(int)Math.sqrt(n);
for(int i=2;i<=p;i++){
if(n%i==0){System.out.print("NO");return;}
}
System.out.print("YES");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code: import math
def isprime(A):
if A == 1:
return False
sqrt = int(math.sqrt(A))
for i in range(2,sqrt+1):
if A%i == 0:
return False
return True
inp = int(input())
if isprime(inp):
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 N, your task is to check whether the given number is prime or notThe input contains a single integer N.
Constraints:-
1 <= N <= 100000000000Print "YES" If the given number is prime else print "NO".Sample Input:-
2
Sample Output:-
YES
Sample Input:-
4
Sample Output:-
NO, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
long n;
cin>>n;
long x = sqrt(n);
for(int i=2;i<=x;i++){
if(n%i==0){cout<<"NO";return 0;}
}
cout<<"YES";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
int n = io.nextInt(), k = io.nextInt(), j = io.nextInt() - 1;
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = io.nextInt();
}
int cost = arr[j];
arr[j] = Integer.MAX_VALUE;
Arrays.sort(arr);
for(int i = 0; i < k - 1; i++) {
cost += arr[i];
}
io.println(cost);
io.close();
}
static IO io = new IO();
static class IO {
private byte[] buf;
private InputStream in;
private PrintWriter pw;
private int total, index;
public IO() {
buf = new byte[1024];
in = System.in;
pw = new PrintWriter(System.out);
}
public int next() throws IOException {
if(total < 0)
throw new InputMismatchException();
if(index >= total) {
index = 0;
total = in.read(buf);
if(total <= 0)
return -1;
}
return buf[index++];
}
public int nextInt() throws IOException {
int n = next(), integer = 0;
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
return neg * integer;
}
public int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for(int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public long nextLong() throws IOException {
long integer = 0l;
int n = next();
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
return neg * integer;
}
public double nextDouble() throws IOException {
double doub = 0;
int n = next();
while(isWhiteSpace(n))
n = next();
int neg = 1;
if(n == '-') {
neg = -1;
n = next();
}
while(!isWhiteSpace(n) && n != '.') {
if(n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = next();
}
else
throw new InputMismatchException();
}
if(n == '.') {
n = next();
double temp = 1;
while(!isWhiteSpace(n)) {
if(n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = next();
}
else
throw new InputMismatchException();
}
}
return doub * neg;
}
public String nextString() throws IOException {
StringBuilder sb = new StringBuilder();
int n = next();
while(isWhiteSpace(n))
n = next();
while(!isWhiteSpace(n)) {
sb.append((char)n);
n = next();
}
return sb.toString();
}
public String nextLine() throws IOException {
int n = next();
while(isWhiteSpace(n))
n = next();
StringBuilder sb = new StringBuilder();
while(!isEndOfLine(n)) {
sb.append((char)n);
n = next();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
}
private boolean isEndOfLine(int n) {
return n == '\n' || n == '\r' || n == -1;
}
public void print(Object obj) {
pw.print(obj);
}
public void println(Object... obj) {
if(obj.length == 1)
pw.println(obj[0]);
else {
for(Object o: obj)
pw.print(o + " ");
pw.println();
}
}
public void flush() throws IOException {
pw.flush();
}
public void close() throws IOException {
pw.close();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, I have written this Solution Code:
a=input().split()
b=input().split()
for j in [a,b]:
for i in range(0,len(j)):
j[i]=int(j[i])
n,k,j=a[0],a[1],a[2]
c_j=b[j-1]
b.sort()
if b[k-1]<=c_j:
b[k-1]=c_j
sum=0
for i in range(0,k):
sum+=b[i]
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Tono loves to do shopping. Today, she went to the market where there are N different types of products. She wants to buy exactly K of them at the minimum cost. Although she is super smart, she wants to check your smartness as well. Can you tell her the minimum cost required to buy exactly K products if she has already decided to buy product J?
<b>Note:</b> Tono does not buy the same product twice, and Tono will definitely buy product J (J is the <b>index</b> of the item).The first line of the input contains three integers, N, K, and J, denoting the number of products in the market, the number of products Tono needs to buy, and the product that Tono will definitely buy.
The next line contains N singly spaced integers, the cost of the N products C[1], C[2], ..., C[N].
<b>Constraints:</b>
1 <= N <= 200000
1 <= K <= N
1 <= J <= N
1 <= C[i] <= 1000
Output a single integer, the minimum amount Tono needs to pay.Sample Input 1:
5 3 4
1 2 3 4 5
Sample Output 1:
7
Sample Input 2:
5 1 3
2 4 3 1 1
Sample Output 2:
3
<b>Explanation:</b>
Tono needs to buy exactly 3 products, and she will definitely buy the 4th product. Thus, she will buy the 1st, 2nd, and the 4th product. The total cost she pays is 1+2+4=7.
, 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, k, j; cin>>n>>k>>j;
vector<int> vect;
int ans = 0;
For(i, 1, n+1){
int a; cin>>a;
if(i!=j)
vect.pb(a);
else
ans += a;
}
sort(all(vect));
for(int i=0; i<k-1; i++){
ans += vect[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 resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 β€ N β€ 10^5
1 β€ Ai β€ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, 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());
double arr[] = new double[N];
String str[] = br.readLine().trim().split(" ");
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
double resistance=0;
int equResistance=0;
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
for(int i=0;i<N;i++)
{
resistance=resistance+(1/arr[i]);
}
equResistance = (int)Math.floor((1/resistance));
System.out.println(equResistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 β€ N β€ 10^5
1 β€ Ai β€ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("")
r = int(r)
n = input("").split()
resistance=0.0
for i in range(0,r):
resistor = float(n[i])
resistance = resistance + (1/resistor)
print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 β€ N β€ 10^5
1 β€ Ai β€ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
double s = 0;
for(int i = 1; i <= n; i++){
double p; cin >> p;
s = s + (1/p);
}
s = 1/s;
cout << floor(s);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively.
Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v.
Constraints:
1 <= N, M <= 1000
0 <= u, v <= N-1, u != v
There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output 1:
Yes
Explanation:
There is a cycle with nodes 0, 1, 2, 3
Sample Input 2:
4 4
0 1
1 2
2 3
0 3
Sample Output 2:
No
Explanation:
There is no cycle in this graph, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static ArrayList<ArrayList<Integer>> adj;
static void graph(int v){
adj =new ArrayList<>();
for(int i=0;i<=v;i++) adj.add(new ArrayList<Integer>());
}
static void addedge(int u, int v){
adj.get(u).add(v);
}
static boolean dfs(int i, boolean [] vis, int parent[]){
vis[i] = true; parent[i] = 1;
for(Integer it: adj.get(i)){
if(vis[it]==false) {
if(dfs(it, vis, parent)==true) return true;
}
else if(parent[it]==1) return true;
}
parent[i] = 0;
return false;
}
static boolean helper(int n){
boolean vis[] = new boolean [n+1];
int parent[] = new int[n+1];
for(int i=0;i<=n;i++){
if(vis[i]==false){
if(dfs(i, vis, parent)) return true;
}
}
return false;
}
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String t[] = br.readLine().split(" ");
int n = Integer.parseInt(t[0]);
graph(n);
int e = Integer.parseInt(t[1]);
for(int i=0;i<e;i++) {
String num[] = br.readLine().split(" ");
int u = Integer.parseInt(num[0]);
int v = Integer.parseInt(num[1]);
addedge(u, v);
}
if(helper(n)) System.out.println("Yes");
else System.out.println("No");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively.
Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v.
Constraints:
1 <= N, M <= 1000
0 <= u, v <= N-1, u != v
There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output 1:
Yes
Explanation:
There is a cycle with nodes 0, 1, 2, 3
Sample Input 2:
4 4
0 1
1 2
2 3
0 3
Sample Output 2:
No
Explanation:
There is no cycle in this graph, I have written this Solution Code: from collections import defaultdict
class Graph():
def __init__(self,vertices):
self.graph = defaultdict(list)
self.V = vertices
def addEdge(self,u,v):
self.graph[u].append(v)
def isCyclicUtil(self, v, visited, recStack):
visited[v] = True
recStack[v] = True
for neighbour in self.graph[v]:
if visited[neighbour] == False:
if self.isCyclicUtil(neighbour, visited, recStack) == True:
return True
elif recStack[neighbour] == True:
return True
recStack[v] = False
return False
def isCyclic(self):
visited = [False] * (self.V + 1)
recStack = [False] * (self.V + 1)
for node in range(self.V):
if visited[node] == False:
if self.isCyclicUtil(node,visited,recStack) == True:
return True
return False
V,edges=map(int,input().split())
g = Graph(V)
for i in range(edges):
u,v=map(int,input().split())
g.addEdge(u,v)
if g.isCyclic() == 1:
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 directed graph, detect the presence of a cycle in the graph.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively.
Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v.
Constraints:
1 <= N, M <= 1000
0 <= u, v <= N-1, u != v
There are no self loops or multiple edges.The method should return 1 if there is a cycle else it should return 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output 1:
Yes
Explanation:
There is a cycle with nodes 0, 1, 2, 3
Sample Input 2:
4 4
0 1
1 2
2 3
0 3
Sample Output 2:
No
Explanation:
There is no cycle in this graph, 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;
vector<int> g[N];
int vis[N];
bool flag = 0;
void dfs(int u){
vis[u] = 1;
for(auto i: g[u]){
if(vis[i] == 1)
flag = 1;
if(vis[i] == 0) dfs(i);
}
vis[u] = 2;
}
signed main() {
IOS;
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
}
for(int i = 0; i < n; i++){
if(vis[i]) continue;
dfs(i);
}
if(flag)
cout << "Yes";
else
cout << "No";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. 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 N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: def checkConevrtion(a):
return str(a)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer <b>N</b>, you need to typecast this integer to String. 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 N as a parameter.You need to return the typecasted string value. The driver code will print "<b>Nice Job</b>" otherwise "<b>Wrong answer</b>".Sample Input:
5
Sample Output:
Nice Job
Sample Input:
6
Sample Output:
Nice Job, I have written this Solution Code: static String checkConevrtion(int a)
{
return String.valueOf(a);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code:
#include <iostream>
using namespace std;
int Dishes(int N, int T){
return T-N;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
printf("%d",Dishes(n,k));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.