Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

You are given an undirected tree with N nodes and the tree is rooted at node 1. Each node has an integer value A[i] associated with it represented by an array A of size N.


Also, you are given Q queries of the following type:


• uvk: Find the kth smallest value present on the simple path between node u and node v. If the number of nodes on the simple path between node u and node v is less than k, then print —1.


Input format

•  The first line contains two space-separated integers NQ denoting the number of nodes and queries respectively.

•  The second line contains N space-separated integers denoting array A.

•  Next N — 1 line contains two space-separated integers denoting the edges of the tree.

•  Next Q lines contain three space-separated integers denoting the queries.


Output format

Print Q space-separated integers denoting the answer of queries.


Constraints


1 ≤ N ≤ 4 x 104

1 ≤ Q ≤ 105

1 ≤ A[i] ≤ 109

There is an N x N board. Rows and columns are numbered from 1 to N. Two persons P1 and P2 randomly select two numbers A and B in between 2 to 2 * N respectively. They independently paint each block whose sum of row and column numbers is a multiple of their chosen number. The beauty of the board is equal to the number of blocks painted at least once by either one of them. Note that even if they both painted the same block, it only counts once. Print the expected beauty of the board.


Rows and columns are numbered from 1 to N.


Input format

•  The first line contains an integer T denoting the number of test cases.

•  The first line of each test case contains an integer N denoting the size of the board.


Output format


For each test case, print the expected beauty of the board in a new line. Print your answer modulo 1e9+ 7.


Constraints


1 T 1000001 N 1000000


It is guaranteed that the sum of N over T test cases does not exceed 1e6.


Robert has a special set of cards to play with. Each card has an integer written on it and the integer can be negative, positive, or zero. The absolute value of the integer on the card cannot exceed x.

 

Now, Robert misplaced some of the cards and currently has only N cards. He wants to have the sum of integers present on the cards to be zero.

 

Find the minimum number of cards that Robert has to add to N cards to make the sum of integers present on all the cards to be zero.

 

Input format

 

•  The first line contains an integer T denoting the number of test cases.

•  The first line of each test case contains two space-separated integers Nx denoting the number of cards and maximum absolute value present on the card.

•  The second line of each test case contains N space-separated integers denoting the integer written on N cards.

 

Output format

For each test case, print the minimum number of cards that Robert has to add to satisfy the conditions.

 

Constraints

1 ≤ T ≤ 10

1 N 105

1 c 106

-x ≤ A[i] ≤ x

Robert has a special set of cards to play with. Each card has an integer written on it and the integer can be negative, positive, or zero. The absolute value of the integer on the card cannot exceed x.


Now, Robert misplaced some of the cards and currently has only N cards. He wants to have the sum of integers present on the cards to be zero.


Find the minimum number of cards that Robert has to add to N cards to make the sum of integers present on all the cards to be zero.


Input format


•  The first line contains an integer T denoting the number of test cases.

•  The first line of each test case contains two space-separated integers Nx denoting the number of cards and maximum absolute value present on the card.

•  The second line of each test case contains N space-separated integers denoting the integer written on N cards.


Output format


For each test case, print the minimum number of cards that Robert has to add to satisfy the conditions.


Any number is called beautiful if it consists of 2N digits and the sum of the first N digits is equal to the sum of the last N digits. Your task is to find the count of beautiful numbers in the interval from L to R (including L and R).


Beautiful numbers do not have leading zeroes.


Input format


•  The first line contains an integer T denoting the number of test cases.

•  The first line of each test case contains two space-separated integers L and R denoting the range interval [L, R].


Output format


For each test case, print the count of beautiful numbers in a new line.


Constraints


1 T ≤ 2000001 ≤ L ≤ R ≤ 100000000
  SAMPLE INPUT                  SAMPLE OUTPUT

     1                                                                                            9

1 100

Write code using binary sort that


Finds the total number of boys and girls in class.

1) Create a class Course with instance members – Course Code and Course Title. Include default and parameterized constructors to initialize the instance members and a display method.


Create another class called CAT1MCQ that extends Course class. The class should include the instance members – Question, Choice1, Choice2, Choice3, and correctChoice. Include default and parameterized constructors to initialize the instance members and a display method.


Create an interface VerifyAnswer with a method verify().


Create another class that extends CAT1MCQ and implements VerifyInterface. The class should override verify() to display the course details, question and choices and wait for the user to enter the answer. Once the user inputs the answer, check is if matches with the correctChoice or not.


Create a main class that test the above hierarchy for an array of 'n' objects.



Describe your experience so far with peer assessment of Programming Assignments.


  • How do you feel about the aspect assessments and feedback you have received from your peers?
  • How do you think your peers feel about the aspect assessments and feedback you provided them?

An electricity board charges the following rates to domestic users to

discourage large consumption of energy.


 For the first 100 units − 50 P per unit


 Beyond 100 units − 60 P per unit


If the total cost is more than Rs.250.00 then an additional surcharge of

15% is added on the difference. Define a class Electricity in which the

function Bill computes the cost. Define a derived class More_Electricity

and override Bill to add the surcharge.



Given the definition of Laptop class as follows:

public class Laptop

{

private String brand; //HP, Acer, ASUS

private double price; //price per unit

private int RAM; // memory space in GigaByte(GB),e.g:2,4

private int USBport; //number of USB port e.g:2, 3, 4

//normal constructor: public Laptop (String, double, int, int)

//processor method: upradeRAM(int)

//accessors: getBrand (), getPrice(), getRAM(), getUSB()

}


2. Write the upgradeRAM(int) processor method as folows:

A processor method named upragedRAM(int) that receive the size of RAM to be upgraded as its parameter. This method will determine and return the price of RAM based on the following table:


RAM Size Price(RM)

8GB 98.00

16GB 299.00


3. Write main program :

a. Declare an array of objects named Laptops that store 10 laptop objects.

b. Ask user to enter all information required and store the data in the array above.

c. Calculate and display the total price of all Acer laptops

d. Display the brand of laptop that provides 4 USB ports



LATEST TUTORIALS
APPROVED BY CLIENTS