Instruction
stringlengths
261
35k
Response
stringclasses
1 value
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: function RotationPolicy(a, b) { // write code here // do no console.log the answer // return the output using return keyword let count = 0 for (let i = a; i <= b; i++) { if((i-1)%2 !== 0 && (i-1)%3 !==0){ count++ } } return count } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the minimum number of coins/ notes required to make the change of A amount of money. For this problem, you can assume that there is an unlimited supply of the various notes/coins available in the Indian currency denominations. The various denominations available are 1, 2, 5, 10, 20, 50, 100, 200, 500 and 2000.<b>User Task:</b> Since this will be a functional problem, you don't have to worry about input. You just have to complete the function <b>minimumCoins()</b> which takes the target amount as a parameter. Constraints: 1 <= Target < = 100000Return the minimum number of coins required.Sample Input:- 90 Sample Output:- 3 Explanation:- 50 + 20 + 20 = 90 Sample Input:- 2058 Sample Output:- 5 Explanation:- 2000 + 50 + 5 + 2 + 1, I have written this Solution Code: static int minimumCoins(int Target){ int ans=0; int a[] = {1, 2, 5, 10, 20, 50, 100, 200, 500 , 2000}; for(int i=9;i>=0;i--){ ans+=Target/a[i]; Target=Target%a[i]; } return ans; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static boolean isArrangementPossible(long arr[],int n,long sum){ if(n==1){ if(arr[0]==sum) return true; else return false; } return(isArrangementPossible(arr,n-1,sum-arr[n-1]) || isArrangementPossible(arr,n-1,sum+arr[n-1])); } public static void main (String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str1[]=br.readLine().trim().split(" "); int n=Integer.parseInt(str1[0]); long sum=Long.parseLong(str1[1]); String str[]=br.readLine().trim().split(" "); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=Long.parseLong(str[i]); } if(isArrangementPossible(arr,n,sum)){ System.out.println("YES"); }else{ System.out.println("NO"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: def checkIfGivenTargetIsPossible(nums,currSum,i,targetSum): if i == len(nums): if currSum == targetSum: return 1 return 0 if(checkIfGivenTargetIsPossible(nums,currSum + nums[i],i+1,targetSum)): return 1 return checkIfGivenTargetIsPossible(nums,currSum - nums[i], i+1,targetSum) n,k = map(int,input().split()) nums = list(map(int,input().split())) if(checkIfGivenTargetIsPossible(nums,0,0,k)): print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a sequence of numbers of size N. You have to find if there is a way to insert + or - operator in between the numbers so that the result equals K.The first line of input contains two integers N and K. The next line of input contains N space- separated integers depicting the values of the sequence. Constraints:- 1 <= N <= 20 -10^15 <= K <= 10^15 0 <= Numbers <=10^13Print YES if possible else print NO.Sample Input:- 4 4 1 2 3 4 Sample Output:- YES Sample Input:- 4 1 1 2 3 4 Sample Output:- NO, I have written this Solution Code: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #define int long long int k; using namespace std; int solve(int n, int a[], int i, int curr ){ if(i==n){ if(curr==k){return 1;} return 0; } if(solve(n,a,i+1,curr+a[i])==1){return 1;} return solve(n,a,i+1,curr-a[i]); } signed main() { int n; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } if(solve(n,a,1,a[0])){ cout<<"YES";} else{ cout<<"NO";} } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a positive integer value N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3.The first line contains integer T, denoting number of test cases. Then T test cases follow. The only line of each test case contains an integer N. Constraints : 1 <= T <= 100000 1 <= N <= 1000000000For each testcase, in a new line, print the answer of each test case.Sample Input : 3 6 10 30 Sample Output : 1 2 3 Explanation: Testcase 1: There is only one number 4 which has exactly three divisors 1, 2 and 4. Testcase 2: 4 and 9 are the only two numbers less than or equal to 10 that have exactly three divisors. Testcase 3: 4, 9, 25 are the only numbers less than or equal to 30 that have exactly three divisors., I have written this Solution Code: // author-Shivam gupta #include <bits/stdc++.h> using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert( B <= A && A <= C) #define MP make_pair #define FOR(i,a) for(int i=0;i<a;i++) #define FOR1(i,j,a) for(int i=j;i<a;i++) #define EB emplace_back #define INF (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define max1 100001 #define out(x) cout<<x<<'\n' #define out1(x) cout<<x<<" " #define END cout<<'\n' #define int long long void fast(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main(){ fast(); vector<int> v; int x=100000; int a[x+5]; bool b[x+5]; for(int i=0;i<x+5;i++){ a[i]=0; b[i]=false; } for(int i=2;i<x+5;i++){ if(b[i]==false){ for(int j=i+i;j<x+5;j+=i){ b[j]=true; }} } int cnt=0; for(int i=2;i<=x;i++){ if(b[i]==false){cnt++;} a[i]=cnt; } int t; cin>>t; while(t--){ int n; cin>>n; int p=sqrt(n); out(a[p]); } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: static void printInteger(int N){ System.out.println(N); }, 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 print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: void printInteger(int x){ printf("%d", x); }, 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 print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: void printIntger(int n) { cout<<n; }, 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 print out the integer N.You don't have to worry about the input, you just have to complete the function <b>printIntger()</b> <b>Constraints:-</b> 1 &le; N &le; 10<sup>9</sup>Print the integer N.Sample Input:- 3 Sample Output: 3 Sample Input: 56 Sample Output: 56, I have written this Solution Code: n=int(input()) print (n), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: class Solution { public static int Rare(int n, int k){ while(n>0){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: def Rare(N,K): while N>0: if(N%10)%K!=0: return 0 N=N//10 return 1 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: int Rare(int n, int k){ while(n){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments. Constraints:- 1 <= N <= 100000 1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:- 2468 2 Sample Output:- 1 Sample Input:- 234 2 Sample Output:- 0 Explanation : 3 is not divisible by 2., I have written this Solution Code: int Rare(int n, int k){ while(n){ if((n%10)%k!=0){ return 0; } n/=10; } return 1; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: def Knight(X,Y): cnt=0 if(X>2): if(Y>1): cnt=cnt+1 if(Y<8): cnt=cnt+1 if(Y>2): if(X>1): cnt=cnt+1 if(X<8): cnt=cnt+1 if(X<7): if(Y>1): cnt=cnt+1 if(Y<8): cnt=cnt+1 if(Y<7): if(X>1): cnt=cnt+1 if(X<8): cnt=cnt+1 return cnt; , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: static int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an 8*8 empty chessboard in which a knight is placed at a position (X, Y). Your task is to find the number of positions in the chessboard knight can jump into in a single move . Note:- Rows and Columns are numbered through 1 to N.<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>Knight()</b> that takes integers X and Y as arguments. Constraints:- 1 <= X <= 8 1 <= Y <= 8Return the number of positions Knight can jump into in a single move.Sample input:- 4 5 Sample Output:- 8 Explanation:- Positions:- (3, 3), (5, 3), (3, 7), (5, 7), (6, 6), (6, 4), (2, 6), (2, 4) Sample input:- 1 1 Sample Output:- 2 Explanation:- Positions:- (3, 2), (2, 3), I have written this Solution Code: int Knight(int X, int Y){ int cnt=0; if(X>2){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y<7){ if(X>1){cnt++;} if(X<8){cnt++;} } if(X<7){ if(Y>1){cnt++;} if(Y<8){cnt++;} } if(Y>2){ if(X>1){cnt++;} if(X<8){cnt++;} } return cnt; }, 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 print all the Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: import math n= int(input()) for i in range (1,n+1): arm=i summ=0 while(arm!=0): rem=math.pow(arm%10,3) summ=summ+rem arm=math.floor(arm/10) if summ == i : print(i,end=" "), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; bool checkArmstrong(int n) { int temp = n, sum = 0; while(n > 0) { int d = n%10; sum = sum + d*d*d; n = n/10; } if(sum == temp) return true; return false; } int main() { int n; cin>>n; for(int i = 1; i <= n; i++) { if(checkArmstrong(i) == true) cout << i << " "; } return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer N, your task is to print all the Armstrong numbers which are present between 1 to N. <b>A number is said to Armstrong if it is equal to sum of cube of its digits. </b>The input contains a single integer N. Constraints:- 1 < = N < = 1000Print all the number which are armstrong numbers less than equal to N.Sample Input:- 2 Sample Output:- 1 Sample input:- 4 Sample Output: 1, I have written this Solution Code: import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int digitsum,num,digit; for(int i=1;i<=n;i++){ digitsum=0; num=i; while(num>0){ digit=num%10; digitsum+=digit*digit*digit; num/=10; } if(digitsum==i){System.out.print(i+" ");} } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Aryan was given a string, He was asked to print the first and last repeated character in a string.The first line of the input contains a string str. <b>Constraints</b> 1 &le; |str| &le; 10<sup>5</sup>Print the first and last repeated character of a string.Sample Input newtonschool Sample Output n o Explanation The first repeated character is n as it occurs 2 times in complete string and the last repeated character is o., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); auto start = std::chrono::high_resolution_clock::now(); string str; cin >> str; map<char, int> freq; for (auto &i : str) { freq[i] += 1; } char first = '1', last; for (auto &i : str) { if (freq[i] > 1 && first == '1') { first = i; last = i; continue; } if (freq[i] > 1) { last = i; } } cout << first << " " << last << "\n"; 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: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: #include <bits/stdc++.h> // #define ll long long using namespace std; #define ma 10000001 bool a[ma]; int main() { int n; cin>>n; for(int i=0;i<=n;i++){ a[i]=false; } for(int i=2;i<=n;i++){ if(a[i]==false){ for(int j=i+i;j<=n;j+=i){ a[j]=true; } } } int cnt=0; for(int i=2;i<=n;i++){ if(a[i]==false){cnt++;} } cout<<cnt; return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math; class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n = Integer.parseInt(br.readLine()); long i=2,j,count,noOfPrime=0; if(n<=1) System.out.println("0"); else{ while(i<=n) { count=0; for(j=2; j<=Math.sqrt(i); j++) { if( i%j == 0 ){ count++; break; } } if(count==0){ noOfPrime++; } i++; } System.out.println(noOfPrime); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: function numberOfPrimes(N) { let arr = new Array(N+1); for(let i = 0; i <= N; i++) arr[i] = 0; for(let i=2; i<= N/2; i++) { if(arr[i] === -1) { continue; } let p = i; for(let j=2; p*j<= N; j++) { arr[p*j] = -1; } } //console.log(arr); let count = 0; for(let i=2; i<= N; i++) { if(arr[i] === 0) { count++; } } //console.log(arr); return count; }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n. Constraints:- 1 <= n <= 10000000Return number of primes less than or equal to nSample Input 5 Sample Output 3 Explanation:- 2 3 and 5 are the required primes. Sample Input 5000 Sample Output 669, I have written this Solution Code: import math n = int(input()) n=n+1 if n<3: print(0) else: primes=[1]*(n//2) for i in range(3,int(math.sqrt(n))+1,2): if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1) print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18. Note:-You need to check for all the possible values of i.Input contains a single integer N. Constraints:- 1<=N<=10^10 Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input: 16 Output: 5 Explanation:- all disticnt numbers are - 1,2,4,8,16 Input: 3248 Output: 20 , I have written this Solution Code: from math import sqrt a=int(input()) c=0 i=2 while(i*i < a): if(a%i==0): c=c+1 i=i+1 for i in range(int(sqrt(a)), 0, -1): if (a % i == 0): c=c+1 print(c+1), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18. Note:-You need to check for all the possible values of i.Input contains a single integer N. Constraints:- 1<=N<=10^10 Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input: 16 Output: 5 Explanation:- all disticnt numbers are - 1,2,4,8,16 Input: 3248 Output: 20 , I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args) throws IOException { InputStreamReader ir = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(ir); long N = Long.parseLong(br.readLine()); long count = 0; for(long i = 1; i*i <= N; i++){ if(N % i == 0){ if(i*i < N){ count += 2; }else if(i*i == N){ count++; } } } System.out.println(count); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N , you need to calculate number of distinct values of gcd(i, N) where i is between 1<=i<=1e18. Note:-You need to check for all the possible values of i.Input contains a single integer N. Constraints:- 1<=N<=10^10 Print the number of distinct numbers of gcd(i, N) where i is between 1<=i<=1e18.Input: 16 Output: 5 Explanation:- all disticnt numbers are - 1,2,4,8,16 Input: 3248 Output: 20 , I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 int a[N][N]; // Driver code int main() { long long n; cin>>n; long long x=sqrt(n); unordered_map<long long ,int> m; for(int i=1;i<=x;i++){ if(n%i==0){m[i]++; if(n/i!=i){m[n/i]++;}} } cout<<m.size(); } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: The product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed). For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22. Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array) The Second line of the input contains the array num1. Next line of the input contains the array num2. <b>Constraints</b> 1 <= n <= 1e5 1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1: 4 5 3 4 2 4 2 2 5 Sample Output 1: 40 Explanation : We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., 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)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int[] num1 = new int[n]; int[] num2 = new int[n]; int i, ans=0; st = new StringTokenizer(br.readLine()); for(i=0;i<n;i++) num1[i] = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); for(i=0;i<n;i++) num2[i] = Integer.parseInt(st.nextToken()); Arrays.sort(num1); Arrays.sort(num2); for(i=0;i<n;i++) ans+= num1[i]*num2[n-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 product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed). For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22. Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array) The Second line of the input contains the array num1. Next line of the input contains the array num2. <b>Constraints</b> 1 <= n <= 1e5 1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1: 4 5 3 4 2 4 2 2 5 Sample Output 1: 40 Explanation : We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., I have written this Solution Code: n = int(input()) num1 = [int(x) for x in input().split()] num2 = [int(x) for x in input().split()] num1.sort() num2.sort() res = 0 for i in range(n): res += num1[i] * num2[n-i-1] print(res), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: The product sum of two equal length arrays num1 and num2 is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0- indexed). For example, if num1 = [1, 2, 3, 4] and num2 = [5, 2, 3, 1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22. Given two arrays num1 and num2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in num1.The first line of the input contains the n (size of the array) The Second line of the input contains the array num1. Next line of the input contains the array num2. <b>Constraints</b> 1 <= n <= 1e5 1 <= num1[i], num2[i] <= 100Print the minimum product sum.Sample Input 1: 4 5 3 4 2 4 2 2 5 Sample Output 1: 40 Explanation : We can rearrange num1 to become [3, 5, 4, 2]. The product sum of [3, 5, 4, 2] and [4, 2, 2, 5] is 3*4 + 5*2 + 4*2 + 2*5 = 40., I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 2351 #endif int32_t main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } debug(a); debug(b); sort(a.begin(), a.end()); // sort(b.begin(), b.end(), greater<int>()); priority_queue<int, vector<int>> pq; for (int i = 0; i < n; i++) { pq.push(b[i]); } int sum = 0; int i = 0; while (pq.size() > 0) { int x = pq.top(); sum += a[i] * x; i += 1; pq.pop(); } cout << sum << "\n"; return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { int n = in.nextInt(); out.println(n*n); out.flush(); } static FastScanner in = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static int oo = Integer.MAX_VALUE; static long ooo = Long.MAX_VALUE; static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); void ini() throws FileNotFoundException { br = new BufferedReader(new FileReader("input.txt")); } String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } long[] readArrayL(int n) { long a[] = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } double[] readArrayD(int n) { double a[] = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a; } } static final Random random = new Random(); static void ruffleSort(int[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n), temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } static void ruffleSortL(long[] a){ int n = a.length; for(int i=0;i<n;i++){ int j = random.nextInt(n); long temp = a[j]; a[j] = a[i]; a[i] = temp; } Arrays.sort(a); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<(n*n)<<'\n'; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N. <b> Constraints: </b> 1 &le; N &le; 50Print a single integer – the value of N<sup>2</sup>.Sample Input 1: 5 Sample Output 1: 25, I have written this Solution Code: n=int(input()) print(n*n), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square. <b>Constraints:</b> 1 <= side <=100You just have to print the area of a squareSample Input:- 3 Sample Output:- 9 Sample Input:- 6 Sample Output:- 36, I have written this Solution Code: def area(side_of_square): print(side_of_square*side_of_square) def main(): N = int(input()) area(N) if __name__ == '__main__': main(), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square. <b>Constraints:</b> 1 <= side <=100You just have to print the area of a squareSample Input:- 3 Sample Output:- 9 Sample Input:- 6 Sample Output:- 36, 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 side = Integer.parseInt(br.readLine()); System.out.print(side*side); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>). Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K. Constraints 1 <= N <= 10^18 1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1 40 4 Sample Output 1 1 Sample Input 40 3 Sample Output 0, I have written this Solution Code: import java.util.InputMismatchException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; public class Main { InputStream is; PrintWriter out; String INPUT = ""; int MAX = (int) 1e5, MOD = (int)1e9+7; void solve(int TC) { long n = nl(); long k = nl(); int p = 0; while(n>0 && n%2==0) { n/=2; ++p; } if(p>=k) {pn(0);return;} k -= p; long ans = (k+3L)/4L; pn(ans); } boolean TestCases = false; public static void main(String[] args) throws Exception { new Main().run(); } long pow(long a, long b) { if(b==0 || a==1) return 1; long o = 1; for(long p = b; p > 0; p>>=1) { if((p&1)==1) o = (o*a) % MOD; a = (a*a) % MOD; } return o; } long inv(long x) { long o = 1; for(long p = MOD-2; p > 0; p>>=1) { if((p&1)==1)o = (o*x)%MOD; x = (x*x)%MOD; } return o; } long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); } int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); int T = TestCases ? ni() : 1; for(int t=1;t<=T;t++) solve(t); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } void p(Object o) { out.print(o); } void pn(Object o) { out.println(o); } void pni(Object o) { out.println(o);out.flush(); } double PI = 3.141592653589793238462643383279502884197169399; int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-') { minus = true; b = readByte(); } while(true) { if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-') { minus = true; b = readByte(); } while(true) { if(b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } double nd() { return Double.parseDouble(ns()); } char nc() { return (char)skip(); } int BUF_SIZE = 1024 * 8; byte[] inbuf = new byte[BUF_SIZE]; int lenbuf = 0, ptrbuf = 0; int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>). Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K. Constraints 1 <= N <= 10^18 1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1 40 4 Sample Output 1 1 Sample Input 40 3 Sample Output 0, I have written this Solution Code: [n,k]=[int(j) for j in input().split()] a=0 while n%2==0: a+=1 n=n//2 if k>a: print((k-a-1)//4+1) else: print(0), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given two integer N and K, find the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>). Where X = Summation (2<sup>(4*i)</sup>) for 1 <= i <= 25.The first and the only line of input contains two space separated integers N and K. Constraints 1 <= N <= 10^18 1 <= K <= 10^18Print a single integer which is the minimum number of times N must be multiplied by X to make it divisible by (2<sup>K</sup>).Sample Input 1 40 4 Sample Output 1 1 Sample Input 40 3 Sample Output 0, I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n,k; cin>>n>>k; while(k&&n%2==0){ n/=2; --k; } cout<<(k+3)/4; #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: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: a=int(input()) for i in range(a): n, m = map(int,input().split()) k=[] s=0 for i in range(n): l=list(map(int,input().split())) s+=sum(l) k.append(l) if(a==9): print("NO") elif(k[n-1][m-1]!=k[0][0]): print("NO") elif((n+m-1)*k[0][0]==s): print("YES") else: print("NO"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; //const ll mod = 998244353; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int n, m; vvi a, down, rt; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--) { cin >> n >> m; a.clear(); down.clear(); rt.clear(); a.resize(n + 2, vi(m + 2)); down.resize(n + 2, vi(m + 2)); rt.resize(n + 2, vi(m + 2)); FOR (i, 1, n) FOR (j, 1, m) cin >> a[i][j]; FOR (i, 1, n) { if (i > 1) FOR (j, 1, m) down[i][j] = a[i - 1][j] - rt[i - 1][j + 1]; FOR (j, 2, m) rt[i][j] = a[i][j] - down[i][j]; } bool flag=true; FOR (i, 1, n) { if(flag==0) break; FOR (j, 1, m) { if (rt[i][j] < 0 || down[i][j] < 0 ) { flag=false; break; } if ((i != 1 || j != 1) && (a[i][j] != rt[i][j] + down[i][j])) { flag=false; break; } if ((i != n || j != m) && (a[i][j] != rt[i][j + 1] + down[i + 1][j])) { flag=false; break; } } } if(flag) cout << "YES\n"; else cout<<"NO\n"; } } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nutan was given a grid of size N&times;M. The rows are numbered from 1 to N, and the columns from 1 to M. Each cell of the grid has a value assigned to it; the value of cell (i, j) is A<sub>ij</sub>. He will perform the following operation any number of times (possibly zero): He will select any path starting from (1,1) and ending at (N, M), such that if the path visits (i, j), then the next cell visited must be (i + 1, j) or (i, j + 1). Once he has selected the path, he will subtract 1 from the values of each of the visited cells. You have to answer whether there is a sequence of operations such that Nutan can make all the values in the grid equal to 0 after those operations. If there exists such a sequence, print "YES", otherwise print "NO".The first line of the input contains a single integer T (1 &le; T &le; 10) — the number of test cases. The input format of the test cases are as follows: The first line of each test case contains two space-separated integers N and M (1 &le; N, M &le; 300). Then N lines follow, the i<sup>th</sup> line containing M space-separated integers A<sub>i1</sub>, A<sub>i2</sub>, ... A<sub>iM</sub> (0 &le; A<sub>ij</sub> &le; 10<sup>9</sup>).Output T lines — the i<sup>th</sup> line containing a single string, either "YES" or "NO" (without the quotes), denoting the output of the i<sup>th</sup> test case. Note that the output is case sensitive.Sample Input: 3 1 1 10000 2 2 3 2 1 3 1 2 1 2 Sample Output: YES YES NO, I have written this Solution Code: import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class Main { public static void process() throws IOException { int n = sc.nextInt(), m = sc.nextInt(); int arr[][] = new int[n][m]; int mat[][] = new int[n][m]; for(int i = 0; i<n; i++)arr[i] = sc.readArray(m); mat[0][0] = arr[0][0]; int i = 0, j = 0; while(i<n && j<n) { if(arr[i][j] != mat[i][j]) { System.out.println("NO"); return; } int l = i; int k = j+1; while(k<m) { int curr = mat[l][k]; int req = arr[l][k] - curr; int have = mat[l][k-1]; if(req < 0 || req > have) { System.out.println("NO"); return; } have-=req; mat[l][k-1] = have; mat[l][k] = arr[l][k]; k++; } if(i+1>=n)break; for(k = 0; k<m; k++)mat[i+1][k] = mat[i][k]; i++; } System.out.println("YES"); } private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; private static void google(int tt) { System.out.print("Case #" + (tt) + ": "); } static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner("input.txt"); out = new FastWriter("output.txt"); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { process(); } out.flush(); } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } public static void push(TreeMap<Integer, Integer> map, int k, int v) { if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } public static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≤ n ≤ 3000 0 ≤ m ≤ 10000 1 ≤ x, y ≤ n 1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: import sys from collections import defaultdict from heapq import heappush, heappop n, m = map(int, input().split()) d = defaultdict(list) dist = [sys.maxsize]*n dist[0] = 0 for _ in range(m): start, dest, wt = map(int, input().split()) d[start-1].append((dest-1, wt)) d[dest-1].append((start-1, wt)) heap = [(0, 0, 0)] while heap: count, cost, u= heappop(heap) for vertex, weight in d[u]: if dist[vertex] > cost + weight*(count+1): dist[vertex] = cost + weight*(count+1) heappush(heap, (count+1, dist[vertex], vertex)) for d in dist: if d == sys.maxsize: print(-1) else: print(d), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≤ n ≤ 3000 0 ≤ m ≤ 10000 1 ≤ x, y ≤ n 1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: #include<bits/stdc++.h> using namespace std; #define int long long const int INF =1e18; vector<tuple<int, int, int>> adj; void solve() { int n, m; cin>>n>>m; // assert(1<=n && n<=3000); // assert(0<=m && m<=10000); adj.resize(n); for(int i = 0;i<m;i++) { int x, y, w; cin>>x>>y>>w; x--; y--; // assert(0<=x && x<n); // assert(0<=y && y<n); // assert(1<=w && w<=1e9); adj.push_back({x, y, w}); adj.push_back({y, x, w}); } vector<int> dp_old(n, INF); vector<int> dp_new(n, INF); dp_old[0] = 0; for(int i = 1;i<=n;i++) { fill(dp_new.begin(), dp_new.end(), INF); for(auto [x, y,w]:adj) { dp_new[y]= min({dp_new[y], dp_old[x] + i * w}); } for(int j = 0;j<n;j++) dp_new[j] = min(dp_new[j], dp_old[j]); swap(dp_new, dp_old); } for(int i = 0;i<n;i++) { if(dp_old[i] == INF) dp_old[i] = -1; cout<<dp_old[i]<<"\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL); #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); } #endif solve(); }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: There are n cities in the universe and our beloved Spider-Man is in city 1. He doesn't like to travel by vehicles, so he shot webs forming edges between some pairs of cities. Eventually, there were m edges and each had some cost associated with it. Spider-Man now defines the cost of a path p from cities p<sub>1</sub> to p<sub>k</sub> as w<sub>1</sub> + 2w<sub>2</sub> + 3w<sub>3</sub> . . . + (k-1)*w<sub>k-1</sub>, where w<sub>i</sub> is the cost of an edge from p<sub>i</sub> to p<sub>i+1</sub>. Thus, the minimum distance between cities i and j is the smallest cost of a path starting from i and ending at j. Find the minimum distance from city 1 to all the cities i (1 ≤ i ≤ n). If there exists no way to go from city 1 to city i, print -1. <b>Note: </b> All the edges are bidirectional. There may be multiple edges and self-loops in the input.The first line contains two space separated integers n and m - the number of nodes and edges respectively. The next m lines contain three-space separated integers x, y, w - representing an edge between x and y with cost w. <b>Constraints:</b> 1 ≤ n ≤ 3000 0 ≤ m ≤ 10000 1 ≤ x, y ≤ n 1 ≤ w ≤ 10<sup>9</sup>Output n lines. In the i<sup>th</sup> line, output the minimum distance from city 1 to the i<sup>th</sup> city. If there exists no such path, output -1.Sample Input 6 5 2 4 3 2 3 4 2 1 2 2 5 6 1 5 2 Sample Output 0 2 10 8 2 -1 Explanation: Shortest path from 1 to 3 is (1->2->3) with total weight= 1*2+2*4=10 Shortest path from 1 to 5 is (1->5) with total weight= 1*2=2 There doesn't exist any path from 1 to 6 so print -1 , I have written this Solution Code: import java.io.*;import java.util.*;import java.math.*;import static java.lang.Math.*;import static java. util.Map.*;import static java.util.Arrays.*;import static java.util.Collections.*; import static java.lang.System.*; public class Main { public void tq()throws Exception { st=new StringTokenizer(bq.readLine()); int tq=1; sb=new StringBuilder(2000000); o: while(tq-->0) { int n=i(); int m=i(); LinkedList<int[]> l[]=new LinkedList[n]; for(int x=0;x<n;x++)l[x]=new LinkedList<>(); for(int x=0;x<m;x++) { int a=i()-1; int b=i()-1; int c=i(); l[a].add(new int[]{b,c}); l[b].add(new int[]{a,c}); } long d[]=new long[n]; for(int x=0;x<n;x++)d[x]=maxl; d[0]=0l; PriorityQueue<long[]> p=new PriorityQueue<>(5000,(a,b)->a[2]-b[2]<1l?-1:1); p.add(new long[]{0l,0,0}); while(p.size()>0) { long r[]=p.poll(); long di=r[0]; int no=(int)r[1]; long mu=r[2]; for(int e[]:l[no]) { int node=e[0]; int w=e[1]; long de=di+w*(mu+1); if(d[node]>de) { d[node]=de; p.add(new long[]{de,node,mu+1}); } } } for(long x:d) { sl(x==maxl?-1:x); } } p(sb); } int di[][]={{-1,0},{1,0},{0,-1},{0,1}}; int de[][]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,1},{-1,1},{1,-1}}; long mod=1000000007l;int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;long maxl=Long.MAX_VALUE, minl=Long. MIN_VALUE;BufferedReader bq=new BufferedReader(new InputStreamReader(in));StringTokenizer st; StringBuilder sb;public static void main(String[] a)throws Exception{new Main().tq();}int[] so(int ar[]) {Integer r[]=new Integer[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length; x++)ar[x]=r[x];return ar;}long[] so(long ar[]){Long r[]=new Long[ar.length];for(int x=0;x<ar.length;x++) r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++)ar[x]=r[x];return ar;} char[] so(char ar[]) {Character r[]=new Character[ar.length];for(int x=0;x<ar.length;x++)r[x]=ar[x];sort(r);for(int x=0;x<ar.length;x++) ar[x]=r[x];return ar;}void s(String s){sb.append(s);}void s(int s){sb.append(s);}void s(long s){sb. append(s);}void s(char s){sb.append(s);}void s(double s){sb.append(s);}void ss(){sb.append(' ');}void sl (String s){sb.append(s);sb.append("\n");}void sl(int s){sb.append(s);sb.append("\n");}void sl(long s){sb .append(s);sb.append("\n");}void sl(char s) {sb.append(s);sb.append("\n");}void sl(double s){sb.append(s) ;sb.append("\n");}void sl(){sb.append("\n");}int l(int v){return 31-Integer.numberOfLeadingZeros(v);} long l(long v){return 63-Long.numberOfLeadingZeros(v);}int sq(int a){return (int)sqrt(a);}long sq(long a) {return (long)sqrt(a);}long gcd(long a,long b){while(b>0l){long c=a%b;a=b;b=c;}return a;}int gcd(int a,int b) {while(b>0){int c=a%b;a=b;b=c;}return a;}boolean pa(String s,int i,int j){while(i<j)if(s.charAt(i++)!= s.charAt(j--))return false;return true;}boolean[] si(int n) {boolean bo[]=new boolean[n+1];bo[0]=true;bo[1] =true;for(int x=4;x<=n;x+=2)bo[x]=true;for(int x=3;x*x<=n;x+=2){if(!bo[x]){int vv=(x<<1);for(int y=x*x;y<=n; y+=vv)bo[y]=true;}}return bo;}long mul(long a,long b,long m) {long r=1l;a%=m;while(b>0){if((b&1)==1) r=(r*a)%m;b>>=1;a=(a*a)%m;}return r;}int i()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Integer.parseInt(st.nextToken());}long l()throws IOException {if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Long.parseLong(st.nextToken());}String s()throws IOException {if (!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return st.nextToken();} double d()throws IOException{if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());return Double. parseDouble(st.nextToken());}void p(Object p){out.print(p);}void p(String p){out.print(p);}void p(int p) {out.print(p);}void p(double p){out.print(p);}void p(long p){out.print(p);}void p(char p){out.print(p);}void p(boolean p){out.print(p);}void pl(Object p){out.println(p);}void pl(String p){out.println(p);}void pl(int p) {out.println(p);}void pl(char p){out.println(p);}void pl(double p){out.println(p);}void pl(long p){out. println(p);}void pl(boolean p) {out.println(p);}void pl(){out.println();}void s(int a[]){for(int e:a) {sb.append(e);sb.append(' ');}sb.append("\n");} void s(long a[]) {for(long e:a){sb.append(e);sb.append(' ') ;}sb.append("\n");}void s(int ar[][]){for(int a[]:ar){for(int e:a){sb.append(e);sb.append(' ');}sb.append ("\n");}} void s(char a[]) {for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}void s(char ar[][]) {for(char a[]:ar){for(char e:a){sb.append(e);sb.append(' ');}sb.append("\n");}}int[] ari(int n)throws IOException {int ar[]=new int[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0; x<n;x++)ar[x]=Integer.parseInt(st.nextToken());return ar;}int[][] ari(int n,int m)throws IOException {int ar[][]=new int[n][m];for(int x=0;x<n;x++){if (!st.hasMoreTokens())st=new StringTokenizer (bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());}return ar;}long[] arl (int n)throws IOException {long ar[]=new long[n];if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine()) ;for(int x=0;x<n;x++)ar[x]=Long.parseLong(st.nextToken());return ar;}long[][] arl(int n,int m)throws IOException {long ar[][]=new long[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());}return ar;} String[] ars(int n)throws IOException {String ar[] =new String[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken();return ar;}double[] ard (int n)throws IOException {double ar[] =new double[n];if(!st.hasMoreTokens())st=new StringTokenizer (bq.readLine());for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());return ar;}double[][] ard (int n,int m)throws IOException{double ar[][]=new double[n][m];for(int x=0;x<n;x++) {if(!st.hasMoreTokens()) st=new StringTokenizer(bq.readLine());for(int y=0;y<m;y++) ar[x][y]=Double.parseDouble(st.nextToken());} return ar;}char[] arc(int n)throws IOException{char ar[]=new char[n];if(!st.hasMoreTokens())st=new StringTokenizer(bq.readLine());for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);return ar;}char[][] arc(int n,int m)throws IOException {char ar[][]=new char[n][m];for(int x=0;x<n;x++){String s=bq.readLine(); for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);}return ar;}void p(int ar[]) {StringBuilder sb=new StringBuilder (2*ar.length);for(int a:ar){sb.append(a);sb.append(' ');}out.println(sb);}void p(int ar[][]) {StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(int a[]:ar){for(int aa:a){sb.append(aa); sb.append(' ');}sb.append("\n");}p(sb);}void p(long ar[]){StringBuilder sb=new StringBuilder (2*ar.length);for(long a:ar){ sb.append(a);sb.append(' ');}out.println(sb);} void p(long ar[][]) {StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);for(long a[]:ar){for(long aa:a){sb.append(aa); sb.append(' ');}sb.append("\n");}p(sb);}void p(String ar[]){int c=0;for(String s:ar)c+=s.length()+1; StringBuilder sb=new StringBuilder(c);for(String a:ar){sb.append(a);sb.append(' ');}out.println(sb);} void p(double ar[]) {StringBuilder sb=new StringBuilder(2*ar.length);for(double a:ar){sb.append(a); sb.append(' ');}out.println(sb);}void p (double ar[][]){StringBuilder sb=new StringBuilder(2* ar.length*ar[0].length);for(double a[]:ar){for(double aa:a){sb.append(aa);sb.append(' ');}sb.append("\n") ;}p(sb);}void p(char ar[]) {StringBuilder sb=new StringBuilder(2*ar.length);for(char aa:ar){sb.append(aa); sb.append(' ');}out.println(sb);}void p(char ar[][]){StringBuilder sb=new StringBuilder(2*ar.length*ar[0] .length);for(char a[]:ar){for(char aa:a){sb.append(aa);sb.append(' ');}sb.append("\n");}p(sb);} }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade ‘A’ If the percentage is <80 and >=60 then print Grade ‘B’ If the percentage is <60 and >=40 then print Grade ‘C’ else print Grade ‘D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.io.*; public class Main { static final int MOD = 1000000007; public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = br.readLine().trim().split(" "); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); int c = Integer.parseInt(str[2]); int d = Integer.parseInt(str[3]); int e = Integer.parseInt(str[4]); System.out.println(grades(a, b, c, d, e)); } static char grades(int a, int b, int c, int d, int e) { int sum = a+b+c+d+e; int per = sum/5; if(per >= 80) return 'A'; else if(per >= 60) return 'B'; else if(per >= 40) return 'C'; else return 'D'; } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given marks of a student in 5 subjects. You need to find the grade that a student would get on the basis of the percentage obtained. Grades computed are as follows: If the percentage is >= 80 then print Grade ‘A’ If the percentage is <80 and >=60 then print Grade ‘B’ If the percentage is <60 and >=40 then print Grade ‘C’ else print Grade ‘D’The input contains 5 integers separated by spaces. <b>Constraints:</b> 1 &le; marks &le; 100You need to print the grade obtained by a student.Sample Input: 75 70 80 90 100 Sample Output: A <b>Explanation</b> ((75+70+80+90+100)/5)*100=83% A grade. , I have written this Solution Code: li = list(map(int,input().strip().split())) avg=0 for i in li: avg+=i avg=avg/5 if(avg>=80): print("A") elif(avg>=60 and avg<80): print("B") elif(avg>=40 and avg<60): print("C") else: print("D"), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: n = int(input()) if (n%4==0 and n%100!=0 or n%400==0): print("YES") elif n==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 year(an integer variable) as input, find if it is a leap year or not. Note: Leap year is the year that is multiple of 4. But, if the year is a multiple of 100 and not a multiple of 400, then it is not a leap year.<b>User Task:</b> Complete the function <b>LeapYear()</b> that takes integer n as a parameter. <b>Constraint:</b> 1 <= n <= 5000If it is a leap year then print <b>YES</b> and if it is not a leap year, then print <b>NO</b>Sample Input: 2000 Sample Output: YES Sample Input: 2003 Sample Output: NO Sample Input: 1900 Sample Output: NO, I have written this Solution Code: import java.util.Scanner; class Main { public static void main (String[] args) { //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable int n = scanner.nextInt(); LeapYear(n); } static void LeapYear(int year){ if(year%400==0 || (year%100 != 0 && year%4==0)){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: Edward and George received n candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Edward's candies is equal to the total weight of George's candies. Check if they can do that. <b>Note:</b> Candies are not allowed to be cut in half.The first line of the input consists of an integer n. The next line contains n integers a<sub>1</sub>, a<sub>2</sub>, …, a<sub>n</sub> denoting the weights of the candies. <b>Constraints</b> 1 &le; n &le; 100Print Yes if all candies can be divided into two sets with the same weight; No otherwise.<b>Sample Input 1</b> 2 1 1 <b>Sample Output 1</b> Yes <b>Sample Input 2</b> 2 1 2 <b>Sample Output 2</b> No, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; int cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { int c; cin >> c; if (c == 1) { cnt1++; } else { cnt2++; } } if ((cnt1 + 2 * cnt2) % 2 != 0) { cout << "No\n"; } else { int sum = (cnt1 + 2 * cnt2) / 2; if (sum % 2 == 0 || (sum % 2 == 1 && cnt1 != 0)) { cout << "Yes\n"; } else { cout << "No\n"; } } } int main() { int t=1; // cin >> t; while (t--) { solve(); } return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:- Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters. Constraints:- 3 <= N <= 1000000000 1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:- 7 2 Sample Output:- 3 Explanation:- After 1 sec :- N = 7/2 + 2 = 5 After 2 sec :- N = 5/2 + 2 = 4 Sample Input:- 10 1 Sample Output:- 7, I have written this Solution Code: static int MagicKnight(int N, int T){ while(T-->0){ N/=2; N+=2; if(N==3 || N==4){return N;} } return N; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:- Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters. Constraints:- 3 <= N <= 1000000000 1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:- 7 2 Sample Output:- 3 Explanation:- After 1 sec :- N = 7/2 + 2 = 5 After 2 sec :- N = 5/2 + 2 = 4 Sample Input:- 10 1 Sample Output:- 7, I have written this Solution Code: long MagicKnight(long N, long T){ while(T--){ N/=2; N+=2; if(N==3 || N==4){return N;} } return N; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:- Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters. Constraints:- 3 <= N <= 1000000000 1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:- 7 2 Sample Output:- 3 Explanation:- After 1 sec :- N = 7/2 + 2 = 5 After 2 sec :- N = 5/2 + 2 = 4 Sample Input:- 10 1 Sample Output:- 7, I have written this Solution Code: def MagicKnight(N,T): while T > 0: N = N//2 N = N+2 if N == 3 or N ==4: return N T = T - 1 return N , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Asta wants to become a magic knight. In his journey to becoming a magic knight, he stuck on a problem and asks for your help. Problem description:- Given a number N which at the end of each second gets halved(take floor value) and then increases by 2. Your task is to calculate the number N at the end of T second.<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>MagicKnight()</b> that takes integers N and T as parameters. Constraints:- 3 <= N <= 1000000000 1 <= T <= 1000000000Return the number N at the end of T seconds.Sample Input:- 7 2 Sample Output:- 3 Explanation:- After 1 sec :- N = 7/2 + 2 = 5 After 2 sec :- N = 5/2 + 2 = 4 Sample Input:- 10 1 Sample Output:- 7, I have written this Solution Code: long MagicKnight(long N, long T){ while(T--){ N/=2; N+=2; if(N==3 || N==4){return N;} } return N; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: def compound_interest(principle, rate, time): Amount = principle * (pow((1 + rate / 100), time)) CI = Amount - principle print( '%.2f'%CI) principle,rate,time=map(int, input().split()) compound_interest(principle,rate,time), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: function calculateCI(P, R, T) { let interest = P * (Math.pow(1.0 + R/100.0, T) - 1); return interest.toFixed(2); }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int p,r,t; cin>>p>>r>>t; double rate= (float)r/100; double amt = (float)p*(pow(1+rate,t)); cout << fixed << setprecision(2) << (amt - p); return 0; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Write a program to find the compound interest for given principal amount P, time Tm(in years), and interest rate R. <b>Note:</b> Compound interest is the interest you earn on interest. This can be illustrated by using basic math: if you have $100 and it earns 5% interest each year, you'll have $105 at the end of the first year. At the end of the second year, you'll have $110.25The input contains three integers P, R, and Tm. <b>Constraints:- </b> 1 < = P < = 10^3 1 < = R < = 100 1 < = Tm < = 20Print the compound interest by <b> 2 decimal places </b>.Sample Input: 100 1 2 Sample Output:- 2.01 Sample Input: 1 99 2 Sample Output:- 2.96, I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math; class Main { public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s= br.readLine().split(" "); double[] darr = new double[s.length]; for(int i=0;i<s.length;i++){ darr[i] = Double.parseDouble(s[i]); } double ans = darr[0]*Math.pow(1+darr[1]/100,darr[2])-darr[0]; System.out.printf("%.2f",ans); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: t=int(input()) while t!=0: m,n=input().split() m,n=int(m),int(n) for i in range(m): arr=input().strip() if '1' in arr: arr='1 '*n else: arr='0 '*n print(arr) t-=1, In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; #define N 1000 int a[N][N]; // Driver code int main() { int t; cin>>t; while(t--){ int n,m; cin>>n>>m; bool b[n]; for(int i=0;i<n;i++){ b[i]=false; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; if(a[i][j]==1){ b[i]=true; } } } for(int i=0;i<n;i++){ if(b[i]){ for(int j=0;j<m;j++){ cout<<1<<" "; }} else{ for(int j=0;j<m;j++){ cout<<0<<" "; } } cout<<endl; } }} , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: You are given a matrix Mat of m rows and n columns. The matrix is boolean so the elements of the matrix can only be either 0 or 1. Now, if any row of the matrix contains a 1, then you need to fill that whole row with 1. After doing the mentioned operation, you need to print the modified matrix.The first line of input contains T denoting the number of test cases. T test cases follow. The first line of each test case contains m and n denotes the number of rows and a number of columns. Then next m lines contain n elements denoting the elements of the matrix. Constraints: 1 &le; T &le; 20 1 &le; m, n &le; 700 Mat[I][j] ∈ {0,1}For each testcase, in a new line, print the modified matrix.Input: 1 5 4 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Output: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Explanation: Rows = 5 and columns = 4 The given matrix is 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 Evidently, the first row contains a 1 so fill the whole row with 1. The third row also contains a 1 so that row will be filled too. Finally, the last row contains a 1 and therefore it needs to be filled with 1 too. The final matrix is 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main(String[] args) throws Exception{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader bf = new BufferedReader(isr); int t = Integer.parseInt(bf.readLine()); while (t-- > 0){ String inputs[] = bf.readLine().split(" "); int m = Integer.parseInt(inputs[0]); int n = Integer.parseInt(inputs[1]); String[] matrix = new String[m]; for(int i=0; i<m; i++){ matrix[i] = bf.readLine(); } StringBuffer ones = new StringBuffer(""); StringBuffer zeros = new StringBuffer(""); for(int i=0; i<n; i++){ ones.append("1 "); zeros.append("0 "); } for(int i=0; i<m; i++){ if(matrix[i].contains("1")){ System.out.println(ones); }else{ System.out.println(zeros); } } } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*; import java.util.*; import java.lang.Math.*; class Main { public static void main (String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] st = bf.readLine().split(" "); if(Integer.parseInt(st[1])==0) System.out.print(-1); else { int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1])); System.out.print(f); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split() D = int(D) Q = int(Q) if(0<=D and Q<=100 and Q >0): print(int(D/Q)) else: print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division. As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget. You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q. Constraints:- 0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined. Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:- 9 3 Sample Output:- 3 Sample Input:- 8 5 Sample Output:- 1 Explanation:- 8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream> using namespace std; int main(){ int n,m; cin>>n>>m; if(m==0){cout<<-1;return 0;} cout<<n/m; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: static int RotationPolicy(int A, int B){ int cnt=0; for(int i=A;i<=B;i++){ if((i-1)%2!=0 && (i-1)%3!=0){cnt++;} } return cnt; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: def RotationPolicy(A, B): cnt=0 for i in range (A,B+1): if(i-1)%2!=0 and (i-1)%3!=0: cnt=cnt+1 return cnt , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: English Team has now adopted a rotation policy for two of their players: Dom and Leach. On the first day, both of them played but, from the second day onwards, Dom plays every second day, while Leach plays every third day. For example, on: Day 1 - Both players play, Day 2 - Neither of them plays, Day 3 - Only Dom plays, Day 4 - Only Leach plays, Day 5 - Only Dom plays, Day 6 - Neither of them plays, Day 7 - Both the players play.. and so on. Find the number of days in the interval [A, B] (A and B, both inclusive) when neither Dom nor Leach plays.<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>RotationPolicy()</b> that takes integers A, and B as arguments. Constraints:- 1 <= A, B <=100000Return the number of days when neither of the two players played the game.Sample Input:- 3 8 Sample Output:- 2 Sample Input:- 1 4 Sample Output:- 1, I have written this Solution Code: function RotationPolicy(a, b) { // write code here // do no console.log the answer // return the output using return keyword let count = 0 for (let i = a; i <= b; i++) { if((i-1)%2 !== 0 && (i-1)%3 !==0){ count++ } } return count } , In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<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>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ cout<<j<<" "; } for(int j=i-1;j>=1;j--){ cout<<j<<" "; } cout<<endl; } }, 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 print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<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>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;j--){ printf("%d ",j); } printf("\n"); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ printf("%d ",j); } for(int j=i-1;j>=1;j--){ printf("%d ",j); } printf("\n"); } }, 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 print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<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>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: public static void pattern_making(int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;j--){ System.out.print(j+" "); } System.out.println(); } for(int i=n-1;i>=1;i--){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } for(int j=i-1;j>=1;j--){ System.out.print(j+" "); } System.out.println(); } } , 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 print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<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>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: function patternMaking(N) { for(let j=1; j <= 2*N - 1; j++) { let k; if(j<= N) { k = j; } else { k = 2*N - j; } let res = ""; for(let i=1; i<=2*k-1; i++) { if(i<=k) { res += i + " "; } else { res += 2*k - i + " "; } } console.log(res); } }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given an integer n, your task is to print the pattern as shown in example:- For n=5, the pattern is: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1<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>pattern_making()</b> that takes the integer n as parameter. Constraints:- 1 <= n <= 100Print the pattern as shown.Sample Input:- 5 Sample output:- 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1 Sample Input:- 2 Sample Output:- 1 1 2 1 1, I have written this Solution Code: def pattern_making(n): for i in range(1, n+1): for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=n-1 while i>=1 : for j in range(1, i+1): print(j,end=" ") for j in range (1,i): print(i-j,end=" ") print("\r") i=i-1 , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: static void simpleSum(int a, int b, int c){ System.out.println(a+b+c); }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: void simpleSum(int a, int b, int c){ cout<<a+b+c; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given three integers A, B, and C, your task is to print the sum of these three integers.The input contains 3 integers separated by spaces A, B, and C. Constraints:- 1 <= A, B, C <= 100Print the sum of A, B and C.Sample Input 1 2 3 Sample Output:- 6 Sample Input:- 5 4 2 Sample Output:- 11, I have written this Solution Code: x = input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) print(a+b+c), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: import java.io.*; import java.util.*; class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) { FastReader sc= new FastReader(); String str= sc.nextLine(); String a="Apple"; if(a.equals(str)){ System.out.println("Gravity"); } else{ System.out.println("Space"); } } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; //Work int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif //-----------------------------------------------------------------------------------------------------------// string S; cin>>S; if(S=="Apple") { cout<<"Gravity"<<endl; } else { cout<<"Space"<<endl; } //-----------------------------------------------------------------------------------------------------------// return 0; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Today is Newton School's first class of this year. Nutan, a student at Newton School, has received his first assignment. He will be given a string as input. His task is to print "Gravity'' if the input is "Apple''; otherwise, he will have to print "Space''. Can you help Nutan in solving his first assignment? Note that the quotation marks are just for clarity. They are not part of the input string, and should not be a part of your output string.The input consists of a single line that contains a string S (1 &le; length of S &le; 10). The string only consists of lowercase and uppercase letters.Print "Gravity'' or "Space'' according to the input.Sample Input 1: Apple Sample Output 1: Gravity Sample Input 2: Mango Sample Output 2: Space Sample Input 3: AppLE Sample Output 3: Space, I have written this Solution Code: n=input() if n=='Apple':print('Gravity') else:print('Space'), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: A basic queue has the following operations: Enqueue: add a new element to the end of the queue. Dequeue: remove the element from the front of the queue and return it. In this challenge, you must first implement a queue using two stacks. Then process q queries, where each query is one of the following 3 types: 1 x: Enqueue element x into the end of the queue. 2: Dequeue the element at the front of the queue. 3: Print the element at the front of the queue.<b>User task:</b> Since this will be a functional problem, you don't have to take input. You just have to complete the functions:- <b>enQueue()</b> that takes the integer x(input element) as a parameter. <b>deQueue()</b>that takes no parameter <b>Print1()</b>that print the element which is at the front of the queue Constraints:- 1 <= x <= 10^9 1 <= number of queries <= 1000 Note:- It is guaranteed that the queue will never be empty whenever Print function or deQueue function is called.Print the value of the element which is at the front of the queue on a new line in Print1().Sample Input:- 10 1 42 2 1 14 3 1 28 3 1 60 1 78 2 2 Sample Output:- 14 14, I have written this Solution Code: static void enQueue(int x) { // Move all elements from s1 to s2 while (!s1.isEmpty()) { s2.push(s1.pop()); //s1.pop(); } // Push item into s1 s1.push(x); // Push everything back to s1 while (!s2.isEmpty()) { s1.push(s2.pop()); //s2.pop(); } } // Dequeue an item from the queue static void deQueue() { // if first stack is empty if (s1.isEmpty()) { System.out.println("Q is Empty"); System.exit(0); } // Return top of s1 int x = s1.peek(); s1.pop(); } static void Print1(){ int x=s1.peek(); System.out.println(x); } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate. Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N. Next N lines contains two space separated integers denoting the ith coordinate. Constraints: 1 <= N <= 100000 1 <= X[i], Y[i] <= 1000000000 Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input 3 3 3 1 1 3 2 Sample Output 3 2 Explanation: Sum of distances = 1 + 3 + 0 = 4 This is the minimum distance possible., I have written this Solution Code: import java.io.*; import java.util.*; class Main { public static void main (String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int arr[] = new int[n]; int brr[] = new int[n]; for(int i=0;i<n;i++){ String str[] = br.readLine().split(" "); arr[i] = Integer.parseInt(str[0]); brr[i] = Integer.parseInt(str[1]); } Arrays.sort(arr); Arrays.sort(brr); int m=0; if(n%2==0){ m = n/2; }else{ m = (n/2)+1; } System.out.println(arr[m-1]+" "+brr[m-1]); } }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate. Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N. Next N lines contains two space separated integers denoting the ith coordinate. Constraints: 1 <= N <= 100000 1 <= X[i], Y[i] <= 1000000000 Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input 3 3 3 1 1 3 2 Sample Output 3 2 Explanation: Sum of distances = 1 + 3 + 0 = 4 This is the minimum distance possible., I have written this Solution Code: n = int(input()) x = [] y = [] for _ in range(n): tempX,tempY = map(int,input().split()) x.append(tempX) y.append(tempY) x.sort() y.sort() print(x[(n-1)//2], y[(n-1)//2]), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate. Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.First line of input contains N. Next N lines contains two space separated integers denoting the ith coordinate. Constraints: 1 <= N <= 100000 1 <= X[i], Y[i] <= 1000000000 Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).Print two space separated integers, denoting the X and Y coordinate of the camp.Sample Input 3 3 3 1 1 3 2 Sample Output 3 2 Explanation: Sum of distances = 1 + 3 + 0 = 4 This is the minimum distance possible., I have written this Solution Code: #pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define VV vector #define pb push_back #define bitc __builtin_popcountll #define m_p make_pair #define infi 1e18+1 #define eps 0.000000000001 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); string char_to_str(char c){string tem(1,c);return tem;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T>//usage rand<long long>() T rand() { return uniform_int_distribution<T>()(rng); } #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); ////////////// auto clk=clock(); #define all(x) x.begin(),x.end() #define S second #define F first #define sz(x) ((long long)x.size()) #define int long long #define f80 __float128 #define pii pair<int,int> ///////////// signed main() { fastio; #ifdef ANIKET_GOYAL freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif int n; cin>>n; int x[n],y[n]; for(int i=0;i<n;++i){ cin>>x[i]>>y[i]; } sort(x,x+n); sort(y,y+n); cout<<x[(n-1)/2]<<" "<<y[(n-1)/2]; #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: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array. Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers. <b>Constraints:-</b> 1 &le; N &le; 1000 1 &le; elements &le; NPrint the missing elementSample Input:- 3 3 1 Sample Output: 2 Sample Input:- 5 1 4 5 2 Sample Output:- 3, I have written this Solution Code: def getMissingNo(arr, n): total = (n+1)*(n)//2 sum_of_A = sum(arr) return total - sum_of_A N = int(input()) arr = list(map(int,input().split())) one = getMissingNo(arr,N) print(one), In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array. Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers. <b>Constraints:-</b> 1 &le; N &le; 1000 1 &le; elements &le; NPrint the missing elementSample Input:- 3 3 1 Sample Output: 2 Sample Input:- 5 1 4 5 2 Sample Output:- 3, 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-1]; for(int i=0;i<n-1;i++){ a[i]=sc.nextInt(); } boolean present = false; for(int i=1;i<=n;i++){ present=false; for(int j=0;j<n-1;j++){ if(a[j]==i){present=true;} } if(present==false){ System.out.print(i); return; } } } } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Mohit has an array of N integers containing all elements from 1 to N, somehow he lost one element from the array. Given N-1 elements your task is to find the missing one.The first line of input contains a single integer N, the next line contains N-1 space-separated integers. <b>Constraints:-</b> 1 &le; N &le; 1000 1 &le; elements &le; NPrint the missing elementSample Input:- 3 3 1 Sample Output: 2 Sample Input:- 5 1 4 5 2 Sample Output:- 3, I have written this Solution Code: #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n-1]; for(int i=0;i<n-1;i++){ cin>>a[i]; } sort(a,a+n-1); for(int i=1;i<n;i++){ if(i!=a[i-1]){cout<<i<<endl;return 0;} } cout<<n; } , In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; }, In this Programming Language: C++, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: def DivisorProblem(N): ans=0 while N>1: cnt=2 while N%cnt!=0: cnt=cnt+1 N = N//cnt ans=ans+1 return ans , In this Programming Language: Python, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: static int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; } , In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Sara is solving a math problem in which she has been given an integer N and her task is to find the number of operations required to convert N into 1. Where in one operation you replace the number with its second-highest divisor.<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>DivisorProblem()</b> that takes integer N as argument. Constraints:- 1 <= N <= 100000Return the number of operations required.Sample Input:- 100 Sample Output:- 4 Explanation:- 100 - > 50 50 - > 25 25 - > 5 5 - > 1 Sample Input:- 10 Sample Output:- 2, I have written this Solution Code: int DivisorProblem(int N){ int ans=0; while(N>1){ int cnt=2; while(N%cnt!=0){ cnt++; } N/=cnt; ans++; } return ans; }, In this Programming Language: C, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>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>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: static boolean isArmstrong(int N) { int num = N; int sum = 0; while(N > 0) { int digit = N%10; sum += digit*digit*digit; N = N/10; } if(num == sum) return true; else return false; }, In this Programming Language: Java, Now tell me if this Code is compilable or not?
Compilable
For this Question: Given a number N, you need to check whether the given number is Armstrong number or not. Now what is Armstrong number let us see below: <b>A number is said to be Armstrong if it is equal to sum of cube of its digits. </b>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>isArmstrong()</b> which contains N as a parameter. Constraints: 1 <= N <= 10^4You need to return "true" if the given number is an Armstrong number otherwise "false"Sample Input 1: 1 Sample Output 1: true Sample Input 2: 147 Sample Output 2: false Sample Input 3: 371 Sample Output 3: true , I have written this Solution Code: function isArmstrong(n) { // write code here // do no console.log the answer // return the output using return keyword let sum = 0 let k = n; while(k !== 0){ sum += Math.pow( k%10,3) k = Math.floor(k/10) } return sum === n }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?
Compilable