import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
} Main public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    } main {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    } Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = std.nextInt(); n std.nextInt() std.nextInt std int[] ws = new int[n]; ws new int[n] n for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ws[i] = std.nextInt();
        } {
            ws[i] = std.nextInt();
        } ws[i] = std.nextInt() ws[i] ws i std.nextInt() std.nextInt std int left = 0; left 0 int right = 0; right 0 int rightIndex = n - 1; rightIndex n - 1 n 1 for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        } {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        } for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            } int j = rightIndex; int j = rightIndex; j rightIndex j >= 0 j 0 j-- j-- j {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            } {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            } if (rightIndex < i) {
                    break;
                } rightIndex < i rightIndex i {
                    break;
                } break; int rightValue = ws[j]; rightValue ws[j] ws j if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                } right <= left right left {
                    right += rightValue;
                    rightIndex--;
                } right += rightValue right rightValue rightIndex-- rightIndex {
                    break;
                } break; if (rightIndex < i) {
                break;
            } rightIndex < i rightIndex i {
                break;
            } break; int leftValue = ws[i]; leftValue ws[i] ws i if (left <= right) {
                left += leftValue;
            } left <= right left right {
                left += leftValue;
            } left += leftValue left leftValue System.out.println(Math.abs(left - right)) System.out.println System.out System System.out Math.abs(left - right) Math.abs Math left - right left right String[] args args public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
}
