This page is still under construction.

Parts of this page are still being built. What you see may change.

Campus

Time limit1sMemory limit512 MB

Summary
For each room number, find its floor given that each entrance has x rooms on floors divisible by k and y rooms otherwise, with room numbering continuing across entrances.
Level

Medium5 of 10

Topics
Math, Binary search, Implementation, Prefix sum
Solved
No attempts yet

Problem

The new campus building of Byteburg University has nn floors, numbered from 1 to nn going up. Student rooms are located in several entrances.

In each entrance, floors whose number is a multiple of kk have xx rooms, and the remaining floors have yy rooms.

Rooms within an entrance are numbered with consecutive positive integers. The rooms on the first floor have the smallest numbers in that entrance, then come the rooms on the second floor, and so on. The rooms in the first entrance are numbered starting from 1, and in each following entrance room numbering starts with the number right after the largest room number in the previous entrance.

Figure 1 shows the room numbers in a building with n=7n = 7 floors, 3 entrances, and parameters k=3k = 3, x=2x = 2, y=3y = 3.

Entrance 1Entrance 2Entrance 3
Floor 717, 18, 1936, 37, 3855, 56, 57
Floor 615, 1634, 3553, 54
Floor 512, 13, 1431, 32, 3350, 51, 52
Floor 49, 10, 1128, 29, 3047, 48, 49
Floor 37, 826, 2745, 46
Floor 24, 5, 623, 24, 2542, 43, 44
Floor 11, 2, 320, 21, 2239, 40, 41

Figure 1. An example of room numbering in a building

To assign students to rooms, the campus administration must quickly determine the floor of a room from its number.

Given the numbers nn, kk, xx, yy and a list of room numbers, write a program that determines the floor of each room.

Input

The first line of the input file contains the positive integers nn, kk, xx, yy (1≤n≤1091 \le n \le 10^9, 1≤k≤n1 \le k \le n, 1≤x,y≤1091 \le x, y \le 10^9). Adjacent numbers are separated by exactly one space.

The second line of the input file contains the positive integer qq, the number of room numbers whose floors must be determined (1≤q≤10001 \le q \le 1000).

The third line contains qq integers a1,a2,…,aqa_1, a_2, \ldots, a_q, the room numbers (1≤ai≤10181 \le a_i \le 10^{18}). You may assume that the building has enough entrances that all rooms with the given numbers exist.

Output

Print qq numbers, one per line. For each room number in the input file, print the number of the floor on which it is located.

Examples1

  1. Example 1

    Input
    7 3 2 3
    4
    1 19 20 50
    
    Expected output
    1
    7
    1
    5