codeparrot/codecomplex huggingface dataset:
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.util.*;

public class Rules {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    double maxSpeed = in.nextInt();
    double len = in.nextInt();
    double delayDist = in.nextInt();
    double delaySpeed = in.nextInt();
    
    // two cases: I reach the delayPoint at a speed higher than the delaySpeed, or I don't.
    double timeToDelayAtMax = travelS(a, 0.0, maxSpeed, delayDist);
    double timeToDelayAtDelay = travelS(a, 0.0, delaySpeed, delayDist);
    if (Math.abs(timeToDelayAtMax-timeToDelayAtDelay) < 0.00001) {
      // I can reach the delayPoint without being delayed
      double time = travelS(a, 0.0, maxSpeed, len);
      System.out.printf("%.9f\n", time);
      return;
    }
    
    // binary search to find best velocity to stop acceleration in beginning
    double lowV = delaySpeed;
    double highV = maxSpeed;
    int loopCount = 1000;
    double[] initial = null;
    double[] secondary = null;
    while (loopCount-->0) {
      double guessV = (lowV+highV)/2.0;
      initial = travelA(a, 0.0, guessV);
      secondary = travelA(a, guessV, Math.min(delaySpeed, maxSpeed));
      if (initial[1] + secondary[1] < delayDist) { // okay, we can go faster
        lowV = guessV;
      } else {
        highV = guessV;
      }
    }
    double totalTime = 0.0;
    double finalSpeed = 0.0;
    initial = travelA(a, 0.0, lowV);
    secondary = travelA(a, lowV, delaySpeed);
    totalTime = initial[0] + secondary[0];
    double totalDist = initial[1] + secondary[1];
    totalTime += (delayDist-totalDist)/maxSpeed;
    
    // now we have delayDist to go, and we are at delaySpeed
    totalTime += travelS(a, delaySpeed, maxSpeed, len-delayDist);
    System.out.printf("%.9f\n", totalTime);
  }
  
  // [0] = time in h, [1] = dist travelled, in km
  // input units are in km/h^2, km/h, km/h
  public static double[] travelA(int a, double startSpeed, double endSpeed) {
    if (startSpeed > endSpeed)
      a = -a;
    
    double time = (endSpeed - startSpeed) / a;
    double dist = 0.5*a*time*time + startSpeed*time;
    return new double[] {time, dist};
  }
  
  // returns time it takes to travel dist, with given inputs
  public static double travelS(int a, double startSpeed, double maxSpeed, double dist) {
    double timeToMax = (maxSpeed - startSpeed) / a;
    double targetTime = (-startSpeed + Math.sqrt(startSpeed*startSpeed + 2*a*dist)) / a;
    if (targetTime < timeToMax)
      return targetTime;
    
    double partialDist = 0.5*timeToMax*timeToMax*a + startSpeed*timeToMax;
    double remainingDist = dist - partialDist;
    targetTime = remainingDist / maxSpeed;
    return targetTime + timeToMax;
  }
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.io.*;
import java.util.*;

public class D {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	double f(int dist, double initSp, int a, int maxSp) {
		double distToReachMaxSpeed = 0.5 * (maxSp * maxSp - initSp * initSp)
				/ a;

		if (dist > distToReachMaxSpeed)
			return 1d * (maxSp - initSp) / a + (dist - distToReachMaxSpeed)
					/ maxSp;

		return (Math.sqrt(initSp * initSp + 2 * a * dist) - initSp) / a;
	}

	void solve() throws IOException {
		int a = nextInt();
		int maxSp = nextInt();
		int len = nextInt();
		int signX = nextInt();
		int signSp = nextInt();

		if (maxSp <= signSp) {
			out.printf("%.9f\n", f(len, 0, a, maxSp));
			return;
		}

		double distToReachSignSp = 0.5 * signSp * signSp / a;
		if (distToReachSignSp >= signX) {
			out.printf("%.9f\n", f(len, 0, a, maxSp));
			return;
		}

		double distToReachMaxThenSign = 0.5
				* (maxSp * maxSp + maxSp * maxSp - signSp * signSp) / a;
		if (distToReachMaxThenSign <= signX) {
			double t = 1d * (2 * maxSp - signSp) / a
					+ (signX - distToReachMaxThenSign) / maxSp
					+ f(len - signX, signSp, a, maxSp);
			out.printf("%.9f\n", t);
			return;
		}
		
		double xSp = Math.sqrt(a * signX + signSp * signSp * 0.5);
		double xTime = (2 * xSp - signSp) / a;
		out.printf("%.9f\n", xTime + f(len - signX, signSp, a, maxSp));
	}

	void inp() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new D().inp();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.util.*;
import java.io.*;

public class D0005 {

    public static void main(String args[]) throws Exception {
        new D0005();
    }

    D0005() throws Exception {
        PandaScanner sc = null;
        PrintWriter out = null;
        try {
            sc = new PandaScanner(System.in);
            out = new PrintWriter(System.out);
        } catch (Exception ignored) {
        }

        a = sc.nextInt();
        max = sc.nextInt();

        double length = sc.nextInt();
        double dist = sc.nextInt();
        double limit = sc.nextInt();

        if (max <= limit) {
            out.println(travelTime(length, 0));
        }
        else {
            double tLimit = limit / a;
            double dLimit = distance(0, tLimit);
            if (dLimit >= dist) {
                out.println(travelTime(length, 0));
            }
            else {
                double res = tLimit + 2 * (travelTime(0.5 * (dist - dLimit), limit)) +
                        travelTime(length - dist, limit);
                out.println(res);
            }
        }

        out.close();
        System.exit(0);
    }
    double a, max;
    double distance(double v, double t) {
        return v * t + 0.5 * a * t * t;
    }
    double travelTime(double d, double v) {
        double tAll = (-v + Math.sqrt(v * v + 2 * a * d)) / a;
        double tMax = (max - v) / a;
        if (tAll <= tMax) {
            return tAll;
        }
        else {
            return tMax + (d - distance(v, tMax)) / max;
        }
    }

    //The PandaScanner class, for Panda fast scanning!
    public class PandaScanner {
        BufferedReader br;
        StringTokenizer st;
        InputStream in;

        PandaScanner(InputStream in) throws Exception {
            br = new BufferedReader(new InputStreamReader(this.in = in));
        }

        public String next() throws Exception {
            if (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine().trim());
                return next();
            }
            return st.nextToken();
        }

        public boolean hasNext() throws Exception {
            return (st != null && st.hasMoreTokens()) || in.available() > 0;
        }

        public long nextLong() throws Exception {
            return Long.parseLong(next());
        }

        public int nextInt() throws Exception {
            return Integer.parseInt(next());
        }
    }
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.util.*;
import java.io.*;

public class Traffic extends Template{
	public double search1(int a, int w, int d){
		double s = 0;
		double l = 2*w+2*a*d;
		int repeat = 100;
		while( repeat-- > 0 ){
			double x = (s+l)/2;
			if( a*a*x*x + 2*a*w*x - w*w - 4*a*d > 0 ){
				l = x;
			} else {
				s = x;
			}
		}
		return l;
	}
	
	public double search2(int a, double lim, int k){
		double s = 0;
		double l = lim + 2*a*k;
		int repeat = 100;
		while( repeat-- > 0 ){
			double x = (s+l)/2;
			if( a*x*x + 2*lim*x - 2*k > 0 ){
				l = x;
			} else {
				s = x;
			}
		}
		return l;
	}
	
	public void solve() throws IOException {
		int a = nextInt();
		int v = nextInt();
		int l = nextInt();
		int d = nextInt();
		int w = nextInt();
		if( w > v ){
			w = v;
		}
		double time_max = Math.sqrt((double)2*d/a);
		double time_d = search1(a,w,d);
	//	writer.println(time_max*a < w); writer.println(v <= (w+a*time_d)/2); writer.println(w < v); 
		double t1 = (time_max*a < w) ? time_max : (v >= (w+a*time_d)/2) ? time_d : (w < v) ? (double)(2*v*v-2*v*w+2*a*d+w*w)/(2*a*v) : (double)v/a + (double)(d-(double)v*v/(2*a))/v;
		double lim = (time_max*a < w) ? time_max*a : w;
		double t3 = Math.min((double)(v-lim)/a, search2(a, lim, l-d));
//		double t = (Math.sqrt(limit*limit+2*a*(l-d))-limit)/a;
		double dist2 = (l-d) - t3*t3*a/2 - t3*lim;
		double t4 = dist2/v;
//		writer.println("t1 = " + t1);
//		writer.println("dist1 = " + dist1);
//		writer.println("t3 = " + t3);
//		writer.println("dist2 = " + dist2);
//		writer.println("t4 = " + t4);
		writer.println((t1+t3+t4));
	}
	
	public static void main(String[] args){
		new Traffic().run();
	}
}

abstract class Template implements Runnable{
	public abstract void solve() throws IOException;
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run(){
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;

public class Main implements Runnable {

    static Throwable sError;

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(new Main());
        t.start();
        t.join();
        if (sError != null)
            throw sError;
    }

    PrintWriter pw;
    BufferedReader in;
    StringTokenizer st;

    void initStreams() throws FileNotFoundException,
            UnsupportedEncodingException {
        pw = new PrintWriter(System.out);
        if (System.getProperty("ONLINE_JUDGE") == null) {
            System.setIn(new FileInputStream("1"));
        }
        in = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-9"));
    }

    String nextString() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextString());
    }

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextString());
    }

    public void run() {
        try {
            initStreams();
            double a = nextDouble(), vmax = nextDouble(), l = nextDouble(), d = nextDouble(), w = nextDouble();
            if (vmax <= w) {
                double v = Math.sqrt(2 * a * l);
                if (v <= vmax) {
                    out(v / a);
                } else {
                    double s = vmax * vmax / (2 * a);
                    double t = (l - s) / vmax;
                    out(vmax / a + t);
                }
            } else {
                double v = Math.sqrt(a * d + w * w / 2);
                double t1 = 0;
                if (w <= Math.sqrt(2 * a * d)) {
                    if (v <= vmax) {
                        t1 = v / a + (v - w) / a;
                    } else {
                        double s = d - vmax * vmax / (2 * a) - (vmax * vmax - w * w) / (2 * a);
                        t1 = s / vmax + vmax / a + (vmax - w) / a;
                    }   
                } else {
                    t1 = Math.sqrt(2 * d / a);
                    w = a * t1;
                }
                v = Math.sqrt(2 * a * (l - d) + w * w);
                double t2 = 0;
                if (v <= vmax) {
                    t2 = (v - w) / a;
                } else {
                    double s = l - d - (vmax * vmax - w * w) / (2 * a);
                    t2 = (vmax - w) / a + s / vmax;
                }
                out(t1 + t2);
            }
        } catch (Throwable e) {
            sError = e;
        } finally {
            pw.flush();
            pw.close();
        }
    }

    private void out(double t) {
        pw.println(t);
    }

}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RespectTheRules {
    private static final double E = 1E-10;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double maxV = scanner.nextDouble();
        double l = scanner.nextDouble();
        double d = scanner.nextDouble();
        double w = scanner.nextDouble();

        double r = l - d;
        w = Math.min(w, maxV);

        List<WayPoint> wayPoints = new ArrayList<WayPoint>(256);
        double t = 0;

        wayPoints.add(new WayPoint(0));

        double dW = dTo(w, 0, a);
        if (leq(dW, d)) {
            wayPoints.add(new WayPoint(w));
            {
                double v = v(w, a, (d - dW) / 2);
                v = Math.min(v, maxV);

                wayPoints.add(new WayPoint(v));
                wayPoints.add(new WayPoint(w));

                double dW_V = dTo(v, w, a);
                double vDistance = d - dW - 2 * dW_V;
                if (!eq(vDistance)) {
                    t += vDistance / maxV;
                }
            }
            {
                double dW_MaxV = dTo(maxV, w, a);
                dW_MaxV = Math.min(dW_MaxV, r);
                double v = v(w, a, dW_MaxV);
                wayPoints.add(new WayPoint(v));
                double dMaxV = r - dW_MaxV;
                if (!eq(dMaxV)) {
                    t += dMaxV / maxV;
                }
            }

        } else {
            double dMaxV = dTo(maxV, 0, a);
            dMaxV = Math.min(dMaxV, l);
            double v = v(0, a, dMaxV);
            wayPoints.add(new WayPoint(v));
            double dv = l - dMaxV;
            if (!eq(dMaxV)) {
                t += dv / maxV;
            }
        }

        for (int i = 1; i < wayPoints.size(); ++i) {
            double v0 = wayPoints.get(i - 1).v;
            double v = wayPoints.get(i).v;
            t += Math.abs(tTo(v, v0, a));
        }
        System.out.println(t);
    }

    static double tTo(double v, double v0, double a) {
        return (v - v0) / a;
    }

    static double dTo(double v, double v0, double a) {
        return (v * v - v0 * v0) / (2 * a);
    }

    static double v(double v0, double a, double d) {
        return Math.sqrt(2 * d * a + v0 * v0);
    }

    static boolean eq(double value) {
        return Math.abs(value) <= E;
    }

    static boolean l(double v) {
        return v < -E;
    }

    static boolean leq(double v) {
        return l(v) || eq(v);
    }

    static boolean leq(double one, double another) {
        return leq(one - another);
    }

    static class WayPoint {
        double v;

        WayPoint(double v) {
            this.v = v;
        }
    }
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    private static final double EPS = 1e-11;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");
    
    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        
        double a = nextDouble();
        double v = nextDouble();
        double l = nextDouble();
        double d = nextDouble();
        double w = nextDouble();
        
        double ans = 0.0;
        
        if (v < w + EPS || sqr(w) / 2 / a > d - EPS) {
            double t1 = sqrt(2 * l / a);
            double t2 = v / a;
            
            if (t1 < t2 + EPS) {
                ans = t1;
            } else {
                ans = t2 + (l - a * sqr(t2) / 2) / v;
            }
        } else {
            double t1 = v / a;
            double t2 = (v - w) / a;
            double s12 = a * sqr(t1) / 2 + w * t2 + a * sqr(t2) / 2;
            
            if (s12 < d + EPS) {
                ans += t1 + t2 + (d - s12) / v;
            } else {
                double ta = sqrt(d / a + sqr(w / a) / 2);
                double tb = ta - w / a;
                ans += ta + tb;
            }
            
            double r = l - d;
            double tm = (v - w) / a;
            double tx = (sqrt(sqr(w) + 2 * a * r) - w) / a;
            
            if (tx < tm + EPS) {
                ans += tx;
            } else {
                ans += tm + (r - w * tm - a * sqr(tm) / 2) / v;
            }
        }           
        
        out.printf(Locale.US, "%.12f%n", ans);
        out.close();
    }
    
    double sqr(double x) { 
        return x * x;
    }
    
    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        
        return st.nextToken();
    }
    
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant

import java.util.Scanner;

public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double a = in.nextDouble();
        double v = in.nextDouble();
        double l = in.nextDouble();
        double d = in.nextDouble();
        double w = in.nextDouble();
        double ans = 0;
        double maxSpeedBySign = Math.sqrt(2 * a * d);
        double speedAtSign = -1;
        if (v <= w) {
            if (maxSpeedBySign <= v) {
                ans += Math.sqrt(2 * d / a);
                speedAtSign = maxSpeedBySign;

            } else {
                ans += v / a;
                double distanceLeftTillSign = d - v * v / a / 2;
                ans += distanceLeftTillSign / v;
                speedAtSign = v;
            }
        } else {
            if (maxSpeedBySign <= w) {
                ans += Math.sqrt(2 * d / a);
                speedAtSign = maxSpeedBySign;
            } else {
                double S = d / 2 - w * w / 4 / a;
                double X = d - S;
                double speed = Math.sqrt(2 * a * X);
                if (speed <= v) {
                    ans += Math.sqrt(2 * X / a);
                    ans += (speed - w) / a;
                    speedAtSign = w;
                } else {
                    double distanceToAc = v * v / a / 2;
                    double distanceToDe = (v * v - w * w) / a / 2;
                    ans += Math.sqrt(2 * distanceToAc / a);
                    ans += (d - distanceToAc - distanceToDe) / v;
                    ans += (v - w) / a;
                }
                speedAtSign = w;
            }
        }
        l -= d;
        double timeToGetMaxSpeed = (v - speedAtSign) / a;
        double timeToReachEnd = (-2 * speedAtSign + Math.sqrt(4 * speedAtSign
                * speedAtSign + 8 * a * l))
                / 2 / a;
        if (timeToGetMaxSpeed < timeToReachEnd) {
            ans += timeToGetMaxSpeed;
            double distanceCoveredToMaxSpeed = speedAtSign * timeToGetMaxSpeed
                    + 0.5 * a * timeToGetMaxSpeed * timeToGetMaxSpeed;
            l -= distanceCoveredToMaxSpeed;
            ans += l / v;
        } else {
            ans += timeToReachEnd;
        }
        System.out.println(ans);
    }
}
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.util.*;

public class Main {
	static boolean LOCAL = System.getSecurityManager() == null;
	Scanner sc = new Scanner(System.in);
	
	void run() {
		double a = sc.nextDouble(), v = sc.nextDouble();
		double L = sc.nextDouble(), d = sc.nextDouble(), w = sc.nextDouble();
		w = min(w, v);
		double t = 0;
		if (w * w / (2 * a) <= d) {
			if ((v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a) <= d) {
				t = (2 * v - w) / a + (d - (v * v + 2 * v * (v - w) - (v - w) * (v - w)) / (2 * a)) / v;
			} else {
				double A = a, B = w, C = (w * w) / (2 * a) - d;
				t = w / a + (-B + sqrt(max(0, B * B - A * C))) / A * 2;
			}
			if ((2 * w * (v - w) + (v - w) * (v - w)) / (2 * a) <= L - d) {
				t += (v - w) / a + (L - d - (2 * w * (v - w) + (v - w) * (v - w)) / (2 * a)) / v;
			} else {
				double A = a, B = w, C = -2 * (L - d);
				t += (-B + sqrt(max(0, B * B - A * C))) / A;
			}
		} else if (v * v / (2 * a) <= L) {
			t = v / a + (L - (v * v / (2 * a))) / v;
		} else {
			t = sqrt(2 * L / a);
		}
		System.out.printf("%.10f%n", t);
	}
	
	class Scanner {
		BufferedReader br;
		StringTokenizer st;
		Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			eat("");
		}
		void eat(String s) {
			st = new StringTokenizer(s);
		}
		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		boolean hasNext() {
			while (!st.hasMoreTokens()) {
				String s = nextLine();
				if (s == null) return false;
				eat(s);
			}
			return true;
		}
		String next() {
			hasNext();
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
	
	void debug(Object...os) {
		System.err.println(deepToString(os));
	}
	
	public static void main(String[] args) {
		if (LOCAL) {
			try {
				System.setIn(new FileInputStream("in.txt"));
			} catch (Throwable e) {
				LOCAL = false;
			}
		}
		if (!LOCAL) {
			try {
				Locale.setDefault(Locale.US);
				System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
			} catch (Throwable e) {
			}
		}
		new Main().run();
		System.out.flush();
	}
}