import java.util.Scanner;

//音乐研究--滑动窗口
public class Main {

    private int helper(int[] num1, int[] num2) {
        int sum = Integer.MAX_VALUE;
        int left = 0, right = num1.length - 1;
        while (right < num2.length) {
            if (right - left == num1.length) {
                sum = Math.min(sum(num1, num2, left, right),sum);
                left++;
            }else right++;
        }
        return sum;
    }

    private int sum(int[] num1, int[] num2, int left, int right) {
        int sum=0;
        for (int i = left; i < right; i++) {
            sum+=(num1[i-left]-num2[i])*(num1[i-left]-num2[i]);
        }
        return sum;
    }

    public static void main(String[] args) {
        Main meituan01 = new Main();
        //int[]a={6};
        //int[]b={3 ,1 ,2 ,4};
        //System.out.println(meituan01.helper(a, b));
        Scanner scanner = new Scanner(System.in);
        String n = scanner.nextLine();
        String nArr = scanner.nextLine();
        String[] narr = nArr.split(" ");
        String m = scanner.nextLine();
        String mArr = scanner.nextLine();
        String[] marr = mArr.split(" ");
        int[] n1=new int[Integer.parseInt(n)];
        int[] m1=new int[Integer.parseInt(m)];
        for (int i = 0; i <Integer.parseInt(m) ; i++) {
            if (i<Integer.parseInt(n))
                n1[i]=Integer.parseInt(narr[i]);
            m1[i]=Integer.parseInt(marr[i]);
        }
        System.out.println(meituan01.helper(n1, m1));
    }
}