A higher resolution is required to access the IDE

- 12

## Statement

## Goal

Bricks ofThe ball will bounce off of:

- The left, right, and top of the playfield

- Any side of any brick

- The top of a

All bounces are treated classically. The accidental angle is equal to the incidental angle. So, for example, if the ball's vector is (

`vX`,

`vY`) = (

You don't need to worry about what happens if the ball hits the corner of something. The tests are engineered to avoid this situation.

Each brick has an associated

`kStrength`value, indicating the "strength" of the brick. A brick with a strength of

For many of the tests, the paddle is stationary, but in some of the latter tests, the paddle can move around the playfield to keep the ball in play. Multiple coordinate sets are provided to specify the various locations of the paddle throughout the test. The paddle "moves" to the next coordinate set after being hit by the ball. If there are no other coordinate sets provided in the input, then the paddle doesn't move for the rest of the test, and remains at the last specified position.

The ball is lost if it goes off the bottom of the playfield. Your program must calculate and report points acquired by breaking bricks before the ball is lost.

Input

**Line 1:**Two space-separated integers

`bX`and

`bY`indicating the starting position of the ball.

**Line 2:**Two space-separated integers

`vX`and

`vY`indicating the starting vector of the ball.

**Line 3:**An integer

`pN`indicating the number of positions that will be occupied by the paddle during the game.

**Line 4:**An integer

`kN`indicating the number of bricks initially on the playfield.

**Next**Two space-separated integers

`pN`lines:`pX`and

`pY`for the coordinates of the top-left-hand pixel of the paddle.

**Next**Four space-separated integers

`kN`lines:`kX`,

`kY`,

`kStrength`,

`kPoints`for the coordinates of the top-left corner of the brick, the strength of the brick, and the number of points earned for breaking the brick.

Output

The number of points earned before the ball is lost.

Constraints

0≤

0≤

-100≤

-100≤

1≤

1≤

0≤

2200≤

0≤

0≤

1≤

`bX`<16000≤

`bY`<2400-100≤

`vX`≤100-100≤

`vY`≤1001≤

`pN`≤321≤

`kN`≤640≤

`pX`≤14002200≤

`pY`≤23000≤

`kX`≤15000≤

`kY`≤15001≤

`kStrength`≤5Example

Input

100 100 0 100 1 1 1400 2300 1500 0 1 1

Output

0

A higher resolution is required to access the IDE

Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!

JOIN US ON DISCORD Online Participants