Problem:
Score : 300 points

Problem Statement

Given is a positive integer L.
Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

Constraints

1 ≤ L ≤ 1000

L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

3

Sample Output 1

1.000000000000

For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.

On the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.

Sample Input 2

999

Sample Output 2

36926037.000000000000

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int L = sc.nextInt();
      double maxArea = 0.0;

      double leftLen = 0.0, rightLen = L * 1.0;
      while(Math.abs(rightLen - leftLen) > 1e-10) {
        double midLen1 = leftLen + (rightLen - leftLen) / 3;
        double midLen2 = rightLen - (rightLen - leftLen) / 3;
        double maxArea1 = maxArea(L - midLen1) * midLen1;
        double maxArea2 = maxArea(L - midLen2) * midLen2;
        maxArea = Math.max(maxArea, Math.max(maxArea1, maxArea2));
        if(maxArea1 < maxArea2)
          leftLen = midLen1;
        else
          rightLen = midLen2;
      }
      System.out.println(maxArea);
  }

  private static double maxArea(double l) {
    double leftLen = 0.0, rightLen = l;
    while(Math.abs(rightLen - leftLen) > 1e-10) {
        double midLen1 = leftLen + (rightLen - leftLen) / 3;
        double midLen2 = rightLen - (rightLen - leftLen) / 3;
        double area1 = midLen1 * (l - midLen1);
        double area2 = midLen2 * (l - midLen2);
        if(area1 < area2)
          leftLen = midLen1;
        else
          rightLen = midLen2;
    }
    double len = (rightLen + leftLen) / 2;
    return len * (l - len);
  }
}