import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}


func disco2020b() -> Int {
    let N = Int(readLine()!)!
    let A = readLine()!.toIntList()
    var left = 0
    var right = N-1
    var diff = 0
    while left <= right {
        if diff < 0 {
            diff += A[left]
            left += 1
        }else{
            diff -= A[right]
            right -= 1
        }
    }
    return abs(diff)
}

print(disco2020b())
