Under construction

Still being built. Things may change

Experiments with Gorlum

Time limit1sMemory limit64 MB

Summary
A creature repeats a move string K times and you report the smallest and largest squared distances from a laser over all visited points.
Level

Medium6 of 10

Topics
Math, Simulation
Solved
No attempts yet

Problem

Yerzhan built a laser that measures the distance to a distant object. For the test he uses Gorlum, a creature he caught in the forest. Gorlum is not bright and performs exactly five commands.

  • L: one step to the left, from (x,y)(x, y) to (x−1,y)(x - 1, y).
  • R: one step to the right, from (x,y)(x, y) to (x+1,y)(x + 1, y).
  • F: one step forward, from (x,y)(x, y) to (x,y+1)(x, y + 1).
  • B: one step backward, from (x,y)(x, y) to (x,y−1)(x, y - 1).
  • I: Gorlum takes a shiny ring with glowing letters out of his pocket and stays where he is.

The laser sits at (Lx,Ly)(L_x, L_y) and Gorlum starts at (Gx,Gy)(G_x, G_y). The command list TT is the string SS concatenated KK times (T=SKT = S^K), and Gorlum performs the commands of TT one by one from the front.

The laser measures the distance to Gorlum once at the start and once after each command, so it takes K×∣S∣+1K \times |S| + 1 measurements.

Report the smallest and the largest measured distance. A distance is usually irrational, so this problem asks for the squared distance instead. The squared distance is always an integer, the point with the smallest square is the closest point, and the point with the largest square is the farthest one.

Input

The first line contains a natural number KK (1≤K≤1051 \le K \le 10^5).

The second line contains the string SS. It consists only of L, R, F, B, I, and 1≤∣S∣≤1041 \le |S| \le 10^4.

The third line contains the laser coordinates LxL_x and LyL_y, separated by a space.

The fourth line contains Gorlum's starting coordinates GxG_x and GyG_y, separated by a space.

Every coordinate is an integer with absolute value at most 10410^4.

Output

Print the smallest and the largest squared distance on one line, separated by a space. Both values fit in a signed 64-bit integer.

Examples4

  1. Example 1

    Input
    100000
    LRFBI
    10000 10000
    10000 10000
    
    Expected output
    0 1
    
  2. Example 2

    Input
    1
    I
    0 0
    3 4
    
    Expected output
    25 25
    
  3. Example 3

    Input
    3
    R
    0 0
    0 0
    
    Expected output
    0 9
    
  4. Example 4

    Input
    10
    R
    5 0
    0 0
    
    Expected output
    0 25