Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char str[] = br.readLine().toCharArray(); int ans = 0; char arr[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; Set<String> set = new HashSet<>(); for(int i=0;i<str.length;i++){ char p = str[i]; for(char ch:arr){ if(ch==p) continue; str[i] = ch; if(isPallindrome(str)){ if(set.contains(String.valueOf(str))==false){ set.add(String.valueOf(str)); ans++; } } str[i] = p; } } System.out.println(ans); } static boolean isPallindrome(char[] str){ int i = 0; int j = str.length-1; while(i<j){ if(str[i]!=str[j]) return false; i++; j--; } return true; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: n=input() n=list(n) ln=len(n) cnt=0 for i in range(ln//2): if not(n[i]==n[ln-i-1]): cnt+=1 if(cnt==1): print(2) elif(cnt==0 and ln%2==1): print(25) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <i>s</i> consisting of lowercase English letters. Find the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter.The first and single line contains string <i>s</i> (1 &le; |<i>s</i>| &le; 10).Print the number of different palindromes you can make by changing <b>exactly</b> one charecter from the string to some other lowercase English letter. Sample Input 1 abbb Sample Output 1 2 Explanation: The possible palindromes are: 1. abba 2. bbbb ======================================================================== Sample Input 2 abba Sample Output 2 0 , I have written this Solution Code: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n' #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define sz(x) ((ll)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x = min(x,y) #define maxi(x,y) x = max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(0, 1e9); // DEBUG FUNCTIONS START void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void deb() {cerr << "\n";} template <typename T, typename... V> void deb(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; deb(v...);} // DEBUG FUNCTIONS END const int N = 2e5 + 5; void solve(){ string s; cin >> s; int n = sz(s); int x = 0; rep(i, 0, n / 2){ x += s[i] != s[n - 1 - i]; } if(x == 1){ cout << 2 << endl; } else if(x > 1){ cout << 0 << endl; } else{ if(n & 1){ cout << 25 << endl; } else{ cout << 0 << endl; } } } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e) { System.out.println(a); System.out.println(b); System.out.printf("%.2f",c); System.out.println(); System.out.printf("%.4f",d); System.out.println(); System.out.println(e); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){ cout<<a<<endl; cout<<b<<endl; cout <<fixed<< std::setprecision(2) << c << '\n'; cout <<fixed<< std::setprecision(4) << d << '\n'; cout<<e<<endl; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Some Data types are given below:- Integer Long float Double char Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input. Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:- 2 2312351235 1.21 543.1321 c Sample Output:- 2 2312351235 1.21 543.1321 c, I have written this Solution Code: a=int(input()) b=int(input()) x=float(input()) g = "{:.2f}".format(x) d=float(input()) e = "{:.4f}".format(d) u=input() print(a) print(b) print(g) print(e) print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer value N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3.The first line contains integer T, denoting number of test cases. Then T test cases follow. The only line of each test case contains an integer N. Constraints : 1 <= T <= 100000 1 <= N <= 1000000000For each testcase, in a new line, print the answer of each test case.Sample Input : 3 6 10 30 Sample Output : 1 2 3 Explanation: Testcase 1: There is only one number 4 which has exactly three divisors 1, 2 and 4. Testcase 2: 4 and 9 are the only two numbers less than or equal to 10 that have exactly three divisors. Testcase 3: 4, 9, 25 are the only numbers less than or equal to 30 that have exactly three divisors., I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define max1 100001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ fast(); vector<int> v; int x=100000; int a[x+5]; bool b[x+5]; for(int i=0;i<x+5;i++){ a[i]=0; b[i]=false; } for(int i=2;i<x+5;i++){ if(b[i]==false){ for(int j=i+i;j<x+5;j+=i){ b[j]=true; }} } int cnt=0; for(int i=2;i<=x;i++){ if(b[i]==false){cnt++;} a[i]=cnt; } int t; cin>>t; while(t--){ int n; cin>>n; int p=sqrt(n); out(a[p]); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alexa's house has only one socket. Alexa wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum number of power strips required.The input consists of two space separated integers. A B <b>Constraints</b> All values in input are integers. 2&le;A&le;20 1&le;B&le;20Print the minimum number of power strips required.<b>Sample Input 1</b> 4 10 <b>Sample Output 1</b> 3 <b>Sample Input 2</b> 8 9 <b>Sample Output 2</b> 2 <b>Sample Input 3</b> 8 8 <b>Sample Output 3</b> 1, I have written this Solution Code: #include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; const int MOD=1000000007; int main(){ int a,b;cin>>a>>b;b--; a--; cout<<(b+a-1)/a<<endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int M=sc.nextInt(); int N=sc.nextInt(); for(int col=0;col<N;col++){ System.out.print("*"); } System.out.println(); for(int row=0;row<M-2;row++){ System.out.print("*"); for(int col=0;col<N-2;col++){ System.out.print(" "); } System.out.print("*"); System.out.println(); } for(int col=0;col<N;col++){ System.out.print("*"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: li = list(map(int,input().strip().split())) m=li[0] n=li[1] for i in range(0,n): if i==n-1: print("*",end="\n") else: print("*",end="") for i in range(1,m-1): print("*",end="") for j in range(0,n-2): print(" ",end="") print("*",end="\n") for i in range(0,n): print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int m,n; cin>>m>>n; for(int i=0;i<n;i++){ cout<<'*'; } cout<<endl; m-=2; while(m--){ cout<<'*'; for(int i=0;i<n-2;i++){ cout<<' '; } cout<<'*'<<endl; } for(int i=0;i<n;i++){ cout<<'*'; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle. See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>. In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input: No Input Sample Output:- * * * * * * * * * * * * * * *, I have written this Solution Code: class Solution { public static void printTriangle(){ System.out.println("*"); System.out.println("* *"); System.out.println("* * *"); System.out.println("* * * *"); System.out.println("* * * * *"); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to print the pattern of "*" in the form of the Right Angle Triangle. See the below example for clarity.Since this is a functional problem, you don't have to worry about the input. It will be handled by driver code. You just have to complete <b>printTriangle()</b>. In the custom input area, you can provide any positive integer and check whether your code is working or not.Print the right angle triangle of height 5 as shown.Sample Input: No Input Sample Output:- * * * * * * * * * * * * * * *, I have written this Solution Code: j=1 for i in range(0,5): for k in range(0,j): print("*",end=" ") if(j<=4): print() j=j+1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: static int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: def Phone(N,K,M): if N*K < M : return -1 x = M//K if M%K!=0: x=x+1 return x, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Hi, it's Monica! Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle. Constraints 1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input 3 Sample Output Yes Sample Input 10 Sample Output No, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Cf cf = new Cf(); cf.solve(); } static class Cf { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int mod = (int)1e9+7; public void solve() { int t = in.readInt(); if(t>=6) { out.printLine("No"); }else { out.printLine("Yes"); } } public long findPower(long x,long n) { long ans = 1; long nn = n; while(nn>0) { if(nn%2==1) { ans = (ans*x) % mod; nn-=1; }else { x = (x*x)%mod; nn/=2; } } return ans%mod; } public static int log2(int x) { return (int) (Math.log(x) / Math.log(2)); } private static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { 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 String readString() { 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 double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { 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 boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } private static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } writer.flush(); } public void printLine(Object... objects) { print(objects); writer.println(); writer.flush(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Hi, it's Monica! Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle. Constraints 1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input 3 Sample Output Yes Sample Input 10 Sample Output No, 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(); ////////////// template<class C> void mini(C&a4, C b4){a4=min(a4,b4);} typedef unsigned long long ull; 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 mod 1000000007ll #define pii pair<int,int> ///////////// signed main(){ #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; if(n<6) cout<<"Yes"; else cout<<"No"; #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: Hi, it's Monica! Monica looks at her FRIENDS circle and wonders if her circle is bigger than yours. Please let her know if her friends' circle is bigger than yours, given she has a friends' circle of size 6.The first and the only line of input contains a single integer N, the size of your friends' circle. Constraints 1 <= N <= 10Output "Yes" if the size of Monica's friends circle has more friends than yours, else output "No".Sample Input 3 Sample Output Yes Sample Input 10 Sample Output No, I have written this Solution Code: n=int(input()) if(n>=6): print("No") else: print("Yes"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) { FastReader sc= new FastReader(); String str= sc.nextLine(); String a="Apple"; if(a.equals(str)){ System.out.println("Gravity"); } else{ System.out.println("Space"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif //-----------------------------------------------------------------------------------------------------------// string S; cin>>S; if(S=="Apple") { cout<<"Gravity"<<endl; } else { cout<<"Space"<<endl; } //-----------------------------------------------------------------------------------------------------------// return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: n=input() if n=='Apple':print('Gravity') else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples. <b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. 1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT: 1 2 3 4 OUTPUT: 14 Explanation: Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int m1,a1,m2,a2; cin >> m1 >> a1 >> m2 >> a2; cout << (m1*a1)+(m2*a2) << endl; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: n=int(input()) for i in range(1,n+1): if i%3==0 and i%5==0: print("NewtonSchool",end=" ") elif i%3==0: print("Newton",end=" ") elif i%5==0: print("School",end=" ") else: print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each i (1 < = i < = N), you have to print the number except :- For each multiple of 3, print "Newton" instead of the number. For each multiple of 5, print "School" instead of the number. For numbers that are multiples of both 3 and 5, print "NewtonSchool" instead of the number.The first line of the input contains N. <b>Constraints</b> 1 < = N < = 1000 Print N space separated number or Newton School according to the condition.Sample Input:- 3 Sample Output:- 1 2 Newton Sample Input:- 5 Sample Output:- 1 2 Newton 4 School, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { static void NewtonSchool(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){System.out.print("NewtonSchool ");} else if(i%5==0){System.out.print("School ");} else if(i%3==0){System.out.print("Newton ");} else{System.out.print(i+" ");} } } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int x= sc.nextInt(); NewtonSchool(x); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:- T<sup>°F</sup> = T<sup>°C</sup> × 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter. <b>Constraints</b> -10^3 <= C <= 10^3 <b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input : 25 Sample Output: 77 Sample Input:- -40 Sample Output:- -40, I have written this Solution Code: def CelsiusToFahrenheit(C): F = int((C * 1.8) + 32) return F , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a temperature C in Celsius, your task is to convert it into Fahrenheit using the following equation:- T<sup>°F</sup> = T<sup>°C</sup> × 9/5 + 32<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>CelsiusToFahrenheit()</b> that takes the integer C parameter. <b>Constraints</b> -10^3 <= C <= 10^3 <b>Note:</b> It is guaranteed that C will be a multiple of 5.Return a integer containing converted temperature in Fahrenheit.Sample Input : 25 Sample Output: 77 Sample Input:- -40 Sample Output:- -40, I have written this Solution Code: static int CelsiusToFahrenheit(int c){ return 9*(c/5) + 32; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length. <b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter <b>Constraints:-</b> 1 <= R <= 100 Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:- 9 ( Sample Output:- 4 Sample Input:- 9 ) Sample Output:- -5, I have written this Solution Code: static int focal_length(int R, char Mirror) { int f=R/2; if((R%2==1) && Mirror==')'){f++;} if(Mirror == ')'){f=-f;} return f; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length. <b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter <b>Constraints:-</b> 1 <= R <= 100 Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:- 9 ( Sample Output:- 4 Sample Input:- 9 ) Sample Output:- -5, I have written this Solution Code: int focal_length(int R, char Mirror) { int f=R/2; if((R&1) && Mirror==')'){f++;} if(Mirror == ')'){f=-f;} return f; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length. <b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter <b>Constraints:-</b> 1 <= R <= 100 Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:- 9 ( Sample Output:- 4 Sample Input:- 9 ) Sample Output:- -5, I have written this Solution Code: int focal_length(int R, char Mirror) { int f=R/2; if((R&1) && Mirror==')'){f++;} if(Mirror == ')'){f=-f;} return f; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length. <b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<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>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter <b>Constraints:-</b> 1 <= R <= 100 Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:- 9 ( Sample Output:- 4 Sample Input:- 9 ) Sample Output:- -5, I have written this Solution Code: def focal_length(R,Mirror): f=R/2; if(Mirror == ')'): f=-f if R%2==1: f=f-1 return int(f) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int M=sc.nextInt(); int N=sc.nextInt(); for(int col=0;col<N;col++){ System.out.print("*"); } System.out.println(); for(int row=0;row<M-2;row++){ System.out.print("*"); for(int col=0;col<N-2;col++){ System.out.print(" "); } System.out.print("*"); System.out.println(); } for(int col=0;col<N;col++){ System.out.print("*"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: li = list(map(int,input().strip().split())) m=li[0] n=li[1] for i in range(0,n): if i==n-1: print("*",end="\n") else: print("*",end="") for i in range(1,m-1): print("*",end="") for j in range(0,n-2): print(" ",end="") print("*",end="\n") for i in range(0,n): print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Give integer values M and N. Using the character ‘*’ draw a rectangle of height M and breadth N.The input contains two integers M and N. Constraints:- 3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:- 3 3 Sample Output:- *** * * *** Sample Input:- 5 3 Sample Output:- *** * * * * * * ***, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int m,n; cin>>m>>n; for(int i=0;i<n;i++){ cout<<'*'; } cout<<endl; m-=2; while(m--){ cout<<'*'; for(int i=0;i<n-2;i++){ cout<<' '; } cout<<'*'<<endl; } for(int i=0;i<n;i++){ cout<<'*'; } }, 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 positive integers and a number K. The task is to find the kth largest element in the array. Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= arr[i] <= 10^5 1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input: 2 5 3 3 5 4 2 9 5 5 4 3 7 6 5 Sample Output: 4 3 Explanation: Testcase 1: Third largest element in the array is 4. Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { Reader sc = new Reader(); int t = sc.nextInt(); while(t!=0) { int n= sc.nextInt(); int k=sc.nextInt(); int arr[]= new int[n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); System.out.println(findKthLargest(arr,k)); t--; } } public static int largestEle(int []arr,int k) { PriorityQueue<Integer> pq= new PriorityQueue<>(Collections.reverseOrder ()); for(int i=0;i<arr.length;i++) { pq.offer(arr[i]); } for(int i=0;i<k-1;i++) { pq.poll(); } return pq.peek(); } public static int findKthLargest(int[] nums, int k) { int start = 0, end = nums.length - 1, index = nums.length - k; while (start < end) { int pivot = partion(nums, start, end); if (pivot < index) start = pivot + 1; else if (pivot > index) end = pivot - 1; else return nums[pivot]; } return nums[start]; } private static int partion(int[] nums, int start, int end) { int pivot = start, temp; while (start <= end) { while (start <= end && nums[start] <= nums[pivot]) start++; while (start <= end && nums[end] > nums[pivot]) end--; if (start > end) break; temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; } temp = nums[end]; nums[end] = nums[pivot]; nums[pivot] = temp; return end; } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }, 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 positive integers and a number K. The task is to find the kth largest element in the array. Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= arr[i] <= 10^5 1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input: 2 5 3 3 5 4 2 9 5 5 4 3 7 6 5 Sample Output: 4 3 Explanation: Testcase 1: Third largest element in the array is 4. Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code: t=int(input()) while t>0: t-=1 n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort(reverse=True) print(arr[k-1]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array arr[] of N positive integers and a number K. The task is to find the kth largest element in the array. Note: DO NOT USE sort() stl.First line of input contains number of testcases. For each testcase, there will be a single line of input containing number of elements in the array and K. Next line contains N elements. Constraints: 1 <= T <= 100 1 <= N <= 10^4 1 <= arr[i] <= 10^5 1 <= K <= NFor each testcase, print a single line of output containing the kth largest element in the array.Sample Input: 2 5 3 3 5 4 2 9 5 5 4 3 7 6 5 Sample Output: 4 3 Explanation: Testcase 1: Third largest element in the array is 4. Testcase 2: Fifth largest element in the array is 3., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i];} sort(a,a+n); cout<<a[n-k]<<endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import static java.lang.System.out; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader reader = new FastReader(); int n = reader.nextInt(); String S = reader.next(); int ncount = 0; int tcount = 0; for (char c : S.toCharArray()) { if (c == 'N') ncount++; else tcount++; } if (ncount > tcount) { out.print("Nutan\n"); } else { out.print("Tusla\n"); } out.flush(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: n = int(input()) s = input() a1 = s.count('N') a2 = s.count('T') if(a1 > a2): print("Nutan") else: print('Tusla'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan and Tusla are both students at Newton School. They are both among the best students in the class. In order to know who is better among them, a game was organised. The game consisted of L rounds, where L is an odd integer. The student winning more rounds than the other was declared the winner. You would be given a string of odd length L in which each character is 'N' or 'T'. If the i<sup>th</sup> character is 'N', then the i<sup>th</sup> round was won by Nutan, else if the character is 'T' it was won by Tusla. Print "Nutan'' if Nutan has won more rounds than Tusla, else print "Tusla'' if Tusla has won more rounds than Nutan. Note: You have to print everything without quotes.The first line of the input contains a single integer L — the number of rounds (1 &le; L &le; 100 and L is odd). The second line contains a string S of length L. Each character of S is either 'N' or 'T'.Print "Nutan" or "Tusla" according to the input.Sample Input: 3 NNT Sample Output: Nutan Explanation: Nutan has won two games while Tusla has only won a single game, so the overall winner is Nutan., I have written this Solution Code: //Author: Xzirium //Time and Date: 02:18:28 24 March 2022 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll b, ll e) { ll r = 1ll; for(; e > 0; e /= 2, (b *= b) %= MOD) if(e % 2) (r *= b) %= MOD; return r; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //-----------------------------------------------------------------------------------------------------------// READV(N); string S; cin>>S; ll n=0,t=0; FORI(i,0,N) { if(S[i]=='N') { n++; } else if(S[i]=='T') { t++; } } if(n>t) { cout<<"Nutan"<<endl; } else { cout<<"Tusla"<<endl; } //-----------------------------------------------------------------------------------------------------------// 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 N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array. Next line denotes N space-separated array elements. Constraints: 2 <= N <= 100000 0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input 4 0 2 5 7 Sample Output 2 Explanation: 0 xor 2 = 2 Sample Input 4 0 4 7 9 Sample Output 3, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) { int ans = 0; int mini = Integer.MAX_VALUE; Scanner sc = new Scanner(System.in); int array_size = sc.nextInt(); int N[] = new int[array_size]; for (int i = 0; i < array_size; i++) { if(mini == 0){ break; } N[i] = sc.nextInt(); for (int j = i - 1; j >= 0; j--) { ans = N[i] ^ N[j]; if (mini > ans) { mini = ans; } } } System.out.println(mini); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array. Next line denotes N space-separated array elements. Constraints: 2 <= N <= 100000 0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input 4 0 2 5 7 Sample Output 2 Explanation: 0 xor 2 = 2 Sample Input 4 0 4 7 9 Sample Output 3, I have written this Solution Code: a=int(input()) lis = list(map(int,input().split())) val=666666789 for i in range(a+1): for j in range(i+1,a): temp = lis[i]^lis[j] if(temp<val): val = temp if(val==0): break print(val), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer array A of N integers, find the pair of integers in the array which have minimum XOR value. Report the minimum XOR value.First line denotes N, the size of the array. Next line denotes N space-separated array elements. Constraints: 2 <= N <= 100000 0 <= A[i] <= 10^7Print a single integer denoting minimum xor valueSample Input 4 0 2 5 7 Sample Output 2 Explanation: 0 xor 2 = 2 Sample Input 4 0 4 7 9 Sample Output 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; // Function to find minimum XOR pair int minXOR(int arr[], int n) { // Sort given array sort(arr, arr + n); int minXor = INT_MAX; int val = 0; // calculate min xor of consecutive pairs for (int i = 0; i < n - 1; i++) { val = arr[i] ^ arr[i + 1]; minXor = min(minXor, val); } return minXor; } // Driver program int main() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } cout << minXOR(arr, n) << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: static int Phone(int n, int k, int m){ if(n*k<m){ return -1; } int x = m/k; if(m%k!=0){x++;} return x; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara's Phone has N apps and each app takes K unit of memory. Now Sara wants to release M units of memory. Your task is to tell the minimum apps Sara needs to delete or say it is not possible.<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>Phone()</b> that takes integers N, K, and M as arguments. Constraints:- 1 <= N <= 1000 1 <= K <= 100 0 <= M <= 10000Return minimum apps to delete and if it is not possible return -1.Sample Input:- 10 3 10 Sample Output:- 4 Sample Input:- 10 3 40 Sample Output:- -1, I have written this Solution Code: def Phone(N,K,M): if N*K < M : return -1 x = M//K if M%K!=0: x=x+1 return x, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments. Constraints:- 1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:- 8 2 5 3 Sample Output:- 1 Explanation:- Natsu's attack:- A = 5, B = 2, C = 5, D = 3 Dragon's attack:- A = 5, B = 2, C = 3, D =3 Natsu's attack:- A = 2, B =2, C = 3, D=3 Dragon's attack:- A = 2, B =2, C = 1, D=3 Natsu's attack:- A = -1, B =2, C = 1, D=3 Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){ int x = C/B; if(C%B!=0){x++;} int y = A/D; if(A%D!=0){y++;} if(x<y){return 0;} return 1; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments. Constraints:- 1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:- 8 2 5 3 Sample Output:- 1 Explanation:- Natsu's attack:- A = 5, B = 2, C = 5, D = 3 Dragon's attack:- A = 5, B = 2, C = 3, D =3 Natsu's attack:- A = 2, B =2, C = 3, D=3 Dragon's attack:- A = 2, B =2, C = 1, D=3 Natsu's attack:- A = -1, B =2, C = 1, D=3 Natsu's win, I have written this Solution Code: static int DragonSlayer(int A, int B, int C,int D){ int x = C/B; if(C%B!=0){x++;} int y = A/D; if(A%D!=0){y++;} if(x<y){return 0;} return 1; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments. Constraints:- 1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:- 8 2 5 3 Sample Output:- 1 Explanation:- Natsu's attack:- A = 5, B = 2, C = 5, D = 3 Dragon's attack:- A = 5, B = 2, C = 3, D =3 Natsu's attack:- A = 2, B =2, C = 3, D=3 Dragon's attack:- A = 2, B =2, C = 1, D=3 Natsu's attack:- A = -1, B =2, C = 1, D=3 Natsu's win, I have written this Solution Code: int DragonSlayer(int A, int B, int C,int D){ int x = C/B; if(C%B!=0){x++;} int y = A/D; if(A%D!=0){y++;} if(x<y){return 0;} return 1; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Natsu is fighting with a dragon that has A Health and B attack power and Natsu has C health and D attack power. The fight goes in turns first Natsu will attack the Dragon then Dragon will attack Natsu and this goes on. The fight will stop when either the dragon's or Natsu's health drops zero or below. Your task is to check whether Natsu will able to slay the Dragon or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>DragonSlayer()</b> that takes integers A, B, C, and D as arguments. Constraints:- 1 <= A, B, C, D <= 1000Return 0 if Dragon wins else return 1.Sample Input:- 8 2 5 3 Sample Output:- 1 Explanation:- Natsu's attack:- A = 5, B = 2, C = 5, D = 3 Dragon's attack:- A = 5, B = 2, C = 3, D =3 Natsu's attack:- A = 2, B =2, C = 3, D=3 Dragon's attack:- A = 2, B =2, C = 1, D=3 Natsu's attack:- A = -1, B =2, C = 1, D=3 Natsu's win, I have written this Solution Code: def DragonSlayer(A,B,C,D): x = C//B if(C%B!=0): x=x+1 y = A//D if(A%D!=0): y=y+1 if(x<y): return 0 return 1 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y). Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N. Constraints:- 1 <= N <= 1000000Print the minimum number of operations required.Sample Input 5 Sample Output 3 Explanation (1, 1) -> (2, 1) -> (2, 3) -> (2, 5) Sample Input 1 Sample Output 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int x = 1; int y = 1; int count = 0; while(x<n && y<n){ if(x<=y){ x = x+y; } else{ y = x+y; } count++; } if(n<100000) System.out.print(count); else System.out.print(count+1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y). Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N. Constraints:- 1 <= N <= 1000000Print the minimum number of operations required.Sample Input 5 Sample Output 3 Explanation (1, 1) -> (2, 1) -> (2, 3) -> (2, 5) Sample Input 1 Sample Output 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 int long long int count_gcd(int a, int b) { if(a==1) return b-1; if(a>b) return count_gcd(b, a); if(b%a) return b/a + count_gcd(b%a, a); else return 1e9; } int n; int32_t main() { IOS; cin>>n; if(n==1) { cout<<"0"; return 0; } int ans=1e9; for(int i=1;i<n;i++) ans=min(ans, count_gcd(i, n)); cout<<ans; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are X seats in the assembly. To form a government, an alliance should win </b> more than (X/2) (rounded down, for example, if there are 231 seats to win will require 231/2 = 115 seats) </b> seats. There are three alliances formed for the election: NDA => BJP + LJP UPA => Congress + Shiv sena Left => RJD + JDU + SP Given the number of seats won by each party, find out if it is possible for any alliance to form the government. If it is possible, then print the name of the alliance that can form the government. NOTE: it is possible that some seats are won by Independent candidates who don't belong to any party.First line will contains X, total number of seats. Next line will contain 7 integers denoting the number of seats won by BJP, LJP, Congress, Shiv sena, RJD, JDU and SP respectively. <b>Constraints</b> 1 &le; X &le; 10<sup>18</sup> sum of seats won by all party &le; XOutput "No government" if impossible, to form a government by any alliance. If possible, print the alliance's name, i. e NDA, UPA, or Left.Input: 13 2 1 1 0 4 3 0 Output: Left Explanation: NDA => BJP + LJP = 2 + 1 => 3 UPA => Congress + Shiv sena = 1 + 0 => 1 Left => RJD + JDU + SP => 4 + 3 + 0 => 7 1 seat is won by an independent candidate. To form a government, an alliance needs more than (13/2) = 6 seats. The left alliance has 7 seats. Input: 20 4 3 1 1 1 3 2 Output: No government Explanation: NDA => BJP + LJP = 4 + 3 => 7 UPA => Congress + Shiv sena = 1 + 1 => 2 Left => RJD + JDU + SP => 1 + 3 + 2 => 6 5 seats are won by independent candidates. To form a government, an alliance needs more than (20/2) = 10 seats, i.e., at least 11 seats. No alliance has that many seats., I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Long x=Long.parseLong(in.next()); Long b=Long.parseLong(in.next()); Long l=Long.parseLong(in.next()); Long c=Long.parseLong(in.next()); Long s=Long.parseLong(in.next()); Long r=Long.parseLong(in.next()); Long j=Long.parseLong(in.next()); Long sp=Long.parseLong(in.next()); long y=b+l+c+s+r+j+sp; x=x/2 + 1; if((b+l) >= x){ out.print("NDA"); } else if((c+s) >= x){ out.print("UPA"); } else if((r+j+sp) >= x){ out.print("Left"); } else{ out.print("No government"); } out.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y). Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N. Constraints:- 1 <= N <= 1000000Print the minimum number of operations required.Sample Input 5 Sample Output 3 Explanation (1, 1) -> (2, 1) -> (2, 3) -> (2, 5) Sample Input 1 Sample Output 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int x = 1; int y = 1; int count = 0; while(x<n && y<n){ if(x<=y){ x = x+y; } else{ y = x+y; } count++; } if(n<100000) System.out.print(count); else System.out.print(count+1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have two numbers X and Y in one operation you can replace either of the numbers to their sum i.e in one operation you can either have (X+Y, Y) or (X, X+Y). Find the minimum number of operations it takes to transform one of the numbers to N. Assuming initial value of X and Y are (1, 1).The input contains a single integer N. Constraints:- 1 <= N <= 1000000Print the minimum number of operations required.Sample Input 5 Sample Output 3 Explanation (1, 1) -> (2, 1) -> (2, 3) -> (2, 5) Sample Input 1 Sample Output 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 int long long int count_gcd(int a, int b) { if(a==1) return b-1; if(a>b) return count_gcd(b, a); if(b%a) return b/a + count_gcd(b%a, a); else return 1e9; } int n; int32_t main() { IOS; cin>>n; if(n==1) { cout<<"0"; return 0; } int ans=1e9; for(int i=1;i<n;i++) ans=min(ans, count_gcd(i, n)); 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 array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:- i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P. next line contains N space separated integers depicting the values of the Arr[]. Constraints:- 3 <= N <= 10<sup>5</sup> 1 <= Arr[i], P <= 10<sup>9</sup> 0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:- 5 4 1 3 2 5 9 Sample Output:- 4 Explanation:- (1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets Sample Input:- 5 3 1 8 4 2 9 Sample Output:- 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1 = br.readLine(); String str2[] = str1.split(" "); int n = Integer.parseInt(str2[0]); int k = Integer.parseInt(str2[1]); String str3 = br.readLine(); String str4[] = str3.split(" "); long[] arr = new long[n]; for(int i = 0; i < n; ++i) { arr[i] = Long.parseLong(str4[i]); } Arrays.sort(arr); int i=0,j=2; long ans=0; while(j!=n){ if(i==j-1){j++;continue;} if((arr[j]-arr[i])>k){i++;} else{ int x = j-i; ans+=(x*(x-1))/2; j++; } } System.out.print(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:- i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P. next line contains N space separated integers depicting the values of the Arr[]. Constraints:- 3 <= N <= 10<sup>5</sup> 1 <= Arr[i], P <= 10<sup>9</sup> 0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:- 5 4 1 3 2 5 9 Sample Output:- 4 Explanation:- (1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets Sample Input:- 5 3 1 8 4 2 9 Sample Output:- 1, I have written this Solution Code: n, p = input().split(' ') n = int(n) p = int(p) arr = input().split(' ')[:n] for i in range(n): arr[i] = int(arr[i]) arr.sort() i = 0 k = 2 count = 0 while k!=n: if i == k-1: k = k + 1 continue if (arr[k] - arr[i]) <= p: count = count + (int)(((k-i)*(k-i-1))/2) k = k + 1 else: i = i + 1 print(count) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:- i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P. next line contains N space separated integers depicting the values of the Arr[]. Constraints:- 3 <= N <= 10<sup>5</sup> 1 <= Arr[i], P <= 10<sup>9</sup> 0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:- 5 4 1 3 2 5 9 Sample Output:- 4 Explanation:- (1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets Sample Input:- 5 3 1 8 4 2 9 Sample Output:- 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n,p; cin>>n>>p; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); int i=0,j=2; int ans=0; while(j!=n){ if(i==j-1){j++;continue;} if((a[j]-a[i])>p){i++;} else{ int x = j-i; ans+=(x*(x-1))/2; j++; } } cout<<ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: def QueenAttack(X, Y, P, Q): if X==P or Y==Q or abs(X-P)==abs(Y-Q): return 1 return 0, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: static int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || Math.abs(X-P)==Math.abs(Y-Q) ){ return 1; } return 0; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: In an 8X8 chessboard. Given the positions of the Queen as (X, Y) and the King as (P, Q) . Your task is to check whether the queen can attack the king in one move or not. The queen is the most powerful piece in the game of chess. It can move any number of squares vertically, horizontally or diagonally .<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>QueenAttack()</b> that takes integers X, Y, P, and Q as arguments. Constraints:- 1 <= X, Y, P, Q <= 8 Note:- King and Queen can not be in the same positionReturn 1 if the king is in the check position else return 0.Sample Input:- 1 1 5 5 Sample Output:- 1 Sample Input:- 3 4 6 6 Sample Output:- 0, I have written this Solution Code: int QueenAttack(int X, int Y, int P, int Q){ if(X==P || Y==Q || abs(X-P)==abs(Y-Q) ){ return 1; } 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, Print <b>true</b> if the string can be palindrome after deleting at most one character from it, otherwise print <b>false</b>.The first line of the input contains a string s. <b>Constraints</b> 1 <= s. length() <= 1e5Print "true" if the string can be made palindromic after deleting atmost one character from it, otherwise "false".<b>Sample Input 1:</b> aba <b>Sample Output 1:</b> true <b>Explanation:</b> In the string "aba" if we remove b then we can get a palindromic string "aa" hence Output is True <b>Sample Input 2:</b> abba <b>Sample Output 2:</b> true <b>Explanation:</b> The string is already a palindrome so there is no need to remove any character hence the Output is True., I have written this Solution Code: def isPalindrome(string: str, low: int, high: int) -> bool: while low < high: if string[low] != string[high]: return False low += 1 high -= 1 return True def possiblepalinByRemovingOneChar(string: str) -> int: low = 0 high = len(string) - 1 while low < high: if string[low] == string[high]: low += 1 high -= 1 else: if isPalindrome(string, low + 1, high): return low if isPalindrome(string, low, high - 1): return high return -1 return -2 string = input() idx = possiblepalinByRemovingOneChar(string) if idx == -1: print("false") else: print("true"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string s, Print <b>true</b> if the string can be palindrome after deleting at most one character from it, otherwise print <b>false</b>.The first line of the input contains a string s. <b>Constraints</b> 1 <= s. length() <= 1e5Print "true" if the string can be made palindromic after deleting atmost one character from it, otherwise "false".<b>Sample Input 1:</b> aba <b>Sample Output 1:</b> true <b>Explanation:</b> In the string "aba" if we remove b then we can get a palindromic string "aa" hence Output is True <b>Sample Input 2:</b> abba <b>Sample Output 2:</b> true <b>Explanation:</b> The string is already a palindrome so there is no need to remove any character hence the Output is True., I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { private static boolean checkPalindrome(String s, int i, int j) { while (i < j) { if (s.charAt(i) != s.charAt(j)) { return false; } i++; j--; } return true; } public static boolean validPalindrome(String s) { int i = 0; int j = s.length() - 1; while (i < j) { // Found a mismatched pair - try both deletions if (s.charAt(i) != s.charAt(j)) { return (checkPalindrome(s, i, j - 1) || checkPalindrome(s, i + 1, j)); } i++; j--; } return true; } public static void main (String[] args) throws java.lang.Exception { BufferedReader inp = new BufferedReader (new InputStreamReader(System.in)); String str = inp.readLine(); // for taking a string as an input System.out.println(validPalindrome(str)); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static long count(int[] arr, int l, int h, int[] aux) { if (l >= h) return 0; int mid = (l +h) / 2; long count = 0; count += count(aux, l, mid, arr); count += count(aux, mid + 1, h, arr); count += merge(arr, l, mid, h, aux); return count; } static long merge(int[] arr, int l, int mid, int h, int[] aux) { long count = 0; int i = l, j = mid + 1, k = l; while (i <= mid || j <= h) { if (i > mid) { arr[k++] = aux[j++]; } else if (j > h) { arr[k++] = aux[i++]; } else if (aux[i] <= aux[j]) { arr[k++] = aux[i++]; } else { arr[k++] = aux[j++]; count += mid + 1 - i; } } return count; } public static void main (String[] args)throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); String str[]; str = br.readLine().split(" "); int n = Integer.parseInt(str[0]); str = br.readLine().split(" "); int arr[] =new int[n]; for (int j = 0; j < n; j++) { arr[j] = Integer.parseInt(str[j]); } int[] aux = arr.clone(); System.out.print(count(arr, 0, n - 1, aux)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: count=0 def implementMergeSort(arr,s,e): global count if e-s==1: return mid=(s+e)//2 implementMergeSort(arr,s,mid) implementMergeSort(arr,mid,e) count+=merge_sort_place(arr,s,mid,e) return count def merge_sort_place(arr,s,mid,e): arr3=[] i=s j=mid count=0 while i<mid and j<e: if arr[i]>arr[j]: arr3.append(arr[j]) j+=1 count+=(mid-i) else: arr3.append(arr[i]) i+=1 while (i<mid): arr3.append(arr[i]) i+=1 while (j<e): arr3.append(arr[j]) j+=1 for x in range(len(arr3)): arr[s+x]=arr3[x] return count n=int(input()) arr=list(map(int,input().split()[:n])) c=implementMergeSort(arr,0,len(arr)) print(c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Calculate inversion count of array of integers. Inversion count of an array is quantisation of how much unsorted an array is. A sorted array has inversion count 0, while an unsorted array has maximum inversion count. Formally speaking inversion count = number of pairs i, j such that i < j and a[i] > a[j].The first line contain integers N. The second line of the input contains N singly spaces integers. 1 <= N <= 100000 1 <= A[i] <= 1000000000Output one integer the inversion count.Sample Input 5 1 1 3 2 2 Sample Output 2 Sample Input 5 5 4 3 2 1 Sample Output 10, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; long long _mergeSort(long long arr[], int temp[], int left, int right); long long merge(long long arr[], int temp[], int left, int mid, int right); /* This function sorts the input array and returns the number of inversions in the array */ long long mergeSort(long long arr[], int array_size) { int temp[array_size]; return _mergeSort(arr, temp, 0, array_size - 1); } /* An auxiliary recursive function that sorts the input array and returns the number of inversions in the array. */ long long _mergeSort(long long arr[], int temp[], int left, int right) { long long mid, inv_count = 0; if (right > left) { /* Divide the array into two parts and call _mergeSortAndCountInv() for each of the parts */ mid = (right + left) / 2; /* Inversion count will be sum of inversions in left-part, right-part and number of inversions in merging */ inv_count += _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid + 1, right); /*Merge the two parts*/ inv_count += merge(arr, temp, left, mid + 1, right); } return inv_count; } /* This funt merges two sorted arrays and returns inversion count in the arrays.*/ long long merge(long long arr[], int temp[], int left, int mid, int right) { int i, j, k; long long inv_count = 0; i = left; /* i is index for left subarray*/ j = mid; /* j is index for right subarray*/ k = left; /* k is index for resultant merged subarray*/ while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; /* this is tricky -- see above explanation/diagram for merge()*/ inv_count = inv_count + (mid - i); } } /* Copy the remaining elements of left subarray (if there are any) to temp*/ while (i <= mid - 1) temp[k++] = arr[i++]; /* Copy the remaining elements of right subarray (if there are any) to temp*/ while (j <= right) temp[k++] = arr[j++]; /*Copy back the merged elements to original array*/ for (i = left; i <= right; i++) arr[i] = temp[i]; return inv_count;} int main(){ int n; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i];} long long ans = mergeSort(a, n); cout << ans; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Take an integer as input and print it.The first line contains integer as input. <b>Constraints</b> 1 <= N <= 10Print the input integer in a single lineSample Input:- 2 Sample Output:- 2 Sample Input:- 4 Sample Output:- 4, I have written this Solution Code: /* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void printVariable(int variable){ System.out.println(variable); } public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); printVariable(num); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){cout<<"FizzBuzz"<<" ";} else if(i%5==0){cout<<"Buzz ";} else if(i%3==0){cout<<"Fizz ";} else{cout<<i<<" ";} } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, 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 x= sc.nextInt(); fizzbuzz(x); } static void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){System.out.print("FizzBuzz ");} else if(i%5==0){System.out.print("Buzz ");} else if(i%3==0){System.out.print("Fizz ");} else{System.out.print(i+" ");} } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: def fizzbuzz(n): for i in range (1,n+1): if (i%3==0 and i%5==0): print("FizzBuzz",end=' ') elif i%3==0: print("Fizz",end=' ') elif i%5==0: print("Buzz",end=' ') else: print(i,end=' '), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N for each I (1 < = I < = N), you have to print the number except:- For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number.The input contains a single integer N. <b>Constraints:-</b> 1 &le; N &le; 1000Print N space separated number or Fizz buzz according to the condition.Sample Input:- 3 Sample Output:- 1 2 Fizz Sample Input:- 5 Sample Output:- 1 2 Fizz 4 Buzz, I have written this Solution Code: void fizzbuzz(int n){ for(int i=1;i<=n;i++){ if(i%3==0 && i%5==0){printf("FizzBuzz ");} else if(i%5==0){printf("Buzz ");} else if(i%3==0){printf("Fizz ");} else{printf("%d ",i);} } }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces. Constraints: 1 <= T <= 100 1 <= n, m <= 30 0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input: 4 4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 4 1 2 3 4 4 1 1 2 3 4 Output: 1 2 3 4 8 12 16 15 14 13 9 5 12 11 10 9 5 1 2 3 4 8 1 2 3 4 1 2 3 4 Explanation: Testcase1: The matrix is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5 Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8. Testcase 3: Boundary Traversal will be 1 2 3 4. Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code: def boundaryTraversal(matrix, N, M): #N = 3, M = 4 start_row = 0 start_col = 0 count = 0 if N != 1 and M != 1: total = 2 * (N - 1) + 2 * (M - 1) else: total = max(M, N) #First row for i in range(start_col, M, 1): #0,1, 2, 3 count += 1 print(matrix[start_row][i], end = " ") if count == total: return start_row += 1 #Last column for i in range(start_row, N, 1): # 1, 2 count += 1 print(matrix[i][M - 1], end = " ") if count == total: return M -= 1 #Last Row for i in range(M - 1, start_col - 1, -1): # 2, 1, 0 count += 1 print(matrix[N - 1][i], end = " ") if count == total: return #First Column N -= 1 # 2 for i in range(N - 1, start_row - 1, -1): count += 1 print(matrix[i][start_col], end = " ") start_col += 1 testcase = int(input().strip()) for test in range(testcase): dim = input().strip().split(" ") N = int(dim[0]) M = int(dim[1]) matrix = [] elements = input().strip().split(" ") #N * M start = 0 for i in range(N): matrix.append(elements[start : start + M]) # (0, M - 1) | (M, 2*m-1) start = start + M boundaryTraversal(matrix, N, M) print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix <b>A</b> of dimensions <b>n x m</b>. The task is to perform <b>boundary traversal</b> on the matrix in clockwise manner.The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase has two lines of input. The first line contains dimensions of the matrix A, n and m. The second line contains n*m elements separated by spaces. Constraints: 1 <= T <= 100 1 <= n, m <= 30 0 <= A[i][j] <= 100For each testcase, in a new line, print the boundary traversal of the matrix A.Input: 4 4 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 3 4 12 11 10 9 8 7 6 5 4 3 2 1 1 4 1 2 3 4 4 1 1 2 3 4 Output: 1 2 3 4 8 12 16 15 14 13 9 5 12 11 10 9 5 1 2 3 4 8 1 2 3 4 1 2 3 4 Explanation: Testcase1: The matrix is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The boundary traversal is 1 2 3 4 8 12 16 15 14 13 9 5 Testcase 2: Boundary Traversal will be 12 11 10 9 5 1 2 3 4 8. Testcase 3: Boundary Traversal will be 1 2 3 4. Testcase 4: Boundary Traversal will be 1 2 3 4., I have written this Solution Code: import java.io.*; import java.lang.*; import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n1 = sc.nextInt(); int m1 = sc.nextInt(); int arr1[][] = new int[n1][m1]; for(int i = 0; i < n1; i++) { for(int j = 0; j < m1; j++) arr1[i][j] = sc.nextInt(); } boundaryTraversal(n1, m1,arr1); System.out.println(); } } static void boundaryTraversal( int n1, int m1, int arr1[][]) { // base cases if(n1 == 1) { int i = 0; while(i < m1) System.out.print(arr1[0][i++] + " "); } else if(m1 == 1) { int i = 0; while(i < n1) System.out.print(arr1[i++][0]+" "); } else { // traversing the first row for(int j=0;j<m1;j++) { System.out.print(arr1[0][j]+" "); } // traversing the last column for(int j=1;j<n1;j++) { System.out.print(arr1[j][m1-1]+ " "); } // traversing the last row for(int j=m1-2;j>=0;j--) { System.out.print(arr1[n1-1][j]+" "); } // traversing the first column for(int j=n1-2;j>=1;j--) { System.out.print(arr1[j][0]+" "); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given candies of different sizes and their respective count. There are many students standing in a line. Each student is given a single candy one by one in non- decreasing order of size of candy. Given the position P of a student in the line, find the size of the candy he will receive. Print -1 if the student does not receive any candy.The first line contains two integers N and P. The second line contains N space seperated integers A<sub>i</sub>, the size of i<sup>th</sup> candy. The third line contains N space seperated integers B<sub>i</sub>, the count of i<sup>th</sup> candy. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub>, B<sub>i</sub> <= 10<sup>9</sup> 1 <= P <= 10<sup>14</sup>Find the size of the candy the student at position P will receive. If the student doesn't receive any candy, print -1.Sample Input: 5 10 1 2 3 4 5 1 2 3 4 5 Sample Output: 4, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n, p; cin >> n >> p; vector<pair<int, int>> a(n); for(auto &i : a) cin >> i.first; for(auto &i : a) cin >> i.second; sort(a.begin(), a.end()); int ans = -1; for(int i = 0; i < n; i++){ if(p <= a[i].second){ ans = a[i].first; break; } p -= a[i].second; } cout << ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a string <em>S</em> and an integer <em>A</em>. You have to check whether or not the given integer A is smaller than 3200 or not. If it's smaller, print "red", otherwise print the string S.The first line of the input contains an integer A The second line of the input contains a string S <b>Constraints:</b> 1) 2800 &le; A &le; 5000Print the output string.<b>Sample Input 1:</b> 3400 lol <b>Sample Output 1:</b> lol <b>Sample Input 2:</b> 3000 lol <b>Sample Output 2:</b> red, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int A; string S; cin >> A >> S; if(A < 3200){ cout << "red" << endl; } else{ cout << S << endl; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N cities on X-axis and you want to visit all of them. For traveling you can walk or teleport. For 1 unit walk the cost is A unit. The price is B units for teleportation from any point to any other. Find the minimum possible total cost when you visit all the cities. Initially, you are at city 1.The first line of input contains three space-separate integers N, A, B The second input line includes N distinct space-separated integers X1, X2,.....Xn which are the coordinates of the city on the X-axis. <b>Constraints:-</b> 1 <= N <= 10<sup>5</sup> 1 <= A,B <= 10^9 1 <= Xi <= 10^9 Xi < X(i+1)Print the minimum possible total cost when you visit all the cities.Sample Input : 4 2 5 1 2 5 7 Sample Output : 11 <b>Explanation:</b> From town 1, walk a distance of 1 to town 2, then teleport to town 3, then walk a distance of 2 to town 4. The total increase of your fatigue level, in this case, is 2×1 + 5 + 2×2 = 11, which is the minimum possible value., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define YES(j) cout << (j ? "YES" : "NO") << endl; #define Yes(j) std::cout << (j ? "Yes" : "No") << endl; #define yes(j) std::cout << (j ? "yes" : "no") << endl; typedef long long ll; int main(void) { #ifdef ANIKET_GOYAL freopen("inputf.in", "r", stdin); freopen("outputf.in", "w", stdout); #endif long long n, a, b; cin >> n >> a >> b; assert(1 <= n <= 100000); assert(1 <= a <= 1000000000); assert(1 <= b <= 1000000000); long long ans = 0; int pos = 0; int prev; REP(i, n) { int x; cin >> x; assert(1 <= x <= 1000000000); if (i) { if (x < prev) { cout << prev << " " << x << "\n"; return 0; } } if (i == 0) { pos = x; } else { ans += min(a * (x - pos), b); pos = x; } prev = x; } cout << ans << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N cities on X-axis and you want to visit all of them. For traveling you can walk or teleport. For 1 unit walk the cost is A unit. The price is B units for teleportation from any point to any other. Find the minimum possible total cost when you visit all the cities. Initially, you are at city 1.The first line of input contains three space-separate integers N, A, B The second input line includes N distinct space-separated integers X1, X2,.....Xn which are the coordinates of the city on the X-axis. <b>Constraints:-</b> 1 <= N <= 10<sup>5</sup> 1 <= A,B <= 10^9 1 <= Xi <= 10^9 Xi < X(i+1)Print the minimum possible total cost when you visit all the cities.Sample Input : 4 2 5 1 2 5 7 Sample Output : 11 <b>Explanation:</b> From town 1, walk a distance of 1 to town 2, then teleport to town 3, then walk a distance of 2 to town 4. The total increase of your fatigue level, in this case, is 2×1 + 5 + 2×2 = 11, which is the minimum possible value., I have written this Solution Code: import java.util.*; public class Main { public static void main (String [] args) { Scanner scan = new Scanner (System.in); int n = scan.nextInt(); int a = scan.nextInt(); int b = scan.nextInt(); int [] cities = new int [n]; // int resArr [] = new int [n]; for (int i=0; i<n; i++) { cities[i] = scan.nextInt(); } //Arrays.sort(cities); long sum =0; // if(cities[0] != 1) // { // int diffInCities = cities[0]-1; // int walkCost = a * diffInCities; // int teleportCost = b; // sum = sum + (walkCost>teleportCost?teleportCost:walkCost); // } for(int i=1; i<n; i++) { int diffInCities = cities[i]-cities[i-1]; int walkCost = a * diffInCities; int teleportCost = b; sum = sum + (walkCost>teleportCost?teleportCost:walkCost); } System.out.println(sum); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice loves coins. He gets 1000 enjoyment points for each 500 rupees coin he has and 5 enjoyment points for each 5 rupees coin he has. Alice has X rupees. How many enjoyment points can he earn from X amount? We assume that there are six kinds of coins available: 500- rupees, 100- rupees, 50- rupees, 10- rupees, 5- rupees, and 1- rupees coins.The first line contains a single integer X. Constraints: 1 <= X <=10^9 X is an integerFind the maximum enjoyment points that Alice can earn.Sample Input 1: 1024 Sample Output 1: 2020 Sample Input 2: 1000000000 Sample Output 2: 2000000000, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int count = 0; while(n > 4) { if(n >= 500) { n -= 500; count += 1000; } else if(n >= 5) { n-= 5; count += 5; } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice loves coins. He gets 1000 enjoyment points for each 500 rupees coin he has and 5 enjoyment points for each 5 rupees coin he has. Alice has X rupees. How many enjoyment points can he earn from X amount? We assume that there are six kinds of coins available: 500- rupees, 100- rupees, 50- rupees, 10- rupees, 5- rupees, and 1- rupees coins.The first line contains a single integer X. Constraints: 1 <= X <=10^9 X is an integerFind the maximum enjoyment points that Alice can earn.Sample Input 1: 1024 Sample Output 1: 2020 Sample Input 2: 1000000000 Sample Output 2: 2000000000, I have written this Solution Code: X=int(input()) Y=X//500 Y=Y*1000 Z=X%500 Z=Z//5 Z=Z*5 print(Y+Z), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Alice loves coins. He gets 1000 enjoyment points for each 500 rupees coin he has and 5 enjoyment points for each 5 rupees coin he has. Alice has X rupees. How many enjoyment points can he earn from X amount? We assume that there are six kinds of coins available: 500- rupees, 100- rupees, 50- rupees, 10- rupees, 5- rupees, and 1- rupees coins.The first line contains a single integer X. Constraints: 1 <= X <=10^9 X is an integerFind the maximum enjoyment points that Alice can earn.Sample Input 1: 1024 Sample Output 1: 2020 Sample Input 2: 1000000000 Sample Output 2: 2000000000, I have written this Solution Code: #include <iostream> using namespace std; int X; int a, b, r; int main() { cin >> X; a = X / 500; r = X % 500; if(r == 0){ cout << (1000 * a) << endl; }else{ b = r / 5; cout << (1000 * a) + (5 * b); } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary. Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N. Next N lines contains two integers x[i] and y[i]. Constraints: 2 <= N <= 100000 0 <= x[i], y[i] <= 1000000000 Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input 2 0 0 1 1 Sample Output 1 Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE; int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE; for(int i = 0; i < N; i++) { StringTokenizer tokens = new StringTokenizer(reader.readLine()); int x = Integer.parseInt(tokens.nextToken()); int y = Integer.parseInt(tokens.nextToken()); minX = Math.min(minX, x); maxX = Math.max(maxX, x); minY = Math.min(minY, y); maxY = Math.max(maxY, y); } long X = maxX - minX; long Y = maxY - minY; long area = X * Y; System.out.println(X * Y); reader.close(); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary. Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N. Next N lines contains two integers x[i] and y[i]. Constraints: 2 <= N <= 100000 0 <= x[i], y[i] <= 1000000000 Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input 2 0 0 1 1 Sample Output 1 Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), I have written this Solution Code: minx = 1000000000 maxx= 0 miny=1000000000 maxy=0 n = int(input()) while(n): a,b = map(int,input().split()) minx = min(minx,a); maxx = max(maxx,a); miny = min(miny,b); maxy = max(maxy,b); n -=1 l = (maxx-minx); b = (maxy-miny); print(l*b), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N coordinates on a two dimensional plane. Find the area of the smallest rectangle such that all the points can lie inside or on the rectangle boundary. Note - the sides of rectangle should be parallel to x and y axis.First line of input contains N. Next N lines contains two integers x[i] and y[i]. Constraints: 2 <= N <= 100000 0 <= x[i], y[i] <= 1000000000 Note the required rectangle will never have 0 area.Print the area of the smallest rectangle such that all the points can lie inside or on the rectangle the boundary.Sample Input 2 0 0 1 1 Sample Output 1 Explanation: required rectangle has corners at (0, 0) (0, 1) (1, 1) (1, 0), I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int mix=infi,maax=0; int miy=infi,may=0; for(int i=0;i<n;++i){ int x,y; cin>>x>>y; mix=min(mix,x); miy=min(miy,y); maax=max(maax,x); may=max(may,y); } cout<<(maax-mix)*(may-miy); #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: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static boolean isArrangementPossible(long arr[],int n,long sum){ if(n==1){ if(arr[0]==sum) return true; else return false; } return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1])); } public static void main (String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str1[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str1[0]); long sum=Long.parseLong(str1[1]); String str[]=br.readLine().trim().split(" "); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=Long.parseLong(str[i]); } if(isArrangementPossible(arr,n,sum)){ System.out.println("YES"); }else{ System.out.println("NO"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum): if i == len(nums): if currSum == targetSum: return 1 return 0 if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)): return 1 return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum) n,k = map(int,input().split()) nums = list(map(int,input().split())) if(checkIfGivenTargetIsPossible(nums,0,0,k)): 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 a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #define int long long int k; using namespace std; int solve(int n, int a[], int i, int curr ){ if(i==n){ if(curr==k){return 1;} return 0; } if(solve(n,a,i+1,curr+a[i])==1){return 1;} return solve(n,a,i+1,curr-a[i]); } signed main() { int n; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } if(solve(n,a,1,a[0])){ cout<<"YES";} else{ cout<<"NO";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array A of size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out= new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t>0){ t-=1; int n=Integer.parseInt(br.readLine()); String s[]=br.readLine().split(" "); int arr[]=new int[n]; int zero_counter=0,one_counter=0,two_counter=0; for(int i=0;i<n;i++){ arr[i]=Integer.parseInt(s[i]); if(arr[i]==0) zero_counter+=1; else if(arr[i]==1) one_counter+=1; else two_counter+=1; } for(int i=0;i<zero_counter;i++){ out.print(0+" "); } for(int i=0;i<one_counter;i++){ out.print(1+" "); } for(int i=0;i<two_counter;i++){ out.print(2+" "); } out.flush(); out.println(" "); } out.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 size N containing 0's, 1's and 2's. The task is to segregate the 0's, 1's and 2's in the array as all the 0's should appear in the first part of the array, 1's should appear in middle part of the array and finally all the 2's in the remaining part of the array. Note: Do not use inbuilt sort function. Try to solve in O(N) per test caseThe first line contains an integer T denoting the total number of test cases. Then T testcases follow. Each testcases contains two lines of input. The first line denotes the size of the array N. The second lines contains the elements of the array A separated by spaces. Constraints: 1 <= T <= 100 1 <= N <= 100000 0 <= Ai <= 2 Sum of N for each test case does not exceed 10^5For each testcase, in a newline, print the sorted array.Input : 2 5 0 2 1 2 0 3 0 1 0 Output: 0 0 1 2 2 0 0 1 Explanation: Testcase 1: After segragating the 0s, 1s and 2s, we have 0 0 1 2 2 which shown in the output. Testcase 2: For the given array input, output will be 0 0 1., I have written this Solution Code: t=int(input()) while t>0: t-=1 n=input() a=map(int,input().split()) z=o=tc=0 for i in a: if i==0:z+=1 elif i==1:o+=1 else:tc+=1 while z>0: z-=1 print(0,end=' ') while o>0: o-=1 print(1,end=' ') while tc>0: tc-=1 print(2,end=' ') print(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable