import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  double Sum=0;
	  long S1=0,S2=0;
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      }
 
      for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      }
      
      
	  System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2));
  }
  
 
} import java.util.*; util.* java class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  double Sum=0;
	  long S1=0,S2=0;
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      }
 
      for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      }
      
      
	  System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2));
  }
  
 
} Main static int mod=1_000_000_007; mod 1_000_000_007 public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  double Sum=0;
	  long S1=0,S2=0;
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      }
 
      for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      }
      
      
	  System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2));
  } main {
	  Scanner sc = new Scanner(System.in);
	  double Sum=0;
	  long S1=0,S2=0;
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      }
 
      for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      }
      
      
	  System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) double Sum=0; Sum 0 long S1=0 S1 0 S2=0; S2 0 long N = sc.nextLong(); N sc.nextLong() sc.nextLong sc long[] a = new long[(int)N]; a new long[(int)N] (int)N for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      } int i=0 ; int i=0 ; i 0 i<N i N i++ i++ i {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      } {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      } a[i] = sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc Sum=Sum+a[i] Sum Sum+a[i] Sum a[i] a i for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      } int i=0 ; int i=0 ; i 0 i<N i N i++ i++ i {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      } {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      } S1 = S1 + a[i] S1 S1 + a[i] S1 a[i] a i if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  } S1>=Sum/2 S1 Sum/2 Sum 2 {
    		  S2=S1-a[i];
    		  break;
    	  } S2=S1-a[i] S2 S1-a[i] S1 a[i] a i break; System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2)) System.out.println System.out System System.out (long)Math.min(2*S1-Sum, Sum-2*S2) Math.min Math 2*S1-Sum 2*S1 2 S1 Sum Sum-2*S2 Sum 2*S2 2 S2 String[] args args
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  double Sum=0;
	  long S1=0,S2=0;
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          Sum=Sum+a[i];
      }
 
      for (int i=0 ; i<N; i++) {
    	  S1 = S1 + a[i];
    	  if(S1>=Sum/2) {
    		  S2=S1-a[i];
    		  break;
    	  }
      }
      
      
	  System.out.println((long)Math.min(2*S1-Sum, Sum-2*S2));
  }
  
 
}