Description

Given a *n* × *n* matrix *A* and a positive integer *k*, find the sum *S* = *A* + *A²* + *A³* + … + *Ak*.

Input

The input contains exactly one test case. The first line of input contains three positive integers *n* (*n* ≤ 30), *k* (*k*…

Description

Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, green or yellow. For some…

Description

Once upon a time, there was a traveler.

He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the route for him.

There are…

Description

You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array segment.

That is, given an array a[1…n] of different…

Description

You have *N* integers, *A*1, *A*2, … , *AN*. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.

…

Description

ACM has bought a new crane (crane — jeřáb) . The crane consists of n segments of various lengths, connected by flexible joints. The end of the i-th segment is joined to the beginning of the i + 1-th one, for 1 ≤ i < n. The beginning of…

Description

Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. …

Description

Farmer John has arranged his *N* (1 ≤ *N* ≤ 5,000) cows in a row and many of them are facing forward, like good cows. Some of them are facing backward, though, and he needs them all to face forward to make his life perfect.

Fortunately, FJ recently bought…

Given a set of **distinct** positive integers `nums`

, return the largest subset `answer`

such that every pair `(answer[i], answer[j])`

of elements in this subset satisfies:

`answer[i] % answer[j] == 0`

, or`answer[j] % answer[i] == 0`

If there are multiple solutions, return any of them.

**Example 1:**

**Input:** nums =…

You are given two jugs with capacities `jug1Capacity`

and `jug2Capacity`

liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly `targetCapacity`

liters using these two jugs.

If `targetCapacity`

liters of water are measurable, you must have `targetCapacity`

liters of water contained **within…**