A simple sorting algorithm C++

I suppose it has its own name, but I don’t know it, though I’d like to know. Nowadays it’s just a piece of unnamed code written by me and left for future examination.

 

 

Problem 1

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the number is 1245,it will become 5421 .Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

Input

The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

Output

For each case, print exactly one line containing only one integer — the reversed sum of two reversed numbers. Omit any leading zeros in the output.

Example

Input:
1
24 1

Output:
34
Читать далее Problem 1

Odd

 

The captain of the ship TITANIC is a little …. off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers — 1,2,3,4,5…
After first pass, people left are — 2,4,…
After second pass — 4,….
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.

Input

First line contains the number of test cases t (t<=10^5). The next t lines contain integer n, the number of applicants for that case. (n<=10^9)

Output

Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.

Example

Input:
2
5
12

Output:
4
8
Читать далее Odd

Enormous Input Test

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.

Input

The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.

Output

Write a single integer to output, denoting how many integers ti are divisible by k.

Example

Input:
7 3
1
51
966369
7
9
999996
11

Output:
4
Читать далее Enormous Input Test

ATM

Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if Xis a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.

Calculate Pooja’s account balance after an attempted transaction.

Input

Positive integer 0 < X <= 2000 — the amount of cash which Pooja wishes to withdraw.

Nonnegative number 0<= Y <= 2000 with two digits of precision — Pooja’s initial account balance.

Output

Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

Example — Successful Transaction

Input:
30 120.00

Output:
89.50

Example — Incorrect Withdrawal Amount (not multiple of 5)

Input:
42 120.00

Output:
120.00

Example — Insufficient Funds

Input:
300 120.00

Output:
120.00
Читать далее ATM