// Arup Guha
// 12/26/2021
// Solution to 2021 December USACO Bronze Problem: Air Cownditioning

import java.util.*;

public class air {

	public static void main(String[] args) {
	
		// Read arrays, store delta.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int[] end = new int[n];
		for (int i=0; i<n; i++) end[i] = stdin.nextInt();
		int[] start = new int[n];
		for (int i=0; i<n; i++) start[i] = stdin.nextInt();
		int[] delta = new int[n];
		for (int i=0; i<n; i++) delta[i] = end[i] - start[i];
		
		int res = 0;
		
		// Sweep through the data, solving all subsections that are the same sign.
		int low = 0;
		while (low < n) {
		
			// Keep going here.
			if (delta[low] == 0) {
				low++;
				continue;
			}
			
			// Get stretch with same sign.
			boolean sign = (delta[low] > 0);
			int high = low+1;
			boolean curS = sign;
			while (high < n && (delta[high] > 0) == sign) high++;
			
			// Create list.
			ArrayList<item> list = new ArrayList<item>();
			for (int i=low; i<high; i++)
				if (sign)
					list.add(new item(delta[i], i-low));
				else
					list.add(new item(-delta[i], i-low));
			Collections.sort(list);
				
			// Add in score for this list.
			res += go(list);
			
			// Update low.
			low = high;
		}
		
		// Ta da!
		System.out.println(res);
	}
	
	public static int go(ArrayList<item> list) {
	
		// List of indexes already processed.
		TreeSet<tsItem> idxList = new TreeSet<tsItem>();
		idxList.add(new tsItem(0,-1));
		idxList.add(new tsItem(0, list.size()));
		int res = 0;
		
		// Go through each point from order of lowest to highest.
		for (int i=0; i<list.size(); i++) {
			
			// Figures out which subsection we are filling.
			tsItem me = new tsItem(list.get(i).val, list.get(i).idx);
			tsItem before = idxList.lower(me);
			tsItem after = idxList.higher(me);
			
			// Determines the current fill level.
			int past = Math.max(before.val, after.val);
			
			// How much more we fill here.
			res += (me.val - past);
			
			// Now this is another barrier we've filled to.
			idxList.add(me);
		}
		
		return res;
	}
	
}

// Just to use to sort for my TreeSet.
class tsItem implements Comparable<tsItem> {
	
	public int val;
	public int idx;
	
	public tsItem(int x, int i) {
		val = x;
		idx = i;
	}
	
	public int compareTo(tsItem other) {
		return idx - other.idx;
	}
	
}

// For original sorting by value.
class item implements Comparable<item> {

	public int val;
	public int idx;
	
	public item(int x, int i) {
		val = x;
		idx = i;
	}
	
	public int compareTo(item other) {
		if (val != other.val) return val - other.val;
		return idx - other.idx;
	}
}