Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: You have to write 4 classes as BubbleSort, InsertionSort, MergeSort and SelectionSort, and each of should implement following interface: <code> interface ISort{ public int[] sort(int[] arr); } </code> Each class should be defined as: Implement sort in each class with respective method, after sorting return sorted array.You don't have to take any input, you have to write classes mentioned in question which implements ISort.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Test: BubbleSort bubbleSort = new BubbleSort(); arr = bubbleSort.sort(arr); if(arr.isSorted()) System.out.println("Correct"); else System.out.println("Wrong"); Sample Output: Correct, I have written this Solution Code: class BubbleSort implements ISort{ public int[] sort(int[] arr){ int n = arr.length; int temp = 0; for(int i=0; i < n; i++){ for(int j=1; j < (n-i); j++){ if(arr[j-1] > arr[j]){ temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp; } } } return arr; } } class InsertionSort implements ISort{ public int[] sort(int[] arr){ int n = arr.length; for (int i = 1; i < n; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } return arr; } } class MergeSort implements ISort{ void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void sort(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort(arr, l, m); sort(arr , m+1, r); merge(arr, l, m, r); } } public int[] sort(int[] arr){ int n=arr.length; sort(arr,0,n-1); return arr; } } class SelectionSort implements ISort{ public int[] sort(int[] arr){ for (int i = 0; i < arr.length - 1; i++) { int index = i; for (int j = i + 1; j < arr.length; j++){ if (arr[j] < arr[index]){ index = j;//searching for lowest index } } int smallerNumber = arr[index]; arr[index] = arr[i]; arr[i] = smallerNumber; } return arr; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input()) bSum=0 wSum=0 for i in range(n): c=(input().split()) for j in range(len(c)): if(i%2==0): if(j%2==0): bSum+=int(c[j]) else: wSum+=int(c[j]) else: if(j%2==0): wSum+=int(c[j]) else: bSum+=int(c[j]) print(bSum) print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int mat[][] = new int[N][N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) mat[i][j] = sc.nextInt(); } alternate_Matrix_Sum(mat,N); } static void alternate_Matrix_Sum(int mat[][], int N) { long sum =0, sum1 = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if((i+j)%2 == 0) sum += mat[i][j]; else sum1 += mat[i][j]; } } System.out.println(sum); System.out.print(sum1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: #include <iostream> using namespace std; int Dishes(int N, int T){ return T-N; } int main(){ int n,k; scanf("%d%d",&n,&k); printf("%d",Dishes(n,k)); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sheldon and Leonard are gone for lunch but none of them have money so they decided to wash dishes. In total, they washed T dishes from which N dishes are washed by Leonard. Now Leonard wants to know the number of dishes Sheldon washed. Help him to find it.The first line of the input contains N and T Constraints:- 1 <= N <= T <= 1000Return the number of dishes Sheldon washed.Sample Input:- 3 6 Sample Output:- 3 Sample Input:- 2 4 Sample Output:- 2, I have written this Solution Code: nan, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: void magicTrick(int a, int b){ cout<<a+b/2; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: static void magicTrick(int a, int b){ System.out.println(a + b/2); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is trying a new magic trick on you, The magic trick goes in 6 steps:- 1. Think of a number X(don't tell Sara) 2. Add A(Given by Sara) to it. 3. Double the sum in your mind. 4. Add an even number B(Given by Sara) to it. 5. Half the amount 6. Subtract the initial number which you had taken from the sum After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her? <b>Note: B is always even. </b>You don't have to worry about the input, you just have to complete the function <b>magicTrick()</b> <b>Constraints</b>:- 1 <= A, B <= 1000Print the resulting amountSample Input:- 3 4 Sample Output:- 5 Sample Input:- 8 4 Sample Output:- 10, I have written this Solution Code: A,B = map(int,input().split(' ')) C = A+B//2 print(C) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N such that no digit of N is 0, find minimum numbers of digits that need to be removed from N such that N becomes divisible by 3. Note: if all the digits of N needs to removed report -1.Input contains a single integer N. Constraints: 1 <= N <= 10^18 No digit of N is 0.Print the minimum number of digits that needs to removed to make N divisible by 3. Note: if all the digits of N needs to removed report -1.Sample Input 1 35 Sample Output 1 1 Explanation: we remove 5 from 35 making it 3. Sample Input 2 44 Sample Output 2 -1 Explanation: As we have to remove all digits we report -1., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader s=new BufferedReader(new InputStreamReader(System.in)); String S=s.readLine(); int arr[]=new int[3]; for(int i=0;i<3;i++){ arr[i]=0; } int sum=0; for(int i=0;i<S.length();i++){ sum+=(int)S.charAt(i); int num=(int)S.charAt(i); int rem=num%3; if(rem==0){ arr[0]++; } if(rem==1){ arr[1]++; } if(rem==2){ arr[2]++; } } int cnt=S.length(); if(sum % 3 == 0) { System.out.println("0"); } else if(sum % 3 == 1) { if(arr[1]>=1 && cnt > 1) { System.out.println("1"); } else if(arr[2] >= 2 && cnt > 2) { System.out.println("2"); } else { System.out.println("-1"); } } else if(sum % 3 == 2) { if(arr[2]>=1 && cnt > 1) { System.out.println("1"); } else if(arr[1] >= 2 && cnt > 2) { System.out.println("2"); } else { System.out.println("-1"); } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N such that no digit of N is 0, find minimum numbers of digits that need to be removed from N such that N becomes divisible by 3. Note: if all the digits of N needs to removed report -1.Input contains a single integer N. Constraints: 1 <= N <= 10^18 No digit of N is 0.Print the minimum number of digits that needs to removed to make N divisible by 3. Note: if all the digits of N needs to removed report -1.Sample Input 1 35 Sample Output 1 1 Explanation: we remove 5 from 35 making it 3. Sample Input 2 44 Sample Output 2 -1 Explanation: As we have to remove all digits we report -1., I have written this Solution Code: number = input() def divisible(num): n = len(num) sum_ = 0 for i in range(n): sum_ += int(num[i]) if (sum_ % 3 == 0): return 0 if (n == 1): return -1 for i in range(n): if (sum_ % 3 == int(num[i]) % 3): return 1 if (n == 2): return -1 return 2 print(divisible(number)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N such that no digit of N is 0, find minimum numbers of digits that need to be removed from N such that N becomes divisible by 3. Note: if all the digits of N needs to removed report -1.Input contains a single integer N. Constraints: 1 <= N <= 10^18 No digit of N is 0.Print the minimum number of digits that needs to removed to make N divisible by 3. Note: if all the digits of N needs to removed report -1.Sample Input 1 35 Sample Output 1 1 Explanation: we remove 5 from 35 making it 3. Sample Input 2 44 Sample Output 2 -1 Explanation: As we have to remove all digits we report -1., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// int n; int num[20]; int cnt = 0; int sum = 0; int amount[3]; signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif cin >> n; while(n) { num[++cnt] = n % 10; n /= 10; } for(int i = 1; i <= cnt; i++) { sum += num[i]; } for(int i = 1; i <= cnt; i++) { amount[num[i] % 3]++; } if(sum % 3 == 0) { printf("0\n"); } else if(sum % 3 == 1) { if(amount[1] && cnt > 1) { printf("1\n"); } else if(amount[2] >= 2 && cnt > 2) { printf("2\n"); } else { printf("-1\n"); } } else if(sum % 3 == 2) { if(amount[2] && cnt > 1) { printf("1\n"); } else if(amount[1] >= 2 && cnt > 2) { printf("2\n"); } else { printf("-1\n"); } } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: import java.io.*; import java.io.IOException; import java.util.*; class Main { public static long mod = (long)Math.pow(10,9)+7 ; public static double epsilon=0.00000000008854; public static InputReader sc = new InputReader(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { String s=sc.nextLine(); int n=s.length(); int hnum[]=new int[26]; int hpast[]=new int[26]; Arrays.fill(hpast,-1); long hsum[]=new long[26]; long ans=0; for(int i=0;i<n;i++){ int k=s.charAt(i)-'a'; if(hpast[k]!=-1) hsum[k]=hsum[k]+(i-hpast[k])*hnum[k]; ans+=hsum[k]; hnum[k]++; hpast[k]=i; } pw.println(ans); pw.flush(); pw.close(); } public static Comparator<Long[]> column(int i){ return new Comparator<Long[]>() { @Override public int compare(Long[] o1, Long[] o2) { return o1[i].compareTo(o2[i]); } }; } public static Comparator<Integer[]> col(int i){ return new Comparator<Integer[]>() { @Override public int compare(Integer[] o1, Integer[] o2) { return o1[i].compareTo(o2[i]); } }; } public static String reverseString(String s){ StringBuilder input1 = new StringBuilder(); input1.append(s); input1 = input1.reverse(); return input1.toString(); } public static int[] scanArray(int n){ int a[]=new int [n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); return a; } public static long[] scanLongArray(int n){ long a[]=new long [n]; for(int i=0;i<n;i++) a[i]=sc.nextLong(); return a; } public static String [] scanStrings(int n){ String a[]=new String [n]; for(int i=0;i<n;i++) a[i]=sc.nextLine(); return a; } public static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: def findS(s): visited= [ 0 for i in range(256)]; distance =[0 for i in range (256)]; for i in range(256): visited[i]=0; distance[i]=0; sum=0; for i in range(len(s)): sum+=visited[ord(s[i])] * i - distance[ord(s[i])]; visited[ord(s[i])] +=1; distance[ord(s[i])] +=i; return sum; if __name__ == '__main__': s=input(""); print(findS(s));, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: #pragma GCC optimize ("O3") #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 string s; cin>>s; int c[26]={}; int f[26]={}; int ans=0; int n=s.length(); for(int i=0;i<n;++i){ ans+=f[s[i]-'a']*i-c[s[i]-'a']; f[s[i]-'a']++; c[s[i]-'a']+=i; } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException{ InputStreamReader r = new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); String num = br.readLine(); int N = Integer.parseInt(num); String result = ""; if(N < 1000 && N > 0 && N == 1){ result = "AC"; } else { result = "WA"; } System.out.println(result); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: N=int(input()) if N==1: print("AC") else: print("WA"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Santa has been trying to solve the following task. Would you please help him so that he can go back to distributing gifts? Given an integer N, print "AC" if N is 1. Otherwise, print "WA". Note: You are supposed to print "AC" and "WA" without the quotes.The input consists of a single line containing the integer N. <b> Constraints: </b> 0 ≤ N ≤ 1000Print the required answer.Sample Input 1 1 Sample Output 1 AC Sample Input 2 0 Sample Output 2 WA , I have written this Solution Code: //Author: Xzirium //Time and Date: 03:04:29 27 December 2021 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(1e9+7); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll b, ll e) { ll r = 1ll; for(; e > 0; e /= 2, (b *= b) %= MOD) if(e % 2) (r *= b) %= MOD; return r; } ll modInverse(ll a) { return power(a,MOD-2); } //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk; clk = clock(); //-----------------------------------------------------------------------------------------------------------// READV(N); if(N==1) { cout<<"AC"<<endl; } else { cout<<"WA"<<endl; } //-----------------------------------------------------------------------------------------------------------// clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You have to write 4 classes as BubbleSort, InsertionSort, MergeSort and SelectionSort, and each of should implement following interface: <code> interface ISort{ public int[] sort(int[] arr); } </code> Each class should be defined as: Implement sort in each class with respective method, after sorting return sorted array.You don't have to take any input, you have to write classes mentioned in question which implements ISort.Output will be printed by tester, "Correct" if your code is perfectly fine otherwise "Wrong".Sample Test: BubbleSort bubbleSort = new BubbleSort(); arr = bubbleSort.sort(arr); if(arr.isSorted()) System.out.println("Correct"); else System.out.println("Wrong"); Sample Output: Correct, I have written this Solution Code: class BubbleSort implements ISort{ public int[] sort(int[] arr){ int n = arr.length; int temp = 0; for(int i=0; i < n; i++){ for(int j=1; j < (n-i); j++){ if(arr[j-1] > arr[j]){ temp = arr[j-1]; arr[j-1] = arr[j]; arr[j] = temp; } } } return arr; } } class InsertionSort implements ISort{ public int[] sort(int[] arr){ int n = arr.length; for (int i = 1; i < n; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } return arr; } } class MergeSort implements ISort{ void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void sort(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort(arr, l, m); sort(arr , m+1, r); merge(arr, l, m, r); } } public int[] sort(int[] arr){ int n=arr.length; sort(arr,0,n-1); return arr; } } class SelectionSort implements ISort{ public int[] sort(int[] arr){ for (int i = 0; i < arr.length - 1; i++) { int index = i; for (int j = i + 1; j < arr.length; j++){ if (arr[j] < arr[index]){ index = j;//searching for lowest index } } int smallerNumber = arr[index]; arr[index] = arr[i]; arr[i] = smallerNumber; } return arr; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We define a weird series as follows: 7, 77, 777, 7777, 77777, 777777,. . Given a positive integer N find where is first occurrence of a number divisible by N in the given series. If the series contains no multiple of N, print -1 instead.Input contains a single integer N. Constraints: 1 <= N <= 1000000Print the position of the first position of a multiple of N in the series. (For example, if the first occurrence is the third element of the series, print 3)Sample Input 1 101 Sample Output 1 4 Explanation: 7, 77, 777 are not multiple of 101 whereas 7777 is a multiple of 101. Sample Input 2 2 Sample Output 2 -1 Sample Input 3 7 Sample Output 3 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)); int num = Integer.parseInt(br.readLine()); System.out.print(wierdSeven(num)); } private static int wierdSeven(int n){ int temp = 7,multiple=0; for(int i=1;i<=n;i++){ multiple = multiple+temp; if(multiple%n==0){ return i; } multiple = multiple%n; temp = temp*10; temp = temp%n; } return -1; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: We define a weird series as follows: 7, 77, 777, 7777, 77777, 777777,. . Given a positive integer N find where is first occurrence of a number divisible by N in the given series. If the series contains no multiple of N, print -1 instead.Input contains a single integer N. Constraints: 1 <= N <= 1000000Print the position of the first position of a multiple of N in the series. (For example, if the first occurrence is the third element of the series, print 3)Sample Input 1 101 Sample Output 1 4 Explanation: 7, 77, 777 are not multiple of 101 whereas 7777 is a multiple of 101. Sample Input 2 2 Sample Output 2 -1 Sample Input 3 7 Sample Output 3 1, I have written this Solution Code: a = int(input()) lst = 0 ans = 1 if(a%2!=0 and a%5!=0 and a%17!=0): lst = 7%a while(lst!=0): ans = ans+1 lst*=10 lst=lst+7 lst%=a print(ans) else: print("-1", end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: We define a weird series as follows: 7, 77, 777, 7777, 77777, 777777,. . Given a positive integer N find where is first occurrence of a number divisible by N in the given series. If the series contains no multiple of N, print -1 instead.Input contains a single integer N. Constraints: 1 <= N <= 1000000Print the position of the first position of a multiple of N in the series. (For example, if the first occurrence is the third element of the series, print 3)Sample Input 1 101 Sample Output 1 4 Explanation: 7, 77, 777 are not multiple of 101 whereas 7777 is a multiple of 101. Sample Input 2 2 Sample Output 2 -1 Sample Input 3 7 Sample Output 3 1, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int i, j; long long law; long long seven_multi = 0; long long temp_pow = 7; cin >> law; for (i = 1, temp_pow = 7; i <= law; i++) { seven_multi += temp_pow; if ((seven_multi %= law) == 0) { cout << i << endl; return 0; } temp_pow *= 10; temp_pow %= law; } cout << -1 << endl; return 0; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is palindrome or not. A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter. Constraints:- 1<=N<=1000 1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:- 5 1 2 3 2 1 Sample Output 1:- Yes Sample Input 2:- 3 1 2 2 Sample Output 2:- No, I have written this Solution Code: n=int(input()) l=input().split() l=[int(i) for i in l] if l[::-1]==l: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is palindrome or not. A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter. Constraints:- 1<=N<=1000 1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:- 5 1 2 3 2 1 Sample Output 1:- Yes Sample Input 2:- 3 1 2 2 Sample Output 2:- No, I have written this Solution Code: public static boolean IsPalindrome(Node head) { Node slow = head; boolean ispalin = true; Stack<Integer> stack = new Stack<Integer>(); while (slow != null) { stack.push(slow.val); slow = slow.next; } while (head != null) { int i = stack.pop(); if (head.val == i) { ispalin = true; } else { ispalin = false; break; } head = head.next; } return ispalin; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings numbered from 1 to N in a straight line, the i<sup>th</sup> building having height h<sub>i</sub>. You start from building 1 and move towards building N. If the height of the next building is greater than the current, you expend twice the difference in the heights of the building's energy units. If the height of the next building is lesser than the current, you expend the difference in the heights of the building's energy units. Find the total amount of energy you would have to expend up until you reach building N.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= h<sub>i</sub> <= 10<sup>9</sup>Print the total amount of energy you would have to expend uptill you reach building N.Sample Input: 5 3 5 2 1 7 Sample Output: 20 <b>Explanation</b> 3 --> 5 = 2*2=4 5 --> 2 = 3*1=3 2 --> 1= 1*1=1 1 --> 7= 6*2=12 Total = 4+3+1+12=20, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin >> n; vector<int> a(n); for(auto &i : a) cin >> i; int ans = 0; for(int i = 1; i < n; i++){ if(a[i] > a[i - 1]){ ans += 2 * (a[i] - a[i - 1]); } else ans += a[i - 1] - a[i]; } cout << ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are N buildings numbered from 1 to N in a straight line, the i<sup>th</sup> building having height h<sub>i</sub>. You start from building 1 and move towards building N. If the height of the next building is greater than the current, you expend twice the difference in the heights of the building's energy units. If the height of the next building is lesser than the current, you expend the difference in the heights of the building's energy units. Find the total amount of energy you would have to expend up until you reach building N.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 2 <= N <= 10<sup>5</sup> 1 <= h<sub>i</sub> <= 10<sup>9</sup>Print the total amount of energy you would have to expend uptill you reach building N.Sample Input: 5 3 5 2 1 7 Sample Output: 20 <b>Explanation</b> 3 --> 5 = 2*2=4 5 --> 2 = 3*1=3 2 --> 1= 1*1=1 1 --> 7= 6*2=12 Total = 4+3+1+12=20, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); int arr[] = new int[n]; for(int i=0; i<n; i++) arr[i] = Integer.parseInt(st.nextToken()); long expend = 0; for(int i=1; i<n; i++){ long diff = Math.abs(arr[i-1]-arr[i]); if(arr[i-1]<arr[i]){ expend+=2*diff; } else expend+=diff; } System.out.print(expend); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String input[]=br.readLine().split("\\s"); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(input[i]); } System.out.print(implementMergeSort(a,0,n-1)); } public static long implementMergeSort(int arr[], int start, int end) { long count=0; if(start<end) { int mid=start+(end-start)/2; count +=implementMergeSort(arr,start,mid); count +=implementMergeSort(arr,mid+1,end); count +=merge(arr,start,end,mid); } return count; } public static long merge(int []a,int start,int end,int mid) { int i=start; int j=mid+1; int k=0; int len=end-start+1; int c[]=new int[len]; long inv_count=0; while(i<=mid && j<=end) { if(a[i]<=a[j]) { c[k++]=a[i]; i++; } else { c[k++]=a[j]; j++; inv_count +=(mid-i)+1; } } while(i<=mid) { c[k++]=a[i++]; } while(j<=end) { c[k++]=a[j++]; } for(int l=0;l<len;l++) a[start+l]=c[l]; return inv_count; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of positive integers. The task is to find inversion count of array. Inversion Count : For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. Asked in Adobe, Amazon, Microsoft.The first line of each test case is N, the size of the array. The second line of each test case contains N elements. Constraints:- 1 ≤ N ≤ 10^5 1 ≤ a[i] ≤ 10^5Print the inversion count of array.Sample Input: 5 2 4 1 3 5 Sample Output: 3 Explanation: Testcase 1: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3)., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long long long _mergeSort(int arr[], int temp[], int left, int right); long long merge(int 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(int 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(int arr[], int temp[], int left, int right) { int 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(int 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; } signed main() { int n; cin>>n; int a[n]; unordered_map<int,int> m; for(int i=0;i<n;i++){ cin>>a[i]; if(m.find(a[i])==m.end()){ m[a[i]]=i; } } cout<<mergeSort(a,n); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Find whether the given number is a perfect cube. Expected Time Complexity: O(log n)First line contains an integer N Constraints 1 <= N <= 100000Print "YES" if x is a perfect cube otherwise print "NO".Sample Input: 8 Output: YES Sample Input: 7 Output: NO, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(reader.readLine()); int cbrt = (int) Math.cbrt(n); if(cbrt*cbrt*cbrt == n) { System.out.println("YES"); } else { System.out.println("NO"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N. Find whether the given number is a perfect cube. Expected Time Complexity: O(log n)First line contains an integer N Constraints 1 <= N <= 100000Print "YES" if x is a perfect cube otherwise print "NO".Sample Input: 8 Output: YES Sample Input: 7 Output: NO, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long int #define f(n) for(int i=0;i<n;i++) #define fo(n) for(int j=0;j<n;j++) #define foo(n) for(int i=1;i<=n;i++) #define ff first #define ss second #define pb push_back #define pii pair<int,int> #define vi vector<int> #define vp vector<pii> #define test int tt; cin>>tt; while(tt--) #define mod 1000000007 void fastio() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("Input 4.txt", "r", stdin); freopen("Output 4.txt", "w", stdout); #endif } bool check(ll n) { ll l = 0, r = n; ll ans = -1; while (l <= r) { ll a = (2 * l + r) / 3; ll b = (l + 2 * r) / 3; bool x = (a * a * a >= n); bool y = (b * b * b >= n); if (x == false && y == false) { l = b + 1; } else if ((x == true) && (y == true)) { ans = a; r = a - 1; } else { ans = b; l = a + 1; r = b - 1; } } return (ans * ans * ans == n); } int main() { fastio(); ll n; cin >> n; if (check(n)) { 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 a number N. Find whether the given number is a perfect cube. Expected Time Complexity: O(log n)First line contains an integer N Constraints 1 <= N <= 100000Print "YES" if x is a perfect cube otherwise print "NO".Sample Input: 8 Output: YES Sample Input: 7 Output: NO, I have written this Solution Code: a=int(input()) def perfectCube(a): for i in range(2,int(a/2)): if a%i==0 and i*i*i==a: return "YES" return "NO" print(perfectCube(a)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces. String contains only uppercase English letters.Print the sorted array.INPUT : AS KF ER DD JK OUTPUT : AS DD ER JK KF, I have written this Solution Code: function easySorting(arr) { for(let i = 1; i < 5; i++) { let str = arr[i]; let j = i-1; while(j >= 0 && (arr[j].toString().localeCompare(str)) > 0 ) { arr[j+1] = arr[j]; j--; } arr[j+1] = str; } return arr; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces. String contains only uppercase English letters.Print the sorted array.INPUT : AS KF ER DD JK OUTPUT : AS DD ER JK KF, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { map<string,int> m; string s; for(int i=0;i<5;i++){ cin>>s; m[s]++; } for(auto it=m.begin();it!=m.end();it++){ while(it->second>0){ cout<<it->first<<" "; it->second--;} } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces. String contains only uppercase English letters.Print the sorted array.INPUT : AS KF ER DD JK OUTPUT : AS DD ER JK KF, I have written this Solution Code: inp = input("").split(" ") print(" ".join(sorted(inp))), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: An array of 5 string is given where each string contains 2 characters, Now you have to sort these strings, like in a dictionary.Input contains 5 strings of length 2 separated by spaces. String contains only uppercase English letters.Print the sorted array.INPUT : AS KF ER DD JK OUTPUT : AS DD ER JK KF, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static void printArray(String str[]) { for (String string : str) System.out.print(string + " "); } public static void main (String[] args) throws IOException { BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int len = 5; String[] str = new String[len]; str = br.readLine().split(" "); Arrays.sort(str, String.CASE_INSENSITIVE_ORDER); printArray(str); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: static int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: int forgottenNumbers(int N){ int ans=0; for(int i=1;i<=50;i++){ for(int j=1;j<=50;j++){ if(i!=j && i+j==N){ ans++; } } } return ans/2; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara selects two different numbers from the range 1 to 50 and noted their sum as N. However later she Forgets which numbers she selected and now wants to know the total number of possible combinations she can have.<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>forgottenNumbers()</b> that takes integer N argument. Constraints:- 3 <= N <= 99Return the total number of choices Sara has.Sample Input:- 8 Sample Output:- 3 Explanation:- (1, 7), (2, 6), (3, 5) Sample Input:- 3 Sample Output:- 1, I have written this Solution Code: def forgottenNumbers(N): ans = 0 for i in range (1,51): for j in range (1,51): if i != j and i+j==N: ans=ans+1 return ans//2 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Implement <code>getObjKeys</code> which only takes one argument which will be a object. The function should return all they keys present in object as a string where elements are seperated by a ', '. (No nested objects)(Use JS Built in function)Function will take one argument which will be an objectFunction will is string which contain all the keys from the input object seperated by a ', 'const obj = {email:"akshat. sethi@newtonschool. co", password:"123456"} const keyString = getObjKeys(obj) console. log(keyString) // prints email, password, I have written this Solution Code: function getObjKeys(obj){ return Object.keys(obj).join(",") }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: L,B,H=input().split() a=4*(int(L)+int(B)+int(H)) print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: static int Perimeter(int L, int B, int H){ return 4*(L+B+H); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: the user would input n first, which is the number of datapoints in the dataset, then he will enter the actual dataset consisting of n numbers, find the mode of those, there might NOT be a unique mode, so print the first element which is a possible mode as entered by user. find the mean and median of the data too Now an empirical relation exists in between mean, median and mode which is Mode =3(Median)−2(Mean) find the mode from this method too, and find (actual mode- mode from empirical formula) to check the difference and print it by rounding up to 2 decimal places. hint - use statistics library for mean, median and mode5 6 6 7 8 9--0.6-, I have written this Solution Code: from statistics import mean from statistics import mode from statistics import median a=int(input()) arr=[] for i in range(a): arr.append(int(input())) mean = mean(arr) median=median(arr) mode=mode(arr) mode_e=3*median - 2*mean print(round(mode-mode_e,2)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: the user would input n first, which is the number of datapoints in the dataset, then he will enter the actual dataset consisting of n numbers, find the mode of those, there might NOT be a unique mode, so print the first element which is a possible mode as entered by user. find the mean and median of the data too Now an empirical relation exists in between mean, median and mode which is Mode =3(Median)−2(Mean) find the mode from this method too, and find (actual mode- mode from empirical formula) to check the difference and print it by rounding up to 2 decimal places. hint - use statistics library for mean, median and mode5 6 6 7 8 9--0.6-, I have written this Solution Code: import statistics n = int(input()) inputs = [] for i in range(n): inp = input() inputs.append(int(inp)) mode = statistics.mode(inputs) median = statistics.median(inputs) mean = statistics.mean(inputs) mode_e = 3*median - 2*mean sol = mode-mode_e print(round(sol,2)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the largest number that can be formed by appending the numbers from the given array. For eg:- If the numbers are { 10, 3, 31} then the largest number will be 33110First line of input contains a single integer N, next line contains N space separated integers depicting values of array. Constraints:- 1 < = N < = 100000 1 < = Arr[i] < = 100000Print the largest number that can be formed using the array elements.Sample Input:- 3 10 3 31 Sample Output:- 33110 Sample Input:- 5 8 9 10 11 12 Sample Output:- 98121110, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static void Largest(ArrayList<String> a) { Collections.sort(a, new Comparator<String>(){ @Override public int compare(String X, String Y) { String XY=X + Y; String YX=Y + X; return XY.compareTo(YX) > 0 ? -1:1; } }); for(String value:a) { System.out.print(value); } } public static void main (String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); ArrayList<String> al=new ArrayList<>(); String[] nums=br.readLine().split("\\s"); for(int i=0;i<n;i++) { al.add(nums[i]); } Largest(al); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N integers, your task is to calculate the largest number that can be formed by appending the numbers from the given array. For eg:- If the numbers are { 10, 3, 31} then the largest number will be 33110First line of input contains a single integer N, next line contains N space separated integers depicting values of array. Constraints:- 1 < = N < = 100000 1 < = Arr[i] < = 100000Print the largest number that can be formed using the array elements.Sample Input:- 3 10 3 31 Sample Output:- 33110 Sample Input:- 5 8 9 10 11 12 Sample Output:- 98121110, I have written this Solution Code: // C++ program to find sum of all minimum and maximum // elements Of Sub-array Size k. #include<bits/stdc++.h> using namespace std; #define int long long int int myCompare(string X, string Y) { // first append Y at the end of X string XY = X.append(Y); // then append X at the end of Y string YX = Y.append(X); // Now see which of the two formed numbers is greater return XY.compare(YX) > 0 ? 1: 0; } // The main function that prints the arrangement with the largest value. // The function accepts a vector of strings void printLargest(vector<string> arr) { // Sort the numbers using library sort function. The function uses // our comparison function myCompare() to compare two strings. // See http://www.cplusplus.com/reference/algorithm/sort/ for details sort(arr.begin(), arr.end(), myCompare); for (int i=0; i < arr.size() ; i++ ) cout << arr[i]; } // Driver program to test above functions signed main() { int n,k; cin>>n; vector<string> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } printLargest(v); 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. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: import java.io.*; import java.io.IOException; import java.util.*; class Main { public static long mod = (long)Math.pow(10,9)+7 ; public static double epsilon=0.00000000008854; public static InputReader sc = new InputReader(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { String s=sc.nextLine(); int n=s.length(); int hnum[]=new int[26]; int hpast[]=new int[26]; Arrays.fill(hpast,-1); long hsum[]=new long[26]; long ans=0; for(int i=0;i<n;i++){ int k=s.charAt(i)-'a'; if(hpast[k]!=-1) hsum[k]=hsum[k]+(i-hpast[k])*hnum[k]; ans+=hsum[k]; hnum[k]++; hpast[k]=i; } pw.println(ans); pw.flush(); pw.close(); } public static Comparator<Long[]> column(int i){ return new Comparator<Long[]>() { @Override public int compare(Long[] o1, Long[] o2) { return o1[i].compareTo(o2[i]); } }; } public static Comparator<Integer[]> col(int i){ return new Comparator<Integer[]>() { @Override public int compare(Integer[] o1, Integer[] o2) { return o1[i].compareTo(o2[i]); } }; } public static String reverseString(String s){ StringBuilder input1 = new StringBuilder(); input1.append(s); input1 = input1.reverse(); return input1.toString(); } public static int[] scanArray(int n){ int a[]=new int [n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); return a; } public static long[] scanLongArray(int n){ long a[]=new long [n]; for(int i=0;i<n;i++) a[i]=sc.nextLong(); return a; } public static String [] scanStrings(int n){ String a[]=new String [n]; for(int i=0;i<n;i++) a[i]=sc.nextLine(); return a; } public static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: def findS(s): visited= [ 0 for i in range(256)]; distance =[0 for i in range (256)]; for i in range(256): visited[i]=0; distance[i]=0; sum=0; for i in range(len(s)): sum+=visited[ord(s[i])] * i - distance[ord(s[i])]; visited[ord(s[i])] +=1; distance[ord(s[i])] +=i; return sum; if __name__ == '__main__': s=input(""); print(findS(s));, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string S. Two position i and j of the string are friends if they have the same character. The distance between two friends at positions i and j is defined as |i- j|. Find the sum of distances of all the pairs of friends in the given strings.First line of input contains a single string S. Constraints: 1 <= |S| <= 1000000 String contains lowercase english letters.Output a single integer which is the sum of distance of all the pair of friends in the given strings.Sample Input ababa Sample Output 10 Explanation: Friend pairs - (1, 3) (1, 5) (2, 4) (3, 5), I have written this Solution Code: #pragma GCC optimize ("O3") #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 string s; cin>>s; int c[26]={}; int f[26]={}; int ans=0; int n=s.length(); for(int i=0;i<n;++i){ ans+=f[s[i]-'a']*i-c[s[i]-'a']; f[s[i]-'a']++; c[s[i]-'a']+=i; } cout<<ans; #ifdef ANIKET_GOYAL // cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array A of N integers. Determine the minimum value of the following expression for all i, j valid : (A<sub>i</sub> and A<sub>j</sub>) xor (A<sub>i</sub> or A<sub>j</sub>), where i &ne; j.First line: A single integer T denoting the number of test cases For each test case: <ul style="list- style- type:disc"><li>First line contains a single integer N, denoting the size of the array</li><li>Second line contains N space- separated integers A<sub>1</sub>, A<sub>2</sub>,. , A<sub>n</sub></li></ul> <b>Constraints</b> 1 &le; T &le; 10<sup>3</sup> 1 &le; N &le; 10<sup>5</sup> 0 &le; A<sub>i</sub> &le; 10<sup>9</sup> Note: Sum of N overall test cases does not exceed 10<sup>6</sup>For each test case, print a single line containing one integer that represents the minimum value of the given expressionSample Input 2 5 1 2 3 4 5 3 2 4 7 Sample Output 1 3 Explanation For test case #1, we can select elements 2 and 3, the value of the expression is (2 and 3) xor (2 or 3) = 1, which is the minimum possible value. Another possible pair is 4 and 5. For test case #2, we can select elements 4 and 7, the value of the expression is (4 and 7) xor (4 or 7) = 3, which is the minimum possible value., I have written this Solution Code: #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif #define int long long mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) { uniform_int_distribution<int64_t> generator(l, r); return generator(rng); } void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int ans = INT_MAX; for (int i = 1; i < n; i++) { ans = min(ans, ((a[i] | a[i - 1]) ^ (a[i] & a[i - 1]))); } cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start = std::chrono::high_resolution_clock::now(); int tt; cin >> tt; while (tt--) { solve(); } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array A of N integers. Determine the minimum value of the following expression for all i, j valid : (A<sub>i</sub> and A<sub>j</sub>) xor (A<sub>i</sub> or A<sub>j</sub>), where i &ne; j.First line: A single integer T denoting the number of test cases For each test case: <ul style="list- style- type:disc"><li>First line contains a single integer N, denoting the size of the array</li><li>Second line contains N space- separated integers A<sub>1</sub>, A<sub>2</sub>,. , A<sub>n</sub></li></ul> <b>Constraints</b> 1 &le; T &le; 10<sup>3</sup> 1 &le; N &le; 10<sup>5</sup> 0 &le; A<sub>i</sub> &le; 10<sup>9</sup> Note: Sum of N overall test cases does not exceed 10<sup>6</sup>For each test case, print a single line containing one integer that represents the minimum value of the given expressionSample Input 2 5 1 2 3 4 5 3 2 4 7 Sample Output 1 3 Explanation For test case #1, we can select elements 2 and 3, the value of the expression is (2 and 3) xor (2 or 3) = 1, which is the minimum possible value. Another possible pair is 4 and 5. For test case #2, we can select elements 4 and 7, the value of the expression is (4 and 7) xor (4 or 7) = 3, which is the minimum possible value., I have written this Solution Code: import java.util.*; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main(String [] args) throws IOException { Reader r = new Reader(); int t = r.nextInt(); while(t-->0) { int n = r.nextInt(); int a[] = new int[n]; for(int i=0; i<n; i++) a[i] = r.nextInt(); Arrays.sort(a); int min = Integer.MAX_VALUE; for(int i=0; i<n-1; i++) min = Math.min(min,(a[i] ^ a[i+1])); System.out.println(min); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it. <b>Problem description:- </b> Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234. Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0 25 - > 18 - > 9 - > 0). Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N. Constraints:- 1 <= T <= 10000 1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:- 4 25 8 17 842 Sample Output:- 3 1 2 72 Explanation:- 25 - > 18 - > 9 - > 0 8 - > 0 17 - > 9 - > 0, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static int[] dp = new int[1000002]; public static void main (String[] args) throws IOException { int x = 1000000; int sum = 0; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); for(int i = 1; i <= x; ++i) { int j = i; sum = total(j); dp[i] = dp[i-sum]+1; } int t = Integer.parseInt(br.readLine()); while(t-- > 0) { int count = 0; int n = Integer.parseInt(br.readLine()); System.out.println(dp[n]); } } static int total(int n) { int temp = 0; while(n > 0) { temp += n%10; n = n/10; } return temp; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it. <b>Problem description:- </b> Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234. Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0 25 - > 18 - > 9 - > 0). Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N. Constraints:- 1 <= T <= 10000 1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:- 4 25 8 17 842 Sample Output:- 3 1 2 72 Explanation:- 25 - > 18 - > 9 - > 0 8 - > 0 17 - > 9 - > 0, I have written this Solution Code: import sys sys.setrecursionlimit(40000) dic = {} def sumi(n): x = 0 while(n>0): x += n%10 n //= 10 return x def Num_of_times(n): if (n==0): return 0 if dic.get(n): count = dic[n] return count else: x = sumi(n) count = 1+Num_of_times(n-x) dic[n] = count return count arr = [] maxi = 0 for i in range(int(input())): x = int(input()) maxi = max(maxi,x) arr.append(x) maxi_ans = Num_of_times(maxi) for i in arr: if i == maxi: print(maxi_ans) else: print(Num_of_times(i)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara wants to be the best programmer in the world but today she is stuck on an easy problem. Help her to solve it. <b>Problem description:- </b> Choose an integer N and subtract the sum of digits of the number N from it i. e. if N is 245 then subtract 2+4+5 from it making it 245 - 11 = 234. Keep on doing this operation until the number becomes 0 (for eg. 25 requires 3 operations to reduce to 0 25 - > 18 - > 9 - > 0). Given a number N, your task is to print the number of operations required to make the number 0.The first line of input contains a single integer containing the number of test cases T. Next T lines contain a single integer N. Constraints:- 1 <= T <= 10000 1 <= N <= 1000000For each test case print the number of operations required to make the number 0.Sample Input:- 4 25 8 17 842 Sample Output:- 3 1 2 72 Explanation:- 25 - > 18 - > 9 - > 0 8 - > 0 17 - > 9 - > 0, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define LL long long int dp[1000001]; void solve() { int n; cin >> n; cout << dp[n] << '\n'; } int main() { ios::sync_with_stdio(0), cin.tie(0); for(int i = 1; i <= 1000000; i++) { int s = 0, j = i; while(j > 0) { s += j % 10; j /= 10; } dp[i] = dp[i - s] + 1; } int tt; cin >> tt; while(tt--) solve(); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a function that creates a binary tree similar to given figure:NonePreorder traversal of the binary treeInput: None Output: 1 2 5 6 3, I have written this Solution Code: public static void main(String[] args) { Node root = new Node(1); root.left = new Node(2); root.right = new Node(3); root.left.left = new Node(5); root.left.right = new Node(6); // print out the values of the nodes System.out.print(root.value+ " "); System.out.print(root.left.value+ " "); System.out.print(root.left.left.value+ " "); System.out.print(root.left.right.value+ " "); System.out.print(root.right.value+ " "); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two integers N and M (N > M). You have to find the smallest integer <b>X</b> such that <i>N - M <= X <= N + M</i> and <i>M - X <= X - N</i>First and the only line of the input contains two integers N and M. Constraints: 1 <= N < M <= 10<sup>9</sup>Find and print the smallest integer X which satisifes the above condition. If no such integer exists, print -1.Sample Input: 8 4 Sample Output: 6 Explaination: 6 is the smallest integer X between <b>N - M</b> (8 - 4 = 4) and <b>N + M</b> (8 + 4 = 12) such that M - X <= X - N., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long #define pb push_back #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using T = pair<int, int>; typedef long long ll; const int mod = 1e9 + 7; const int INF = 1e9; void solve() { int n, m; cin >> n >> m; int y = (n + m + 1)/2; cout << y; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); if(i != t) cout << endl; } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); double arr[] = new double[N]; String str[] = br.readLine().trim().split(" "); for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); double resistance=0; int equResistance=0; for(int i=0;i<N;i++) arr[i]=Integer.parseInt(str[i]); for(int i=0;i<N;i++) { resistance=resistance+(1/arr[i]); } equResistance = (int)Math.floor((1/resistance)); System.out.println(equResistance); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: r = input("") r = int(r) n = input("").split() resistance=0.0 for i in range(0,r): resistor = float(n[i]) resistance = resistance + (1/resistor) print(int(1/resistance)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given resistance value of N resistors. Find the net resistance of the system when all of these N resistors are connected in parallel. If there are three resistors A1, A2, A3, when they are connected in parallel, the net resistance will be 1/((1/A1) + (1/A2) + (1/A3)) Since this number can also have a fraction part, you only have to print the floor of the result obtained. For example, if value of 1/((1/A1) + (1/A2) + (1/A3)) if 7.54567, you only have to print 7.First line contains a single integer N denoting the number of resistors. Next line contains N space separated integers containing the value of different resistors. Constraints 1 ≤ N ≤ 10^5 1 ≤ Ai ≤ 10^9Print the integral part or floor of the value obtained from the formula 1/((1/A1) + (1/A2) + ..... + (1/AN)).Input 2 10 30 Output 7 1/((1/10) + (1/30)) = 30/4 = 7.5 and floor of 7.5 is 7, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; signed main() { IOS; int n; cin >> n; double s = 0; for(int i = 1; i <= n; i++){ double p; cin >> p; s = s + (1/p); } s = 1/s; cout << floor(s); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A graph is given with N nodes and M edges. The first visit to a vertex i will give 2<sup>i-1</sup> -1 score. Initially, we are at node 1. Then calculate the maximum score that we can get if we are only allowed to move to an adjacent vertex at most K times.First line contains 3 integers separated by space denoting N (1<=N<=60) , M (1<=M<=N*(N-1)/2) , and K (1<=K<=15), the number of nodes, edges, and the maximum move allowed respectively. Then, M lines follow with each line containing two integers u and v representing edge between vertex u and v (u≠v).Output maximum score in first line.Input: 4 3 1 1 2 1 3 1 4 Output: 7 Explanation: Alice can move to node 2 or node 3 or node 4. Here node 4 has (2^3 - 1 = 7)coins., I have written this Solution Code: //*** Author: ShlokG ***// #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fix(f,n) std::fixed<<std::setprecision(n)<<f typedef long long int ll; typedef unsigned long long int ull; #define pb push_back #define endl "\n" const ll MAX=1e18+5; ll mod=1e9+7; ll mod1=998244353; const int infi = 1e9; const ll INF=1e18; void precompute(){ } void TEST_CASE(){ int n,m,k; cin >> n >> m >> k; int mat[100][100]; int dp[1<<17][17]; vector<int> v; for(int i=0 ; i<100 ; i++) for(int j=0 ; j<100 ; j++) mat[i][j]=1000; for(int i=0 ; i<100 ; i++) mat[i][i]=0; for(int i=0 ; i<m ; i++){ int x,y; cin >> x >> y; mat[x-1][y-1]=mat[y-1][x-1]=1; } for(int i=0 ; i<n ; i++) for(int j=0 ; j<n ; j++) for(int l=0 ; l<n ; l++) mat[j][l] = min (mat [j] [l], mat [j] [i] + mat [i] [l ]); v.push_back (0); ll ret = 0 ; for(int i=n-1 ; i>0 ; i--) { if(v.size()>=k+1) break; v.push_back(i); memset(dp,0x3f,sizeof(dp)); dp[1][0]=0; for(int mask=1 ; mask<(1<<v.size()) ; mask++){ for(int x=0 ; x<v.size() ; x++) if(mask&(1<<x)) { for(int y=0 ; y<v.size() ; y++) if(x!=y && (mask&(1<<y))) dp[mask][x] = min(dp[mask][x], dp[mask^(1<<x)][y] + mat[v[x]][v[y]]); } } int ok = 0 ; for(int j=0 ; j<v.size() ; j++) if(dp[(1<<v.size())-1][j]<=k) ok++; if (ok == 0 ) v.pop_back(); else ret += ( 1LL << i) -1 ; } cout << ret << endl; } signed main(){ fast; //freopen ("INPUT.txt","r",stdin); //freopen ("OUTPUT.txt","w",stdout); int test=1,TEST=1; precompute(); //cin >> test; while(test--){ //cout << "Case #" << TEST++ << ": "; TEST_CASE(); } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the first 2 terms A and B of an Arithmetic Series, tell the Nth term of the series.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>NthAP()</b> that takes the integer A, B, and N as a parameter. <b>Constraints:</b> -10<sup>3</sup> &le; A &le; 10<sup>3</sup> -10<sup>3</sup> &le; B &le; 10<sup>3</sup> 1 &le; N &le; 10<sup>4</sup>Return the Nth term of AP series.Sample Input 1: 2 3 4 Sample Output 1: 5 Sample Input 2: 1 2 10 Sample output 2: 10, I have written this Solution Code: class Solution { public static int NthAP(int a, int b, int n){ return a+(n-1)*(b-a); } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s. <b>Constraints</b> 1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput s = "newtonschool" Output 1 Explanation "e" is the first non- repeating character in a string, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); System.out.print(nonRepeatChar(s)); } static int nonRepeatChar(String s){ char count[] = new char[256]; for(int i=0; i< s.length(); i++){ count[s.charAt(i)]++; } for (int i=0; i<s.length(); i++) { if (count[s.charAt(i)]==1){ return i; } } return -1; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s. <b>Constraints</b> 1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput s = "newtonschool" Output 1 Explanation "e" is the first non- repeating character in a string, I have written this Solution Code: from collections import defaultdict s=input() d=defaultdict(int) for i in s: d[i]+=1 ans=-1 for i in range(len(s)): if(d[s[i]]==1): ans=i break print(ans), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a string s, find the first non-repeating character in the string and return its index. If it does not exist, return -1.First line of the input contains the string s. <b>Constraints</b> 1<= s. length <= 100000Print the index of the first non- repeating character in a stringInput s = "newtonschool" Output 1 Explanation "e" is the first non- repeating character in a string, I have written this Solution Code: /** * Author : tourist1256 * Time : 2022-01-10 12:51:16 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif int firstUniqChar(string s) { map<char, int> charCount; int len = s.length(); for (int i = 0; i < len; i++) { charCount[s[i]]++; } for (int i = 0; i < len; i++) { if (charCount[s[i]] == 1) return i; } return -1; } int main() { ios::sync_with_stdio(0); cin.tie(0); string str; cin>>str; cout<<firstUniqChar(str)<<"\n"; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t= Integer.parseInt(br.readLine()); int max = 1000001; boolean isNotPrime[] = new boolean[max]; ArrayList<Integer> arr = new ArrayList<Integer>(); isNotPrime[0] = true; isNotPrime[1] = true; for (int i=2; i*i <max; i++) { if (!isNotPrime[i]) { for (int j=i*i; j<max; j+= i) { isNotPrime[j] = true; } } } for(int i=2; i<max; i++) { if(!isNotPrime[i]) { arr.add(i); } } while(t-- > 0) { String str[] = br.readLine().trim().split(" "); int l = Integer.parseInt(str[0]); int r = Integer.parseInt(str[1]); System.out.println(primeRangeSum(l,r,arr)); } } static long primeRangeSum(int l , int r, ArrayList<Integer> arr) { long sum = 0; for(int i=l; i<=r;i++) { sum += arr.get(i-1); } return sum; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, I have written this Solution Code: def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] pri = [] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 for p in range(2, n+1): if prime[p]: pri.append(p) return pri N = int(input()) X = [] prim = SieveOfEratosthenes(1000000) for i in range(1,len(prim)): prim[i] = prim[i]+prim[i-1] for i in range(N): nnn = input() X.append((int(nnn.split()[0]),int(nnn.split()[1]))) for xx,yy in X: if xx==1: print(prim[yy-1]) else: print(prim[yy-1]-prim[xx-2]) , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on. Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].The first line of the input contains an integer T denoting the number of test cases. The next T lines contain two integers L and R. Constraints 1 <= T <= 50000 1 <= L <= R <= 50000For each test case, print one line corresponding to the required valueSample Input 4 1 3 2 4 5 5 1 5 Sample Output 10 15 11 28, I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; vector<int> v; v.push_back(0); for(int i = 2; i < N; i++){ if(a[i]) continue; v.push_back(i); for(int j = i*i; j < N; j += i) a[j] = 1; } int p = 0; for(auto &i: v){ i += p; p = i; } int t; cin >> t; while(t--){ int l, r; cin >> l >> r; cout << v[r] - v[l-1] << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given two sorted arrays A and B of size N and M respectively. You have to find the value V, which is the summation of (A[j] - A[i]) for all pairs of i and j such that (j - i) is present in array B.The first line contains two space separated integers N and M – size of arrays A and B respectively. The second line contains N integers A<sub>1</sub>, A<sub>2</sub>, ... A<sub>N</sub>. The third line contains M integers B<sub>1</sub>, B<sub>2</sub>, ... B<sub>M</sub>. <b> Constraints: </b> 1 ≤ N ≤ 2×10<sup>5</sup> 1 ≤ M < N 1 ≤ A<sub>1</sub> ≤ A<sub>2</sub> ≤ ... ≤ A<sub>N</sub> ≤ 10<sup>8</sup>. 1 ≤ B<sub>1</sub> < B<sub>2</sub> < ... < B<sub>M</sub> < N.Print a single integer, the value of V.Sample Input 1: 4 2 1 2 3 4 1 3 Sample Output 1: 6 Sample Explanation 1: Valid pairs of (i, j) are (1, 2), (2, 3), (3, 4), (1, 4)., I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define fix(f,n) std::fixed<<std::setprecision(n)<<f #define epsi (double)(0.00000000001) typedef long long int ll; typedef unsigned long long int ull; #define vi vector<ll> #define pii pair<ll,ll> #define vii vector<pii> #define vvi vector<vi> //#define max(a,b) ((a>b)?a:b) //#define min(a,b) ((a>b)?b:a) #define min3(a,b,c) min(min(a,b),c) #define min4(a,b,c,d) min(min(a,b),min(c,d)) #define max3(a,b,c) max(max(a,b),c) #define max4(a,b,c,d) max(max(a,b),max(c,d)) #define ff(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 pb push_back #define mp make_pair #define endl "\n" #define all(v) v.begin(),v.end() #define sz(a) (ll)a.size() #define F first #define S second #define ld long double #define mem0(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define ub upper_bound #define lb lower_bound #define setbits(x) __builtin_popcountll(x) #define trav(a,x) for(auto &a:x) #define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) #define rev(arr) reverse(all(arr)) #define gcd(a,b) __gcd(a,b); #define ub upper_bound // '>' #define lb lower_bound // '>=' #define qi queue<ll> #define fsh cout.flush() #define si stack<ll> #define rep(i, a, b) for(int i = a; i < (b); ++i) #define fill(a,b) memset(a, b, sizeof(a)) template<typename T,typename E>bool chmin(T& s,const E& t){bool res=s>t;s=min<T>(s,t);return res;} const ll INF=1LL<<60; void solve(){ ll n,m; cin >> n >> m; vi v1(n),v2(m); for(auto &i:v1){ cin >> i; } for(auto &i:v2){ cin >> i; } ll ans=0; for(int i=1 ; i<=n ; i++){ auto it=lower_bound(all(v2),i); ll x=it-v2.begin(); ans+=(x*v1[i-1]); it=lower_bound(all(v2),n-i+1); x=it-v2.begin(); ans-=(x*v1[i-1]); } cout << ans << endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin >> t; while(t--){ solve(); } }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, I have written this Solution Code: // arr is the array of numbers, n is the number fo elements function replaceArray(arr, n) { // write code here // do not console.log // return the new array const newArr = [] newArr[0] = arr[0] * arr[1] newArr[n-1] = arr[n-1] * arr[n-2] for(let i= 1;i<n-1;i++){ newArr[i] = arr[i-1] * arr[i+1] } return newArr } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, I have written this Solution Code: n = int(input()) X = [int(x) for x in input().split()] lst = [] for i in range(len(X)): if i == 0: lst.append(X[i]*X[i+1]) elif i == (len(X) - 1): lst.append(X[i-1]*X[i]) else: lst.append(X[i-1]*X[i+1]) for i in lst: print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; long long b[n],a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=1;i<n-1;i++){ b[i]=a[i-1]*a[i+1]; } b[0]=a[0]*a[1]; b[n-1]=a[n-1]*a[n-2]; for(int i=0;i<n;i++){ cout<<b[i]<<" ";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of N elements, your task is to update every element with multiplication of previous and next elements with following exceptions:- a) First element is replaced by multiplication of first and second. b) Last element is replaced by multiplication of last and second last. See example for more clarityFirst line of input contains the size of array N, next line contains N space separated integers denoting values of array. Constraints:- 2 < = N < = 100000 1 < = arr[i] < = 100000Print the modified arraySample Input :- 5 2 3 4 5 6 Sample Output:- 6 8 15 24 30 Explanation:- {2*3, 2*4, 3*5, 4*6, 5*6} Sample Input:- 2 3 4 Sample Output:- 12 12, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } System.out.print(a[0]*a[1]+" "); for(int i=1;i<n-1;i++){ System.out.print(a[i-1]*a[i+1]+" "); } System.out.print(a[n-1]*a[n-2]); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to count the minimum number of operations required to make N a perfect square. In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectSquare()</b> that takes the integer N as parameter. <b>Constraints:</b> 3 <= N <= 100000 <b>Note:</b> <i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Return the minimum count of operations required.Sample Input:- 15 Sample Output:- 3 Explanation:- 15 - > 13 - > 11 - > 9 Sample Input:- 7 Sample Output:- 1, I have written this Solution Code: int PerfectSquare(int N){ int x=sqrt(N); if(x*x==N){return 0;} if(N%2==0){ if(x%2==0){return (N-x*x)/2;} else{ return min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } } else{ if(x%2==0){ return min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } else{ return (N-x*x)/2; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to count the minimum number of operations required to make N a perfect square. In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectSquare()</b> that takes the integer N as parameter. <b>Constraints:</b> 3 <= N <= 100000 <b>Note:</b> <i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Return the minimum count of operations required.Sample Input:- 15 Sample Output:- 3 Explanation:- 15 - > 13 - > 11 - > 9 Sample Input:- 7 Sample Output:- 1, I have written this Solution Code: static int PerfectSquare(int N){ int x=(int)Math.sqrt(N); if(x*x==N){return 0;} if(N%2==0){ if(x%2==0){return (N-x*x)/2;} else{ return Math.min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } } else{ if(x%2==0){ return Math.min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } else{ return (N-x*x)/2; } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to count the minimum number of operations required to make N a perfect square. In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectSquare()</b> that takes the integer N as parameter. <b>Constraints:</b> 3 <= N <= 100000 <b>Note:</b> <i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Return the minimum count of operations required.Sample Input:- 15 Sample Output:- 3 Explanation:- 15 - > 13 - > 11 - > 9 Sample Input:- 7 Sample Output:- 1, I have written this Solution Code: int PerfectSquare(int N){ int x=sqrt(N); if(x*x==N){return 0;} if(N%2==0){ if(x%2==0){return (N-x*x)/2;} else{ return min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } } else{ if(x%2==0){ return min((N-(x-1)*(x-1))/2,((x+1)*(x+1)-N)/2); } else{ return (N-x*x)/2; } } } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to count the minimum number of operations required to make N a perfect square. In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectSquare()</b> that takes the integer N as parameter. <b>Constraints:</b> 3 <= N <= 100000 <b>Note:</b> <i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Return the minimum count of operations required.Sample Input:- 15 Sample Output:- 3 Explanation:- 15 - > 13 - > 11 - > 9 Sample Input:- 7 Sample Output:- 1, I have written this Solution Code: def PerfectSquare(N): x=int(math.sqrt(N)) if (N%2 == x%2): return (N-x*x)//2 else: return min((N-(x-1)*(x-1))//2,((x+1)*(x+1)-N)//2); , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static int BS(int arr[],int x,int start,int end){ if( start > end) return start-1; int mid = start + (end - start)/2; if(arr[mid]==x) return mid; if(arr[mid]>x) return BS(arr,x,start,mid-1); return BS(arr,x,mid+1,end); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); String[] s; for(;t>0;t--){ s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int x = Integer.parseInt(s[1]); s = br.readLine().split(" "); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i] = Integer.parseInt(s[i]); int res = BS(arr,x,0,arr.length-1); System.out.println(res); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: def bsearch(arr,e,l,r): if(r>=l): mid = l + (r - l)//2 if (arr[mid] == e): return mid elif arr[mid] > e: return bsearch(arr, e,l, mid-1) else: return bsearch(arr,e, mid + 1, r) else: return r t=int(input()) for i in range(t): ip=list(map(int,input().split())) l=list(map(int,input().split())) le=ip[0] e=ip[1] print(bsearch(sorted(l),e,0,le-1)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a sorted array <b>arr[]</b> of size <b>N</b> without duplicates, and given a value <b>x</b>. Find the floor of x in given array. Floor of x is defined as the largest element K in arr[] such that K is smaller than or equal to x. Try to use binary search to solve this problem.First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements. <b>Constraints:</b> 1 ≤ T ≤ 100 1 ≤ N ≤ 10^5 1 ≤ arr[i] ≤ 10^18 0 ≤ X ≤ arr[n-1]Output the index of floor of x if exists, else print -1. Use 0-indexingInput: 3 7 0 1 2 8 10 11 12 19 7 5 1 2 8 10 11 12 19 7 10 1 2 8 10 11 12 19 Output: -1 1 3 Explanation: Testcase 1: No element less than or equal to 0 is found. So output is "-1". Testcase 2: Number less than or equal to 5 is 2, whose index is 1(0-based indexing). Testcase 3: Number less than or equal to 10 is 10 and its index is 3., I have written this Solution Code: #include "bits/stdc++.h" #pragma GCC optimize "03" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int a[N]; signed main() { IOS; int t; cin >> t; while(t--){ int n, x; cin >> n >> x; for(int i = 0; i < n; i++) cin >> a[i]; int l = -1, h = n; while(l+1 < h){ int m = (l + h) >> 1; if(a[m] <= x) l = m; else h = m; } cout << l << endl; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd. Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store The second line contains N integers— the number of flowers of each type 1 <= N <= 100000 1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input 3 3 5 8 Sample output 15 Sample input 3 1 1 1 Sample output 3, I have written this Solution Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)) ; int n = Integer.parseInt(read.readLine()) ; String[] str = read.readLine().trim().split(" ") ; int[] arr = new int[n] ; for(int i=0; i<n; i++) { arr[i] = Integer.parseInt(str[i]) ; } long ans = 0L; if((n & 1) == 1) { for(int i=0; i<n; i++) { ans += ((arr[i] & 1) == 1) ? arr[i] : arr[i] - 1 ; } } else { Arrays.sort(arr); for(int i=1; i<n; i++) { ans += ((arr[i] & 1) == 1) ? arr[i] : arr[i] - 1 ; } } System.out.println(ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd. Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store The second line contains N integers— the number of flowers of each type 1 <= N <= 100000 1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input 3 3 5 8 Sample output 15 Sample input 3 1 1 1 Sample output 3, I have written this Solution Code: n=int(input()) arr=map(int,input().split()) result=[] for item in arr: if item%2==0: result.append(item-1) else: result.append(item) if sum(result)%2==0: result.sort() result.pop(0) print(sum(result)) else: print(sum(result)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The flower shop near his house sells flowers of N types. It is found that the store has Ai flowers of the i-th type. We like odd numbers. Therefore, we have decided that there should be an odd number of flowers of each type in the bouquet, and the total number of flowers in the bouquet should also be odd. Determine the maximum number of flowers the bouquet can consist of.The first line contains an integer N — the number of types of flowers that are sold in the store The second line contains N integers— the number of flowers of each type 1 <= N <= 100000 1 <= Ai <= 1000Print one number — the maximum number of flowers the bouquet can consist of.Sample input 3 3 5 8 Sample output 15 Sample input 3 1 1 1 Sample output 3, I have written this Solution Code: #include <bits/stdc++.h> #define ll long long int using namespace std; int main(){ int n; cin >> n ; long long int ans = 0; // int arr[n]; int odd = 0,minn=INT_MAX; for(int i=0;i<n;i++){ ll temp; cin >> temp; // cin >> arr[i]; ans += (temp&1) ? temp : temp-1; if(minn>temp) minn = temp; } if(n&1) cout << ans ; else{ if(minn&1) cout <<ans-minn; else cout << ans - minn + 1; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array. Constraints:- 1 <= N <= 10000 1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:- 3 1 2 3 4 5 6 Sample Output:- 1 4 2 5 3 6 Sample Input:- 2 2 4 6 8 Sample Output:- 2 6 4 8, I have written this Solution Code: a=input() a=int(a) arr=input().split() i=0 j=int(len(arr)/2) while(i<len(arr)/2): print (arr[i], arr[j], end=' ') i+=1 j+=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array. Constraints:- 1 <= N <= 10000 1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:- 3 1 2 3 4 5 6 Sample Output:- 1 4 2 5 3 6 Sample Input:- 2 2 4 6 8 Sample Output:- 2 6 4 8, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define max1 10001 #define MOD 1000000007 #define read(type) readInt<type>() #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main() { int n; cin>>n; int a[2*n]; FOR(i,2*n){ cin>>a[i];} FOR(i,n){ cout<<a[i]<<" "<<a[n+i]<<" "; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an array of size 2*N in the form as [x1, x2.. xn, y1, y2,. yn], your task is to shuffle the array in the form given as [x1, y1, x2, y2,. xN, yN]First line of input contains a single integer N. Next line of input contains 2*N space separated integers depicting the values of the array. Constraints:- 1 <= N <= 10000 1 <= Arr[i] <= 100000Print the shuffled array.Sample Input:- 3 1 2 3 4 5 6 Sample Output:- 1 4 2 5 3 6 Sample Input:- 2 2 4 6 8 Sample Output:- 2 6 4 8, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[2*n]; int j=0; for(int i=0;i<2*n;i++){ a[j]=sc.nextInt(); j+=2; if(j>=2*n){ j=1; } } for(int i=0;i<2*n;i++){ System.out.print(a[i]+" "); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: L,B,H=input().split() a=4*(int(L)+int(B)+int(H)) print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given the length, breadth, and height of a cuboid. Your task is to calculate its Perimeter. Note:- Formula for the perimeter of the cuboid is 4(Length + Breadth + height)<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>Perimeter()</b> that takes integers L, B, and H as parameters. Constraints:- 1 <= L, B, H <= 100Return the length of the Cuboid.Sample Input:- L = 3, B = 5, H = 1 Sample Output:- 36 Sample Input:- L = 1, B = 1, H = 1 Sample Output:- 12, I have written this Solution Code: static int Perimeter(int L, int B, int H){ return 4*(L+B+H); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N. <b>Constraints:</b> 1 < = T < = 1000 1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:- 2 625 624 Sample Output:- YES NO, I have written this Solution Code: import math cases=int(input("")) for case in range(cases): n=int(input()) if math.sqrt(n) % 1 == 0:print("YES") else:print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N. <b>Constraints:</b> 1 < = T < = 1000 1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:- 2 625 624 Sample Output:- YES NO, 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 main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ long n = sc.nextLong(); if(check(n)==1){ System.out.println("YES"); } else{ System.out.println("NO"); } } } static int check(long n){ long l=1; long h = 10000000; long m=0; long p=0; long ans=0; while(l<=h){ m=l+h; m/=2; p=m*m; if(p > n){ h=m-1; } else{ l=m+1; ans=m; } //System.out.println(l+" "+h); } if(ans*ans==n){return 1;} return 0; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, your task is to find if it is a perfect square or not.The first line of input contains the number of test cases T, the next T lines contains a single integer N. <b>Constraints:</b> 1 < = T < = 1000 1 < = N < = 10<sup>12</sup>For each test case, print "YES" if the number N is a perfect square else print "NO".Sample Input:- 2 625 624 Sample Output:- YES NO, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ long long n; cin>>n; long long x=sqrt(n); long long p = x*x; if(p==n){cout<<"YES"<<endl;;} else{ cout<<"NO"<<endl; } } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: n=int(input()) bSum=0 wSum=0 for i in range(n): c=(input().split()) for j in range(len(c)): if(i%2==0): if(j%2==0): bSum+=int(c[j]) else: wSum+=int(c[j]) else: if(j%2==0): wSum+=int(c[j]) else: bSum+=int(c[j]) print(bSum) print(wSum), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a chessboard of size N x N, where the top left square is black. Each square contains a value. Find the sum of the values of all black squares and all white squares. Remember that in a chessboard black and white squares are alternate.The first line of input will be the N size of the matrix. Then next N lines will consist of elements of the matrix. Each row will contain N elements since it is a square matrix. <b>Constraints:-</b> 1 &le; N &le; 800 1 &le; Matrix[i][j] &le; 100000 Print two lines, the first line containing the sum of black squares and the second line containing the sum of white squares.Input 1: 3 1 2 3 4 5 6 7 8 9 Output 1: 25 20 Sample Input 2: 4 1 2 3 4 6 8 9 10 11 12 13 14 15 16 17 18 Sample Output 2: 80 79 <b>Explanation 1</b> The black square contains 1, 3, 5, 7, 9; sum = 25 The white square contains 2, 4, 6, 8; sum = 20, I have written this Solution Code: import java.util.*; import java.io.*; import java.lang.*; class Main { public static void main (String[] args)throws IOException { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int mat[][] = new int[N][N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) mat[i][j] = sc.nextInt(); } alternate_Matrix_Sum(mat,N); } static void alternate_Matrix_Sum(int mat[][], int N) { long sum =0, sum1 = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if((i+j)%2 == 0) sum += mat[i][j]; else sum1 += mat[i][j]; } } System.out.println(sum); System.out.print(sum1); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included). <b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0. <b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M. Constraints:- 1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:- 1 10 Sample Output:- 4 Sample Input:- 8 10 Sample Output:- 0, I have written this Solution Code: from math import sqrt def isPrime(n): if (n <= 1): return False for i in range(2, int(sqrt(n))+1): if (n % i == 0): return False return True x=input().split() n=int(x[0]) m=int(x[1]) count = 0 for i in range(n,m): if isPrime(i): count = count +1 print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integers N and M, your task is to print the number of primes present between N and M (both included). <b>Note</b>:- You have already provided a function that will check if the given number is prime or not. To use the given function you need to call <b>check_prime(x)</b> where x is the number you want to check. If the given number is prime the function will return 1 else it returns 0. <b>Note</b>:- Do not close your main class.The input contains two space- separated integers depicting the values of N and M. Constraints:- 1 <= N <= M <= 10000Print the count of prime numbers in the given range.Sample Input:- 1 10 Sample Output:- 4 Sample Input:- 8 10 Sample Output:- 0, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int m = sc.nextInt(); int cnt=0; for(int i=n;i<=m;i++){ if(check_prime(i)==1){cnt++;} } System.out.println(cnt); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is palindrome or not. A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter. Constraints:- 1<=N<=1000 1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:- 5 1 2 3 2 1 Sample Output 1:- Yes Sample Input 2:- 3 1 2 2 Sample Output 2:- No, I have written this Solution Code: n=int(input()) l=input().split() l=[int(i) for i in l] if l[::-1]==l: print("Yes") else: print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a linked list consisting of N nodes, your task is to check if the given list is palindrome or not. A palindrome is a string/number that mirrors itself, for example, 21312 reverse is also 21312.User task: Since this will be a functional problem, you don't have to take input. You just have to complete the functions <b>Ispalindrome()</b> that takes the head of the linked list as parameter. Constraints:- 1<=N<=1000 1<=Node.data<=1000Return true if given list is palindrome else return false.Sample Input 1:- 5 1 2 3 2 1 Sample Output 1:- Yes Sample Input 2:- 3 1 2 2 Sample Output 2:- No, I have written this Solution Code: public static boolean IsPalindrome(Node head) { Node slow = head; boolean ispalin = true; Stack<Integer> stack = new Stack<Integer>(); while (slow != null) { stack.push(slow.val); slow = slow.next; } while (head != null) { int i = stack.pop(); if (head.val == i) { ispalin = true; } else { ispalin = false; break; } head = head.next; } return ispalin; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n holding some random value, your task is to assign value 10 to the given integer.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>Assignment_Operator()</b>, which takes no parameter. <b>Constraints:</b> 1 <= n <= 100You don't need to print anything you just need to assign value 10 to the integer n.Sample Input:- 48 Sample output:- 10 Sample Input:- 24 Sample Output:- 10, I have written this Solution Code: static void Assignment_Operator(){ n=10; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given an array A of size N. Find the number of pairs of indices (i, j) in the array A such that i < j and A<sub>i</sub> - i = A<sub>j</sub> - j.The first line of the input contains a single integer N. The second line of the input contains N space seperated integers. Constraints: 1 <= N <= 10<sup>5</sup> 1 <= A<sub>i</sub> <= 10<sup>5</sup>Print the number of pairs of indices (i, j) in the given array A such that i < j and A<sub>i</sub> - i = A<sub>j</sub> - j.Sample Input: 4 1 3 3 4 Sample Output: 3 Explaination: The three pairs of indices are: (1, 3) -> A[1] - 1 = A[3] - 3 -> 1 - 1 = 3 - 3 -> 0 = 0 (1, 4) -> A[1] - 1 = A[4] - 4 -> 1 - 1 = 4 - 4 -> 0 = 0 (3, 4) -> A[3] - 3 = A[4] - 4 -> 3 - 3 = 4 - 4 -> 0 = 0, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; map<int, int> mp; int ans = 0; for(int i = 1; i <= n; ++i){ int x; cin >> x; mp[x - i]++; } for(auto i:mp) ans += i.second * (i.second - 1)/2; cout << ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n holding some random value, your task is to assign value 10 to the given integer.User task: Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>Assignment_Operator()</b>, which takes no parameter. <b>Constraints:</b> 1 <= n <= 100You don't need to print anything you just need to assign value 10 to the integer n.Sample Input:- 48 Sample output:- 10 Sample Input:- 24 Sample Output:- 10, I have written this Solution Code: static void Assignment_Operator(){ n=10; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable