#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::io::{Write, BufWriter, stdout};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize,
        t: [usize; N],
        v: [f64; N],
    }
    let mut time = vec![0; N+2];
    for ind in 0..N {
        time[ind+1] = time[ind] + 2*t[ind];
    }
    v.push(0.0);

    let mut max_speed = vec![ vec![0f64; N+2]; time[N]+1];
    for step in 0..N+1 {
        for current_time in 0..time[N]+1 {
            max_speed[current_time][step] =
                if current_time <= time[step] {
                    v[step] + (time[step] - current_time) as f64 * 0.5
                } else if current_time >= time[step+1] {
                    v[step] + (current_time - time[step+1]) as f64 * 0.5
                } else {
                    v[step]
                };
        }
    }

    for current_time in 0..time[N] + 1 {
        max_speed[current_time][N+1] = current_time as f64 * 0.5;
    }

    let mut dist = 0.0;
    let mut current_speed = 0.0 as f64;
    for current_time in 1..time[N]+1 { 
        let mut ms = max_speed[current_time][0];
        for step in 1..N+2 {
            if ms > max_speed[current_time][step] {
                ms = max_speed[current_time][step]
            }
        }
        dist += (current_speed + ms) * 0.5 / 2.0;
        current_speed = ms;
    }
    println!("{:?}", dist);
}


Measured memory_bytes: 41212