Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: A tuple (R, G, B) is considered good if R*G+B <= N and R, G and B are all positive. Given N, find number of good tuples.Input contains a single integer N.
Constraints:
1 <= N <= 1000000Print number of good tuples.Sample Input
3
Sample Output
4
Explanation:
Following are the good tuples:
(1, 1, 1)
(1, 1, 2)
(1, 2, 1)
(2, 1, 1), I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;++i)
{
int j=i;
while(j<=n){
ans+=n-j;
j+=i;
}
}
cout<<ans;
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick wants to give Morty a chapo (a super awesome treat :P).
The only condition for Morty to get a chapo is that he should be able to reach Rick's place. Both Rick and Morty live on the number line at integer points A and B respectively. There are N types of moves M<sub>1</sub>, M<sub>2</sub>,. , M<sub>N</sub>. Morty can only take steps of size M<sub>i</sub> (1 <= i <= N) in either of the two directions on the number line (any number of times), while Rick prefers to stay at his place.
Please let Morty know if he can ever reach Rick's place and get a chapo.The first line of the input contains three integers N, A, and B denoting the total number of step sizes, the position of Rick, and the position of Morty.
The next line contains N integers M<sub>i</sub> denoting the various step sizes that Morty can take.
Constraints
1 <= N <= 200000
1 <= M<sub>i</sub> <= 10<sup>9</sup>
-10<sup>9</sup> <= A, B <= 10<sup>9</sup>Output <b>Yes</b> if Morty can reach Rick's place, else output <b>No</b>Sample Input
3 19 2
3 5 4
Sample Output
Yes
Explanation: Morty lives at position 2, while Rick lives at position 19. Morty can take the following path to reach Rick's place (there are several other ways as well):
Move M<sub>2</sub> = 5 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Sample Input 2
4 10 15
10 20 30 40
Sample Output 2
No, I have written this Solution Code: import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main implements Runnable {
private boolean console=false;
private long MOD = 1000_000_007L;
private int MAX = 1000_001;
private void solve1(){
int n=in.ni();
long a=in.nl(),b=in.nl();
long g = 0;
for(int i=0;i<n;++i){
g = gcd(g,in.nl());
}
if( Math.abs(a-b)%g==0){
out.printLn("Yes");
}else{
out.printLn("No");
}
}
private void solve() {
int testCases = 1;
while (testCases-->0){
solve1();
}
}
private void add(TreeMap<Integer, Integer> map, int key){
map.put(key,map.getOrDefault(key,0)+1);
}
private void remove(TreeMap<Integer,Integer> map,int key){
if(!map.containsKey(key))
return;
map.put(key,map.getOrDefault(key,0)-1);
if(map.get(key)==0)
map.remove(key);
}
@Override
public void run() {
long time = System.currentTimeMillis();
try {
init();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
solve();
out.flush();
System.err.println(System.currentTimeMillis()-time);
System.exit(0);
}catch (Exception e){
e.printStackTrace(); System.exit(1);
}
}
private FastInput in;
private FastOutput out;
public static void main(String[] args) throws Exception {
new Main().run();
}
private void init() throws FileNotFoundException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
try {
if (!console && System.getProperty("user.name").equals("puneetkumar")) {
outputStream = new FileOutputStream("/Users/puneetkumar/output.txt");
inputStream = new FileInputStream("/Users/puneetkumar/input.txt");
}
} catch (Exception ignored) {
}
out = new FastOutput(outputStream);
in = new FastInput(inputStream);
}
private void maualAssert(int a,int b,int c){
if(a<b || a>c) throw new RuntimeException();
}
private void maualAssert(long a,long b,long c){
if(a<b || a>c) throw new RuntimeException();
}
private void sort(int[] arr) {
List<Integer> list = new ArrayList<>();
for (int object : arr) list.add(object);
Collections.sort(list);
for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
}
private void sort(long[] arr) {
List<Long> list = new ArrayList<>();
for (long object : arr) list.add(object);
Collections.sort(list);
for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
}
private long ModPow(long x, long y, long MOD) {
long res = 1L;
x = x % MOD;
while (y >= 1L) {
if ((y & 1L) > 0) res = (res * x) % MOD;
x = (x * x) % MOD;
y >>= 1L;
}
return res;
}
private int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
private long gcd(long a, long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
private int[] arrInt(int n){
int[] arr=new int[n];for(int i=0;i<n;++i)arr[i]=in.ni();
return arr;
}
private long[] arrLong(int n){
long[] arr=new long[n];for(int i=0;i<n;++i)arr[i]=in.nl();
return arr;
}
private int arrMax(int[] arr){
int ans = arr[0];
for(int i=1;i<arr.length;++i){
ans = max(ans,arr[i]);
}
return ans;
}
private long arrMax(long[] arr){
long ans = arr[0];
for(int i=1;i<arr.length;++i){
ans = max(ans,arr[i]);
}
return ans;
}
private int arrMin(int[] arr){
int ans = arr[0];
for(int i=1;i<arr.length;++i){
ans = max(ans,arr[i]);
}
return ans;
}
private long arrMin(long[] arr){
long ans = arr[0];
for(int i=1;i<arr.length;++i){
ans = max(ans,arr[i]);
}
return ans;
}
class FastInput { InputStream obj;
public FastInput(InputStream obj) {
this.obj = obj;
}
private byte inbuffer[] = new byte[1024];
private int lenbuffer = 0, ptrbuffer = 0;
private int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
try { lenbuffer = obj.read(inbuffer);
} catch (IOException e) { throw new InputMismatchException(); } }
if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }
String ns() { int b = skip();StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b)))
{ sb.appendCodePoint(b);b = readByte(); }return sb.toString();}
int ni() {
int num = 0, b;boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') { minus = true;b = readByte(); }
while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else {
return minus ? -num : num; }b = readByte(); }}
long nl() { long num = 0;int b;boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') { minus = true;b = readByte(); }
while (true) { if (b >= '0' && b <= '9') { num = num * 10L + (b - '0'); } else {
return minus ? -num : num; }b = readByte(); } }
private boolean isSpaceChar(int c) {
return (!(c >= 33 && c <= 126));
}
int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
float nf() {return Float.parseFloat(ns());}
double nd() {return Double.parseDouble(ns());}
char nc() {return (char) skip();}
}
class FastOutput{
private final PrintWriter writer;
public FastOutput(OutputStream outputStream) {
writer = new PrintWriter(outputStream);
}
public PrintWriter getWriter(){
return writer;
}
public void print(Object obj){
writer.print(obj);
}
public void printLn(){
writer.println();
}
public void printLn(Object obj){
writer.print(obj);
printLn();
}
public void printSp(Object obj){
writer.print(obj+" ");
}
public void printArr(int[] arr){
for(int i:arr)
printSp(i);
printLn();
}
public void printArr(long[] arr){
for(long i:arr)
printSp(i);
printLn();
}
public void flush(){
writer.flush();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Rick wants to give Morty a chapo (a super awesome treat :P).
The only condition for Morty to get a chapo is that he should be able to reach Rick's place. Both Rick and Morty live on the number line at integer points A and B respectively. There are N types of moves M<sub>1</sub>, M<sub>2</sub>,. , M<sub>N</sub>. Morty can only take steps of size M<sub>i</sub> (1 <= i <= N) in either of the two directions on the number line (any number of times), while Rick prefers to stay at his place.
Please let Morty know if he can ever reach Rick's place and get a chapo.The first line of the input contains three integers N, A, and B denoting the total number of step sizes, the position of Rick, and the position of Morty.
The next line contains N integers M<sub>i</sub> denoting the various step sizes that Morty can take.
Constraints
1 <= N <= 200000
1 <= M<sub>i</sub> <= 10<sup>9</sup>
-10<sup>9</sup> <= A, B <= 10<sup>9</sup>Output <b>Yes</b> if Morty can reach Rick's place, else output <b>No</b>Sample Input
3 19 2
3 5 4
Sample Output
Yes
Explanation: Morty lives at position 2, while Rick lives at position 19. Morty can take the following path to reach Rick's place (there are several other ways as well):
Move M<sub>2</sub> = 5 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Sample Input 2
4 10 15
10 20 30 40
Sample Output 2
No, I have written this Solution Code: def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a,b):
return (a / gcd(a,b))* b
n,x,y=map(int,input().split())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,len(a)):
ans=gcd(ans,a[i])
if abs(x-y)%ans==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: Rick wants to give Morty a chapo (a super awesome treat :P).
The only condition for Morty to get a chapo is that he should be able to reach Rick's place. Both Rick and Morty live on the number line at integer points A and B respectively. There are N types of moves M<sub>1</sub>, M<sub>2</sub>,. , M<sub>N</sub>. Morty can only take steps of size M<sub>i</sub> (1 <= i <= N) in either of the two directions on the number line (any number of times), while Rick prefers to stay at his place.
Please let Morty know if he can ever reach Rick's place and get a chapo.The first line of the input contains three integers N, A, and B denoting the total number of step sizes, the position of Rick, and the position of Morty.
The next line contains N integers M<sub>i</sub> denoting the various step sizes that Morty can take.
Constraints
1 <= N <= 200000
1 <= M<sub>i</sub> <= 10<sup>9</sup>
-10<sup>9</sup> <= A, B <= 10<sup>9</sup>Output <b>Yes</b> if Morty can reach Rick's place, else output <b>No</b>Sample Input
3 19 2
3 5 4
Sample Output
Yes
Explanation: Morty lives at position 2, while Rick lives at position 19. Morty can take the following path to reach Rick's place (there are several other ways as well):
Move M<sub>2</sub> = 5 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Move M<sub>1</sub> = 4 to the right.
Sample Input 2
4 10 15
10 20 30 40
Sample Output 2
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(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, a, b; cin>>n>>a>>b;
a = abs(a-b);
int gv = 0;
For(i, 0, n){
int m; cin>>m;
gv = __gcd(gv, m);
}
if(a%gv == 0){
cout<<"Yes";
}
else{
cout<<"No";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry wants to rescue Fleur's sister Gabrielle in the underwater task. For that he needs to get ahead of all the people in the two magical queues.
Our small Tono and Solo are busy casting spells alternatively to remove people from the two magical queues. But since they are highly competitive, both of them wish to be the last person to remove people from the queue.
We can consider the removal of people as game played between Tono and Solo with the following rules:
<li> The turn goes alternatively. Tono starts the game.
<li> In each turn, the player first chooses a queue, then removes 3*X people from the queue, and then adds X people to the other queue (X > 0).
<li> The player who is unable to make a move loses.
<li> Both the players play with the most optimal strategy.
Since this game can take a lot of time to complete, Harry can declare the last person to remove people from the queue directly. Can you please help Harry accomplish the task, and save Gabrielle by being on time?The first line of the input contains an integer T denoting the number of test cases.
The next T lines contains two integers L1 and L2, denoting the initial number of people standing in the two queues.
Constraints
1 <= T <= 100
1 <= L1, L2 <= 200000For each test case, output "Tono" (without quotes) if Tono wins the game, else output "Solo" (without quotes) in a new line.Sample Input
2
0 1
0 2
Sample Output
Solo
Solo
Explanation
For both test cases, since Tono cannot make any move in the first turn itself, she loses.
Sample Input
1
1 4
Sample Output
Tono
Explanation
Tono removes 3 people from second queue, and adds 1 in the first queue. The queues now have 2 and 1 people respectively. Since Solo cannot make a move now, she loses., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
void pre() throws Exception{}
void solve(int TC) throws Exception {
pn(win(ni(), ni())?"Tono":"Solo");
}
boolean win(int l1, int l2){
if(l1%2 == 0)return Math.abs(l1-l2) > 2;
else return Math.abs(l1-l2) > 1;
}
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
void exit(boolean b){if(!b)System.exit(0);}
static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
final long IINF = (long)1e17;
final int INF = (int)1e9+2;
DecimalFormat df = new DecimalFormat("0.00000000000000");
double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-9;
static boolean multipleTC = true, memory = true, fileIO = false;
FastReader in;PrintWriter out;
void run() throws Exception{
long ct = System.currentTimeMillis();
if (fileIO) {
in = new FastReader("");
out = new PrintWriter("");
} else {
in = new FastReader();
out = new PrintWriter(System.out);
}
int T = multipleTC? ni():1;
pre();
for (int t = 1; t <= T; t++) solve(t);
out.flush();
out.close();
System.err.println(System.currentTimeMillis() - ct);
}
public static void main(String[] args) throws Exception{
if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
else new Main().run();
}
int[][] make(int n, int e, int[] from, int[] to, boolean f){
int[][] g = new int[n][];int[]cnt = new int[n];
for(int i = 0; i< e; i++){
cnt[from[i]]++;
if(f)cnt[to[i]]++;
}
for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
for(int i = 0; i< e; i++){
g[from[i]][--cnt[from[i]]] = to[i];
if(f)g[to[i]][--cnt[to[i]]] = from[i];
}
return g;
}
int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
int[][][] g = new int[n][][];int[]cnt = new int[n];
for(int i = 0; i< e; i++){
cnt[from[i]]++;
if(f)cnt[to[i]]++;
}
for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
for(int i = 0; i< e; i++){
g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 1};
if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, -1};
}
return g;
}
int[][] make(int n, int[] par, boolean f){
int[][] g = new int[n][];
int[] cnt = new int[n];
for(int x:par)cnt[x]++;
if(f)for(int i = 1; i< n; i++)cnt[i]++;
for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
for(int i = 1; i< n-1; i++){
g[par[i]][--cnt[par[i]]] = i;
if(f)g[i][--cnt[i]] = par[i];
}
return g;
}
int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p(Object... o){for(Object oo:o)out.print(oo+" ");}
void pn(Object... o){
if(o.length == 0)out.println("");
for(int i = 0; i< o.length; i++){
out.print(o[i]);
out.print((i+1 == o.length?"\n":" "));
}
}
void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
String n()throws Exception{return in.next();}
String nln()throws Exception{return in.nextLine();}
int ni()throws Exception{return Integer.parseInt(in.next());}
long nl()throws Exception{return Long.parseLong(in.next());}
double nd()throws Exception{return Double.parseDouble(in.next());}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception{
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception{
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch (IOException e){
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception{
String str;
try{
str = br.readLine();
}catch (IOException e){
throw new Exception(e.toString());
}
return str;
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Harry wants to rescue Fleur's sister Gabrielle in the underwater task. For that he needs to get ahead of all the people in the two magical queues.
Our small Tono and Solo are busy casting spells alternatively to remove people from the two magical queues. But since they are highly competitive, both of them wish to be the last person to remove people from the queue.
We can consider the removal of people as game played between Tono and Solo with the following rules:
<li> The turn goes alternatively. Tono starts the game.
<li> In each turn, the player first chooses a queue, then removes 3*X people from the queue, and then adds X people to the other queue (X > 0).
<li> The player who is unable to make a move loses.
<li> Both the players play with the most optimal strategy.
Since this game can take a lot of time to complete, Harry can declare the last person to remove people from the queue directly. Can you please help Harry accomplish the task, and save Gabrielle by being on time?The first line of the input contains an integer T denoting the number of test cases.
The next T lines contains two integers L1 and L2, denoting the initial number of people standing in the two queues.
Constraints
1 <= T <= 100
1 <= L1, L2 <= 200000For each test case, output "Tono" (without quotes) if Tono wins the game, else output "Solo" (without quotes) in a new line.Sample Input
2
0 1
0 2
Sample Output
Solo
Solo
Explanation
For both test cases, since Tono cannot make any move in the first turn itself, she loses.
Sample Input
1
1 4
Sample Output
Tono
Explanation
Tono removes 3 people from second queue, and adds 1 in the first queue. The queues now have 2 and 1 people respectively. Since Solo cannot make a move now, she loses., 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 l1, l2; cin>>l1>>l2;
assert(l1<=200000 && l2<=200000);
if(abs(l1-l2)<2){
cout<<"Solo";
return;
}
else if(abs(l1-l2)>=3){
cout<<"Tono";
return;
}
if(l1%2){
cout<<"Tono";
}
else{
cout<<"Solo";
}
}
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 a string, the task is to remove duplicates from it. Expected time complexity O(n) where n is length of the input string and extra space O(1) under the assumption that there are total of 256 possible characters in a string.
Note: that original order of characters must be kept same.The first line of the input is the number of test cases T. And the first line of a test case contains a string.
Constraints:
1 <= T <= 15
1 <= |string|<= 15000Modified string without duplicates and the same order of characters.Input:
2
hello
helloworld
Output:
helo
helowrd, 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 test = Integer.parseInt(br.readLine());
while(test-->0)
{
String line=br.readLine();
char str[] = line.toCharArray();
int n = str.length;
System.out.println(duplicates(str, n));
}
}
static String duplicates(char str[], int n)
{
int index = 0;
for (int i = 0; i < n; i++)
{
int j;
for (j = 0; j < i; j++)
if (str[i] == str[j])
break;
if (j == i)
str[index++] = str[i];
}
return String.valueOf(Arrays.copyOf(str, index));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, the task is to remove duplicates from it. Expected time complexity O(n) where n is length of the input string and extra space O(1) under the assumption that there are total of 256 possible characters in a string.
Note: that original order of characters must be kept same.The first line of the input is the number of test cases T. And the first line of a test case contains a string.
Constraints:
1 <= T <= 15
1 <= |string|<= 15000Modified string without duplicates and the same order of characters.Input:
2
hello
helloworld
Output:
helo
helowrd, I have written this Solution Code: for _ in range(int(input())):
s=input()
a=[]
for i in s:
if (i not in a):
print(i,end="")
a.append(i)
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, the task is to remove duplicates from it. Expected time complexity O(n) where n is length of the input string and extra space O(1) under the assumption that there are total of 256 possible characters in a string.
Note: that original order of characters must be kept same.The first line of the input is the number of test cases T. And the first line of a test case contains a string.
Constraints:
1 <= T <= 15
1 <= |string|<= 15000Modified string without duplicates and the same order of characters.Input:
2
hello
helloworld
Output:
helo
helowrd, I have written this Solution Code: // C++ implementation of above approach
#include <bits/stdc++.h>
#include <string>
using namespace std;
// Function to remove duplicates
string removeDuplicatesFromString(string str)
{
// keeps track of visited characters
int counter = 0;
int i = 0;
int size = str.size();
// gets character value
int x;
// keeps track of length of resultant string
int length = 0;
int table[500];
memset(table,0,sizeof(table));
while (i < size) {
x = str[i]-'a'+97;
// check if Xth bit of counter is unset
if (table[x] == 0) {
str[length] = 'a' + x -97;
// mark current character as visited
table[x]++;
length++;
}
i++;
}
return str.substr(0, length);
}
// Driver code
int main()
{
int t;
cin>>t;
while(t>0)
{ t--;
string str;
cin>>str;
cout << removeDuplicatesFromString(str)<<"\n";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void compress(String str, int l){
for (int i = 0; i < l; i++) {
int count = 1;
while (i < l - 1 && str.charAt(i) == str.charAt(i + 1)) {
count++;
i++;
}
System.out.print(str.charAt(i));
System.out.print(count);
}
System.out.println();
}
public static void main (String[] args) throws IOException{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(rd.readLine());
while(test-->0){
String s = rd.readLine();
int len = s.length();
compress(s,len);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, I have written this Solution Code:
def compress(st):
n = len(st)
i = 0
while i < n:
count = 1
while (i < n-1 and st[i] == st[i + 1]):
count += 1
i += 1
i += 1
print(st[i-1] +str(count),end="")
t=int(input())
for i in range(t):
s=input()
compress(s)
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: We are given a string. Your task is to compress the consecutive letters of the string
For example, given string is "AAACCCBBD", thus here
A's occurrence 3 times
C's occurrence 3 times
B's occurrence 2 times
D's occurrence 1 time
So after compressing string becomes "A3C3B2D1".The first line of input contains an integer T denoting the number of test cases. Each test case will have a string provided in the new line.
Constraints:
1 <= T <= 10
1 <= sizeof(String) <= 10^6
All characters of String are upper case letters. (A-Z)
Sum of size of Strings over all testcases is <= 10^6For each testcase, in a new line, print the compressed string for each test case in a new line. Input:
2
AAACCCBBD
ABCD
Output:
A3C3B2D1
A1B1C1D1, I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
void solve(){
string s; cin >> s;
int c = 1;
char p = 0;
int n = s.length();
for(int i = 1; i < n; i++){
if(s[i] != s[i-1]){
cout << s[i-1] << c;
c = 1;
}
else
c++;
}
cout << s[n-1] << c << endl;
}
void testcases(){
int tt = 1;
cin >> tt;
while(tt--){
solve();
}
}
signed main() {
IOS;
clock_t start = clock();
testcases();
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
} , In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: n = 1000
arr = [True for i in range(n+1)]
i = 2
while i*i <= n:
if arr[i] == True:
for j in range(i*2, n+1, i):
arr[j] = False
i +=1
arr2 = [0] * (n+1)
for i in range(2,n+1):
if arr[i]:
arr2[i] = arr2[i-1] + 1
else:
arr2[i] = arr2[i-1]
x = int(input())
for i in range(x):
y = int(input())
print(arr2[y]), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a number n. Your task is to print the number of prime numbers before that number.The first line of the number of test cases T.
Next T lines contains the value of N.
<b>Constraints</b>
1 <= T <= 100
1 <= N <= 1000Print the number of primes numbers before that number.Sample Input 1:
3
10
19
4
Sample Output 1:
4
8
2, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 2351
#endif
vector<bool> sieve(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
return is_prime;
}
int main() {
vector<bool> prime = sieve(1e5 + 1);
vector<int> prefix(1e5 + 1, 0);
for (int i = 1; i <= 1e5; i++) {
if (prime[i]) {
prefix[i] = prefix[i - 1] + 1;
} else {
prefix[i] = prefix[i - 1];
}
}
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << prefix[n] << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int i=str.length()-1;
if(i==0){
int number=Integer.parseInt(str);
System.out.println(number);
}else{
while(str.charAt(i)=='0'){
i--;
}
for(int j=i;j>=0;j--){
System.out.print(str.charAt(j));
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: n=int(input())
def reverse(n):
return int(str(n)[::-1])
print(reverse(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.First line consists of a single integer denoting n.
Constraint:-
1<=size of n<=100Output is a single line containing reversed number n.Sample Input
123445
Sample Output
544321
Sample Input
16724368
Sample Output
86342761, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
reverse(s.begin(),s.end());
int I;
for( I=0;I<s.length();I++){
if(s[I]!='0'){break;}
}
if(I==s.length()){cout<<0;return 0;}
for(int j=I;j<s.length();j++){
cout<<s[j];}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args)throws IOException
{
StringBuilder out=new StringBuilder();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int test=Integer.parseInt(br.readLine());
while(test-->0)
{
int n=Integer.parseInt(br.readLine());
String s=br.readLine();
int c1=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='1') c1++;
}
if(c1%4==0) out.append("1\n");
else if(c1==s.length() && (c1/2)%2==0) out.append("1\n");
else
out.append("0\n");
}
System.out.print(out);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: T=int(input())
for i in range(T):
n=int(input())
a=input()
count_1=0
for i in a:
if i=='1':
count_1+=1
if count_1%2==0 and ((count_1)//2)%2==0:
print('1')
else:
print('0'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: This is a time of conflict in Westeros as Viserys Targaryen, the king of all seven kingdoms, rejected the hand of Lady Laena Velaryon. So, the Velaryon soldiers are not deemed trustworthy anymore. The Targaryen soldiers have to keep an eye on them.
You are given a sequential order of N soldiers standing in a line. The order is provided as a binary string, with 0 representing Velaryon soldiers, and 1 representing the Targaryen soldiers. Viserys wants each contiguous segment of N/2 soldiers to contain an even number of Targaryen soldiers.
Formally you are given a binary string of length N, where N is an even natural number. Each character of the string is either '0' or '1'. You want to rearrange the elements of the string in such a way that the final string contains an even number of 1s in each contiguous subsegment of length N/2.
Your task is to find out whether there exists a rearrangement of the soldiers that satisfies the above conditions.The first line contains an integer T, the number of test cases. Then, T test cases follow.
The first line of each test case contains an even positive integer N, the length of the line.
The second line of each test case contains a binary string of length N, representing the current arrangement of soldiers.
<b> Constraints: </b>
1 ≤ T ≤ 10
2 ≤ N ≤ 10<sup>4</sup>
N is evenPrint a single character in a new line for each test case. Print '1' (without quotes) if a required rearrangement exists, and '0' (without quotes) otherwise.Sample Input:
3
2
10
2
00
4
0011
Sample Output:
0
1
0
(In the last case, no matter how you rearrange the string, there will always be a single one in at least one subsegment of length 2 of the string), I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
signed main() {
int t;
cin >> t;
for(int i=0; i<t; i++) {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for(int j=0; j<n; j++) {
if(s[j] == '1') cnt++;
}
if(cnt % 4 == 0) cout << 1 << "\n";
else cout << 0 << "\n";
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void sieve(boolean prime[], int n) {
int i,j;
for(i = 0; i <= n; i++)
prime[i] = true;
for(i = 2; i*i <= n; i++)
if(prime[i])
for(j = i*i; j<=n; j+=i)
prime[j] = false;
}
public static void main (String[] args) throws IOException {
int num = 10000005;
boolean prime[] = new boolean[num+1];
sieve(prime, num);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T --> 0) {
int n = Integer.parseInt(br.readLine().trim());
int count = 0;
for(int i=(n/2)+1; i<=n; i++)
if(prime[i])
count++;
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara has developed a new algorithm to find sprime :
For an integer n , To find all the sprime between 1 and n , she will start from the end n , mark it as sprime, and then mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number less than the current sprime number , mark it as sprime, and mark all its factors (excluding itself) as not sprime. She will continue this process till all the numbers between 1 and n has been marked either sprime or not sprime .
Your task is to calculate the the number of sprimes that are also prime between 1 and n.The first line contains T the number of test cases.
Each of the next T lines contain an integer n.
Constraint:-
1 <= T <= 100
2 <= n <= 10000000Output T lines, one for each test case, containing the required answer.Sample Input :
3
2
4
7
Sample Output :
1
1
2
Explanation:-
For test 3:- 7 and 5 are the required primes
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define max1 10000001
bool a[max1];
long b[max1];
void pre(){
b[0]=0;b[1]=0;
for(int i=0;i<max1;i++){
a[i]=false;
}
long cnt=0;
for(int i=2;i<max1;i++){
if(a[i]==false){
cnt++;
for(int j=i+i;j<=max1;j=j+i){a[j]=true;}
}
b[i]=cnt;
}
}
int main(){
pre();
int t;
cin>>t;
while(t--){
long n;
cin>>n;
cout<<(b[n]-b[(n)/2])<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, 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());
String [] str=br.readLine().trim().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
int size=a[n-1]+1;
int c[]=new int[size];
for(int i=0;i<size;i++) c[i]=0;
for(int i=0;i<n;i++) c[a[i]]++;
int max=0,freq=c[1];
for(int i=2;i<size;i++){
if(freq<=c[i]){
freq=c[i];
max=i;
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: n = int(input())
a = [int(x) for x in input().split()]
freq = {}
for x in a:
if x not in freq:
freq[x] = 1
else:
freq[x] += 1
mx = max(freq.values())
rf = sorted(freq)
for i in range(len(rf) - 1, -1, -1):
if freq[rf[i]] == mx:
print(rf[i])
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
int mx = 0, id = -1;
for(int i = 1; i <= 100; i++){
if(a[i] >= mx)
mx = a[i], id = i;
}
cout << id;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function
<b>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function
<b>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: def Race(A,B,C):
if abs(C-A) ==abs(C-B):
return 'D'
if abs(C-A)>abs(C-B):
return 'S'
return 'N'
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function
<b>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code:
char Race(int A, int B, int C){
if(abs(C-A)==abs(C-B)){return 'D';}
if(abs(C-A)>abs(C-B)){return 'S';}
else{
return 'N';}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Naruto and Sasuke are on a S- Rank mission. Now They got bored and thought of competing in a race against each other in a horizontal plane. They decides a common spot C at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke as A and B recpectively.
you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function
<b>Race</b> that takes the integer A (initial position of Naruto) and B (initial position of Sasuke) and C (position of common spot) as parameter.
Constraints
1 <= A, B, C <= 100Return the character according to the given scenario.Sample Input
1 2 3
Sample Output
S
Sample Input
1 3 2
Sample Output
D, I have written this Solution Code: static char Race(int A,int B,int C){
if(Math.abs(C-A)==Math.abs(C-B)){return 'D';}
if(Math.abs(C-A)>Math.abs(C-B)){return 'S';}
else{
return 'N';}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[]=br.readLine().split(" ");
int m=Integer.parseInt(s[0]);
int n=Integer.parseInt(s[1]);
if(m%2==0 && n%2==0)
System.out.println("NO");
else
System.out.println("YES");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, I have written this Solution Code: m,n=map(int, input().split())
if(m%2 or n%2):
print("YES")
else:
print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sky (the blue ranger) wants to replace Jack (the red ranger) from his position. For this, he needs to conquer the entire Base.
The Base can be represented as an M*N grid, and Sky needs to conquer it cell by cell. Sky starts conquering the Base from the cell (1, 1). In each move, he conquers the cell, and moves to an adjacent non- conquered cell (he cannot move if there is no adjacent non- conquered cell). Now, there is a catch, the last cell he needs to conquer is (M, N) so as to complete the quest for the red ranger tag!
Please let us know if Sky can replace Jack by conquering all the cells in the Base.
Note: The diagonal cells are not considered as adjacent cells.The first and the only line of input contains two integers M and N.
Constraints
1 <= M, N <= 1000Output "YES" (without quotes) if Sky can conquer the entire Base to replace Jack, else output "NO" (without quotes).Sample Input
2 2
Sample Output
NO
Explanation
The possible journeys of Sky ending at (2, 2) can be:
(1, 1) - > (1, 2) - > (2, 2)
(1, 1) - > (2, 1) - > (2, 2)
Since, in each of the path that Sky takes, the total cells covered are not 4, hence Sky cannot conquer the entire base.
Sample Input
3 3
Sample Output
YES, 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, m; cin>>n>>m;
if(n%2 || m%2){
cout<<"YES";
}
else{
cout<<"NO";
}
}
signed main()
{
fast
#ifdef SWAPNIL07
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
// cin>>t;
while(t--){
solve();
cout<<"\n";
}
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Numbers are awesome, larger numbers are more awesome!
Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array.
The next line contains N (white-space separated) integers denoting the elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>4</sup>
-10<sup>7</sup> ≤ A[i] ≤10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1:
5
1 2 1 -1 1
output 1:
5
input 2:
5
0 0 -1 0 0
output 2:
0
<b>Explanation 1:</b>
In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-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 sum = 0;
for(int i = 1; i <= n; i++){
int p; cin >> p;
if(p > 0)
sum += p;
}
cout << sum;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Numbers are awesome, larger numbers are more awesome!
Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array.
The next line contains N (white-space separated) integers denoting the elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>4</sup>
-10<sup>7</sup> ≤ A[i] ≤10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1:
5
1 2 1 -1 1
output 1:
5
input 2:
5
0 0 -1 0 0
output 2:
0
<b>Explanation 1:</b>
In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: n=int(input())
li = list(map(int,input().strip().split()))
sum=0
for i in li:
if i>0:
sum+=i
print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Numbers are awesome, larger numbers are more awesome!
Given an array A of size N, you need to find the maximum sum that can be obtained from the elements of the array (the selected elements need not be contiguous). You may even decide to take no element to get a sum of 0.The first line of the input contains the size of the array.
The next line contains N (white-space separated) integers denoting the elements of the array.
<b>Constraints:</b>
1 ≤ N ≤ 10<sup>4</sup>
-10<sup>7</sup> ≤ A[i] ≤10<sup>7</sup>For each test case, output one integer representing the maximum value of the sum that can be obtained using the various elements of the array.Input 1:
5
1 2 1 -1 1
output 1:
5
input 2:
5
0 0 -1 0 0
output 2:
0
<b>Explanation 1:</b>
In order to maximize the sum among [ 1 2 1 -1 1], we need to only consider [ 1 2 1 1] and neglect the [-1]., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
int n = Integer.parseInt(br.readLine());
String str[] = br.readLine().split(" ");
long arr[] = new long[n];
long sum=0;
for(int i=0;i<n;i++){
arr[i] = Integer.parseInt(str[i]);
if(arr[i]>0){
sum+=arr[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 N, your task is to return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code: public static long SumOfDivisors(long N){
long sum=0;
long c=(long)Math.sqrt(N);
for(long i=1;i<=c;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){sum+=N/i;}
}
}
return sum;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
long long SumOfDivisors(long long N){
long long sum=0;
long sq=sqrt(N);
for(long i=1;i<=sq;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){
sum+=N/i;
}
}
}
return sum;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
long long SumOfDivisors(long long N){
long long sum=0;
long sq=sqrt(N);
for(long i=1;i<=sq;i++){
if(N%i==0){
sum+=i;
if(i*i!=N){
sum+=N/i;
}
}
}
return sum;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, your task is to return the sum of all of its divisors.<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>SumOfDivisors()</b> that takes the integer N as parameter.
Constraints:-
1<=N<=10^9Return the sum of all of the divisors.Sample Input:-
4
Sample Output:-
7
Sample Input:-
13
Sample Output:-
14, I have written this Solution Code:
def SumOfDivisors(num) :
# Final result of summation of divisors
result = 0
# find all divisors which divides 'num'
i = 1
while i<= (math.sqrt(num)) :
# if 'i' is divisor of 'num'
if (num % i == 0) :
# if both divisors are same then
# add it only once else add both
if (i == (num / i)) :
result = result + i;
else :
result = result + (i + num/i);
i = i + 1
# Add 1 to the result as 1 is also
# a divisor
return (result); , In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: public static void SuperPrimes(int n){
int x = n/2+1;
for(int i=x ; i<=n ; i++){
out.printf("%d ",i);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: For a given integer N, super primes are those integers from 1 to N whose multiples (other than themselves) do no exist in the range [1, N].
Your task is to generate all super primes <= N in sorted order.
</b>Note: Super primes are not related to primes in any way.</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>SuperPrime()</b> that takes the integer N as a parameter.
Constraints:-
2 < = N <= 1000Printing will be done by the driver code you just need to complete the generator function.Sample Input:-
5
Sample Output:-
3 4 5
Sample Input:-
4
Sample Output:-
3 4, I have written this Solution Code: def SuperPrimes(N):
for i in range (int(N/2)+1,N+1):
yield i
return
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){
int n;
cin>>n;
int a[n][n];
FOR(i,n){
FOR(j,n){
cin>>a[i][j];}}
int sum=0,sum1=0;;
FOR(i,n){
sum+=a[i][i];
sum1+=a[n-i-1][i];
}
out1(sum);out(sum1);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String args[])throws Exception {
InputStreamReader inr= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(inr);
String str=br.readLine();
int row = Integer.parseInt(str);
int col=row;
int [][] arr=new int [row][col];
for(int i=0;i<row;i++){
String line =br.readLine();
String[] elements = line.split(" ");
for(int j=0;j<col;j++){
arr[i][j]= Integer.parseInt(elements[j]);
}
}
int sumPrimary=0;
int sumSecondary=0;
for(int i=0;i<row;i++){
sumPrimary=sumPrimary + arr[i][i];
sumSecondary= sumSecondary + arr[i][row-1-i];
}
System.out.println(sumPrimary+ " " +sumSecondary);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: // mat is the matrix/ 2d array
// the dimensions of array are n * n
function diagonalSum(mat, n) {
// write code here
// console.log the answer as in example
let principal = 0, secondary = 0;
for (let i = 0; i < n; i++) {
principal += mat[i][i];
secondary += mat[i][n - i - 1];
}
console.log(`${principal} ${secondary}`);
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a matrix of size N*N, your task is to find the sum of the primary and secondary diagonal of the matrix.
For Matrix:-
M<sub>00</sub> M<sub>01</sub> M<sub>02</sub>
M<sub>10</sub> M<sub>11</sub> M<sub>12</sub>
M<sub>20</sub> M<sub>21</sub> M<sub>22</sub>
Primary diagonal:- M<sub>00</sub> M<sub>11</sub> M<sub>22</sub>
Secondary diagonal:- M<sub>02</sub> M<sub>11</sub> M<sub>20</sub>The first line of input contains a single integer N, The next N lines of input contains N space-separated integers depicting the values of the matrix.
Constraints:-
1 <= N <= 500
1 <= Matrix[][] <= 100000Print the sum of primary and secondary diagonal separated by a space.Sample Input:-
2
1 4
2 6
Sample Output:-
7 6
Sample Input:-
3
1 4 2
1 5 7
3 8 1
Sample Output:-
7 10, I have written this Solution Code: n = int(input())
sum1 = 0
sum2 = 0
for i in range(n):
a = [int(j) for j in input().split()]
sum1 = sum1+a[i]
sum2 = sum2+a[n-1-i]
print(sum1,sum2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: 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 N, the number of nodes in a Graph and bidirectional edges of the graph. The task is to do Breadth First Search of this Graph starting from node 0.
Note: Traverse the neighbouring nodes of each node in the order they appear in the input. Make adjacency list in the order the edges appear.The first line of input contains an integer N and next line contains N-1 pairs of numbers (pairs as X Y) are given in the next line which represents a bidirectional edge from X to Y.
Constraints:
1 <= N <= 1000
0 <= X, Y <= N-1Print the BFS of the Graph starting from 0.Example 1:
5
0 1
0 2
0 3
2 4
Output:
0 1 2 3 4
Example 2:
Input:
7
0 2
0 1
2 6
2 5
1 3
1 4
Output:
0 2 1 6 5 3 4
Explanation:
For Example 1, First line of each test case represent an integer N denoting number of nodes and edges and then in the next line N-1 pairs of values a and b are fed which denotes there is a bidirectional edge from a to b ., 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());
ArrayList<Integer> a[]=new ArrayList[n];
for (int i = 0; i < n; i++) {
a[i] = new ArrayList<Integer>();
}
for(int i=0;i<n-1;i++){
StringTokenizer st2=new StringTokenizer(br.readLine());
int a1=Integer.parseInt(st2.nextToken());
int a2=Integer.parseInt(st2.nextToken());
a[a1].add(a2);
a[a2].add(a1);
}
int x=0;
doBfsList(a,x);
}
public static void doBfsList(ArrayList<Integer> a[],int x){
Set<Integer> visited=new HashSet<>();
Queue<Integer> qu=new LinkedList<>();
qu.add(0);
while(!qu.isEmpty()){
int el=qu.poll();
System.out.print(el+" ");
if(!visited.contains(el)){
visited.add(el);
for(int i=0;i<a[el].size();i++){
if(!visited.contains(a[el].get(i))){
qu.add(a[el].get(i));
}
}
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N, the number of nodes in a Graph and bidirectional edges of the graph. The task is to do Breadth First Search of this Graph starting from node 0.
Note: Traverse the neighbouring nodes of each node in the order they appear in the input. Make adjacency list in the order the edges appear.The first line of input contains an integer N and next line contains N-1 pairs of numbers (pairs as X Y) are given in the next line which represents a bidirectional edge from X to Y.
Constraints:
1 <= N <= 1000
0 <= X, Y <= N-1Print the BFS of the Graph starting from 0.Example 1:
5
0 1
0 2
0 3
2 4
Output:
0 1 2 3 4
Example 2:
Input:
7
0 2
0 1
2 6
2 5
1 3
1 4
Output:
0 2 1 6 5 3 4
Explanation:
For Example 1, First line of each test case represent an integer N denoting number of nodes and edges and then in the next line N-1 pairs of values a and b are fed which denotes there is a bidirectional edge from a to b ., I have written this Solution Code: class Graph:
def __init__(self):
self.graph_dict = {}
def add_vertex(self,vertex):
if vertex not in self.graph_dict.keys():
self.graph_dict[vertex] = []
def add_edge(self,vertex1,vertex2):
if vertex1 in self.graph_dict.keys() and vertex2 in self.graph_dict.keys():
self.graph_dict[vertex1].append(vertex2)
self.graph_dict[vertex2].append(vertex1)
def bfs(self,vertex):
visited = [vertex]
array = [vertex]
while array:
lst = array.pop(0)
print(lst,end=" ")
for i in self.graph_dict[lst]:
if i not in visited:
visited.append(i)
array.append(i)
graph = Graph()
n = int(input())#n = number of integer
for i in range(0,n):
graph.add_vertex(i)# add_vertex 0,1,2,3,4,5,6 etc up to n
for i in range(0,n-1):
u,v = map(int, input().split())#u and v 0 2,0 1,2 6,2 5 etc up to n-1
graph.add_edge(u,v)
graph.bfs(0), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given N, the number of nodes in a Graph and bidirectional edges of the graph. The task is to do Breadth First Search of this Graph starting from node 0.
Note: Traverse the neighbouring nodes of each node in the order they appear in the input. Make adjacency list in the order the edges appear.The first line of input contains an integer N and next line contains N-1 pairs of numbers (pairs as X Y) are given in the next line which represents a bidirectional edge from X to Y.
Constraints:
1 <= N <= 1000
0 <= X, Y <= N-1Print the BFS of the Graph starting from 0.Example 1:
5
0 1
0 2
0 3
2 4
Output:
0 1 2 3 4
Example 2:
Input:
7
0 2
0 1
2 6
2 5
1 3
1 4
Output:
0 2 1 6 5 3 4
Explanation:
For Example 1, First line of each test case represent an integer N denoting number of nodes and edges and then in the next line N-1 pairs of values a and b are fed which denotes there is a bidirectional edge from a to b ., I have written this Solution Code: #include<bits/stdc++.h>
#define pu push_back
using namespace std;
#define sz 1000000
int vis[sz];
vector<int> NEB[sz];
int L[sz];
int val[sz];
signed main()
{
int n;
cin>>n;
for(int i=0;i<n-1;i++)
{
int a,b;
cin>>a>>b;
NEB[a].pu(b);
NEB[b].pu(a);
}
deque<int> ss;
ss.pu(0);
while(!ss.empty())
{
int yy=ss.front();
ss.pop_front();
//cout<<yy<<endl;
if(vis[yy]==1) continue;
vis[yy]=1;
cout<<yy<<" ";
L[val[yy]]++;
for(int i=0;i<NEB[yy].size();i++)
{
int l=NEB[yy][i];
// cout<<l<<endl;
if(vis[l]==0)
{//cout<<"hh";
ss.pu(l);
val[l]=val[yy]+1;
}
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a circular linked list consisting of N nodes and an integer K, your task is to add the integer K at the end of the list.
<b>Note:
Sample Input and Output just show how a linked list will look depending on the questions. Do not copy-paste as it is in custom input</b><b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Insertion()</b> that takes head node of circular linked list and the integer K as parameter.
Constraints:
1 <=N <= 1000
1 <= Node.data, K<= 1000Return the head node of the modified circular linked list.Sample Input 1:-
3
1- >2- >3
4
Sample Output 1:-
1- >2- >3- >4
Sample Input 2:-
3
1- >3- >2
1
Sample Output 2:-
1- >3- >2- >1, I have written this Solution Code: public static Node Insertion(Node head, int K){
Node node=head;
while ( node.next != head)
{node = node.next; }
Node temp = new Node(K);
node.next=temp;
temp.next=head;
return head;}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 1, I have written this Solution Code: n=int(input())
x=n/3
if n%3==2:
x+=1
print(int(x)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 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 ans = n/3;
if(n%3==2){ans++;}
System.out.print(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order, white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".
You need to find the number of yellow roses that you will buy?The only line of input contains a single integer, N, the number of roses that you will buy.
Constraints
1 <= N <= 1000Output a single integer, the number of yellow roses.Sample Input 1
2
Sample Output 1
1
Sample Input 2
8
Sample Ouput 2
3
Explanation;-
testcase1;- 2 flower will be white,yellow
so number of yellow flower is 1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x=n/3;
if(n%3==2){
x++;}
cout<<x;}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have a house, which you model as an axis-aligned rectangle with corners at (x1, y1) and (x2, y2).
You also have a goat, which you want to tie to a fence post located at (x, y), with a rope of length
l. The goat can reach anywhere within a distance l from the fence post.
Find the largest value of l so that the goat cannot reach your house.Input consists of a single line with six space-separated integers x, y, x1, y1, x2, and y2. All the
values are guaranteed to be between −1000 and 1000 (inclusive).
It is guaranteed that x1 < x2 and y1 < y2, and that (x, y) lies strictly outside the axis-aligned
rectangle with corners at (x1, y1) and (x2, y2).Print, on one line, the maximum value of l, rounded and displayed to exactly three decimal placessample input
7 4 0 0 5 4
sample output
2.000
sample input
6 0 0 2 7 6
sample output
2.000
sample input
4 8 7 8 9 9
sample output
3.000, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static double distance(int x,int y,int x1,int y1)
{
return Math.sqrt(((x-x1)*(x-x1))+((y-y1)*(y-y1)));
}
public static void main (String[] args) throws IOException{
BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
String s[]=scan.readLine().split(" ");
int x=Integer.parseInt(s[0]);
int y=Integer.parseInt(s[1]);
int x1=Integer.parseInt(s[2]);
int y1=Integer.parseInt(s[3]);
int x2=Integer.parseInt(s[4]);
int y2=Integer.parseInt(s[5]);
double ans=0.0;
if(x>=x1&&x<=x2)
{
ans=Math.min(Math.abs(y-y1),Math.abs(y-y2));
}
else if(y>=y1&&y<=y2)
{
ans=Math.min(Math.abs(x-x1),Math.abs(x-x2));
}
else
{
ans=distance(x,y,x1,y1);
ans=Math.min(ans,distance(x,y,x2,y2));
ans=Math.min(ans,distance(x,y,x1,y2));
ans=Math.min(ans,distance(x,y,x2,y1));
}
System.out.printf("%.3f",ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have a house, which you model as an axis-aligned rectangle with corners at (x1, y1) and (x2, y2).
You also have a goat, which you want to tie to a fence post located at (x, y), with a rope of length
l. The goat can reach anywhere within a distance l from the fence post.
Find the largest value of l so that the goat cannot reach your house.Input consists of a single line with six space-separated integers x, y, x1, y1, x2, and y2. All the
values are guaranteed to be between −1000 and 1000 (inclusive).
It is guaranteed that x1 < x2 and y1 < y2, and that (x, y) lies strictly outside the axis-aligned
rectangle with corners at (x1, y1) and (x2, y2).Print, on one line, the maximum value of l, rounded and displayed to exactly three decimal placessample input
7 4 0 0 5 4
sample output
2.000
sample input
6 0 0 2 7 6
sample output
2.000
sample input
4 8 7 8 9 9
sample output
3.000, I have written this Solution Code: import math
x,y,x1,y1,x2,y2=map(int,input().split())
ans=0
coord=[]
if(x>=x1 and x<=x2):
ans=min(abs(y-y1),abs(y-y2))
elif (y>=y1 and y<=y2):
ans=min(abs(x-x1),abs(x-x2))
else:
ans=min( math.sqrt(abs(x-x1)**2 + abs(y-y1)**2), math.sqrt(abs(x-x2)**2 +abs(y-y2)**2), math.sqrt(abs(x-x1)**2 +abs(y-y2)**2), math.sqrt(abs(x-x2)**2+abs(y-y1)**2))
print("%.3f"%ans)
'''x,y,x1,y1,x2,y2=map(int,input().split())
ans=0
coord=[]
coord.append([x1,y1])
coord.append([x2,y2])
coord.append([x1,y1+y2])
coord.append([x1+x2,y1])
f=[]
f.append(math.sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y)))
f.append(math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y)))
f.append(math.sqrt((x1-x)*(x1-x) + (y1+y2-y)*(y1+y2-y)))
f.append(math.sqrt((x1+x2-x)*(x1+x2-x) + (y1-y)*(y1-y)))
needed=coord[f.index(min(f))]
possCoord=[[needed[0],y],[x,needed[1]]]
for i in possCoord:
if x1<=i[0] and i[0]<=x2 and y1<=i[1] and i[1]<=y2:
ans=round(math.sqrt((i[0]-x)*(i[0]-x) + (i[1]-y)*(i[1]-y)),3)
print("%.3f"%ans)''', In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You have a house, which you model as an axis-aligned rectangle with corners at (x1, y1) and (x2, y2).
You also have a goat, which you want to tie to a fence post located at (x, y), with a rope of length
l. The goat can reach anywhere within a distance l from the fence post.
Find the largest value of l so that the goat cannot reach your house.Input consists of a single line with six space-separated integers x, y, x1, y1, x2, and y2. All the
values are guaranteed to be between −1000 and 1000 (inclusive).
It is guaranteed that x1 < x2 and y1 < y2, and that (x, y) lies strictly outside the axis-aligned
rectangle with corners at (x1, y1) and (x2, y2).Print, on one line, the maximum value of l, rounded and displayed to exactly three decimal placessample input
7 4 0 0 5 4
sample output
2.000
sample input
6 0 0 2 7 6
sample output
2.000
sample input
4 8 7 8 9 9
sample output
3.000, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
float dist(int x1, int y1, int x2, int y2)
{
return sqrt(pow(x2-x1,2) + pow(y2-y1,2));
}
int main()
{
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
float d = dist(x,y,x1,y1);
d = min(d, dist(x,y,x1,y2));
d = min(d, dist(x,y,x2,y2));
d = min(d, dist(x,y,x2,y1));
if (x > x1 and x < x2)
{
d = min(d, dist(x,y,x,y1));
d = min(d, dist(x,y,x,y2));
}
if (y > y1 and y < y2)
{
d = min(d, dist(x,y,x1,y));
d = min(d, dist(x,y,x2,y));
}
printf("%.3f", d);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code:
#include <iostream>
using namespace std;
int Dishes(int N, int T){
return T-N;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
printf("%d",Dishes(n,k));
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T
Constraints:-
1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:-
3 6
Sample Output:-
3
Sample Input:-
2 4
Sample Output:-
2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, 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')break;
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 m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
arr[i][j] = sc.nextInt();
}
}
int max_row_index = 0;
int j = n - 1;
for (int i = 0; i < m; i++) {
while (j >= 0 && arr[i][j] == 1) {
j = j - 1;
max_row_index = i;
}
}
System.out.println(max_row_index);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: r, c = list(map(int, input().split()))
max_count = 0
max_r = 0
for i in range(r):
count = input().count("1")
if count > max_count:
max_count = count
max_r = i
print(max_r), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code:
#include <bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,j,a) for(int i=j;i<a;i++)
#define EB emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define max1 1001
#define MOD 1000000007
#define read(type) readInt<type>()
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int a[max1][max1];
signed main()
{
int n,m;
cin>>n>>m;
FOR(i,n){
FOR(j,m){cin>>a[i][j];}}
int cnt=0;
int ans=0;
int res=0;
FOR(i,n){
cnt=0;
FOR(j,m){
if(a[i][j]==1){
cnt++;
}}
if(cnt>res){
res=cnt;
ans=i;
}
}
out(ans);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a boolean matrix of size N*M in which each row is sorted your task is to print the index of the row containing maximum 1's. If multiple answer exist print the smallest one.First line contains two space separated integers denoting values of N and M. Next N lines contains M space separated integers depicting the values of the matrix.
Constraints:-
1 < = M, N < = 1000
0 < = Matrix[][] < = 1Print the smallest index (0 indexing) of a row containing the maximum number of 1's.Sample Input:-
3 5
0 1 1 1 1
0 0 0 1 1
0 0 0 1 1
Sample Output:-
0
Sample Input:-
4 4
0 1 1 1
1 1 1 1
0 0 1 1
1 1 1 1
Sample Output:-
1, I have written this Solution Code: // mat is the matrix/ 2d array
// n,m are dimensions
function max1Row(mat, n, m) {
// write code here
// do not console.log
// return the answer as a number
let j, max_row_index = 0;
j = m - 1;
for (let i = 0; i < n; i++)
{
// Move left until a 0 is found
let flag = false;
// to check whether a row has more 1's than previous
while (j >= 0 && mat[i][j] == 1)
{
j = j - 1; // Update the index of leftmost 1
// seen so far
flag = true;//present row has more 1's than previous
}
// if the present row has more 1's than previous
if (flag)
{
max_row_index = i; // Update max_row_index
}
}
if (max_row_index == 0 && mat[0][m - 1] == 0)
return -1;
return max_row_index;
}
, In this Programming Language: JavaScript, 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: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
double arr[] = new double[N];
String str[] = br.readLine().trim().split(" ");
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
double resistance=0;
int equResistance=0;
for(int i=0;i<N;i++)
arr[i]=Integer.parseInt(str[i]);
for(int i=0;i<N;i++)
{
resistance=resistance+(1/arr[i]);
}
equResistance = (int)Math.floor((1/resistance));
System.out.println(equResistance);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("")
r = int(r)
n = input("").split()
resistance=0.0
for i in range(0,r):
resistor = float(n[i])
resistance = resistance + (1/resistor)
print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel.
If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3))
Since this number can also have a fraction part, you only have to print the floor of the result obtained.
For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors.
Next line contains N space separated integers containing the value of different resistors.
Constraints
1 ≤ N ≤ 10^5
1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input
2
10 30
Output
7
1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
signed main() {
IOS;
int n; cin >> n;
double s = 0;
for(int i = 1; i <= n; i++){
double p; cin >> p;
s = s + (1/p);
}
s = 1/s;
cout << floor(s);
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Write a function called lucky_sevens which takes an array of integers and returns true if any three consecutive elements sum to 7An array containing numbers.Print true if such triplet exists summing to 7 else print falseSample input:-
[2, 1, 5, 1, 0]
[1, 6]
Sample output:-
true
false
Explanation:-
1+5+1 = 7
no 3 consecutive numbers so false, I have written this Solution Code: function lucky_sevens(arr) {
// if less than 3 elements then this challenge is not possible
if (arr.length < 3) {
console.log(false)
return;
}
// because we know there are at least 3 elements we can
// start the loop at the 3rd element in the array (i=2)
// and check it along with the two previous elements (i-1) and (i-2)
for (let i = 2; i < arr.length; i++) {
if (arr[i] + arr[i-1] + arr[i-2] === 7) {
console.log(true)
return;
}
}
// if loop is finished and no elements summed to 7
console.log(false)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: function easySorting(arr)
{
for(let i = 1; i < 5; i++)
{
let str = arr[i];
let j = i-1;
while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 )
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = str;
}
return arr;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int> m;
string s;
for(int i=0;i<5;i++){
cin>>s;
m[s]++;
}
for(auto it=m.begin();it!=m.end();it++){
while(it->second>0){
cout<<it->first<<" ";
it->second--;}
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ")
print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces.
String contains only uppercase English letters.Print the sorted array.INPUT :
AS KF ER DD JK
OUTPUT :
AS DD ER JK KF, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static void printArray(String str[])
{
for (String string : str)
System.out.print(string + " ");
}
public static void main (String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int len = 5;
String[] str = new String[len];
str = br.readLine().split(" ");
Arrays.sort(str, String.CASE_INSENSITIVE_ORDER);
printArray(str);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, 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());
String [] str=br.readLine().trim().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=Integer.parseInt(str[i]);
}
Arrays.sort(a);
int size=a[n-1]+1;
int c[]=new int[size];
for(int i=0;i<size;i++) c[i]=0;
for(int i=0;i<n;i++) c[a[i]]++;
int max=0,freq=c[1];
for(int i=2;i<size;i++){
if(freq<=c[i]){
freq=c[i];
max=i;
}
}
System.out.println(max);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: n = int(input())
a = [int(x) for x in input().split()]
freq = {}
for x in a:
if x not in freq:
freq[x] = 1
else:
freq[x] += 1
mx = max(freq.values())
rf = sorted(freq)
for i in range(len(rf) - 1, -1, -1):
if freq[rf[i]] == mx:
print(rf[i])
break, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array of N integers, give the number with maximum frequency. If multiple numbers have maximum frequency print the maximum number among them.The first line of the input contains an integer N, and the Second line contains N space-separated integers of the array.
<b>Constraints:</b>
3 <= N <= 1000
1 <= Arr[i] <= 100The output should contain single integer, the number with maximum frequency.If multiple numbers have maximum frequency print the maximum number among them.Sample Input
5
1 4 2 4 5
Sample Output
4
<b>Explanation:-</b>
4 has max frequency=2, I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int n; cin >> n;
for(int i = 1; i <= n; i++){
int p; cin >> p;
a[p]++;
}
int mx = 0, id = -1;
for(int i = 1; i <= 100; i++){
if(a[i] >= mx)
mx = a[i], id = i;
}
cout << id;
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: A conveyor belt has parcels that must be shipped from one point to another within D days.
The i-th parcel on the conveyor belt has a weight of weights[i]. Each day, we load the ship with parcels on the conveyor belt (in the order given). We may not load more weight than the maximum weight capacity of the ship.
Return the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.
Note:- the cargo must be shipped in the order givenThe input line contains T, denoting the number of testcases. Each testcase contains two lines. First line N ,contains size of the conveyor belt and D days separated by space. Second line contains weights of parcels.
Constraints:
1 <= T <= 100
1 <= D <= N <= 5*10^4
1 <= weights[i] <= 500
Sum if N over all test cases is <= 1000000For each testcase you need to print the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.Sample Input:
2
10 5
1 2 3 4 5 6 7 8 9 10
6 3
3 2 2 4 1 4
Sample Output:
15
6
Explanation:
Testcase 1:
A ship capacity of 15 is the minimum to ship all the parcels in 5 days like this:
1st day: 1, 2, 3, 4, 5
2nd day: 6, 7
3rd day: 8
4th day: 9
5th day: 10
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the parcels into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed., I have written this Solution Code: def isValid(weight, n, D, mx):
st = 1
sum = 0
for i in range(n):
sum += weight[i]
if (sum > mx):
st += 1
sum = weight[i]
if (st > D):
return False
return True
def shipWithinDays(weight, D, n):
sum = 0
for i in range(n):
sum += weight[i]
s = weight[0]
for i in range(1, n):
s = max(s, weight[i])
e = sum
res = -1
while (s <= e):
mid = s + (e - s) // 2
if (isValid(weight, n, D, mid)):
res = mid
e = mid - 1
else:
s = mid + 1
print(res)
if __name__ == '__main__':
n=int(input())
l=[]
for r in range(n):
leng,D=input().split()
D=int(D)
weight=input().split()
weight = [ int(i) for i in weight ]
N = len(weight)
l.append(shipWithinDays(weight, D, N))
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A conveyor belt has parcels that must be shipped from one point to another within D days.
The i-th parcel on the conveyor belt has a weight of weights[i]. Each day, we load the ship with parcels on the conveyor belt (in the order given). We may not load more weight than the maximum weight capacity of the ship.
Return the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.
Note:- the cargo must be shipped in the order givenThe input line contains T, denoting the number of testcases. Each testcase contains two lines. First line N ,contains size of the conveyor belt and D days separated by space. Second line contains weights of parcels.
Constraints:
1 <= T <= 100
1 <= D <= N <= 5*10^4
1 <= weights[i] <= 500
Sum if N over all test cases is <= 1000000For each testcase you need to print the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.Sample Input:
2
10 5
1 2 3 4 5 6 7 8 9 10
6 3
3 2 2 4 1 4
Sample Output:
15
6
Explanation:
Testcase 1:
A ship capacity of 15 is the minimum to ship all the parcels in 5 days like this:
1st day: 1, 2, 3, 4, 5
2nd day: 6, 7
3rd day: 8
4th day: 9
5th day: 10
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the parcels into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
String str[] = read.readLine().trim().split(" ");
int N = Integer.parseInt(str[0]);
int D = Integer.parseInt(str[1]);
int arr[] = new int[N];
str = read.readLine().trim().split(" ");
for(int i = 0; i < N; i++)
arr[i] = Integer.parseInt(str[i]);
int res = shipWithinDays(arr, D);
//print(res);
System.out.println(res);
}
}
static void print(int list[])
{
for(int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}
public static int shipWithinDays(int[] weights, int D) {
// set lower/upper bound for binary search
int low = 0, high = 0;
for(int weight: weights) {
low = Math.max(low, weight);
high += weight;
}
while(low < high) {
int mid = low + (high - low)/2;
if(calDays(mid, weights) > D) {
low = mid + 1;
} else {
high = mid;
}
}
return low;
}
public static int calDays(int w, int[] weights) {
int days = 0;
int accuSum = 0;
for(int i=0;i<weights.length;i++) {
if(accuSum + weights[i] <= w) {
accuSum += weights[i];
} else {
accuSum = weights[i];
days++;
}
}
if(accuSum>0) {
days++;
}
return days;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A conveyor belt has parcels that must be shipped from one point to another within D days.
The i-th parcel on the conveyor belt has a weight of weights[i]. Each day, we load the ship with parcels on the conveyor belt (in the order given). We may not load more weight than the maximum weight capacity of the ship.
Return the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.
Note:- the cargo must be shipped in the order givenThe input line contains T, denoting the number of testcases. Each testcase contains two lines. First line N ,contains size of the conveyor belt and D days separated by space. Second line contains weights of parcels.
Constraints:
1 <= T <= 100
1 <= D <= N <= 5*10^4
1 <= weights[i] <= 500
Sum if N over all test cases is <= 1000000For each testcase you need to print the least weight capacity of the ship that will result in all the parcels on the conveyor belt being shipped within D days.Sample Input:
2
10 5
1 2 3 4 5 6 7 8 9 10
6 3
3 2 2 4 1 4
Sample Output:
15
6
Explanation:
Testcase 1:
A ship capacity of 15 is the minimum to ship all the parcels in 5 days like this:
1st day: 1, 2, 3, 4, 5
2nd day: 6, 7
3rd day: 8
4th day: 9
5th day: 10
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the parcels into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,d;
cin>>n>>d;
long sum=0;
long ma=0;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
ma=max(ma,a[i]);
}
long low=ma;
long high=sum;
int mid;
while(low<high){
mid=low+(high-low)/2;
int ans=0;
int i=0;
int cnt=1;
while(i<n){
ans+=a[i];
if(ans>mid){
ans=a[i];
cnt++;
}
i++;
}
if(cnt<=d){high=mid;}
else
{
low=mid+1;
}
}
cout<<low<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
long n = Long.parseLong(rdr.readLine());
if(n==0 || n==1){
return ;
}
if(n==2){
System.out.println(21);
}
else{
StringBuilder str= new StringBuilder();
str.append("1");
for(long i=0;i<n-3;i++){
str.append("0");
}
if(n%6==0){
str.append("02");
System.out.println(str.toString());
}
else if(n%6==1){
str.append("20");
System.out.println(str.toString());
}
else if(n%6==2){
str.append("11");
System.out.println(str.toString());
}
else if(n%6==3){
str.append("05");
System.out.println(str.toString());
}
if(n%6==4){
str.append("08");
System.out.println(str.toString());
return;
}
else if(n%6==5){
str.append("17");
System.out.println(str.toString());
}
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: n = input()
n=int(n)
n1=10**(n-1)
n2=10**(n)
while(n1<n2):
if((n1%3==0) and (n1%7==0)):
print(n1)
break
n1 = n1+1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Solo likes to solve simple problems, but this time she is stuck with an easy problem she created herself. Since she cannot visit her friends currently (neither should you), can you code this problem for her? The problem is short and sweet.
Given an integer n, can you find the smallest n-digit number that is divisible by both 3 and 7? (Of course, the number cannot begin with a 0)The only line of input contains a single integer n, the number of digits in the required number.
Constraints
2 <= n <= 100000Output a single integer, the required n digit number. (The answer may not fit into 32 or 64 bit data types).Sample Input 1
2
Sample Output 1
21
Sample Input 2
4
Sample Output
1008
Explanation 1: 21 is the first 2 digit number divisible by both 3 and 7., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(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 int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL
const int N = 100005;
// 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
signed main()
{
fast
int n; cin>>n;
if(n==2){
cout<<"21";
return 0;
}
int mod=1;
for(int i=2; i<=n; i++){
mod = (mod*10)%7;
}
int av = 2;
mod = (mod+2)%7;
while(mod != 0){
av += 3;
mod = (mod+3)%7;
}
string sav = to_string(av);
if(sz(sav)==1){
sav.insert(sav.begin(), '0');
}
string ans = "1";
for(int i=0; i<n-3; i++){
ans += '0';
}
ans += sav;
cout<<ans;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
if(s==null){
System.exit(0);
}
StringTokenizer st = new StringTokenizer(s, " ");
int power = Integer.parseInt(st.nextToken());
int multiple = Integer.parseInt(st.nextToken());
int res = power;
for(int i = 1;i<=multiple;i++){
res = res*2;
}
System.out.println(res);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: #include <iostream>
using namespace std;
int main()
{
int x, n;
cin >> x >> n;
cout << x*(1 << n);
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80.
Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N.
<b>Constraints:</b>
1 ≤ X ≤ 1000
1 ≤ N ≤ 10Print a single integer – the power of Alice after N seconds.Sample Input 1:
5 2
Sample Output 1:
20
Sample Explanation 1:
Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20.
Sample Input 2:
4 3
Sample Output 2:
32, I have written this Solution Code: x,n = map(int,input().split())
print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args)throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0){
int n=Integer.parseInt(br.readLine());
System.out.println(n*(n+1)/2);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: for t in range(int(input())):
n = int(input())
print(n*(n+1)//2), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N. You need to print the sum of the first N natural numbers.The first line of input contains a single integer T, the next T lines contains a single integer N.
Constraints:
1 < = T < = 100
1 < = N < = 100Print the sum of first N natural numbers for each test case in a new line.Sample Input:
2
5
10
Sample Output:
15
55, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
cout<<(n*(n+1))/2<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The cost of stock on each day is given in an array A[] of size N. You can either buy or sell a stock on a particular day. You need to sell the previous stock before buying a new one. Find all the days on which you buy and sell the stock so that in between those days your profit is maximum.
There are no two days with same price of the stock.
See sample for a better explanation.First-line contains an integer value N denoting the number of days, followed by an array of stock prices of N days.
Constraints:
1 <= N <= 10^5
1 <= A[i] <= 10^6For each array of input, print an output with a pair of integers (a, b) where a represents day to buy stock and b represents day of selling stock. Output may contain of more than one pair, print them in all seperate line(assume 0 base indexing).
For no profit, print null.Input:
7
100 180 260 310 40 535 695
Output:
0 3
4 6
Input:
5
68 45 40 12 6
Output:
null
Explanations:-
Testcase1:- For range 0 to 3 the cost of stock is increasing so it is profitable to buy the stock at index 0 and sell it at index 3 same for range 4 to 6, 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));
int n=Integer.parseInt(br.readLine());
int arr[]=new int[n];
String str[]=br.readLine().split(" ");
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(str[i]);
}
int q=0;
for(int i=0;i<n-1;i++){
int p=i;
int j=i;
while(j<n-1 && arr[j]<arr[j+1]){
j++;
}
if(j!=i){
System.out.println(p+" "+j);
q++;
}
i=j;
}
if(q==0){
System.out.println("null");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: The cost of stock on each day is given in an array A[] of size N. You can either buy or sell a stock on a particular day. You need to sell the previous stock before buying a new one. Find all the days on which you buy and sell the stock so that in between those days your profit is maximum.
There are no two days with same price of the stock.
See sample for a better explanation.First-line contains an integer value N denoting the number of days, followed by an array of stock prices of N days.
Constraints:
1 <= N <= 10^5
1 <= A[i] <= 10^6For each array of input, print an output with a pair of integers (a, b) where a represents day to buy stock and b represents day of selling stock. Output may contain of more than one pair, print them in all seperate line(assume 0 base indexing).
For no profit, print null.Input:
7
100 180 260 310 40 535 695
Output:
0 3
4 6
Input:
5
68 45 40 12 6
Output:
null
Explanations:-
Testcase1:- For range 0 to 3 the cost of stock is increasing so it is profitable to buy the stock at index 0 and sell it at index 3 same for range 4 to 6, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int cnt=0;
vector<int> v;
for(int i=0;i<n-1;i++){
if(a[i+1]>a[i]){
if(cnt==0){v.push_back(i);}
cnt++;}
else{if(cnt!=0){
v.push_back(i);}cnt=0;}
}
if(a[n-1]>a[n-2]){v.push_back(n-1);}
if(v.size()==0){cout<<"null";return 0;}
for(int i=0;i<v.size();i+=2){
cout<<v[i]<<" ";
cout<<v[i+1]<<endl;
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N.
Constraints:
1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1
3
Sample Output 1
even
Explanation: Xor of 1, 2 and 3 is 0 which is even.
Sample Input 2
5
Sample Output 2
odd
Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input= Integer.parseInt(reader.readLine());
int result=1;
for(int i=2;i<=input;i++)
{
result = result^i;
}
if(result%2 == 0)
System.out.println("even");
else
System.out.println("odd");
}
catch(Exception e){
System.out.println("Something went wrong"+e);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N.
Constraints:
1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1
3
Sample Output 1
even
Explanation: Xor of 1, 2 and 3 is 0 which is even.
Sample Input 2
5
Sample Output 2
odd
Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., I have written this Solution Code: n=int(input())
odds = n//2 if n%2==0 else (n+1)//2
if(odds % 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: Andy loves Xor. Dwight gives Andy an integer N and asks him to tell whether XOR of all the integers from 1 to N is even or odd. As Andy is busy flirting with Erin, help him solve this problem.Input contains a single integer N.
Constraints:
1 <= N <= 10^9Print "even" if XOR of all the integers from 1 to N is even and if it is odd print "odd".Sample Input 1
3
Sample Output 1
even
Explanation: Xor of 1, 2 and 3 is 0 which is even.
Sample Input 2
5
Sample Output 2
odd
Explanation: Xor of 1, 2, 3, 4 and 5 is 1 which is odd., I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n;
cin>>n;
if(n%4==1||n%4==2)
cout<<"odd";
else
cout<<"even";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Bruce Banner is working on a code involving 3 numbers with their sum as a mystery number. Just then the emergency alarm is sounded and Bruce hulks his way out to save the city of New York yet again. The responsibility of cracking the code is then handed over to you since it is crucial to ensure Hulk’s safety. You find the mystery number as X. Now give Hulk a number of all the triplets and help Hulk as he fights the evil Chitauri.First line of input contains a single integer N (length of the array)
second line contain the array elements
third line contain a single integer K(sum)
Constraint:-
1<=N<=1000
1<=elements<=100000
1<=K<=100000Output a single line containing the number of required tripletsSample Input:
6
1 2 3 4 5 6
8
Sample Output:-
2
Explanation:-
(1,2,5) , (1,3,4) are the required triplets
, I have written this Solution Code: t=int(input())
m=list(map(int,input().rstrip().split()))
n=int(input())
count=0
for i in range(t-1):
s=dict()
for j in range(i+1,t):
x=n-(m[i]+m[j])
if x in s.keys():
count+=1
else:
s[m[j]]=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.