Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, β€œact” and β€œtac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≀ |s1|, |s2| ≀ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: // str1 and str2 are the two input strings function isAnagram(str1,str2){ // Get lengths of both strings let n1 = str1.length; let n2 = str2.length; // If length of both strings is not same, // then they cannot be anagram if (n1 != n2) return "NO"; str1 = str1.split('') str2 = str2.split('') // Sort both strings str1.sort(); str2.sort() // Compare sorted strings for (let i = 0; i < n1; i++) if (str1[i] != str2[i]) return "NO"; return "YES"; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given head which is a reference node to a singly- linked list. Complete the function delete_end which delete all nodes after M Nodes of a Linked List.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions delete_end that takes the head of the linked list as parameter. Constraints: The Linked List is not empty. Number of nodes(N) will not exceed 1000. 1 <= M <= NYou need not return anything. Just modify the original linked list.Sample Input 1:- 3 1 1 2 3 Sample Output 1:- 1 Explanation M = 1 So delete all nodes after 1st node. Sample Input 2:- 5 3 1 2 3 4 5 Sample Output 2:- 1 2 3 Explanation: Delete all nodes after 3rd node., I have written this Solution Code: static void delete_end(Node head,int m) { m--; while (m>0) { head = head.next; m--; } head.next=null; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: For an integer N, your task is to calculate sum of first N natural numbers.<b>User Task:</b> Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>sum()</b> which takes the integer N as a parameter. Constraints: 1 <= N < = 100000000Print the sum of first N natural numbers.Sample Input:- 5 Sample Output:- 15 Sample Input:- 3 Sample Output:- 6, I have written this Solution Code: static void sum(int N){ long x=N; x=x*(x+1); x=x/2; System.out.print(x); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sentence, your task is to print the sentence with its words present in a sorted manner. For eg:- The sentence:- "i am a rockstar developer" will be printed as "a am developer i rockstar"The Input contains only a sentence. Constraints:- Total characters present in the sentence will be less than equal to 1000 Note:- The sentence will contain only lowercase English letters.Print the given sentence with the words present in the sorted order.Sample Input:- i am a rockstar developer Sample Output:- a am developer i rockstar, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ string s; getline(cin,s); string p=""; map<string,int> m; //cout<<s<<endl; for(int i=0;i<s.length();i++){ if(s[i]!=' '){ p+=s[i];} else{ m[p]++; p=""; } } m[p]++; for(auto it=m.begin();it!=m.end();it++){ while(it->second--){ cout<<it->first<<" "; } } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The students of Newton School threw a grand party to celebrate their hard work and achievements. They danced and sang the night away, enjoying delicious food and creating memories that would last a lifetime. There are N guests in the party and N-1 relationships are given. The guests are numbered 1, 2, N. The i<sub>th</sub> relationship depicts that guest a<sub>i</sub> and guest b<sub>i</sub> are friends. Determine whether a guest exists or not who is a friend of all other guests. Here, we only consider direct friendship.Input is given from Standard Input in the following format: N a1 b1 a2 b2 a3 b3 . . an-1 bn-1 <b>Constraints</b> 3 &le; N &le; 10<sup>5</sup> 1 &le; ai, bi &le; N i&le;NIf a guest exists or who is a friend of all other guests, print "Yes" else print "No".<b>Sample Input 1</b> 5 1 4 2 4 3 4 4 5 <b>Sample Output 1</b> Yes <b>Sample Input 2</b> 4 2 4 1 4 2 3 <b>Sample Output 2</b> No <b>Sample Input 3</b> 10 3 10 4 10 9 10 1 10 7 10 5 10 2 10 8 10 6 10 <b>Sample Output 3</b> Yes <b>Explanation</b> In the first case,4 is a friend of everyone else's, while in the third case, 10 is a friend to all, while there is no such number in the second case., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { ll n; cin >> n; vector<ll> guests(n + 1, 0); // Counts the number of friends of each guest for (ll i = 1; i <= n - 1; i++) { ll a, b; cin >> a >> b; guests[a]++; guests[b]++; } for (ll i = 1; i <= n; i++) { if (guests[i] == n - 1) // If any guest is friend with all other guests than we have to return YES { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N light bulbs, however they are currently jumbled up in wires. When you start unravelling the bulbs, you observe that the situation can be described by a directed acyclic graph connecting the bulbs to each other. Formally, you are given a directed graph consisting of N nodes (numbered 1 to N) and M edges such that it contains no cycles. A sequence of vertices (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) is called a path if there exists an edge from v<sub>i</sub> to v<sub>i+1</sub> for every i such that 1 ≀ i ≀ k-1. A path (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) in the graph is called maximal, if for any vertex v, the sequence (v, v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) or (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>, v) do not represent paths in the graph. Find the number of maximal paths in the graph.The first line contains two integers N and M. The next M lines each contain two integers u and v – representing an edge from vertex u to vertex v. <b> Constraints: </b> 1 ≀ N ≀ 10<sup>5</sup> 0 ≀ M ≀ 2Γ—10<sup>5</sup> 1 ≀ u, v ≀ N The graph does not contain any self-loops or multiple edges.Print a single integer – the number of maximal paths.Sample Input 1: 3 1 1 2 Sample Output 1: 2 Sample Explanation 1: The two maximal paths are (1, 2) and (3). Sample Input 2: 3 3 1 2 2 3 1 3 Sample Output 2: 2 Sample Explanation 1: The two maximal paths are (1, 2, 3) and (1, 3). Sample Input 3: 3 2 1 3 3 2 Sample Output 3: 1 Sample Explanation 3: The only maximal path is (1, 3, 2)., I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void solve(FastIO io) { final int N = io.nextInt(); final int M = io.nextInt(); Node[] nodes = new Node[N + 1]; for (int i = 1; i <= N; ++i) { nodes[i] = new Node(i); } for (int i = 0; i < M; ++i) { final int U = io.nextInt(); final int V = io.nextInt(); nodes[U].next.add(nodes[V]); ++nodes[V].indegree; } long total = 0; long[] ans = new long[N + 1]; Arrays.fill(ans, -1); for (int i = 1; i <= N; ++i) { if (nodes[i].indegree == 0) { total += countMaximal(nodes[i], ans); } } io.println(total); } private static long countMaximal(Node u, long[] ans) { if (ans[u.id] < 0) { if (u.next.isEmpty()) { ans[u.id] = 1; } else { long got = 0; for (Node v : u.next) { got += countMaximal(v, ans); } ans[u.id] = got; } } return ans[u.id]; } private static class Node { public int id; public List<Node> next = new LinkedList<>(); public int indegree; public Node(int id) { this.id = id; } } public static class FastIO { private InputStream reader; private PrintWriter writer; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastIO(InputStream r, OutputStream w) { reader = r; writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w))); } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = reader.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printArray(long[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printlnArray(int[] arr) { printArray(arr); writer.println(); } public void printlnArray(long[] arr) { printArray(arr); writer.println(); } public void printf(String format, Object... args) { print(String.format(format, args)); } public void flush() { writer.flush(); } } private static class Solution implements Runnable { @Override public void run() { FastIO io = new FastIO(System.in, System.out); solve(io); io.flush(); } } public static void main(String[] args) throws InterruptedException { Thread t = new Thread(null, new Solution(), "Solution", 1 << 30); t.start(); t.join(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have N light bulbs, however they are currently jumbled up in wires. When you start unravelling the bulbs, you observe that the situation can be described by a directed acyclic graph connecting the bulbs to each other. Formally, you are given a directed graph consisting of N nodes (numbered 1 to N) and M edges such that it contains no cycles. A sequence of vertices (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) is called a path if there exists an edge from v<sub>i</sub> to v<sub>i+1</sub> for every i such that 1 ≀ i ≀ k-1. A path (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) in the graph is called maximal, if for any vertex v, the sequence (v, v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) or (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>, v) do not represent paths in the graph. Find the number of maximal paths in the graph.The first line contains two integers N and M. The next M lines each contain two integers u and v – representing an edge from vertex u to vertex v. <b> Constraints: </b> 1 ≀ N ≀ 10<sup>5</sup> 0 ≀ M ≀ 2Γ—10<sup>5</sup> 1 ≀ u, v ≀ N The graph does not contain any self-loops or multiple edges.Print a single integer – the number of maximal paths.Sample Input 1: 3 1 1 2 Sample Output 1: 2 Sample Explanation 1: The two maximal paths are (1, 2) and (3). Sample Input 2: 3 3 1 2 2 3 1 3 Sample Output 2: 2 Sample Explanation 1: The two maximal paths are (1, 2, 3) and (1, 3). Sample Input 3: 3 2 1 3 3 2 Sample Output 3: 1 Sample Explanation 3: The only maximal path is (1, 3, 2)., I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; //const ll mod = 998244353; vector<vector<int>> adj; int n, m; vector<int> visited, ans; void dfs(int v) { visited[v] = true; for (int u : adj[v]) { if (!visited[u]) dfs(u); } ans.push_back(v); } void topological_sort() { ans.clear(); for (int i = 1; i <= n; ++i) { if (!visited[i]) dfs(i); } reverse(ans.begin(), ans.end()); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; adj.resize(n + 1); visited.resize(n + 1); vi d(n + 1), f(n + 1); FOR (i, 1, m) { readb(u, v); adj[u].pb(v); d[v]++; } topological_sort(); int sum = 0; for (int i: ans) { if (!d[i]) f[i] = 1; for (int v: adj[i]) f[v] += f[i]; if (!sz(adj[i])) sum += f[i]; } cout << sum; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<b>User Task:</b> Complete the function <b>distributingMoney()</b> that takes the integers x, y, z, and K as parameters. <b>Constraints:- </b> 0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:- 1 2 3 3 Sample Output:- 1 Explanation:- initial :- 1 2 3 Final :- 3 3 3 Sample Input:- 1 2 3 4 Sample Output:- 0, I have written this Solution Code: import math def distributingMoney(x,y,z,k) : # Final result of summation of divisors result = x+y+z+k; if result%3!=0: return 0 result =result/3 if result<x or result<y or result<z: return 0 return 1; # Driver program to run the case x,y,z,k= map(int,input().split()); print (int(distributingMoney(x,y,z,k))) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<b>User Task:</b> Complete the function <b>distributingMoney()</b> that takes the integers x, y, z, and K as parameters. <b>Constraints:- </b> 0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:- 1 2 3 3 Sample Output:- 1 Explanation:- initial :- 1 2 3 Final :- 3 3 3 Sample Input:- 1 2 3 4 Sample Output:- 0, I have written this Solution Code: #include <stdio.h> #include <math.h> int distributingMoney(long x, long y, long z,long k){ long long sum=x+y+z+k; if(sum%3!=0){return 0;} sum=sum/3; if(x>sum || y>sum || z>sum){return 0;} return 1; } int main(){ long int x,y,z,k; scanf("%ld %ld %ld %ld",&x,&y,&z,&k); printf("%d",distributingMoney(x,y,z,k)); } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<b>User Task:</b> Complete the function <b>distributingMoney()</b> that takes the integers x, y, z, and K as parameters. <b>Constraints:- </b> 0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:- 1 2 3 3 Sample Output:- 1 Explanation:- initial :- 1 2 3 Final :- 3 3 3 Sample Input:- 1 2 3 4 Sample Output:- 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int distributingMoney(long x, long y, long z,long k){ long long sum=x+y+z+k; if(sum%3!=0){return 0;} sum=sum/3; if(x>sum || y>sum || z>sum){return 0;} return 1; } int main(){ long long x,y,z,k; cin>>x>>y>>z>>k; cout<<distributingMoney(x,y,z,k); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mahesh has won some money K from a lottery, he wants to distribute the money among his three sisters. His sisters already have some money with them. Let's say they have x, y, z amount of money. Now mahesh wants to distribute his money such that all the sisters have the same amount of total money left with them. Your task is to check if it is possible to distribute the money as Mahesh wants.<b>User Task:</b> Complete the function <b>distributingMoney()</b> that takes the integers x, y, z, and K as parameters. <b>Constraints:- </b> 0 <= x, y, z, K <= 10^7Return 1 if possible else return 0.Sample Input:- 1 2 3 3 Sample Output:- 1 Explanation:- initial :- 1 2 3 Final :- 3 3 3 Sample Input:- 1 2 3 4 Sample Output:- 0, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); long x = sc.nextInt(); long y = sc.nextInt(); long z = sc.nextInt(); long K = sc.nextInt(); System.out.println(distributingMoney(x,y,z,K)); } public static int distributingMoney(long x, long y, long z, long K){ long sum=0; sum+=x+y+z+K; if(sum%3!=0){return 0;} sum=sum/3; if(x>sum || y>sum || z>sum){return 0;} return 1; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: def Marks(P,Q,R): return 4*P-2*Q-R , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an exam of JEE one aspirant got P correct answers, Q wrong answer, and R unattempted question. If the mark for the correct answer is 4, for the wrong answer is -2, and for the unattempted questions is -1. Find the final marks the aspirant got.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Marks()</b> that takes integer P, Q, and R as arguments. Constraints:- 0 <= P, Q, R <= 1000Return the final marks of each student.Sample Input:- 4 2 0 Sample Output:- 12 Sample Input:- 1 1 1 Sample Output:- 1, I have written this Solution Code: static int Marks(int P, int Q, int R){ return 4*P - 2*Q - R; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: The college mess offers circular and square parathas at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular paratha. The number of parathas in the mess is equal to the number of students. The sandwiches are placed in a stack. At each step: If the student at the front of the queue prefers the parathas on the top of the stack, they will take it and leave the queue. Otherwise, they will leave it and go to the queue's end. This continues until none of the queue students want to take the top parathas and are thus unable to eat. You are given two integer arrays students and parathas where parathas[i] is the type of i​​​​​​th paratha in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j​​​​​​th student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.There is an integer n(number of students) given as input in the first line. In the Second line, n space- separated integers(Choice of students) are given as input. In the Third line, n space- separated integers(type of parathas) are given as input. <b>Constraints</b> 1 &le; n &le; 10<sup>3</sup> 0 &le; paraths[i], students[i] &le; 1 0 &le; i &le; n-1Return the count of students who left hungry.Sample Input: 4 1 1 0 0 0 1 0 1 Sample Output: 0 Explanation: - Front student leaves the top paratha and returns to the end of the line making students = [1, 0, 0, 1]. - Front student leaves the top paratha and returns to the end of the line making students = [0, 0, 1, 1]. - Front student takes the top paratha and leaves the line making students = [0, 1, 1] and parathas = [1, 0, 1]. - Front student leaves the top paratha and returns to the end of the line making students = [1, 1, 0]. - Front student takes the top paratha and leaves the line making students = [1, 0] and parathas = [0, 1]. - Front student leaves the top paratha and returns to the end of the line making students = [0, 1]. - Front student takes the top paratha and leaves the line making students = [1] and parathas = [1]. - Front student takes the top paratha and leaves the line making students = [] and parathas = []. Hence all students are able to eat., I have written this Solution Code: import java.util.*; public class Main { public int fun(int[] students, int[] parathas) { int[] a = {0, 0}; for (int i=0;i<students.length;i++) a[students[i]]+=1; int k = 0; while (k < parathas.length){ if (a[parathas[k]] > 0) a[parathas[k]]-=1; else break; k+=1;} return parathas.length-k; } public static void main(String[] args) { Main obj=new Main(); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] students=new int[n]; int[] parathas=new int[n]; for(int i=0;i<n;i++){ students[i]=sc.nextInt(); } for(int i=0;i<n;i++){ parathas[i]=sc.nextInt(); } int ans=obj.fun(students, parathas); System.out.println(ans); return; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sequence of three integers, check if the product of all these numbers is divisible by 20.The first line contains 3 space- separated integers a, b, and c. <b>Constraints</b> 1 &le; a, b, c &le; 100Print true, if the product is divisible by 20, otherwise, print false.Sample Input 1 : 8 1 3 Sample Output 1 : false Explanation 1: product = 8*1*3 = 24, which is not divisible by 20. Sample Input 2 : 5 2 2 Sample Output 2 : true Explanation 2 : product = 8*2*2 = 20, which is divisible by 20., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int pd=1; for(int i=0;i<3;i++){ int n=sc.nextInt(); pd*=n; } if(pd%20==0) System.out.println(true); else System.out.println(false); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { Reader sc=new Reader(); int n=sc.nextInt(); int b=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int j, max; long mul=1; Deque<Integer> dq= new LinkedList<Integer>(); for (int i = 0;i<b;i++) { while (!dq.isEmpty() && a[i] >=a[dq.peekLast()]) dq.removeLast(); dq.addLast(i); } mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007; for (int i=b; i < n;i++) { while ((!dq.isEmpty()) && dq.peek() <=i-b) dq.removeFirst(); while ((!dq.isEmpty()) && a[i]>=a[dq.peekLast()]) dq.removeLast(); dq.addLast(i); mul=((mul%1000000007)*(a[dq.peek()]%1000000007))%1000000007; } System.out.println(mul%1000000007); } 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(); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, I have written this Solution Code: from collections import deque deq=deque() n,k=list(map(int,input().split())) array=list(map(int,input().split())) for i in range(k): while(deq and array[deq[-1]]<=array[i]): deq.pop() deq.append(i) ans=1 for j in range(k,n): ans=ans*array[deq[0]] ans=(ans)%1000000007 while(deq and deq[0]<=j-k): deq.popleft() while(deq and array[deq[-1]]<=array[j]): deq.pop() deq.append(j) ans=ans*array[deq[0]] ans=(ans)%1000000007 print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, A of N integers. Find the product of maximum values for every subarray of size K. Print the answer modulo 10<sup>9</sup>+7. A subarray is any contiguous sequence of elements in an array.The first line contains two integers N and K, denoting the size of the array and the size of the subarray respectively. The next line contains N integers denoting the elements of the array. <b>Constarints</b> 1 <= K <= N <= 1000000 1 <= A[i] <= 1000000Print a single integer denoting the product of maximums for every subarray of size K modulo 1000000007Sample Input 1: 6 4 1 5 2 3 6 4 Sample Output 1: 180 <b>Explanation:</b> For subarray [1, 5, 2, 3], maximum = 5 For subarray [5, 2, 3, 6], maximum = 6 For subarray [2, 3, 6, 4], maximum = 6 Therefore, ans = 5*6*6 = 180, I have written this Solution Code: #include<bits/stdc++.h> #define int long long #define ll long long #define pb push_back #define endl '\n' #define pii pair<int,int> #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define sz(x) (int)x.size() #define hell 1000000007 #define rep(i,a,b) for(int i=a;i<b;i++) #define dep(i,a,b) for(int i=a;i>=b;i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; void solve(){ int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; deque<int> q; for(int i = 1; i <= k; i++){ while(!q.empty() && a[q.back()] <= a[i]) q.pop_back(); q.push_back(i); } int ans = a[q.front()]; for(int i = k+1; i <= n; i++){ if(q.front() == i-k) q.pop_front(); while(!q.empty() && a[q.back()] <= a[i]) q.pop_back(); q.push_back(i); ans = (ans*a[q.front()]) % mod; } cout << ans; } void testcases(){ int tt = 1; //cin >> tt; while(tt--){ solve(); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t start = clock(); testcases(); cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: "; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a Binary Search Tree and 2 node value <b>n1</b> and <b>n2</b>, your task is to find the <b>lowest common ancestor(LCA)</b> of the two nodes given. It may happen that values n1 and n2 may or may be not present. <b>Note:</b> Duplicates are not inserted in the BST.<b>User Task:</b> This is a function problem. You don't have to take any input. You are required to complete the function LCA() that takes root node, n1, n2 as parameters and returns the node that is LCA of n1 and n2. <b>Constraints:</b> 1 <= T <= 100 1 <= N <= 10^4 1 <= node values <= 10^4 <b>Sum of "N" over all testcases does not exceed 10^5</b> For <b>Custom Input:</b> First line of input should contains the number of test cases T. For each test case, there will be two lines of input. First line will be a string representing the tree as described below: The values in the string are in the order of level order traversal of the tree where, numbers denote node values, and a character β€œN” denotes NULL child. Second line will contain the values of two nodes <b>Note:</b> If a node has been declared Null using 'N', no information about its children will be given further in the array. Second line will contain the values of two nodesFor each testcase, you need to return the node containing LCA of n1 and n2. The driver code will print the data. If any of the node values (n1, n2) is not present then return null driver code will print -1 for that.Sample Input 2 5 4 6 3 N N 7 N N N 8 7 8 2 1 3 1 3 Sample Output 7 2 Explanation: Testcase1: The BST in above test case will look like 5 / \ 4 6 / \ 3 7 \ 8 Here the LCA of 7 and 8 is 7., I have written this Solution Code: static Node LCA(Node node, int n1, int n2) { if (node == null) { return null; } // If both n1 and n2 are smaller than root, then LCA lies in left if (node.data > n1 && node.data > n2) { return LCA(node.left, n1, n2); } // If both n1 and n2 are greater than root, then LCA lies in right if (node.data < n1 && node.data < n2) { return LCA(node.right, n1, n2); } return node; } , 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: 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: Given an ArrayList of N lowercase characters. The task is to insert given elements in the list and count frequency of elements present in the list. You can use some inbuilt functions as:- add() to append element in the list contains() to check an element is present or not in the list collections.frequency() to find the frequency of the element in the list.<b>User Task:</b> Since this will be a functional problem. You don't have to take input. You just have to complete the function <b>insert()</b> and <b>freq()</b> that takes the array list and the character c as parameters. Constraints: 1 <= T <= 100 1 <= N <= 1000 c will be a lowercase english character You need to print the count of the character c if it is present else you need to print "Not Present" all in a separate line in function freq().Sample Input: 2 6 i n i e i w i t i n f n 4 i c i p i p f f Sample Output: 2 Not Present Explanation: Testcase 1: Inserting n, e, w, t, n into the list. Frequency of n is 2 in the list. Testcase 2: Inserting c, p, p into the list. Frequency of f is 0 in the list., I have written this Solution Code: // Function to insert element public static void insert(ArrayList<Character> clist, char c) { clist.add(c); } // Function to count frequency of element public static void freq(ArrayList<Character> clist, char c) { if(clist.contains(c) == true) System.out.println(Collections.frequency(clist, c)); else System.out.println("Not Present"); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara want to buy a toy and for this purpose she goes to a toy shop, there is a special offer going in the toy shop that is if you buy one toy you can get extra k toys for free now Sara wonders what is the minimum amount of money she need to spend so that she can get all the toys. You are given some queries containing values of k you need to print the minimum amount of cost Sara need to spend to get all the toys for each value of k.First line contain number of toys N and the number of queries Q Second line contains the cost of the toys Next Q line contains a single integer that is the value of k Constraint:- 1<=N, Q<=100000 1<=Arr[i], k<=1000000 Output the minimum cost for each querySample Input : 6 2 100 20 50 10 2 5 3 4 Sample Output : 7 7 Explanation: She can buy toy at index 5 and get toys at index 1, 2, 3 for free than she buy toy at index 6 and get toy at index 4 for free so the total cost becomes 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)); String[] str = br.readLine().split(" "); int N = Integer.parseInt(str[0]); int Case = Integer.parseInt(str[1]); long[] arr = new long[N]; String[] Str = br.readLine().split(" "); for(int i = 0;i < N;i++){ arr[i] = Integer.parseInt(Str[i]); } Arrays.sort(arr); for(int i = 1;i < N;i++){ arr[i] = arr[i-1] + arr[i]; } double Q = 0; while(Case-->0){ Q = Integer.parseInt(br.readLine()); int num = (int)Math.ceil(N/(Q+1)); System.out.println(arr[num-1]); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara want to buy a toy and for this purpose she goes to a toy shop, there is a special offer going in the toy shop that is if you buy one toy you can get extra k toys for free now Sara wonders what is the minimum amount of money she need to spend so that she can get all the toys. You are given some queries containing values of k you need to print the minimum amount of cost Sara need to spend to get all the toys for each value of k.First line contain number of toys N and the number of queries Q Second line contains the cost of the toys Next Q line contains a single integer that is the value of k Constraint:- 1<=N, Q<=100000 1<=Arr[i], k<=1000000 Output the minimum cost for each querySample Input : 6 2 100 20 50 10 2 5 3 4 Sample Output : 7 7 Explanation: She can buy toy at index 5 and get toys at index 1, 2, 3 for free than she buy toy at index 6 and get toy at index 4 for free so the total cost becomes 7 , I have written this Solution Code: toy,qu = map(int,input().split()) cost = list(map(int,input().split())) cost=sorted(cost) for i in range(qu): k=int(input()) l=len(cost) t,s=0,0 while(l>0): l=l-(k+1) s=s+cost[t] t=t+1 print(s,end="\n"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara want to buy a toy and for this purpose she goes to a toy shop, there is a special offer going in the toy shop that is if you buy one toy you can get extra k toys for free now Sara wonders what is the minimum amount of money she need to spend so that she can get all the toys. You are given some queries containing values of k you need to print the minimum amount of cost Sara need to spend to get all the toys for each value of k.First line contain number of toys N and the number of queries Q Second line contains the cost of the toys Next Q line contains a single integer that is the value of k Constraint:- 1<=N, Q<=100000 1<=Arr[i], k<=1000000 Output the minimum cost for each querySample Input : 6 2 100 20 50 10 2 5 3 4 Sample Output : 7 7 Explanation: She can buy toy at index 5 and get toys at index 1, 2, 3 for free than she buy toy at index 6 and get toy at index 4 for free so the total cost becomes 7 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max1 10000001 int main(){ int n,q; cin>>n>>q; int a[n]; long b[n]; long sum=0; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); for(int i=0;i<n;i++){ sum+=a[i]; b[i]=sum; } int k; while(q--){ cin>>k; int c = ceil(1.0*n/(k+1)); cout<<b[c-1]<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(read.readLine()); StringTokenizer st = new StringTokenizer(read.readLine()); int[] arr = new int[N]; for(int i=0; i<N; i++) { arr[i] = Integer.parseInt(st.nextToken()); } int[] prefixArr = new int[200010]; int minIndex = 0; for(int i=0; i<N; i++) { prefixArr[i] = -1; } for(int i=0; i < N; i++) { prefixArr[arr[i]] = arr[i]; while(minIndex < N && prefixArr[minIndex] != -1) { minIndex++; } System.out.println(minIndex); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, I have written this Solution Code: def mis(arr, N): m = 0 c = [0] * (N + 1) for i in range(N): if (arr[i] >= 0 and arr[i] < N): c[arr[i]] = True while (c[m]): m += 1 print(m) if __name__ == '__main__': N = int(input()) arr = list(map(int,input().split())) mis(arr, N), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: While Solo was playing with an array A of N integers, her little sister Tono asked her the following question: For each integer i from 1 to N, find the smallest non- negative integer that is missing in subarray A[0]...A[i-1]. As Solo wants to play, please help her solve the following problem.The first line of the input contains a single integer N. The second line of input contains N space-separated integers, the integers of the array A. Constraints 1 <= N <= 200000 0 <= A[i] <= 200000Output N integers, the answers for each index <b>i</b> in a new line.Sample Input 4 1 1 0 2 Sample Output 0 0 2 3 Explanation: For i=1, subarray = [1], smallest non negative missing integer = 0. For i=2, subarray = [1, 1], smallest non negative missing integer = 0. For i=3, subarray = [1, 1, 0], smallest non negative missing integer = 2. For i=4, subarray = [1, 1, 0, 2], smallest non negative missing integer = 3. Sample Input 10 5 4 3 2 1 0 7 7 6 6 Sample Output 0 0 0 0 0 6 6 6 8 8, 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 cur = 0; set<int> s; int n; cin>>n; For(i, 0, n){ int a; cin>>a; s.insert(a); while(s.find(cur)!=s.end()) cur++; cout<<cur<<"\n"; } } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--){ solve(); // cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a grid having N*M elements. Find the index of the row (1-base indexing) which has the maximum sum of elements. Note: if more than two rows have the same sum of elements, then return the smallest index.The first line of the input contains two integers N and M. The next N lines each contain M space separated integers. <b>Constraints:</b> 1 <= N, M <= 10<sup>3</sup> 1 <= A<sub>i, j</sub> <= 10<sup>9Print the index of the row (1-base indexing) which has the maximum sum of elements.Sample Input: 4 3 3 4 2 5 1 7 2 8 1 2 3 3 Sample Output: 2 <b>Explaination:</b> Row number 2 has sum = 5 + 1 + 7 = 13 which is the maximum among all rows., I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) { FastReader sc=new FastReader(); int n=sc.nextInt(); int m=sc.nextInt(); int arr[][]=new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { arr[i][j]= sc.nextInt(); } } long maxsum=0; int index=0; for(int i=0; i<n; i++) { long sum=0; for(int j=0; j<m; j++) { sum += arr[i][j]; } if(sum > maxsum) { maxsum=sum; index=i+1; } } System.out.print(index); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a grid having N*M elements. Find the index of the row (1-base indexing) which has the maximum sum of elements. Note: if more than two rows have the same sum of elements, then return the smallest index.The first line of the input contains two integers N and M. The next N lines each contain M space separated integers. <b>Constraints:</b> 1 <= N, M <= 10<sup>3</sup> 1 <= A<sub>i, j</sub> <= 10<sup>9Print the index of the row (1-base indexing) which has the maximum sum of elements.Sample Input: 4 3 3 4 2 5 1 7 2 8 1 2 3 3 Sample Output: 2 <b>Explaination:</b> Row number 2 has sum = 5 + 1 + 7 = 13 which is the maximum among all rows., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int> (m)); vector<int> sum(n); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> a[i][j]; sum[i] += a[i][j]; } } int mx = 0, ans = 0; for(int i = 0; i < n; i++){ if(mx < sum[i]){ mx = sum[i]; ans = i; } } cout << ans + 1; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You're given a string S of lowercase letters of the english alphabet. Find whether you can choose some characters of the string S in any order to create the string "red".The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100 All the characters in S are lowercase letters of the english alphabet.Output "Yes" (without quotes) if you can create the string "red", else output "No" (without quotes).Sample Input damngrey Sample Output Yes Explanation: We choose character at position 6, then position 7, then position 1. Sample Input newtonschool Sample Output No, 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(); boolean r=false,e=false,d=false; for(int i=0;i<str.length();i++){ char ch = str.charAt(i); if(ch=='r')r=true; if(ch=='e')e=true; if(ch=='d')d=true; } String ans = (r && e && d)?"Yes":"No"; System.out.print(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You're given a string S of lowercase letters of the english alphabet. Find whether you can choose some characters of the string S in any order to create the string "red".The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100 All the characters in S are lowercase letters of the english alphabet.Output "Yes" (without quotes) if you can create the string "red", else output "No" (without quotes).Sample Input damngrey Sample Output Yes Explanation: We choose character at position 6, then position 7, then position 1. Sample Input newtonschool Sample Output No, I have written this Solution Code: S = input() if ("r" in S and "e" in S and "d" in S ) : print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You're given a string S of lowercase letters of the english alphabet. Find whether you can choose some characters of the string S in any order to create the string "red".The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100 All the characters in S are lowercase letters of the english alphabet.Output "Yes" (without quotes) if you can create the string "red", else output "No" (without quotes).Sample Input damngrey Sample Output Yes Explanation: We choose character at position 6, then position 7, then position 1. Sample Input newtonschool Sample Output 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(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(){ string s; cin>>s; map<char, int> m; For(i, 0, sz(s)){ m[s[i]]++; } if(m['r'] && m['e'] && m['d']){ 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: You will be given an array of several arrays that each contain integers and your goal is to write a function that will sum up all the numbers in all the arrays. For example, if the input is [[3, 2], [1], [4, 12]] then your program should output 22 because 3 + 2 + 1 + 4 + 12 = 22An array containing arrays which can contain any number of elements.Sum of all the elements in all of the arrays.Sample input:- [[3, 2], [1], [4, 12]] Sample output:- 22 Explanation:- 3 + 2 + 1 + 4 + 12 = 22, I have written this Solution Code: function sum_array(arr) { // store our final answer var sum = 0; // loop through entire array for (var i = 0; i < arr.length; i++) { // loop through each inner array for (var j = 0; j < arr[i].length; j++) { // add this number to the current final sum sum += arr[i][j]; } } console.log(sum); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: static boolean isPalindrome(int N) { int sum = 0; int rev = N; while(N > 0) { int digit = N%10; sum = sum*10+digit; N = N/10; } if(rev == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is <b>Palindrome</b> or not. A number is said to be Palindrome when it reads the same from backward as forward.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>isPalindrome()</b> which contains N as a parameter. <b>Constraints:</b> 1 <= N <= 9999You need to return "true" is the number is palindrome otherwise "false".Sample Input: 5 Sample Output: true Sample Input: 121 Sample Output: true, I have written this Solution Code: def isPalindrome(N): sum1 = 0 rev = N while(N > 0): digit = N%10 sum1 = sum1*10+digit N = N//10 if(rev == sum1): return True return False, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≀ X ≀ 1000 1 ≀ N ≀ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); if(s==null){ System.exit(0); } StringTokenizer st = new StringTokenizer(s, " "); int power = Integer.parseInt(st.nextToken()); int multiple = Integer.parseInt(st.nextToken()); int res = power; for(int i = 1;i<=multiple;i++){ res = res*2; } System.out.println(res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≀ X ≀ 1000 1 ≀ N ≀ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: #include <iostream> using namespace std; int main() { int x, n; cin >> x >> n; cout << x*(1 << n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice's power is currently known to be an integer X. It is also known that her power doubles every second. For example, if Alice's power was currently 20, then after 2 seconds her power would have grown to 80. Your task is to find out Alice's power after N seconds.The input consists of a single line containing two space-separated integers X and N. <b>Constraints:</b> 1 ≀ X ≀ 1000 1 ≀ N ≀ 10Print a single integer – the power of Alice after N seconds.Sample Input 1: 5 2 Sample Output 1: 20 Sample Explanation 1: Alice's power after 1 second will be 5*2 = 10. After 2 seconds it will be 10*2 = 20. Sample Input 2: 4 3 Sample Output 2: 32, I have written this Solution Code: x,n = map(int,input().split()) print(x*(2**n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input()) bSum=0 wSum=0 for i in range(n): c=(input().split()) for j in range(len(c)): if(i%2==0): if(j%2==0): bSum+=int(c[j]) else: wSum+=int(c[j]) else: if(j%2==0): wSum+=int(c[j]) else: bSum+=int(c[j]) print(bSum) print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int mat[][] = new int[N][N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) mat[i][j] = sc.nextInt(); } alternate_Matrix_Sum(mat,N); } static void alternate_Matrix_Sum(int mat[][], int N) { long sum =0, sum1 = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if((i+j)%2 == 0) sum += mat[i][j]; else sum1 += mat[i][j]; } } System.out.println(sum); System.out.print(sum1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, β€œact” and β€œtac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≀ |s1|, |s2| ≀ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., 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 s1 = br.readLine(); String s2 = br.readLine(); boolean flag = true; int[] arr1 = new int[26]; int[] arr2 = new int[26]; for(int i=0; i<s1.length(); i++){ arr1[s1.charAt(i)-97]++; } for(int i=0; i<s2.length(); i++){ arr2[s2.charAt(i)-97]++; } for(int i=0; i<25; i++){ if(arr1[i]!=arr2[i]){ flag = false; break; } } if(flag==true) System.out.print("YES"); else System.out.print("NO"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, β€œact” and β€œtac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≀ |s1|, |s2| ≀ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: s1 = input().strip() s2 = input().strip() dict1 = dict() dict2 = dict() for i in s1: dict1[i] = dict1.get(i, 0) + 1 for j in s2: dict2[j] = dict2.get(j, 0) + 1 print(("NO", "YES")[dict1 == dict2]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, β€œact” and β€œtac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≀ |s1|, |s2| ≀ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define pu push_back #define fi first #define se second #define mp make_pair #define int long long #define pii pair<int,int> #define mm (s+e)/2 #define all(x) x.begin(), x.end() #define For(i, st, en) for(int i=st; i<en; i++) #define tr(x) for(auto it=x.begin(); it!=x.end(); it++) #define fast std::ios::sync_with_stdio(false);cin.tie(NULL); #define sz 200000 int A[26],B[26]; signed main() { string s,p; cin>>s>>p; for(int i=0;i<s.size();i++) { int y=s[i]-'a'; A[y]++; } for(int i=0;i<p.size();i++) { int y=p[i]-'a'; B[y]++; }int ch=1; for(int i=0;i<26;i++) { if(B[i]!=A[i])ch=0; } if(ch==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are an anagram of each other or not. An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, β€œact” and β€œtac” are an anagram of each other.Input consists of two strings in lowercase english characters. Constraints: 1 ≀ |s1|, |s2| ≀ 10^5Print "YES" without quotes if the two strings are anagram else print "NO".Sample Input naman manan Sample Output YES Explanation: Both String contain 2 'a's, 2 'n's and 1 'm'., I have written this Solution Code: // str1 and str2 are the two input strings function isAnagram(str1,str2){ // Get lengths of both strings let n1 = str1.length; let n2 = str2.length; // If length of both strings is not same, // then they cannot be anagram if (n1 != n2) return "NO"; str1 = str1.split('') str2 = str2.split('') // Sort both strings str1.sort(); str2.sort() // Compare sorted strings for (let i = 0; i < n1; i++) if (str1[i] != str2[i]) return "NO"; return "YES"; } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class TreeNode{ int data; TreeNode left; TreeNode right; public TreeNode(int data){ this.data = data; } } static int max = Integer.MIN_VALUE; static int min = Integer.MAX_VALUE; static boolean isBST = true; static boolean isBSTUtil(TreeNode root, int min, int max){ if(root == null) return true; if(root.data > max || root.data < min){ return false; } return isBSTUtil(root.left, min, root.data) && isBSTUtil(root.right, root.data, max); } static void inorder(TreeNode root){ if (root != null){ inorder(root.left); if(root.data < min) min = root.data; if(root.data > max) max = root.data; inorder(root.right); } } 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 < str.length; i++){ arr[i] = Integer.parseInt(str[i]); } int root = Integer.parseInt(br.readLine()); TreeNode [] tree = new TreeNode[n]; for(int i = 0; i < n; i++){ tree[i] = new TreeNode(arr[i]); } for(int i = 0; i < n; i++){ String [] in = br.readLine().split(" "); int l = Integer.parseInt(in[0]); int r = Integer.parseInt(in[1]); if(l != 0) tree[i].left = tree[l - 1]; if(r != 0) tree[i].right = tree[r - 1]; } inorder(tree[root - 1]); System.out.println(isBSTUtil(tree[root - 1], min, max) == true ? "YES" : "NO"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: N = int(input()) if N == 1: print("YES") exit() in_arr = list(map(int,input().split())) root = int(input()) in_tree_arr = [list(map(int,input().split())) for i in range(N)] in_order_arr = [] def traverse(root): if root==0: return traverse(in_tree_arr[root-1][0]) in_order_arr.append(in_arr[root-1]) traverse(in_tree_arr[root-1][1]) traverse(root) for i in range(N-1): if in_order_arr[i]<in_order_arr[i+1]: continue else: print("NO") break else: print("YES"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree. The second line of input contains n integers, the values of the nodes of the tree. The third line of the input contains an integer, denoting the root node of the tree. Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child) Constraints 1 <= n <= 50000 0 <= l, r <= n (0 denotes no child) 1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input 5 10 3 9 2 1 4 3 0 0 0 2 0 5 1 0 0 Sample Output YES, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; class Node { public: Node( int v ) { data = v; left = NULL; right = NULL; } int data; Node* left; Node* right; }; bool isBST(Node *tree, int min, int max){ if(tree == NULL) return true; if(tree -> data < min || tree -> data > max) return false; return isBST(tree -> left, min, tree -> data - 1) && isBST(tree -> right, tree -> data + 1, max); } int main(){ int n; cin >> n; Node* *tree; tree = new Node*[n]; for(int i = 0; i < n; i++){ int value; cin >> value; tree[i] = new Node(value); } int root; cin >> root; for(int i = 0; i < n; i++){ int left,right; cin>>left; cin>>right; if(left != 0) tree[i] -> left = tree[left - 1]; if(right != 0) tree[i] -> right = tree[right - 1]; } if(isBST(tree[root - 1], INT_MIN, INT_MAX)) cout<< "YES"; else cout<<"NO"; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: nan, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Remove duplicates of an array and return an array of only unique elements.An array containing numbers.Space separated unique elements from the array.Sample Input:- 1 2 3 5 1 5 9 1 2 8 Sample Output:- 1 2 3 5 9 8 <b>Explanation:-</b> Extra 1, 2, and 5 were removed since they were occurring multiple times. Note: You only have to remove the extra occurrences i.e. each element in the final array should have a frequency equal to one., I have written this Solution Code: inp = eval(input("")) new_set = [] for i in inp: if(str(i) not in new_set): new_set.append(str(i)) print(" ".join(new_set)), 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: 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: Given an integer array A of size N. Another array B is defined as: B[i] = A[j] such that j > i and A[j] < A[i]. If there does not exist any index j satisfying the above conditions then B[i] = -1. Find the array B.The first line contains an integer N. The next line contains N space-separated integers denoting elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; Ai &le; 10<sup>5</sup>Print N space separated integers denoting the elements of array B.Sample Input 1: 4 10 2 5 3 Output 2 -1 3 -1 Explanation: Next element smaller than 10 is 2. There are no elements after 2 that are less than 2. Next element smaller than 5 is 3. There are no elements after 3. Sample Input 2: 2 1 2 Output -1 -1 Explanation: There are no elements after 1 which is less than 1 and there are no elements after 2. , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; void printNSE(vector<int> &arr, int n) { int next, i, j; vector<int> b; for (i = 0; i < n; i++) { next = -1; for (j = i + 1; j < n; j++) { if (arr[i] > arr[j]) { next = arr[j]; break; } } b.push_back(next); } for (int i = 0; i < n; i++) { cout << b[i] << " "; } } int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } printNSE(arr, n); return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array A of size N. Another array B is defined as: B[i] = A[j] such that j > i and A[j] < A[i]. If there does not exist any index j satisfying the above conditions then B[i] = -1. Find the array B.The first line contains an integer N. The next line contains N space-separated integers denoting elements of the array. <b>Constraints:</b> 1 &le; N &le; 10<sup>5</sup> 1 &le; Ai &le; 10<sup>5</sup>Print N space separated integers denoting the elements of array B.Sample Input 1: 4 10 2 5 3 Output 2 -1 3 -1 Explanation: Next element smaller than 10 is 2. There are no elements after 2 that are less than 2. Next element smaller than 5 is 3. There are no elements after 3. Sample Input 2: 2 1 2 Output -1 -1 Explanation: There are no elements after 1 which is less than 1 and there are no elements after 2. , I have written this Solution Code: import java.io.*; // for handling input/output import java.util.*; // contains Collections framework // don't change the name of this class // you can add inner classes if needed class Main { public static void main (String[] args) { // Your code here Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); long res[]=new long[n]; Arrays.fill(res,-1); Stack<Integer> stack=new Stack<>(); stack.push(0); for(int i=1;i<n;i++){ while(!stack.isEmpty() && a[i] < a[stack.peek()]){ res[stack.pop()]=a[i]; } stack.push(i); } for(int k=0;k<n;k++){ System.out.print(res[k]+" "); } } }, In this Programming Language: Java, 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: The head of the doubly linked list will be given to you, and you must sort it using merge sort.You will be given the head of doubly Linked List and its length. Constraints: 0<= n <=10000Return the HEAD of the sorted linked list.Sample Input: 5 3 2 1 3 2 Output: 1 2 2 3 3, I have written this Solution Code: class Node: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def push(head, key): node = Node(key, head) if head: head.prev = node return node def printDDL(head): while head: print(head.data, end=' ') head = head.next def split(head): slow = head fast = head.next while fast: fast = fast.next if fast: slow = slow.next fast = fast.next return slow def merge(a, b): if a is None: return b if b is None: return a if a.data <= b.data: a.next = merge(a.next, b) a.next.prev = a a.prev = None return a else: b.next = merge(a, b.next) b.next.prev = b b.prev = None return b def mergesort(head): if head is None or head.next is None: return head a = head slow = split(head) b = slow.next slow.next = None a = mergesort(a) b = mergesort(b) head = merge(a, b) return head n=int(input()) keys=list(map(int,input().split())) head = None for key in keys: head = push(head, key) head = mergesort(head) printDDL(head), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The head of the doubly linked list will be given to you, and you must sort it using merge sort.You will be given the head of doubly Linked List and its length. Constraints: 0<= n <=10000Return the HEAD of the sorted linked list.Sample Input: 5 3 2 1 3 2 Output: 1 2 2 3 3, I have written this Solution Code: Node split(Node head) { Node fast = head, slow = head; while (fast.next != null && fast.next.next != null) { fast = fast.next.next; slow = slow.next; } Node temp = slow.next; slow.next = null; return temp; } Node mergeSort(Node node, int n) { if (node == null || node.next == null) { return node; } Node second = split(node); node = mergeSort(node,n); second = mergeSort(second,n); return merge(node, second); } Node merge(Node first, Node second) { if (first == null) { return second; } if (second == null) { return first; } if (first.data < second.data) { first.next = merge(first.next, second); first.next.prev = first; first.prev = null; return first; } else { second.next = merge(first, second.next); second.next.prev = second; second.prev = null; return second; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have to complete <code>printName</code> function <ol> <li>Takes 2 arguments which are EventEmitter object , event name </li> <li>Using the <code>EventEmitter</code> object you need to register an eventListener for <code>personEvent</code> event which takes a callback function. </li> <li>The callback function itself takes an argument (which would be emitted by test runner) which is of type string. Using that argument print to console. `My name is ${argument}`. </li> </ol>Function will take two arguments 1) 1st argument will be an object of EventEmitter class 2) 2nd argument will be the event name (string) Function returns a registered Event using an object of EventEmitter class (which then is used to print the name)<pre> <code> const emitter=EventEmitter object const personEvent="event" function printName(emitter,personEvent)//registers event with event Name "event" emitter.emit("event","Dev")//emits the event and give the output "My name is Dev" </code> </pre> , I have written this Solution Code: function printName(emitter,personEvent) { emitter.on(personEvent,(arg)=>{ console.log('My name is ',arg); }); } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a function f(x) = ax<sup>2 </sup> + bx + c and an integer K. Find the minimum non - negative integer value of <b>t</b> such that f(t) >= K.First line contains four positive integers a, b, c, K. Constraints 1 <= a, b, c <=100 0 <= K <= 10^16Print the value of <b>t</b>.Sample Input 1: 1 1 1 1 Output 0 Explanation: f(0) = (0 + 0 + 1) >= 1 Sample Input 2: 1 1 1 2 Output 1 Explanation: f(0) = 1 < 2 f(1) = 3 >=2 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { static long binary_search(long a, long b, long c, long k) { long l = 0; long r = 100000000; long ans = 0; while (l <= r) { long t = (l + r) / 2; long f = a * t * t + b * t + c; if (f >= k) { ans = t; r = t - 1; } else { l = t + 1; } } return ans; } public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); String line = br.readLine(); String[] strs = line.trim().split("\\s+"); long a=Long.parseLong(strs[0]); long b=Long.parseLong(strs[1]); long c=Long.parseLong(strs[2]); long k=Long.parseLong(strs[3]); System.out.print(binary_search(a, b, c, k)); } } , 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: Given an n x n matrix and a number x, find whether given element present in matrix or not, every row and column is sorted in increasing order. The designed algorithm should have linear time complexity.first line contain two element n and x. next n line contain n space separated integer i. e. element of matrix. Constraints: 1<=n,x<=1000print "Yes" is given element is present in matrix otherwise print "No".Sample Input 1: 3 5 1 2 3 2 4 5 3 6 9 Sample Output 1: Yes Explanation : 5 present in given matrix at 2nd row and third column., I have written this Solution Code: n,x=map(int,input().split()) list1=[] flag=0 for i in range(n): li=list(map(int,input().split())) list1.append(li) for i in range(n): for j in range(n): if list1[i][j]==x: flag=1 break else: continue if flag==1: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an n x n matrix and a number x, find whether given element present in matrix or not, every row and column is sorted in increasing order. The designed algorithm should have linear time complexity.first line contain two element n and x. next n line contain n space separated integer i. e. element of matrix. Constraints: 1<=n,x<=1000print "Yes" is given element is present in matrix otherwise print "No".Sample Input 1: 3 5 1 2 3 2 4 5 3 6 9 Sample Output 1: Yes Explanation : 5 present in given matrix at 2nd row and third column., I have written this Solution Code: import java.util.*; class Main { private static void search(int[][] mat, int n, int x) { int i = 0, j = n - 1; while (i < n && j >= 0) { if (mat[i][j] == x) { System.out.print("Yes"); return; } if (mat[i][j] > x) j--; else i++; } System.out.print("No\n"); return; } // driver program to test ab public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n,x; n=sc.nextInt(); x=sc.nextInt(); int [][]arr=new int[n][n]; for(int i=0;i<n;i++) for(int j=0;j<n;j++) arr[i][j]=sc.nextInt(); search(arr, n, x); } } // This code is contributed by Arnav Kr. Mandal, 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: 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: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: static int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: int SillyNumber(int N){ int sum=0; int x=1; while(sum<N){ sum+=x*x; x++; } x--; if(sum-N < N-(sum-x*x)){ return sum; } else{ return sum-x*x; } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number is called Silly if it can be represented as the sum of the square of consecutive natural numbers starting from 1. For a given number N, find the closest silly number.<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>SillyNumber()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the closest Silly number. Note:- If more than one answer exists return the minimum one.Sample Input:- 18 Sample Output:- 14 Explanation:- 1*1 + 2*2 + 3*3 = 14 Sample Input:- 2 Sample Output:- 1, I have written this Solution Code: def SillyNumber(N): sum=0 x=1 while sum<N: sum=sum+x*x x=x+1 x=x-1 if (sum-N) < (N-(sum-x*x)): return sum; else: return sum - x*x , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≀ T ≀ 10 0 ≀ A, B, C ≀ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("").append(String.valueOf(object)); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) throws Exception{ try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); while(testCases-- > 0) { int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(); while ((a>0&&b>0)||(a>0&&c>0)||(b>0&&c>0)) { if (a >= b && a >= c) { a--; if (b >= c) { b--; } else{ c--; } } else if (b >= a && b >= c) { b--; if (a >= c) { a--; } else{ c--; } } else{ c--; if (a >= b) { a--; } else{ b--; } } } if (a==0&&b==0&&c==0){ out.println("Yes"); } else{ out.println("No"); } } out.close(); } catch (Exception e) { return; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≀ T ≀ 10 0 ≀ A, B, C ≀ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: t=int(input()) for i in range(t): arr=list(map(int,input().split())) a,b,c=sorted(arr) if((a+b+c)%2): print("No") elif ((a+b)>=c): print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given 3 non-negative integers A, B and C. In one operation, you can pick any two of the given integers and subtract one from both of them. If it is possible to make all the 3 integers zero after some number of operations (possibly none), print "Yes". Otherwise, print "No".The first line contains a single integer T – the number of test cases. Each of the next T lines contains 3 space separated integers A, B and C respectively. <b> Constraints: </b> 1 ≀ T ≀ 10 0 ≀ A, B, C ≀ 10Output T lines, the i<sup>th</sup> line containing a single word, either "Yes" or "No" – the answer to the i<sup>th</sup> test case.Sample Input 1: 2 3 4 2 2 2 2 Sample Output 1: No Yes Sample Explanation 1: For the first test case, there is no possible way to make all the elements zero. For the second test case, we can pick elements in the following order: (A,B), (B,C), (A,C), I have written this Solution Code: // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define ll long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("input.txt","r")) { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } #endif int t; cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c; if(a>b+c||b>a+c||c>a+b) cout<<"No\n"; else { int sum=a+b+c; if(sum%2) cout<<"No\n"; else cout<<"Yes\n"; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N elements. Find the minimum number of elements that you need to delete from this array such that all the elements in the array become distinct.First line of input contains a single integer N. Second line of input contains N space separated integers, denoting the array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 10^9Print a single integer which is the minimum number of elements that must be deleted.Sample Input 1 6 1 1 2 2 3 3 Sample Output 1 3 Explanation: we will delete 1 of each 1, 2 and 3., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int N = Integer.parseInt(br.readLine()); String[] arr = br.readLine().split(" "); int n = arr.length; int[] array1 = new int[n]; for(int i = 0 ;i<n; i++){ array1[i] = Integer.parseInt(arr[i]); } int res = 0; for (int i = 0; i < n; i++) { int j = 0; for (j = 0; j < i; j++) if (array1[i] == array1[j]) break; if (i == j) res++; } System.out.print(n-res); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N elements. Find the minimum number of elements that you need to delete from this array such that all the elements in the array become distinct.First line of input contains a single integer N. Second line of input contains N space separated integers, denoting the array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 10^9Print a single integer which is the minimum number of elements that must be deleted.Sample Input 1 6 1 1 2 2 3 3 Sample Output 1 3 Explanation: we will delete 1 of each 1, 2 and 3., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; unordered_map<int,int> m; for(int i=1;i<=n;++i){ int d; cin>>d; m[d]++; } int ans=0; for(auto r:m) ans+=r.second-1; cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array Arr of N elements. Find the minimum number of elements that you need to delete from this array such that all the elements in the array become distinct.First line of input contains a single integer N. Second line of input contains N space separated integers, denoting the array Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 10^9Print a single integer which is the minimum number of elements that must be deleted.Sample Input 1 6 1 1 2 2 3 3 Sample Output 1 3 Explanation: we will delete 1 of each 1, 2 and 3., I have written this Solution Code: import numpy as np from collections import defaultdict d=defaultdict(int) n=int(input()) a=np.array([input().strip().split()],int).flatten() for i in a: d[i]+=1 print(n-len(d)), 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: 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: Given an integer N as an input, print a pattern as shown in sample.Input contains a single integer N Constraints:- 1<=N<=15Print the patter for N.Sample Input: 3 Sample Output: 3 3 3 3 3 3 2 2 2 3 3 2 1 2 3 3 2 2 2 3 3 3 3 3 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define max 100 void print(int a[][max], int size) { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { cout << a[i][j]<<" "; } cout <<endl; } } void innerPattern(int n) { int size = 2 * n - 1; int front = 0; int back = size - 1; int a[max][max]; while (n != 0) { for (int i = front; i <= back; i++) { for (int j = front; j <= back; j++) { if (i == front || i == back || j == front || j == back) a[i][j] = n; } } ++front; --back; --n; } print(a, size); } int main() { int n ; cin>>n; innerPattern(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 of length N. You have to select two non- overlapping (no common index) non- empty substrings of odd lengths from that string such that both those substrings are palindrome. You want the product of lengths of those substring to be maximum.Input contains of a single String of length N. Constraints 2 <= N <= 100000 String contains lowercase english letters.Print a single integer which is the maximum possible product of lengths of selected substrings.Sample input 1 aabaaba Sample output 1 9 Explanation : we can select substring [2-4] = aba and [5-7] = aba the product of their lengths is 9. Sample Input 2 aabababaaa Sample Output 2 15 , I have written this Solution Code: import java.io.*; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; class Main { public static void main (String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); String str = read.readLine(); System.out.println(maxProduct(str)); } public static long maxProduct(String str) { StringBuilder sb = new StringBuilder(str); int x = sb.length(); int[] dpl = new int[x]; int[] dpr = new int[x]; modifiedOddManacher(sb.toString(), dpl); modifiedOddManacher(sb.reverse().toString(), dpr); long max=1; for(int i=0;i<x-1;i++) max=Math.max(max, (1+(dpl[i]-1)*2L)*(1+(dpr[x-(i+1)-1]-1)*2L)); return max; } private static void modifiedOddManacher(String str, int[] dp){ int x = str.length(); int[] center = new int[x]; for(int l=0,r=-1,i=0;i<x;i++){ int radius = (i > r) ? 1 : Math.min(center[l+(r-i)], r-i+1); while(i-radius>=0 && i+radius<x && str.charAt(i-radius)==str.charAt(i+radius)) { dp[i+radius] = radius+1; radius++; } center[i] = radius--; if(i+radius>r){ l = i-radius; r = i+radius; } } for(int i=0, max=1;i<x;i++){ max = Math.max(max, dp[i]); dp[i] = max; } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string of length N. You have to select two non- overlapping (no common index) non- empty substrings of odd lengths from that string such that both those substrings are palindrome. You want the product of lengths of those substring to be maximum.Input contains of a single String of length N. Constraints 2 <= N <= 100000 String contains lowercase english letters.Print a single integer which is the maximum possible product of lengths of selected substrings.Sample input 1 aabaaba Sample output 1 9 Explanation : we can select substring [2-4] = aba and [5-7] = aba the product of their lengths is 9. Sample Input 2 aabababaaa Sample Output 2 15 , I have written this Solution Code: s=input() n = len(s) hlen = [0]*n center = right = 0 for i in range(n): if i < right: hlen[i] = min(right - i, hlen[2*center - i]) while 0 <= i-1-hlen[i] and i+1+hlen[i] < len(s) and s[i-1-hlen[i]] == s[i+1+hlen[i]]: hlen[i] += 1 if right < i+hlen[i]: center, right = i, i+hlen[i] left = [0]*n right = [0]*n for i in range(n): left[i+hlen[i]] = max(left[i+hlen[i]], 2*hlen[i]+1) right[i-hlen[i]] = max(right[i-hlen[i]], 2*hlen[i]+1) for i in range(1, n): left[~i] = max(left[~i], left[~i+1]-2) right[i] = max(right[i], right[i-1]-2) for i in range(1, n): left[i] = max(left[i-1], left[i]) right[~i] = max(right[~i], right[~i+1]) print(max(left[i-1]*right[i] for i in range(1, n))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string of length N. You have to select two non- overlapping (no common index) non- empty substrings of odd lengths from that string such that both those substrings are palindrome. You want the product of lengths of those substring to be maximum.Input contains of a single String of length N. Constraints 2 <= N <= 100000 String contains lowercase english letters.Print a single integer which is the maximum possible product of lengths of selected substrings.Sample input 1 aabaaba Sample output 1 9 Explanation : we can select substring [2-4] = aba and [5-7] = aba the product of their lengths is 9. Sample Input 2 aabababaaa Sample Output 2 15 , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountl #define m_p make_pair #define inf 200000000000000 #define MAXN 1000001 #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); } // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// #define S second #define F first #define int long long ///////////// int v1[100001]={}; int v2[100001]={}; signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; string s; cin>>s; n=s.length(); vector<int> d1(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } int c=0; for(int i=0;i<n;++i) { int x=2*d1[i]-1; int j=i+d1[i]-1; while(v1[j]<x&&j>=i) { v1[j]=x; x-=2; ++c; --j; } } for(int i=1;i<n;++i) { v1[i]=max(v1[i],v1[i-1]); } for(int i=n-1;i>=0;--i) { int x=2*d1[i]-1; int j=i-d1[i]+1; while(v2[j]<x&&j<=i) { v2[j]=x; x-=2; ++j; ++c; } } for(int i=n-2;i>=0;--i) { v2[i]=max(v2[i],v2[i+1]); } int ans=0; for(int i=1;i<n;++i) { ans=max(ans,v1[i-1]*v2[i]); } cout<<ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , 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]; } long x=1,y=0; if(n&1){ for(int i=0;i<n;i++){ if(i%2==0){ x*=a[i]; } else{ y+=a[i]; } } } else{ for(int i=0;i<n;i++){ if(i%2==0){ y+=a[i]; } else{ x*=a[i]; } } } cout<<y<<" "<<x; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , I have written this Solution Code: n = int(input()) lst = list(map(int, input().strip().split()))[:n] lst.reverse() lst_1 = 0 for i in range(1, n, 2): lst_1 += lst[i] lst_2 = 1 for i in range(0, n, 2): lst_2 *= lst[i] print(lst_1,lst_2), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You will be given an array of N numbers. Your task is to first reverse the array (the first number becomes last, 2nd number becomes 2nd from the last, and so on) and then print the sum of the numbers at even indices and print the product of the numbers at odd indices. <b>Note :</b> 1 based indexing is followed .The first line contains a single integer N: the number of elements The second line contains N different integers separated by spaces <b>constraints:-</b> 1 <= N <= 35 1 <= a[i] <= 10Two space separated integers representing sum of the numbers at even places and the product of the numbers at odd places. Sample Input 1: 6 1 2 3 4 5 6 Sample Output 1: 9 48 Sample Input 2: 3 1 2 3 Sample Output 2: 2 3 <b>Explanation 1:-</b> After reversing 1 2 3 4 5 6 becomes 6 5 4 3 2 1 Hence the sum of the numbers at even indices: 5+3+1=9 product of the numbers at odd indices: 6*4*2=48 , 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 Arr[] = new int[n]; for(int i=0;i<n;i++){ Arr[i] = sc.nextInt(); } if(n%2==1){ long sum=0; long product=1; for(int i=0;i<n;i++){ if(i%2==0){ product*=Arr[i]; } else{ sum+=Arr[i]; } } System.out.print(sum+" "+product); } else{ long sum=0; long product=1; for(int i=0;i<n;i++){ if(i%2==1){ product*=Arr[i]; } else{ sum+=Arr[i]; } } System.out.print(sum+" "+product); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a Deque and Q queries. The task is to perform some operation on Deque according to the queries as described in input: Note:-if deque is empty than pop operation will do nothing, and -1 will be printed as a front and rear element of queue if it is empty.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions: <b>push_front_pf()</b>:- that takes the deque and the integer to be added as a parameter. <b>push_bac_pb()</b>:- that takes the deque and the integer to be added as a parameter. <b>pop_back_ppb()</b>:- that takes the deque as parameter. <b>front_dq()</b>:- that takes the deque as parameter. Constraints: 1 <= N(Number of queries) <= 10<sup>3</sup> <b>Custom Input: </b> First line of input should contain the number of queries Q. Next, Q lines should contain any of the given operations:- For <b>push_front</b> use <b> pf x</b> where x is the element to be added For <b>push_rear</b> use <b> pb x</b> where x is the element to be added For <b>pop_back</b> use <b> pp_b</b> For <b>Display Front</b> use <b>f</b> Moreover driver code will print Front element of deque in each push_front opertion Last element of deque in each push_back operation Size of deque in each pop_back operation The front_dq() function will return the element at front of your deque in a new line, if the deque is empty you just need to return -1 in the function.Sample Input: 6 push_front 2 push_front 3 push_rear 5 display_front pop_rear display_front Sample Output: 3 3, I have written this Solution Code: static void push_back_pb(Deque<Integer> dq, int x) { dq.add(x); } static void push_front_pf(Deque<Integer> dq, int x) { dq.addFirst(x); } static void pop_back_ppb(Deque<Integer> dq) { if(!dq.isEmpty()) dq.pollLast(); else return; } static int front_dq(Deque<Integer> dq) { if(!dq.isEmpty()) return dq.peek(); else return -1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, Arr of N integers. Find the number of non- empty subarrays such that xor of all the elements of that subarray is divisible by 8.First line of input contains a single integer N. Second line of input contains N integers denoting the elements of Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000Print a single integer, the number of non- empty subarrays such that xor of all the elements of that subarray is divisible by 8.Sample Input 3 6 6 8 Sample Output 3 Explanation: (1-2) xor = 0 (1-3) xor = 8 (3-3) xor = 8, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static int subCountXor(int arr[], int n) { int xorArr[] = new int[8]; Arrays.fill(xorArr, 0); int cumSum = 0; for (int i = 0; i < n; i++) { cumSum ^= arr[i]; xorArr[cumSum % 8]++; } int ans = 0; for (int i = 0; i < 8; i++) if (xorArr[i] > 1) ans += (xorArr[i] * (xorArr[i] - 1)) / 2; ans += xorArr[0]; return ans; } 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(); String strArr[]=str.split(" "); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=Integer.parseInt(strArr[i]); System.out.println(subCountXor(arr,n)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array, Arr of N integers. Find the number of non- empty subarrays such that xor of all the elements of that subarray is divisible by 8.First line of input contains a single integer N. Second line of input contains N integers denoting the elements of Arr. Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 1000000000Print a single integer, the number of non- empty subarrays such that xor of all the elements of that subarray is divisible by 8.Sample Input 3 6 6 8 Sample Output 3 Explanation: (1-2) xor = 0 (1-3) xor = 8 (3-3) xor = 8, 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; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int m[8]={}; m[0]=1; int ans=0; int v=0; for(int i=0;i<n;++i){ int d; cin>>d; d=d%8; v^=d; ans+=m[v]; m[v]++; } 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: Given two strings S1 and S2 you have to make the two strings equal. To make them equal you can change any character of S1 or S2 to any other lowercase letter. You can perform this operation at most X number of times. Find the number of ways to make S1 and S2 equal. Two ways are considered different if the string formed after changes are different in both cases. As the number of ways can be large compute number of ways modulo 1000000007.First line of input contains S1 Second line of input contains S2 Third line of input contains X. Constraints 1 <= |S1| <= 100000 |S1| = |S2| 0 <= K <= |S1| +|S2|Output a single integer, the required value modulo 1000000007.Sample input 1 nlbmb wrbqh 4 Sample output 1 16 Sample input 2 xpc qve 1 Sample output 2 0, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define ll long long #define int long long const int N = 1e5 + 5; const int MOD = 1e9 + 7; int pow(int a, int b, int m) { int ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int fact[N], invfact[N]; int modinv(int k) { return pow(k, MOD-2, MOD); } void precompute() { fact[0]=fact[1]=1; for(int i=2;i<N;i++) { fact[i]=fact[i-1]*i; fact[i]%=MOD; } invfact[N-1]=modinv(fact[N-1]); for(int i=N-2;i>=0;i--) { invfact[i]=invfact[i+1]*(i+1); invfact[i]%=MOD; } } int nCr(int x, int y) { if(y>x) return 0; int num=fact[x]; num*=invfact[y]; num%=MOD; num*=invfact[x-y]; num%=MOD; return num; } int a, b, x; string s, t; int dp[N], pref[N]; int32_t main() { precompute(); IOS; cin >> s >> t; cin >> x; for(int i = 0; i < s.length(); i ++) { if(s[i] == t[i]) a++; else b++; } for(int i = 0; i <= b; i++) { // dp[i] = no.of changes to b such that i of them are involving changing both // = bCi * 24^i * 2^(b-i) int ways = nCr(b, i) * pow(24, i, MOD); ways %= MOD; ways *= pow(2, b - i, MOD); ways %= MOD; dp[i] = ways; if(i == 0) pref[0] = dp[0]; else { pref[i] = pref[i - 1] + dp[i]; pref[i] %= MOD; } } for(int i = b + 1; i < N; i++) pref[i] = pref[i - 1]; int ans = 0; for(int i = 0; 2 * i + b <= x && i <= a; i++) { // 2*i operators to the same characters // 25^i * aCi int ways = pow(25, i, MOD) * nCr(a, i); ways %= MOD; int gg = x - b - 2 * i; // max no. of changes to b where u change both of them ways *= pref[gg]; ways %= MOD; ans += ways; ans %= MOD; } cout << ans << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100000 S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input ABAAABBBAA Sample Output 3 Explanation: Substring from character 3-5 is the longest consisting of As only. Sample Input AAAA Sample Output 4, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String st = br.readLine(); int len = 0; int c=0; for(int i=0;i<st.length();i++){ if(st.charAt(i)=='A'){ c++; len = Math.max(len,c); }else{ c=0; } } System.out.println(len); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100000 S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input ABAAABBBAA Sample Output 3 Explanation: Substring from character 3-5 is the longest consisting of As only. Sample Input AAAA Sample Output 4, I have written this Solution Code: S=input() max=0 flag=0 for i in range(0,len(S)): if(S[i]=='A' or S[i]=='B'): if(S[i]=='A'): flag+=1 if(flag>max): max=flag else: flag=0 print(max), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S consisting of characters 'A' or 'B' only, you need to find the maximum length of substring consisting of character 'A' only.The first and the only line of input contains the string S. Constraints 1 <= |S| <= 100000 S consists of characters 'A' or 'B' only.Output a single integer, the answer to the problem.Sample Input ABAAABBBAA Sample Output 3 Explanation: Substring from character 3-5 is the longest consisting of As only. Sample Input AAAA Sample Output 4, 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(){ string s; cin>>s; int ct = 0; int ans = 0; for(char c: s){ if(c == 'A') ct++; else ct=0; ans = max(ans, ct); } cout<<ans; } signed main() { fast #ifdef SWAPNIL07 freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--){ solve(); cout<<"\n"; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are two number a and b are given as input. Print common digits with common index in these numbers seperated by space.There are two number a and b are given as input. <b>Constraints</b> 1 <= a, b <= 10<sup>6</sup>Print common digits with common index in these numbers seperated by space.Sample Input: 24324345 3546434 Sample Output: 4 3 4, I have written this Solution Code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); String s1=Integer.toString(a); String s2=Integer.toString(b); int m=Math.min(s1.length(), s2.length()); for(int i=0;i<m;i++){ if(s1.charAt(i)==s2.charAt(i)){ System.out.print(s1.charAt(i)); System.out.print(" "); } } System.out.println(""); return; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable