Darts

Time limit1sMemory limit128 MB

Summary
Compute win probabilities up to score 501 for two darts players with different throw distributions, where B optimizes target section each turn.
Level

Medium7 of 10

Topics
Dynamic programming, Probability, Simulation, Math
Solved
No attempts yet

Problem

Every Friday evening, Bill and his friends go to a small pub to have a few beers and play darts. They all know that their darts skill fades at the same rate as the beer left in their mugs.

They always play 501, one of the simplest darts games. Each player starts with a score of NN points (usually N=501N = 501, which is where the name comes from) and the players take turns throwing a single dart. On each throw the player's score drops by the value of the section the dart hits, unless that would make the score negative — in that case the score is left unchanged. The first player whose score reaches exactly 00 wins.

The dartboard. The board is divided into 2020 sections. Read clockwise, their values are

20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 520,\ 1,\ 18,\ 4,\ 13,\ 6,\ 10,\ 15,\ 2,\ 17,\ 3,\ 19,\ 7,\ 16,\ 8,\ 11,\ 14,\ 9,\ 12,\ 5

The board is circular, so the last section (value 55) sits next to the first (value 2020). Two sections are adjacent when they are neighbours in this clockwise order.

Two players, A and B, use different strategies:

  • Player A throws at random: the dart lands in each of the 2020 sections with equal probability 120\frac{1}{20}.
  • Player B aims at a chosen section. Because of the beer, the dart is equally likely to land in the aimed section or in either of its two adjacent sections — each of those three sections with probability 13\frac{1}{3}. Player B is fully aware of this and always aims at the section that maximizes the probability of winning.

Both players start from the same score NN. Throwing first can be an advantage, so the winning probability depends on who starts.

Input

The input contains several lines. Each line has one integer NN (1≤N≤5011 \le N \le 501), the starting score shared by both players. A line with N=0N = 0 marks the end of the input and must not be processed.

Output

For each score NN, print one line with two numbers separated by a single space:

  • the probability that A wins when A throws the first dart, and
  • the probability that B wins when B throws the first dart.

Print each probability rounded to exactly 66 decimal places (for example, 0.136364). Your output is checked for an exact match, so follow this format precisely.

Examples3

  1. Example 1

    Input
    5
    100
    0
    
    Expected output
    0.136364 0.909091
    0.072505 0.950215
    
  2. Example 2

    Input
    1
    0
    
    Expected output
    0.136364 0.909091
    
  3. Example 3

    Input
    501
    0
    
    Expected output
    0.004969 0.996644