import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] w = new int[N];

        for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        }

        int l = 0;
        int r = 0;
        int lsum = 0;
        int rsum = 0;

        for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        }
        System.out.println(Math.abs(rsum - lsum));
    }
}
 import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] w = new int[N];

        for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        }

        int l = 0;
        int r = 0;
        int lsum = 0;
        int rsum = 0;

        for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        }
        System.out.println(Math.abs(rsum - lsum));
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] w = new int[N];

        for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        }

        int l = 0;
        int r = 0;
        int lsum = 0;
        int rsum = 0;

        for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        }
        System.out.println(Math.abs(rsum - lsum));
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] w = new int[N];

        for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        }

        int l = 0;
        int r = 0;
        int lsum = 0;
        int rsum = 0;

        for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        }
        System.out.println(Math.abs(rsum - lsum));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] w = new int[N]; w new int[N] N for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            w[i] = sc.nextInt();
        } {
            w[i] = sc.nextInt();
        } w[i] = sc.nextInt() w[i] w i sc.nextInt() sc.nextInt sc int l = 0; l 0 int r = 0; r 0 int lsum = 0; lsum 0 int rsum = 0; rsum 0 for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        } {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        } if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            } lsum >= rsum lsum rsum {
                rsum += w[N-1-r];
                r++;
                continue;
            } rsum += w[N-1-r] rsum w[N-1-r] w N-1-r N-1-r N 1 r r++ r continue; if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            } rsum > lsum rsum lsum {
                lsum += w[l];
                l++;
                continue;
            } lsum += w[l] lsum w[l] w l l++ l continue; System.out.println(Math.abs(rsum - lsum)) System.out.println System.out System System.out Math.abs(rsum - lsum) Math.abs Math rsum - lsum rsum lsum String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] w = new int[N];

        for (int i=0; i<N; i++) {
            w[i] = sc.nextInt();
        }

        int l = 0;
        int r = 0;
        int lsum = 0;
        int rsum = 0;

        for (int i=0; i<N; i++) {
            if (lsum >= rsum) {
                rsum += w[N-1-r];
                r++;
                continue;
            }
            if (rsum > lsum) {
                lsum += w[l];
                l++;
                continue;
            }
        }
        System.out.println(Math.abs(rsum - lsum));
    }
}

