Melon Field

Interview

Time limit1sMemory limit128 MB

Summary
Given an L-shaped rectilinear hexagon described by six directional side lengths, compute its area and multiply by a melon density constant.
Level

Easy3 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Tae-yang wants to know how many melons grow in a large field at his uncle's house in the countryside. The number K of melons per 1 m^2 is known, so the answer is K times the area of the field.

The field is a rectilinear hexagon shaped like an L, or like that shape rotated by 90, 180, or 270 degrees. Every side runs east-west or north-south. Starting from any vertex, the six side directions and lengths are given in counterclockwise order.

Compute the area of the field and print the total number of melons.

Input

The first line contains K (1 <= K <= 20), the number of melons per 1 m^2. Each of the next six lines contains a side direction and length, in counterclockwise order around the field. Each length is an integer from 1 to 500. Directions are encoded as 1 for east, 2 for west, 3 for south, and 4 for north.

Output

Print the total number of melons growing in the field.

Examples1

  1. Example 1

    Input
    7
    4 50
    2 160
    3 30
    1 60
    3 20
    1 100
    
    Expected output
    47600