Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: Sid is super fascinated with Fibonacci numbers. Since he thinks a lot about Fibonacci numbers, this time he has come up with a strange problem on them, specially designed for you. As usual, he will give you a chapo if you can manage to solve this problem.
You are given four integers x, y, a, b. You need to compute:
The greatest common divisor of Fib(x**a - y**a), Fib(x**b - y**b) modulo 1000000007.
Here, Fib(i) refers to the ith Fibonacci number, Fib(0)=0, Fib(1)=1, Fib(i)=Fib(i-1)+Fib(i-2).
Note:
n**p refers to n raised to the power p.The only line of input contains four integers x, y, a, b.
Constraints
1 <= a, b <= 10000
1 <= y < x <= 1000000000
gcd(x, y) = 1Print a single integer, the answer to the given input.Sample Input
3 2 2 4
Sample Output
5, I have written this Solution Code: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef print
#define print(...)
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
//const int mod=998244353;
const int mod = 1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }
int powm(int a, int b, int mod) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
int pisano = 2000000016;
const int M = 1000000007;
map<int, int> F;
int f(int n) {
if (F.count(n)) return F[n];
int k=n/2;
if (n%2==0) {
return F[n] = ((f(k)*f(k))%M + (f(k-1)*f(k-1))%M) % M;
} else {
return F[n] = ((f(k)*f(k+1))%M + (f(k-1)*f(k))%M) % M;
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int x, y, a, b;
F[0] = 1, F[1] = 1;
cin >> x >> y >> a >> b;
a = __gcd(a, b);
int y1 = (powm(x, a, pisano) - powm(y, a, pisano) + pisano) % pisano;
y1--;
y1 += pisano;
y1 %= pisano;
cout << f(y1);
}, 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: 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: 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: Given two elements A and B, your task is to swap the given two elements.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:-
5 7
Sample Output:-
7 5
Sample Input:-
3 6
Sample Output:-
6 3, I have written this Solution Code: class Solution {
public static void Swap(int A, int B){
int C = A;
A = B;
B = C;
System.out.println(A + " " + B);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two elements A and B, your task is to swap the given two elements.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Swap(int A, int B)</b>.Print one line which contains the output of swapped elements.Sample Input:-
5 7
Sample Output:-
7 5
Sample Input:-
3 6
Sample Output:-
6 3, I have written this Solution Code: # Python program to swap two variables
li= list(map(int,input().strip().split()))
x=li[0]
y=li[1]
# create a temporary variable and swap the values
temp = x
x = y
y = temp
print(x,end=" ")
print(y,end="")
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a Doubly linked list and an integer K . Your task is to insert the integer K at the head of the given linked list<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>insertnew()</b> that takes the head node and the integer K as a parameter.
<b>Constraints:</b>
1 <=N<= 1000
1 <=K, value<= 1000Return the head of the modified linked listSample Input:-
5 2
1 2 3 4 5
Sample Output:
2 1 2 3 4 5
, I have written this Solution Code: public static Node insertnew(Node head, int k) {
Node temp = new Node(k);
temp.next = head;
head.prev=temp;
return temp;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Chef is playing with a number N. If the total number of set bits in N is even then Chef is happy. Determine whether Chef is happy or not.first line contain a single integer N.if the total number of set bits in N is even print "Yes" otherwise print "No"Sample Input 1:
7
Sample Output 1:
NO
Sample Input 2:
24
Sample Output 1:
Yes, I have written this Solution Code: n=int(input())
if (sum(list(map(int,list(bin(n)[2:]))))%2==0):
print('Yes')
else:
print('No'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Chef is playing with a number N. If the total number of set bits in N is even then Chef is happy. Determine whether Chef is happy or not.first line contain a single integer N.if the total number of set bits in N is even print "Yes" otherwise print "No"Sample Input 1:
7
Sample Output 1:
NO
Sample Input 2:
24
Sample Output 1:
Yes, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
int n = Integer.parseInt(br.readLine());
int count = 0;
int mask = 1;
for(int i = 0;i<32;i++){
if((n&mask)>0){
count++;
}
mask = mask<<1;
}
System.out.print((count ^ 1) == count + 1 ?"Yes":"No");
}catch(Exception e){
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Chef is playing with a number N. If the total number of set bits in N is even then Chef is happy. Determine whether Chef is happy or not.first line contain a single integer N.if the total number of set bits in N is even print "Yes" otherwise print "No"Sample Input 1:
7
Sample Output 1:
NO
Sample Input 2:
24
Sample Output 1:
Yes, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int num_of_set_bit(int n){
int ans=0;
while(n)ans+=n%2, n/=2;
return ans;
}
int main()
{
int N;
cin>>N;
int x=num_of_set_bit(N);
cout<<((x&1)? "No":"Yes");
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t= Integer.parseInt(br.readLine());
if(t%2==0)
System.out.println("Even");
else
System.out.println("Odd");
}
catch (Exception e){
return;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: n = int(input())
if n % 2 == 0:
print("Even")
else:
print("Odd"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether a number is even or odd using switch case.First Line of the input contains the number n.
<b>Constraints</b>
1 <= n <= 1e9If the number is even print "Even" otherwise "Odd"Sample Input :
23
Sample Output :
Odd
Sample Input :
24
Sample Output :
Even, I have written this Solution Code: #include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
switch(num % 2)
{
case 0:
printf("Even");
break;
/* Else if n%2 == 1 */
case 1:
printf("Odd");
break;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: def Marks(P,Q,R):
return 4*P-2*Q-R
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<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>Marks()</b> that takes integer P, Q, and R as arguments.
Constraints:-
0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:-
4 2 0
Sample Output:-
12
Sample Input:-
1 1 1
Sample Output:-
1, I have written this Solution Code: static int Marks(int P, int Q, int R){
return 4*P - 2*Q - R;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There are N robots standing in a row. Ultron wants to delegate a task of difficulty X to two of them. Each robot has its own ability, A[i] for the i<sup>th</sup> robot from the left. The task can only be completed if the sum of the abilities of the two robots is exactly equal to X. Ultron wants to find out the number of distinct unordered pairs of robots he can choose to complete this task. He wants to find this number for Q (not necessarily distinct) subarrays of robots.
Formally, for each query, you will be given two integers L and R and you need to calculate the number of pairs (i, j) such that L ≤ i < j ≤ R and A[i] + A[j] = X.
Further, these subarrays have a nice property that for every pair of them at least one of the following three statements hold:
1. Their intersection is one of the two intervals itself (for example, segments [2, 6] and [2, 4]).
2. Their intersection is empty (for example, segments [2, 6] and [7, 8]).
3. Their intersection consists of exactly one element (for example, segments [2, 5] and [5, 8]).
For another example, note that the segments [2, 5] and [4, 7] do not satisfy any of the above conditions, and thus cannot both appear in the input.
You need to find the answer to each one of Ultron's queries and report the XOR of their answers.
<b>Note:</b> Since the input is large, it is recommended that you use fast input/output methods.The first line of the input contains two space-separated integers, N, the number of robots and X, the difficulty of the task.
The second line contains N space-separated integers A[1], A[2], ... A[n] - the abilities of the robots.
The third line of input contains an integer Q - the number of queries Ultron has.
Q lines follow, the i<sup>th</sup> of them contains two integers L and R for the i<sup>th</sup> query.
It is guaranteed that the given subarrays satisfy the properties mentioned in the problem statement.
<b>Constraints: </b>
2 ≤ N ≤ 400000
1 ≤ X ≤ 1000000
0 ≤ A[i] ≤ X
1 ≤ Q ≤ 400000
1 ≤ L < R ≤ N for each queryPrint a single integer, the bitwise XOR of the answers of the Q queries.Sample Input:
7 10
2 9 1 8 4 4 6
5
1 7
2 5
1 6
3 4
4 5
Sample Output:
7
Explanation:
For the first query there are 4 pairs of indices, (2, 3), (1, 4), (5, 7), (6, 7).
For the second query there is 1 pair of indices, (2, 3)
Similarly you can verify that the answers for the five queries are (4, 1, 2, 0, 0) in order. So we print their bitwise XOR = 7.
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long
int X;
vector<int> adj[400005];
int ans[400005];
int cnt[1000005];
int A[400005];
pair<int, int> Q[400005];
void dfs(int x, bool keep = false)
{
int bigChild = -1, sz = 0;
for(auto &p: adj[x])
{
if(Q[p-1].second - Q[p-1].first > sz)
{
sz = Q[p-1].second - Q[p-1].first;
bigChild = p;
}
}
if(x > 0 && bigChild == -1)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
ans[x-1] += cnt[X-A[cur]];
cnt[A[cur]]++;
}
if(!keep)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
cnt[A[cur]]--;
}
}
return;
}
for(auto &p: adj[x])
{
if(p != bigChild)
{
dfs(p);
}
}
dfs(bigChild, true);
if(x > 0)
{
ans[x-1] = ans[bigChild-1];
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
if(cur == Q[bigChild-1].first)
{
cur = Q[bigChild-1].second;
continue;
}
ans[x-1] += cnt[X-A[cur]];
cnt[A[cur]]++;
}
if(!keep)
{
for(int cur = Q[x-1].first; cur <= Q[x-1].second; cur++)
{
cnt[A[cur]]--;
}
}
}
}
bool my(int a, int b)
{
if(Q[a].first < Q[b].first) return true;
else if(Q[a].first == Q[b].first) return Q[a].second > Q[b].second;
return false;
}
void sack(int n, int q)
{
vector<int> order;
for(int i=0; i<q; i++) order.push_back(i);
sort(order.begin(), order.end(), my);
stack<int> right_ends;
stack<int> st;
for(int i=0; i<q; i++)
{
while(right_ends.size() && right_ends.top() <= Q[order[i]].first)
{
int which = st.top();
st.pop();
right_ends.pop();
if(st.empty())
{
adj[0].push_back(which+1);
}
else
{
adj[st.top()+1].push_back(which+1);
}
}
st.push(order[i]);
// cout << "inserting " << queries[i][2] << " into stack\n";
right_ends.push(Q[order[i]].second);
}
while(!st.empty())
{
int which = st.top();
st.pop();
right_ends.pop();
if(st.empty())
{
adj[0].push_back(which+1);
}
else
{
adj[st.top()+1].push_back(which+1);
}
}
// for(int i=0; i<=q; i++)
// {
// for(auto &x: adj[i])
// {
// cout << i << " has child " << x << "\n";
// }
// }
dfs(0);
}
signed main()
{
// freopen("input.txt", "r", stdin);
// freopen("output_sack.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n >> X;
for(int i=0; i<n; i++)
{
cin >> A[i];
}
int q;
cin >> q;
for(int i=0; i<q; i++)
{
cin >> Q[i].first >> Q[i].second;
Q[i].first--;
Q[i].second--;
}
sack(n, q);
int ansr = 0;
for(int i=0; i<q; i++)
{
ansr ^= ans[i];
}
cout << ansr << "\n";
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Create a basic table namely TEST_TABLE with 1 field TEST_FIELD as int.
( USE ONLY UPPER CASE LETTERS )
<schema>[{'name': 'TEST_TABLE', 'columns': [{'name': 'TEST_FIELD', 'type': 'INT'}]}]</schema>nannannan, I have written this Solution Code: CREATE TABLE TEST_TABLE (
TEST_FIELD INT
);, In this Programming Language: SQL, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
// Function to rotate the matrix 90 degree clockwise
void rotate90Clockwise(int a[][N],int n)
{
// Traverse each cycle
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
// Swap elements of each cycle
// in clockwise direction
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
}
// Function for print matrix
void printMatrix(int arr[][N],int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << arr[i][j] << " ";
cout << '\n';
}
}
// Driver code
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
rotate90Clockwise(arr,n);
printMatrix(arr,n);
cout<<endl;
rotate90Clockwise(arr,n);
printMatrix(arr,n);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[][] = new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]= sc.nextInt();
}
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
System.out.println();
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: x=int(input())
l1=[]
for i in range(x):
a1=list(map(int,input().split()))
l1.append(a1)
for j in range(x):
for i in range(1,x+1):
print(l1[-i][j], end=" ")
print()
print()
for i in range(1,x+1):
for j in range(1,x+1):
print(l1[-i][-j], end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
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));
int noofterm=Integer.parseInt(br.readLine());
int arr[] = new int[noofterm];
String s[] = br.readLine().split(" ");
for(int i=0; i<noofterm;i++){
arr[i]= Integer.parseInt(s[i]);
}
System.out.println(unique(arr));
}
public static int unique(int[] inputArray)
{
int result = 0;
for(int i=0;i<inputArray.length;i++)
{
result ^= inputArray[i];
}
return (result>0 ? result : -1);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: n = int(input())
a = [int (x) for x in input().split()]
mapp={}
for index,val in enumerate(a):
if val in mapp:
del mapp[val]
else:
mapp[val]=1
for key, value in mapp.items():
print(key), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N elements. In the array, each element is present twice except for 1 element whose frequency in the array is 1. Hence the length of the array will always be odd.
Find the unique number.An integer, N, representing the size of the array. In the next line, N space-separated integers follow.
<b>Constraints:</b>
1 <= N <=10<sup>5</sup>
1 <= A[i] <=10<sup>8</sup>Output the element with frequency 1.Input :
5
1 1 2 2 3
Output:
3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main()
{
int n;
cin>>n;
int p=0;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
p^=a;
}
cout<<p<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given positive integer N, determine if there exist three <b>positive</b> integers a, b and c such that the following two conditions hold:
1. a + b + c = N
2. a ^ b ^ c = 0 where ^ denotes the bitwise XOR operation.
If there exist such a triple (a, b, c), print the lexicographically smallest one.
Else, print -1.The first line of input contains a single integer, T.
T lines follow, each containing a single integer, N.
<b>Constraints:</b>
1 <= T <= 10<sup>3</sup>
3 <= N <= 10<sup>18</sup>For each test, in a new line, print the lexicographically smallest triple (a, b, c) if it exists, else print -1.Sample Input:
3
3
6
12
Sample Output:
-1
1 2 3
2 4 6, I have written this Solution Code: for _ in range(int(input())):
n = int(input())
if n%2 or n<6:
print(-1)
continue
m = n//2
sl = 1
while m % 2 == 0:
m >>= 1
sl <<= 1
if n == sl*2:
print(-1)
continue
print(sl,n//2-sl,n//2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given positive integer N, determine if there exist three <b>positive</b> integers a, b and c such that the following two conditions hold:
1. a + b + c = N
2. a ^ b ^ c = 0 where ^ denotes the bitwise XOR operation.
If there exist such a triple (a, b, c), print the lexicographically smallest one.
Else, print -1.The first line of input contains a single integer, T.
T lines follow, each containing a single integer, N.
<b>Constraints:</b>
1 <= T <= 10<sup>3</sup>
3 <= N <= 10<sup>18</sup>For each test, in a new line, print the lexicographically smallest triple (a, b, c) if it exists, else print -1.Sample Input:
3
3
6
12
Sample Output:
-1
1 2 3
2 4 6, I have written this Solution Code: //HEADER FILES AND NAMESPACES
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// PRAGMAS (do these even work?)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
// DEFINE STATEMENTS
const long long infty = 1e18;
#define num1 1000000007
#define num2 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define REPd(i,a,n) for(ll i=a; i>=n; i--)
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.000000001)
#define popcount __builtin_popcountll
#define fileio(x) freopen("input.txt", "r", stdin); freopen(x, "w", stdout);
#define out(x) cout << ((x) ? "Yes\n" : "No\n")
#define sz(x) x.size()
#define start_clock() auto start_time = std::chrono::high_resolution_clock::now();
#define measure() auto end_time = std::chrono::high_resolution_clock::now(); cerr << (end_time - start_time)/std::chrono::milliseconds(1) << "ms" << endl;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> vpll;
typedef vector<int> vii;
// DEBUG FUNCTIONS
#ifdef LOCALY
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T>
void __p(std::set<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T>
void __p(std::multiset<T> a) {
cout<<"{";
for(auto it=a.begin(); it!=a.end();){
__p(*it);
cout<<",}"[++it==a.end()];
}
}
template<typename T, typename F>
void __p(std::map<T,F> a) {
cout<<"{\n";
for(auto it=a.begin(); it!=a.end();++it)
{
__p(it->first);
cout << ": ";
__p(it->second);
cout<<"\n";
}
cout << "}\n";
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define error(...)
#endif
// DEBUG FUNCTIONS END
// CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // FOR RANDOM NUMBER GENERATION
ll mod_exp(ll a, ll b, ll c)
{
ll res=1; a=a%c;
while(b>0)
{
if(b%2==1)
res=(res*a)%c;
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return (((a = a%b) < 0) ? a + b : a);
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
g++; //this line was added just to remove compiler warning
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct Graph
{
vector<vector<int>> adj;
Graph(int n)
{
adj.resize(n+1);
}
void add_edge(int a, int b, bool directed = false)
{
adj[a].pb(b);
if(!directed) adj[b].pb(a);
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
REP(i, 0, t)
{
ll n;
cin >> n;
if(n&1) cout << "-1\n";
else
{
ll x = n/2;
vll bits;
REP(i, 0, 60)
{
if((x >> i)&1)
{
bits.pb(i);
}
}
if(bits.size() == 1)
{
cout << "-1\n";
}
else
{
ll a = (1ll << bits[0]);
cout << a << " " << x - a << " " << x << "\n";
}
}
}
return 0;
}
/*
1. Check borderline constraints. Can a variable you are dividing by be 0?
2. Use ll while using bitshifts
3. Do not erase from set while iterating it
4. Initialise everything
5. Read the task carefully, is something unique, sorted, adjacent, guaranteed??
6. DO NOT use if(!mp[x]) if you want to iterate the map later
7. Are you using i in all loops? Are the i's conflicting?
*/
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given positive integer N, determine if there exist three <b>positive</b> integers a, b and c such that the following two conditions hold:
1. a + b + c = N
2. a ^ b ^ c = 0 where ^ denotes the bitwise XOR operation.
If there exist such a triple (a, b, c), print the lexicographically smallest one.
Else, print -1.The first line of input contains a single integer, T.
T lines follow, each containing a single integer, N.
<b>Constraints:</b>
1 <= T <= 10<sup>3</sup>
3 <= N <= 10<sup>18</sup>For each test, in a new line, print the lexicographically smallest triple (a, b, c) if it exists, else print -1.Sample Input:
3
3
6
12
Sample Output:
-1
1 2 3
2 4 6, I have written this Solution Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;
public class Main {
void solve(){
long n= in.nextLong();
if(n%2==1){
sb.append(-1).append("\n");
}
else{
long cnt=0;
n=n/2;
while(n%2==0){
cnt++;
n=n>>1;
}
long x=(1L<<cnt);
long y=(1L<<cnt);
long z=0;
while(n!=0){
n=n>>1;
cnt++;
if((n&1)==1){
y+=(1L<<cnt);
z+=(1L<<cnt);
}
}
long[] a= new long[3];
a[0]=x;
a[1]=y;
a[2]=z;
sort(a);
if(a[0]!=0){
sb.append(a[0]).append(" ");
sb.append(a[1]).append(" ");
sb.append(a[2]).append("\n");
}
else{
sb.append(-1).append("\n");
}
}
}
FastReader in;
StringBuffer sb;
public static void main(String[] args) {
new Main().run();
}
void run(){
in= new FastReader();
start();
}
void start(){
sb= new StringBuffer();
for(int t=in.nextInt();t>0;t--) {
solve();
}
out.print(sb);
}
void swap( int i , int j) {
int tmp = i;
i = j;
j = tmp;
}
long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int lower_bound(long[] a, long x) {
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
int upper_bound(long[] arr, int key) {
int i=0, j=arr.length-1;
if (arr[j]<=key) return j+1;
if(arr[i]>key) return i;
while (i<j){
int mid= (i+j)/2;
if(arr[mid]<=key){
i= mid+1;
}else{
j=mid;
}
}
return i;
}
void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
int[] intArr(int n){
int[] res= new int[n];
for(int i=0;i<n;i++){
res[i]= in.nextInt();
}
return res;
}
long[] longArr(int n){
long[] res= new long[n];
for(int i=0;i<n;i++){
res[i]= in.nextLong();
}
return res;
}
boolean isDigitSumPalindrome(long N) {
long sum= sumOfDigits(String.valueOf(N));
long rev=0;
long org= sum;
while (sum!=0){
long d= sum%10;
rev = rev*10 +d;
sum /= 10;
}
return org == rev;
}
long sumOfDigits(String n){
long sum= 0;
for (char c: n.toCharArray()){
sum += Integer.parseInt(String.valueOf(c));
}
return sum;
}
long[] revArray(long[] arr) {
int n= arr.length;
int i=0, j=n-1;
while (i<j){
long temp= arr[i];
arr[i]= arr[j];
arr[j]= temp;
i++;
j--;
}
return arr;
}
long gcd(long a, long b){
if (b==0)
return a;
return gcd(b, a%b);
}
long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
static class Pair implements Comparable<Pair>{
long first;
long second;
Pair(long x, long y){
this.first=x;
this.second=y;
}
@Override
public int compareTo(Pair o) {
return 0;
}
}
public static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}catch (Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
String str="";
try{
str=br.readLine();
}catch (Exception e){
e.printStackTrace();
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd.
Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store
The second line contains N integers— the number of flowers of each type
1 <= N <= 100000
1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input
3
3 5 8
Sample output
15
Sample input
3
1 1 1
Sample output
3, I have written this Solution Code: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)) ;
int n = Integer.parseInt(read.readLine()) ;
String[] str = read.readLine().trim().split(" ") ;
int[] arr = new int[n] ;
for(int i=0; i<n; i++) {
arr[i] = Integer.parseInt(str[i]) ;
}
long ans = 0L;
if((n & 1) == 1) {
for(int i=0; i<n; i++) {
ans += ((arr[i] & 1) == 1) ? arr[i] : arr[i] - 1 ;
}
}
else {
Arrays.sort(arr);
for(int i=1; i<n; i++) {
ans += ((arr[i] & 1) == 1) ? arr[i] : arr[i] - 1 ;
}
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd.
Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store
The second line contains N integers— the number of flowers of each type
1 <= N <= 100000
1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input
3
3 5 8
Sample output
15
Sample input
3
1 1 1
Sample output
3, I have written this Solution Code: n=int(input())
arr=map(int,input().split())
result=[]
for item in arr:
if item%2==0:
result.append(item-1)
else:
result.append(item)
if sum(result)%2==0:
result.sort()
result.pop(0)
print(sum(result))
else:
print(sum(result)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd.
Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store
The second line contains N integers— the number of flowers of each type
1 <= N <= 100000
1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input
3
3 5 8
Sample output
15
Sample input
3
1 1 1
Sample output
3, I have written this Solution Code: #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
int n; cin >> n ;
long long int ans = 0;
// int arr[n];
int odd = 0,minn=INT_MAX;
for(int i=0;i<n;i++){
ll temp; cin >> temp;
// cin >> arr[i];
ans += (temp&1) ? temp : temp-1;
if(minn>temp)
minn = temp;
}
if(n&1)
cout << ans ;
else{
if(minn&1)
cout <<ans-minn;
else
cout << ans - minn + 1;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find the sum of GCD (Greatest Common Divisor) of all elements with their frequency.First line contains an integers N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 1000
0 <= Ai<= 10^5Print the sum of GCD of all elements with their frequency.Sample Input 1:
3
1 2 3
Output
3
Explanation:
gcd(1, 1) + gcd(2, 1) + gcd(3, 1) = 1+1+1 = 3
Sample Input 2:
6
3 6 6 9 3 3
Output
14
Explanation
gcd(3, 3) + gcd(6, 2) + gcd(6, 2) + gcd(9, 1) + gcd(3, 3) + gcd(3, 3)= 3+2+2+1+3+3= 14, I have written this Solution Code: def computeGCD(a, b):
if(b == 0):
return a
if(a==0):
return b
return computeGCD(b , a%b)
n = int(input())
l = [0]*n
l = list(map(int , input().strip().split(" ")))
c , g , t = 0 , 0 , 0
'''l_c = [0]*n
g,t = 0,0
for i in range(0,n):
l_c[i] = l.count(l[i])'''
for i in l:
c = l.count(i)
g = computeGCD(c , i)
t = t + g
'''for i in range(0,n):
g = computeGCD(l_c[i],l[i])
t = t + g'''
print(t), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find the sum of GCD (Greatest Common Divisor) of all elements with their frequency.First line contains an integers N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 1000
0 <= Ai<= 10^5Print the sum of GCD of all elements with their frequency.Sample Input 1:
3
1 2 3
Output
3
Explanation:
gcd(1, 1) + gcd(2, 1) + gcd(3, 1) = 1+1+1 = 3
Sample Input 2:
6
3 6 6 9 3 3
Output
14
Explanation
gcd(3, 3) + gcd(6, 2) + gcd(6, 2) + gcd(9, 1) + gcd(3, 3) + gcd(3, 3)= 3+2+2+1+3+3= 14, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.math.BigInteger;
class Main {
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int [n];
Map<Integer,Integer>m=new HashMap<Integer, Integer>();
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<n;i++) {
if (m.containsKey(a[i])) m.put(a[i], m.get(a[i]) + 1);
else m.put(a[i], 1);
}
for(int i=0;i<n;i++) {
sum += gcd(a[i],m.get(a[i]));
}
System.out.print(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer array A of size N. Find the sum of GCD (Greatest Common Divisor) of all elements with their frequency.First line contains an integers N.
Next line contains N space separated integers denoting elements of array.
Constraints
1 <= N <= 1000
0 <= Ai<= 10^5Print the sum of GCD of all elements with their frequency.Sample Input 1:
3
1 2 3
Output
3
Explanation:
gcd(1, 1) + gcd(2, 1) + gcd(3, 1) = 1+1+1 = 3
Sample Input 2:
6
3 6 6 9 3 3
Output
14
Explanation
gcd(3, 3) + gcd(6, 2) + gcd(6, 2) + gcd(9, 1) + gcd(3, 3) + gcd(3, 3)= 3+2+2+1+3+3= 14, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define fo(n) for(int j=0;j<n;j++)
#define foo(n) for(int i=1;i<=n;i++)
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define test int tt; cin>>tt; while(tt--)
#define mod 1000000007
void fastio()
{
ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("Input 1.txt", "r", stdin);
freopen("Output 1.txt", "w", stdout);
#endif
}
int main() {
fastio();
int n;
cin >> n;
int a[n];
f(n)cin >> a[i];
map<int, int>m;
int sum = 0;
f(n) {
m[a[i]]++;
}
f(n) {
sum += __gcd(a[i], m[a[i]]);
}
cout << sum << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Doctor Strange stumbles upon a rather curious artefact while spending holidays in Egypt. An antique board game but it can only be unlocked by a magical die. The only clue on the box is to get a sum of B by throwing the die A times. Help Doctor Strange if it is possible to get the particular sum. Print “YES” if it is possible, otherwise print “NO”.
Note:- Consider the die to be a regular one with face {1, 2, 3, 4, 5, 6}.The input contains two integers A and B separated by spaces.
Constraints:-
• 1≤A≤100
• 1≤B≤1000
A and B are integers.Print "YES" if it is possible to get a Sum of B by throwing die A times else print "NO".Sample Input:-
10 100
Sample Output:-
NO
Sample Input:-
6 30
Sample Output:-
YES, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a*6>=b && a<=b){
cout<<"YES";
}
else{
cout<<"NO";
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Doctor Strange stumbles upon a rather curious artefact while spending holidays in Egypt. An antique board game but it can only be unlocked by a magical die. The only clue on the box is to get a sum of B by throwing the die A times. Help Doctor Strange if it is possible to get the particular sum. Print “YES” if it is possible, otherwise print “NO”.
Note:- Consider the die to be a regular one with face {1, 2, 3, 4, 5, 6}.The input contains two integers A and B separated by spaces.
Constraints:-
• 1≤A≤100
• 1≤B≤1000
A and B are integers.Print "YES" if it is possible to get a Sum of B by throwing die A times else print "NO".Sample Input:-
10 100
Sample Output:-
NO
Sample Input:-
6 30
Sample Output:-
YES, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc =new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
if (B<A || B>A*6) {
System.out.print("NO");
}
else {
System.out.print("YES");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Doctor Strange stumbles upon a rather curious artefact while spending holidays in Egypt. An antique board game but it can only be unlocked by a magical die. The only clue on the box is to get a sum of B by throwing the die A times. Help Doctor Strange if it is possible to get the particular sum. Print “YES” if it is possible, otherwise print “NO”.
Note:- Consider the die to be a regular one with face {1, 2, 3, 4, 5, 6}.The input contains two integers A and B separated by spaces.
Constraints:-
• 1≤A≤100
• 1≤B≤1000
A and B are integers.Print "YES" if it is possible to get a Sum of B by throwing die A times else print "NO".Sample Input:-
10 100
Sample Output:-
NO
Sample Input:-
6 30
Sample Output:-
YES, I have written this Solution Code: A,B=map(int, input().split())
if 1*A<=B and B<=A*6:
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: static int Probability(int A,int B){
int x=1;
for(int i=2;i<=A;i++){
if(A%i==0 && B%i==0){
x=i;
}
}
A=A/x;
B=B/x;
return A+B;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a certain event, the value of a favorable outcome is A and the total outcome is B. If the probability of this event is represented by p/q where p and q are coprime then what will be the value of p+q.<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>Probability()</b> that takes integers A, and B as arguments.
Constraints:-
1 <= A <= B <= 10000Return the value of p+q.Sample Input:-
4 6
Sample Output:-
5
Sample Input:-
3 5
Sample Output:-
8, I have written this Solution Code: def Probability(A,B):
x=1
for i in range (2,A+1):
if (A%i==0) and (B%i==0):
x=i
A=A//x
B=B//x
return A+B
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
String code[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",
".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };
Scanner sc =new Scanner(System.in);
String morseCode =sc.nextLine();
morseToWords(code,morseCode);
}
static void morseToWords(String[] code,String morseCode ){
HashMap<String,Character> hs =new HashMap<>();
for(int i=0; i<26; i++)
hs.put(code[i],(char)('A'+i));
String [] array = morseCode.split(" ");
for(int i=0; i< array.length; i++)
System.out.print(hs.get(array[i]));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code:
dict = dict1 = {".-":"A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N", "---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"}
def word(s):
print(''.join(dict.get(i) for i in s.split()))
if __name__ == "__main__":
word(input()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a morse code, Your task is to figure out the exact words from it.
Morse Code Dictionary :
dict = {".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..", "L": "--", "M": "-.", "N": "---", "O": ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z"};
<img src="https://maker.pro/storage/sKEFbex/sKEFbexA2iF4ZvxgtvPaWXGHxMiwohU6FvxJgkCC.jpeg" height="100px" width="100px">The first line of the input contains the morse string.
<b>Constraints </b>
1<= Total Words <= 1000Print the English Alphabets from the given codeSample Input 1:
<pre>
.-- --- --.- - . .-. -..-
</pre>
Sample Output 1:
WOQTERX, I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-18 01:39:40
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
float calculateSD(vector<float> a, int n) {
float sum = 0.0, mean, SD = 0.0;
for (int i = 0; i < n; ++i) {
sum += a[i];
}
mean = sum / n;
for (int i = 0; i < n; ++i) {
SD += pow(a[i] - mean, 2);
}
return sqrt(SD / n);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// Morse Code
{
char str[100000];
cin.getline(str, sizeof(str), '\n');
string temp = "";
vector<string> words;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == ' ') {
if (temp.length() > 0) {
words.push_back(temp);
}
temp = "";
} else {
temp += str[i];
}
}
if (temp.length() > 0) {
words.push_back(temp);
}
// debug(words);
map<string, string> dict = {
{".-", "A"},
{"-...", "B"},
{"-.-.", "C"},
{"-..", "D"},
{".", "E"},
{"..-.", "F"},
{"--.", "G"},
{"....", "H"},
{"..", "I"},
{".---", "J"},
{"-.-", "K"},
{".-..", "L"},
{"--", "M"},
{"-.", "N"},
{"---", "O"},
{".--.", "P"},
{"--.-", "Q"},
{".-.", "R"},
{"...", "S"},
{"-", "T"},
{"..-", "U"},
{"...-", "V"},
{".--", "W"},
{"-..-", "X"},
{"-.--", "Y"},
{"--..", "Z"}};
for (auto &it : words) {
cout << dict[it];
}
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 an array A of N integers. You can perform the following operation as many times as you like:-
Choose two indices i and j (1 <= i < j <= N), replace A[i] by A[i] OR A[j] and replace A[j] by A[i] AND A[j]. (where OR and AND are logical operators).
All you need to do is find the maximum value of sum of squares of all integers in array A.The first line of the input contains an integer N, the number of integers in the array.
The second line of the input contains N non- negative integers of the array A.
Constraints
1 <= N <= 100000
0 <= A[i] <= 1000000Output a single integer, the maximum value for the sum of squares after performing the above defined operation.Sample Input
3
1 3 5
Sample Output
51
Explanation
Choose indices i = 2 and j = 3. A[2] = 3 OR 5 = 7, A[3] = 3 AND 5 = 1. Sum of squares of final array 1<sup>2</sup>+ 1<sup>2</sup>+7<sup>2</sup> = 51.
Sample Input
1
45
Sample Output
2025, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
static long ans = 0;
static int []binary = new int[31];
static void findMaximumSum(long []arr, int n)
{
for(long x : arr)
{
int idx = 0;
while (x > 0)
{
if ((x & 1) > 0)
binary[idx]++;
x >>= 1;
idx++;
}
}
for(int i = 0; i < n; ++i)
{
long total = 0;
for(int j = 0; j < 21; ++j)
{
if (binary[j] > 0)
{
total += Math.pow(2, j);
binary[j]--;
}
}
ans += total * total;
}
System.out.print(ans + " ");
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long arr[] = new long[N];
String str1 = br.readLine();
StringTokenizer st1 = new StringTokenizer(str1, " ");
int j=0;
while(st1.hasMoreTokens() && j<N) {
arr[j] = Long.parseLong(st1.nextToken());
j++;
}
findMaximumSum(arr, N);
}
}, 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 N integers. You can perform the following operation as many times as you like:-
Choose two indices i and j (1 <= i < j <= N), replace A[i] by A[i] OR A[j] and replace A[j] by A[i] AND A[j]. (where OR and AND are logical operators).
All you need to do is find the maximum value of sum of squares of all integers in array A.The first line of the input contains an integer N, the number of integers in the array.
The second line of the input contains N non- negative integers of the array A.
Constraints
1 <= N <= 100000
0 <= A[i] <= 1000000Output a single integer, the maximum value for the sum of squares after performing the above defined operation.Sample Input
3
1 3 5
Sample Output
51
Explanation
Choose indices i = 2 and j = 3. A[2] = 3 OR 5 = 7, A[3] = 3 AND 5 = 1. Sum of squares of final array 1<sup>2</sup>+ 1<sup>2</sup>+7<sup>2</sup> = 51.
Sample Input
1
45
Sample Output
2025, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> ct(21, 0);
For(i, 0, n){
int a; cin>>a;
For(j, 0, 21){
if(a%2){
ct[j]++;
}
a/=2;
}
}
int ans = 0;
For(i, 0, n){
int val = 0;
For(j, 0, 21){
if(ct[j]){
val += (1LL<<j);
ct[j]--;
}
}
ans += (val*val);
}
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: Sara does not like strings which have both the uppercase and the lowercase characters. She thinks only those strings are good which have only lowercase characters(a-z) or only uppercase characters(A-Z).
Given a string s consisting of english alphabets. Find the minimum number of operations required to make it good.
In one operation you can choose any character of the string and change it into uppercase or lowercase.Input contains a single line containing the string s.
Constraint:-
1<=|s|<=100Print the minimum number of operation required to make the string good.Sample Input:
Sara
Sample Output:
1
Explanation:-
'S' should be converted to 's' respectively
Sample Input:
HELLO
Sample Output:-
0
Sample Input:-
pEOpLE
Sample Output:-
2
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String args[])throws Exception
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String name=br.readLine();
int lower=0;
int uper=0;
for(int i=0;i<name.length();i++)
{
Character ch=name.charAt(i);
if (ch >= 'a' && ch <= 'z')
{
lower++;
}
else if(ch>='A' && ch <='Z')
{
uper++;
}
}
if(lower<uper)
{
System.out.print(lower);
}
else
{
System.out.print(uper);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara does not like strings which have both the uppercase and the lowercase characters. She thinks only those strings are good which have only lowercase characters(a-z) or only uppercase characters(A-Z).
Given a string s consisting of english alphabets. Find the minimum number of operations required to make it good.
In one operation you can choose any character of the string and change it into uppercase or lowercase.Input contains a single line containing the string s.
Constraint:-
1<=|s|<=100Print the minimum number of operation required to make the string good.Sample Input:
Sara
Sample Output:
1
Explanation:-
'S' should be converted to 's' respectively
Sample Input:
HELLO
Sample Output:-
0
Sample Input:-
pEOpLE
Sample Output:-
2
, I have written this Solution Code: n = input()
smallAlphabets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
bigAlphabets = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
count = 0
count1 = 0
for i in n:
if i in smallAlphabets:
count += 1
if i in bigAlphabets:
count1 += 1
if count < count1:
print(count)
else:
print(count1), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara does not like strings which have both the uppercase and the lowercase characters. She thinks only those strings are good which have only lowercase characters(a-z) or only uppercase characters(A-Z).
Given a string s consisting of english alphabets. Find the minimum number of operations required to make it good.
In one operation you can choose any character of the string and change it into uppercase or lowercase.Input contains a single line containing the string s.
Constraint:-
1<=|s|<=100Print the minimum number of operation required to make the string good.Sample Input:
Sara
Sample Output:
1
Explanation:-
'S' should be converted to 's' respectively
Sample Input:
HELLO
Sample Output:-
0
Sample Input:-
pEOpLE
Sample Output:-
2
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int x=0,y=0;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(s[i]<'a'){x++;}
}
cout<<min(x,(int)s.length()-x);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
def checkSpecial_M_Visor(N,M) :
# Final result of summation of divisors
i=2;
count=0
while i<=N :
if(N%i==0):
count=count+1
i=i+2
if(count == M):
return "Yes"
return "No"
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
static String checkSpecial_M_Visor(int N, int M)
{
int temp=0;
for(int i = 2; i <=N; i+=2)
{
if(N%i==0)
temp++;
}
if(temp==M)
return "Yes";
else return "No";
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code:
string checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
if(count==M){return "Yes";}
return "No";
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two positive integers N and M. The task is to check whether N is a <b>Special-M-visor</b> or not.
<b>Special-M-visor</b>: A number is called Special-m-visor if it has exactly M even divisors for a given N.<b>User Task:</b>
Since this is a functional problem, you don’t have to worry about the input, you just have to complete the function <b>checkSpecial_M_Visor()</b>. Where you will get N and M as a parameter.
Constraints:
1 <= N <= 10^6
0 <= M <= 10^6Return "Yes" without quotes if the number N is a <b>Special- M- visor</b> else return "No"Sample Input:-
4 2
Sample Output:-
Yes
Explanation:- 2 and 4 are the only even divisors of 4
Sample Input:-
8 5
Sample Output:-
No, I have written this Solution Code: const char* checkSpecial_M_Visor(int N,int M){
int count=0;
for(int i=2;i<=N;i+=2){
if(N%i==0){
count++;
}
}
char* ans;
if(count==M){return "Yes";}
return "No";
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the sum of all the digits of the number
Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 1000000000Return sum of digits.Sample Input
2
25
28
Sample Output
7
10, I have written this Solution Code: // n is the input number
function recSum(n) {
// write code here
// do not console.log
// return the answer as a number
if (n < 10) return n;
return n % 10 + recSum(Math.floor(n / 10))
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N, find the sum of all the digits of the number
Note: Use a recursive method to solve this problem.<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>Sum()</b> that takes the integer N as a parameter.
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 1000000000Return sum of digits.Sample Input
2
25
28
Sample Output
7
10, I have written this Solution Code: static long Sum(long n)
{ if(n==0){return 0;}
return n%10+Sum(n/10);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n holding some random value, your task is to assign value 10 to the given integer.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>Assignment_Operator()</b>, which takes no parameter.
<b>Constraints:</b>
1 <= n <= 100You don't need to print anything you just need to assign value 10 to the integer n.Sample Input:-
48
Sample output:-
10
Sample Input:-
24
Sample Output:-
10, I have written this Solution Code: static void Assignment_Operator(){
n=10;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether character is an alphabet or not using conditional operator.The first line of the input contains a character ch.
<b>Constraints</b>
'a', 'A' <= ch <= 'z', 'Z'Print "YES" if it's alphabet otherwise "NO".Sample Input :
a
Sample Output
YES, 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);
char c = sc.next().charAt(0);
String output =(c>='a' && c<='z') || (c>='A' && c<='Z')
? "YES" : "NO";
System.out.println(output);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether character is an alphabet or not using conditional operator.The first line of the input contains a character ch.
<b>Constraints</b>
'a', 'A' <= ch <= 'z', 'Z'Print "YES" if it's alphabet otherwise "NO".Sample Input :
a
Sample Output
YES, I have written this Solution Code: c = input()
if(c.isalpha()):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a program to check whether character is an alphabet or not using conditional operator.The first line of the input contains a character ch.
<b>Constraints</b>
'a', 'A' <= ch <= 'z', 'Z'Print "YES" if it's alphabet otherwise "NO".Sample Input :
a
Sample Output
YES, I have written this Solution Code: #include <stdio.h>
int main()
{
char ch;
scanf("%c", &ch);
(ch>='a' && ch<='z') || (ch>='A' && ch<='Z')
? printf("YES")
: printf("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 N, find the sum of i*j for each pair (i, j) such that 1 <= i < j <= N.
Since the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of the input contains an integer N.
Constraints
2 <= N <= 200000Output a single integer, the answer to the above problem.Sample Input
4
Sample Output
35
Explanation:
1*2 + 1*3 + 1*4 + 2*3 + 2*4 + 3*4 = 2 + 3 + 4 + 6 + 8 + 12 = 35
Sample Input
87
Sample Output
7215142, I have written this Solution Code: M = 1000000007
n = int(input())
ans = 0;
for i in range(1,n):
result = (((n-i)*(i+1+n))/2)%M
ans = (ans + result*i)%M
print(int(ans)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the sum of i*j for each pair (i, j) such that 1 <= i < j <= N.
Since the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of the input contains an integer N.
Constraints
2 <= N <= 200000Output a single integer, the answer to the above problem.Sample Input
4
Sample Output
35
Explanation:
1*2 + 1*3 + 1*4 + 2*3 + 2*4 + 3*4 = 2 + 3 + 4 + 6 + 8 + 12 = 35
Sample Input
87
Sample Output
7215142, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
long n=Long.parseLong(bf.readLine());
long div=1000000007;
long totalSum=(n)*((n)+1)/2;
long sum=0;
for(long i=1;i<n;i++)
{
totalSum = totalSum - i;
sum = (sum + (totalSum*i))%div;
}
System.out.println(sum);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the sum of i*j for each pair (i, j) such that 1 <= i < j <= N.
Since the answer can be large, output it modulo 10<sup>9</sup>+7.The first and the only line of the input contains an integer N.
Constraints
2 <= N <= 200000Output a single integer, the answer to the above problem.Sample Input
4
Sample Output
35
Explanation:
1*2 + 1*3 + 1*4 + 2*3 + 2*4 + 3*4 = 2 + 3 + 4 + 6 + 8 + 12 = 35
Sample Input
87
Sample Output
7215142, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
int s = 0;
For(i, 1, n+1){
s += i;
}
s %= MOD;
int ans = 0;
For(i, 1, n+1){
s -= i;
ans += (i*s);
ans %= MOD;
}
if(ans < 0)
ans += 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: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., 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());
if(n==1){
System.out.println(2);
}else{
int after = afterPrime(n);
int before = beforePrime(n);
if(before>after){
System.out.println(n+after);
}
else{System.out.println(n-before);}
}
}
public static boolean isPrime(int n)
{
int count=0;
for(int i=2;i*i<n;i++)
{
if(n%i==0)
count++;
}
if(count==0)
return true;
else
return false;
}
public static int beforePrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n-1;
c++;
}
}
}
public static int afterPrime(int n)
{
int c=0;
while(true)
{
if(isPrime(n))
return c;
else
{
n=n+1;
c++;
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., I have written this Solution Code: from math import sqrt
def NearPrime(N):
if N >1:
for i in range(2,int(sqrt(N))+1):
if N%i ==0:
return False
break
else: return True
else: return False
N=int(input())
i =0
while NearPrime(N-i)==False and NearPrime(N+i)==False:
i+=1
if NearPrime(N-i) and NearPrime(N+i):print(N-i)
elif NearPrime(N-i):print(N-i)
elif NearPrime(N+i): print(N+i), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, find the closest prime number to N. If there are multiple print the smaller one.The input contains a single integer N.
Constraints:
1 <= N <= 1000000000Print the closest prime to N.Sample Input 1
12
Sample Output 1
11
Explanation: Closest prime to 12 is 11 and 13 smaller of which is 11.
Sample Input 2
17
Sample Output 2
17
Explanation: Closest prime to 17 is 17., 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>
/////////////
bool isPrime(int n){
if(n<=1)
return false;
for(int i=2;i*i<=n;++i)
if(n%i==0)
return false;
return true;
}
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n==1)
cout<<"2";
else{
int v1=n,v2=n;
while(isPrime(v1)==false)
--v1;
while(isPrime(v2)==false)
++v2;
if(v2-n==n-v1)
cout<<v1;
else{
if(v2-n<n-v1)
cout<<v2;
else
cout<<v1;
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N containing non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements.
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^5
<b>Sum of N over all testcases does not exceed 10^6</b>
For each testcase you need to print the updated array.Sample Input:
2
5
0 1 0 3 12
8
0 0 0 0 1 2 3 4
Sample Output:
1 3 12 0 0
1 2 3 4 0 0 0 0, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t;
t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int j=-1;
for(int i=0;i<n;i++){
if(a[i]==0 && j==-1){
j=i;
}
if(j!=-1 && a[i]!=0){
a[j]=a[i];
a[i]=0;
j++;
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N containing non-negative integers. You have to move all 0's to the end of array while maintaining the relative order of the non-zero elements.
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.The first line of input line contains T, denoting the number of testcases. Each test cases contains 2 lines. First-line contains N, size of array. Second-line contains elements of array separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^5
<b>Sum of N over all testcases does not exceed 10^6</b>
For each testcase you need to print the updated array.Sample Input:
2
5
0 1 0 3 12
8
0 0 0 0 1 2 3 4
Sample Output:
1 3 12 0 0
1 2 3 4 0 0 0 0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n;
int a[n];
int cnt=0;
for(int i=0;i<n;i++){
cin>>a[i];\
if(a[i]==0){cnt++;}
}
for(int i=0;i<n;i++){
if(a[i]!=0){
cout<<a[i]<<" ";
}
}
while(cnt--){
cout<<0<<" ";
}
cout<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: int ludo(int N){
return (N==1||N==6);
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: def ludo(N):
if N==1 or N==6:
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code:
int ludo(int N){
return (N==1||N==6);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: There is a rule in ludo that a token can only be unlocked when either a 1 or 6 shown in the die. Given the die number N, Your task is to check whether the token can be unlocked or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>ludo()</b> that takes integers N as argument.
Constraints:-
1 <= N <= 6Return 1 if the token can be unlocked else return 0.Sample Input:-
1
Sample Output:-
1
Sample Input:-
2
Sample Output:-
0, I have written this Solution Code: static int ludo(int N){
if(N==1 || N==6){return 1;}
return 0;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64];
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main (String[] args) throws IOException {
Reader sc = new Reader();
int arrSize = sc.nextInt();
long[] arr = new long[arrSize];
for(int i = 0; i < arrSize; i++)
{
arr[i] = sc.nextLong();
}
long[] prefix = new long[arrSize];
prefix[0] = arr[0];
for(int i = 1; i < arrSize; i++)
{
long val = 1000000007;
prefix[i - 1] %= val;
long prefixSum = prefix[i - 1] + arr[i];
prefixSum %= val;
prefix[i] = prefixSum;
}
long[] suffix = new long[arrSize];
suffix[arrSize - 1] = arr[arrSize - 1];
for(int i = arrSize - 2; i >= 0; i--)
{
long val = 1000000007;
suffix[i + 1] %= val;
long suffixSum = suffix[i + 1] + arr[i];
suffixSum %= val;
suffix[i] = suffixSum;
}
int query = sc.nextInt();
for(int x = 1; x <= query; x++)
{
int l = sc.nextInt();
int r = sc.nextInt();
long val = 1000000007;
long ans = 0;
ans += (l != 1 ? prefix[l-2] : 0);
ans %= val;
ans += (r != arrSize ? suffix[r] : 0);
ans %= val;
System.out.println(ans);
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: n = int(input())
arr = list(map(int ,input().rstrip().split(" ")))
temp = 0
modified = []
for i in range(n):
temp = temp + arr[i]
modified.append(temp)
q = int(input())
for i in range(q):
s = list(map(int ,input().rstrip().split(" ")))
l = s[0]
r = s[1]
sum = 0
sum = ((modified[l-1]-arr[l-1])+(modified[n-1]-modified[r-1]))%1000000007
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b>
You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.
Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4
5 3 3 1
2
2 3
4 4
Sample Output
6
11
Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(n+1);
vector<int> pre(n+1, 0);
int tot = 0;
For(i, 1, n+1){
cin>>a[i];
assert(a[i]>0LL && a[i]<=1000000000LL);
tot += a[i];
pre[i]=pre[i-1]+a[i];
}
int q; cin>>q;
while(q--){
int l, r; cin>>l>>r;
int s = tot - (pre[r]-pre[l-1]);
s %= MOD;
cout<<s<<"\n";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is palindrome or not.
A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter.
Constraints:-
1<=N<=1000
1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:-
5
1 2 3 2 1
Sample Output 1:-
Yes
Sample Input 2:-
3
1 2 2
Sample Output 2:-
No, I have written this Solution Code: n=int(input())
l=input().split()
l=[int(i) for i in l]
if l[::-1]==l:
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 linked list consisting of N nodes, your task is to check if the given list is palindrome or not.
A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task:
Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter.
Constraints:-
1<=N<=1000
1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:-
5
1 2 3 2 1
Sample Output 1:-
Yes
Sample Input 2:-
3
1 2 2
Sample Output 2:-
No, I have written this Solution Code: public static boolean IsPalindrome(Node head)
{
Node slow = head;
boolean ispalin = true;
Stack<Integer> stack = new Stack<Integer>();
while (slow != null) {
stack.push(slow.val);
slow = slow.next;
}
while (head != null) {
int i = stack.pop();
if (head.val == i) {
ispalin = true;
}
else {
ispalin = false;
break;
}
head = head.next;
}
return ispalin;
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While Solo was enjoying her daddy's party, her little sister Tono gave her the following problem to solve:
Given an array A of N integers, find the number of occurrences of the maximum integer in the array.
As Solo is small and enjoying the party, please help her solve this problem.The first line of the input contains an integer N, the size of the array A.
The next line contains N space separated integers, the elements of the array A.
Constraints
1 <= N <= 100
1 <= A[i] <= 100Output a single integer, the number of occurrences of the maximum integer in the array A.Sample Input
5
1 2 3 2 1
Sample Output
1
Explanation: The maximum integer is 3 and it occurs once in the array.
Sample Input
5
5 5 5 5 5
Sample Output
5, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int[] arr=new int[n];
String[] s=br.readLine().trim().split(" ");
for(int i=0;i<arr.length;i++)
arr[i]=Integer.parseInt(s[i]);
int max=Integer.MIN_VALUE,c=0;
for(int i=0;i<arr.length;i++){
if(max==arr[i])
c++;
if(max<arr[i]){
max=arr[i];
c=1;
}
}
System.out.println(c);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While Solo was enjoying her daddy's party, her little sister Tono gave her the following problem to solve:
Given an array A of N integers, find the number of occurrences of the maximum integer in the array.
As Solo is small and enjoying the party, please help her solve this problem.The first line of the input contains an integer N, the size of the array A.
The next line contains N space separated integers, the elements of the array A.
Constraints
1 <= N <= 100
1 <= A[i] <= 100Output a single integer, the number of occurrences of the maximum integer in the array A.Sample Input
5
1 2 3 2 1
Sample Output
1
Explanation: The maximum integer is 3 and it occurs once in the array.
Sample Input
5
5 5 5 5 5
Sample Output
5, I have written this Solution Code: n=int(input())
a=list(map(int,input().split()))
print(a.count(max(a))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: While Solo was enjoying her daddy's party, her little sister Tono gave her the following problem to solve:
Given an array A of N integers, find the number of occurrences of the maximum integer in the array.
As Solo is small and enjoying the party, please help her solve this problem.The first line of the input contains an integer N, the size of the array A.
The next line contains N space separated integers, the elements of the array A.
Constraints
1 <= N <= 100
1 <= A[i] <= 100Output a single integer, the number of occurrences of the maximum integer in the array A.Sample Input
5
1 2 3 2 1
Sample Output
1
Explanation: The maximum integer is 3 and it occurs once in the array.
Sample Input
5
5 5 5 5 5
Sample Output
5, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;
const int N = 2e5+5;
// it's swapnil07 ;)
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif
void solve(){
int n; cin>>n;
vector<int> a(101, 0);
For(i, 0, n){
int x; cin>>x;
a[x]++;
}
for(int i=100; i>=1; i--){
if(a[i]){
cout<<a[i];
return;
}
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: def OccurenceOfX(N,X):
cnt=0
for i in range(1, N+1):
if(X%i==0 and X/i<=N):
cnt=cnt+1
return cnt, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code:
int OccurenceOfX(int N,long X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
int main()
{
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given number N, Consider a table of N X N in which elements at the intersection of ith row and jth column are the product of i and j, i. e i x j.
Also given a positive integer X. Your task is to count the number of elements in the table that contain the integer X.<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>OccurenceOfX()</b> that takes the integer N and the integer X as parameter.
Constraints:-
1 <= N <= 10^5
1 <= X <= 10^9Return the count of X.Sample Input:-
5 5
Sample Output:-
2
Explanation:-
table :-
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Count of occurrence of X is :- 2
Sample Input:-
10 13
Sample Output:-
0, I have written this Solution Code: public static int OccurenceOfX(int N,int X){
int cnt=0,i;
for( i=1;i<=N;i++){
if(X%i==0 && X/i<=N){cnt++;}}
return cnt;
}
, 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 2 numbers a, b.
You can perform at most b steps
In one step :
1- increase a by 3
2- decrease a by 3
3- multiply a by 2
Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T.
For each test case:
Input two integers a and b.
0 < T <= 100
1 <= a <= 100000
1 <= b <= 9Print answer on a separate line for each test caseSample Input
2
5 1
30 2
Sample Output
4
11
For test 1:-
In 0 steps, 5 can be formed
In 1 steps 2, 8, 10 can be formed
For test 2:-
in 0 step :- 30
in 1 step- 27 33 60
in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120
total unique number = 11, I have written this Solution Code: import java.util.*;
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int a=sc.nextInt();
int b=sc.nextInt();
ArrayList<Integer> arr=new ArrayList();
arr.add(a);
for(int j=1;j<b+1;j++)
{ int decrease=0;
int increse=0;
int mul=0;
int len=arr.size();
for(int e=0;e<len;e++)
{
decrease=arr.get(e)-3;
if(!arr.contains(decrease))
{
arr.add(decrease);
}
increse=arr.get(e)+3;
if(!arr.contains(increse))
{
arr.add(increse);
}
mul=arr.get(e)*2;
if(!arr.contains(mul))
{
arr.add(mul);
}
}
}
System.out.println(arr.size());
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 2 numbers a, b.
You can perform at most b steps
In one step :
1- increase a by 3
2- decrease a by 3
3- multiply a by 2
Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T.
For each test case:
Input two integers a and b.
0 < T <= 100
1 <= a <= 100000
1 <= b <= 9Print answer on a separate line for each test caseSample Input
2
5 1
30 2
Sample Output
4
11
For test 1:-
In 0 steps, 5 can be formed
In 1 steps 2, 8, 10 can be formed
For test 2:-
in 0 step :- 30
in 1 step- 27 33 60
in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120
total unique number = 11, I have written this Solution Code: T = int(input())
for t in range(T):
n, k = map(int, input().strip().split())
s = set()
s.add(n)
l = list(s)
while(k):
for i in range(len(l)):
s.add(l[i]-3)
s.add(l[i]+3)
s.add(l[i]*2)
l = list(s)
k -= 1
print(len(s)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given 2 numbers a, b.
You can perform at most b steps
In one step :
1- increase a by 3
2- decrease a by 3
3- multiply a by 2
Find number of distinct numbers we can make after performing at most b operations on a.The first line contains the number of tests T.
For each test case:
Input two integers a and b.
0 < T <= 100
1 <= a <= 100000
1 <= b <= 9Print answer on a separate line for each test caseSample Input
2
5 1
30 2
Sample Output
4
11
For test 1:-
In 0 steps, 5 can be formed
In 1 steps 2, 8, 10 can be formed
For test 2:-
in 0 step :- 30
in 1 step- 27 33 60
in 2 step:- 24, 30, 54, 30, 36, 66, 57 63 120
total unique number = 11, 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
set<int> ss;
int yy;
void solve(int a,int x)
{
ss.insert(a);
if(yy<=x) return;
solve((a+3LL),x+1);
solve((a-3LL),x+1);
solve((a*2LL),x+1);
}
signed main()
{
int t;
cin>>t;
while(t>0)
{
t--;
int a,b;
cin>>a>>b;
ss.clear();
yy=b+1;
ss.insert(a);
solve(a,1);
cout<<ss.size()<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define N 1000
// Function to rotate the matrix 90 degree clockwise
void rotate90Clockwise(int a[][N],int n)
{
// Traverse each cycle
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
// Swap elements of each cycle
// in clockwise direction
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
}
// Function for print matrix
void printMatrix(int arr[][N],int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << arr[i][j] << " ";
cout << '\n';
}
}
// Driver code
int main()
{
int n;
cin>>n;
int arr[n][N];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}}
rotate90Clockwise(arr,n);
printMatrix(arr,n);
cout<<endl;
rotate90Clockwise(arr,n);
printMatrix(arr,n);
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[][] = new int[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]= sc.nextInt();
}
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
//rotating by 90 degree
for (int i = 0; i < n / 2; i++) {
for (int j = i; j < n - i - 1; j++) {
int temp = a[i][j];
a[i][j] = a[n - 1 - j][i];
a[n - 1 - j][i] = a[n - 1 - i][n - 1 - j];
a[n - 1 - i][n - 1 - j] = a[j][n - 1 - i];
a[j][n - 1 - i] = temp;
}
}
System.out.println();
for(int i =0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of N*N dimensions (Mat). Print the matrix rotated by 90 degrees and 180 degrees.The first line contains N.
N lines follow each containing N space-separated integers.
<b>Constraints</b>
2 <= N <= 100
1 <= Mat[i][j] <= 10000Output 2*N+1 lines.
First N lines should contain the Matrix rotated by 90 degrees.
Then print a blank line.
Then N lines should contain the Matrix rotated by 180 degrees.Sample Input 1:
2
3 4
7 6
Sample Output 1:
7 3
6 4
6 7
4 3
Sample Input 2:
2
1 2
3 4
Sample Output 2:
3 1
4 2
4 3
2 1, I have written this Solution Code: x=int(input())
l1=[]
for i in range(x):
a1=list(map(int,input().split()))
l1.append(a1)
for j in range(x):
for i in range(1,x+1):
print(l1[-i][j], end=" ")
print()
print()
for i in range(1,x+1):
for j in range(1,x+1):
print(l1[-i][-j], end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>nums</b> of N integers where each element is in between 1 to N. Your task is to print all the integers from 1 to N which are not present in the given array.First line contains n the length of input
Second line of input contains the array of integers in range from (1 to n)
<b> Constraints </b>
1 <= n <= 100000
1 <= arr[i] <= nPrint all the integers in range [1, n] that dose not appear in array.Sample Input :
5
1 2 3 4 4
Sample Output :
5
Sample Input:
7
4 1 3 2 5 5 4
Sample Output:
6 7
Explaination:
In the first test, only 5 is the integer from 1 to n, which is missing from the array.
In the second test, both 6 and 7 are missing., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
List<Integer> ans=missing(arr);
for(int i=0;i<ans.size();i++){
System.out.print(ans.get(i)+" ");
}
System.out.println();
}
static List<Integer> missing(int[] arr){
int i=0;
while (i< arr.length){
int correct=arr[i]-1;
if (arr[i]!=arr[correct]){
swap(arr,i,correct);
}else {
i++;
}
}
List<Integer> ans=new ArrayList<>();
for (int j = 0; j < arr.length; j++) {
if (arr[j] != j+1) {
ans.add(j + 1);
}
}
return ans;
}
static void swap(int[] arr,int first,int second){
int temp=arr[first];
arr[first]=arr[second];
arr[second]=temp;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>nums</b> of N integers where each element is in between 1 to N. Your task is to print all the integers from 1 to N which are not present in the given array.First line contains n the length of input
Second line of input contains the array of integers in range from (1 to n)
<b> Constraints </b>
1 <= n <= 100000
1 <= arr[i] <= nPrint all the integers in range [1, n] that dose not appear in array.Sample Input :
5
1 2 3 4 4
Sample Output :
5
Sample Input:
7
4 1 3 2 5 5 4
Sample Output:
6 7
Explaination:
In the first test, only 5 is the integer from 1 to n, which is missing from the array.
In the second test, both 6 and 7 are missing., I have written this Solution Code: /**
* Author : tourist1256
* Time : 2022-01-08 12:34:09
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<int> findDisappearedNumbers(vector<int>& nums) {
int i = 0, size = nums.size();
while (i < size) {
if (nums[i] != i + 1 && nums[nums[i] - 1] != nums[i])
swap(nums[i], nums[nums[i] - 1]);
else
i++;
}
vector<int> ans;
for (i = 0; i < size; i++)
if (nums[i] != i + 1) ans.push_back(i + 1);
return ans;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> x = findDisappearedNumbers(a);
for (auto& it : x) {
cout << it << " ";
}
cout << "\n";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void cal(int arr[], int n){
int countZ = 0;
for(int i = 0; i < n; i++) {
if(arr[i] == 0) {
countZ++;
}
}
for(int i = 1; i <= countZ; i++) {
System.out.print("0 ");
}
for(int i = 1; i <= n - countZ; i++) {
System.out.print("1 ");
}
}
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]);
}
cal(arr, n);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 1, I have written this Solution Code: n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
for i in l:
print(i, end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a binary array A[] of size N. The task is to arrange an array in increasing order.
(O(N) time complexity solution)Every test case contains two lines, first line contains an integer N (size of array) and second line contains space separated elements of array.
1 <= N <= 20
0 <= A[i] <= 1Print a single line containing space separated elements of sorted arrays.Input:
5
1 0 1 1 0
Output:
0 0 1 1 1, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
int a[2] = {0};
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
for(int i = 0; i <= 1; i++)
for(int j = 0; j < a[i]; j++)
cout << i << " ";
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |