jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		long[] a=new long[n];
		Arrays.setAll(a,i->s.nextLong()*2);
		Arrays.parallelPrefix(a,Long::sum);
//		System.err.println(a[n-1]/2);
//		System.err.println(Arrays.toString(a));

		long r=Long.MAX_VALUE;
		for(long i:a)
			r=Math.min(r,Math.abs(a[n-1]/2-i));
		System.out.println(r);
	}
}
//  [java]
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        scanner.nextLine();
        long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
        long sum = Arrays.stream(n).sum();
        for (int i = 1; i < n.length; i++) {
            n[i] += n[i - 1];
        }
        long min = Long.MAX_VALUE;
        for (int i = 0; i < n.length; i++) {
            n[i] *= 2;
            min = Math.min(min, Math.abs(sum - n[i]));
        }
        System.out.println(min);
    }

}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	rep1(i, N) {
		A[i] = getint();
		A[i] += A[i - 1];
	}

	ll saishou = 1e18;
	int k = lower_bound(A + 1, A + N + 1, A[N] / 2) - A;
	if (k - 1 >= 1) chmin(saishou, abs(A[k - 1] * 2 - A[N]));
	chmin(saishou, abs(A[k] * 2 - A[N]));
	if (k + 1 <= N) chmin(saishou, abs(A[k + 1] * 2 - A[N]));

	printf("%lld", saishou);


	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long Ull;
#define fi first
#define se second
#define pb push_back
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read(){
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
namespace modular{
	const int mod=1e9+7;
	inline int add(int a,int b){return a+b<mod?a+b:a+b-mod;}
	inline int dec(int a,int b){return a<b?a-b+mod:a-b;}
	inline int mul(int a,int b){return (ll)a*b%mod;}
	inline void Add(int&a,int b){a=a+b<mod?a+b:a+b-mod;}
	inline void Dec(int&a,int b){a=a<b?a-b+mod:a-b;}
	inline void Mul(int&a,int b){a=(ll)a*b%mod;}
	inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,Mul(a,a))(p&1)&&(Mul(ret,a),1);return ret;}
}
using namespace modular;
const int N=2e5+5;
ll pre[N];
int n,a[N];
inline ll getsum(int l,int r){return pre[r]-pre[l-1];}
inline ll calc(int l1,int r1,int l2,int r2){
	ll mn=max(r1-l1+1,r2-l2+1),A=getsum(l1,r1),B=getsum(l2,r2);
	if(A>B)swap(A,B);
	return B-A;
}
int main(){
	#ifdef ldxcaicai
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(ri i=1;i<=n;++i)a[i]=read();
	for(ri i=1;i<=n;++i)pre[i]=pre[i-1]+a[i];
	ll res=1e18;
	for(ri i=1;i<n;++i)res=min(res,calc(1,i,i+1,n));
	cout<<res;
	return 0;
}
//  [cpp]
#include"bits/stdc++.h"
using namespace std;

int main(){
  int n, w, i,money=0, r=0, l, flag;
  cin>>n;
  vector<int> a(n);

  for(int i=0; i<n; i++){
    cin >> a[i];
  }
 l = n-1;
    for(;;){
      if(w>0){
        w -= a[l];
        l--;

        if(l<r){
          flag = 0;
          break;
        }
      }else{
        w += a[r];
        r++;

        if(l<r){
          flag = 1;
          break;

        }
      }
    }

    if(flag==0) l--;
    else r--;

      i=0;
      for(;;){
        if(w==0){
          break;
        }else if(w>0){
          if(a[i]>2&&i<r){
            w--;
            money++;
          }else
          {
            w--;
            money++;
          }
        }else{
          if(a[n-i]>2&&r>i){
            w++;
            money++;
          }else
          {
            w++;
            money++;
          }
        }

        i++;
      }



    cout << money << endl;



}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<61);

int main() {
  int n; cin >> n;
  vl a(n), dp(n+1,0);
  ll ans = INFL;
  rep(i,n) {
    cin >> a[i];
    dp[i+1] = a[i] + dp[i];
  }
  rep(i,n-1) {
    ll l = dp[i+1], r = dp[n] - dp[i+1];
    cerr << l << ", " << r << endl;
    ll cost = abs(l - r);
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}
//  [c]
#include <stdio.h>
#define min(x, y) ((x)>(y) ? (y) : (x))
#define abs(x) ((x)<0 ? -(x) : (x))

int main(){
  int n;  scanf("%d", &n);
  long a[200005] = {0};
  for(int i=1; i<=n; i++){
    long t;  scanf("%ld", &t);
    a[i] = a[i-1] + t;
  }
  long ans = 20000000000000000;
  for(int i=1; i<n; i++){
    long left = a[i];
    long right = a[n] - a[i];
    ans = min(ans, abs(left-right));
  }

  printf("%ld\n", ans);
  return 0;
}
//  [c]
#include<stdio.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
int main(){
  ll n, a[222222], s = 0;
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    s += a[i];
  }
  int i=0;
  ll t=a[i];
  while(2*t < s){
    i++;
    t += a[i];
  }
  printf("%lld\n",min(2*t-s,s-2*(t-a[i])));
  return 0;
}
//  [c]
#include <stdio.h>

int main(){
   int n,i;
   long a[200000],t,t2,s,r,c;
 
   scanf("%d",&n);
   t=0;
   for (i=0;i<n;i++) {
      scanf("%ld",&a[i]);
      t+=a[i];
   }
   s=0;
   t2=(t+1)/2;
   for (i=0;s<t2 && i<n;i++) s+=a[i];
   r=t-s;
   if (s==r) c=0;
   else      c=s-r;
   s-=a[i-1];
   r=t-s;
   if (r-s<c) c=r-s;
   printf("%ld\n",c);
   return 0;
}
//  [c]
#include <stdio.h>

int main(){
  int N;
  long long int T,A[200002];
  scanf("%d",&N);
  A[0]=0LL;
  for(int i=1;i<=N;i++){
    scanf("%lld",&T);
    A[i]=A[i-1]+T;
  }
  
  long long int min=A[N]-A[1]*2LL;
  if(min<0LL) min*=-1LL;
  for(int i=2;i<N;i++){
    long long int Q=A[N]-A[i]*2LL;
    if(Q<0LL) Q*=-1LL;
    if(Q<min) min=Q;
  }
  printf("%lld\n",min);
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>

int main(){

long sum_A=0,sum_B=0;
int N;
scanf("%d",&N);
int A[N];
for (int  i = 0; i < N; i++)
{
  scanf("%d",&A[i]);
}

int i=0,j=N-1;
while (i<=j)
{
  if (sum_A>=sum_B){
    sum_B += A[j--];
  }else{
    sum_A += A[i++];
  }
}

printf("%d",abs(sum_A-sum_B));

return 0;
}
//  [c]
#include <stdio.h>
int main() {
  int n;
  double len2 = 0;
  double len1, len;
  double len_max = 0;
  int i;
  int j = 0;
  double ans;

  scanf ("%d", &n);

  double a[n];
  for (i = 0; i < n; i++) {
    if(i == n - 1) scanf ("%lf\n", &a[i]);
    else scanf ("%lf", &a[i]);
  }

  for (i = 0; i < n; i++) {
    len_max += a[i];
  }

  while (len2 < len_max / 2) {
    len2 += a[j];
    j++;
  }

  j--;
  len1 = len2 - a[j];
  if ((len_max / 2) - len1 < len2 - (len_max / 2)) {
    len = len_max - len1;
    ans = (len - len1);
  }
  else {
    len = len_max - len2;
    ans = (len2 - len);
  }

  printf ("%.0lf\n", ans);

  return 0;
}
//  [javascript]
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var sum = 0;
  for(var i = 0; i < N; i++){
    sum += list[i];
  }
  var mae = 0;
  var ato = 0;
  for(var i = 0; i < N; i++){
    mae += list[i];
    if(sum / 2 <= mae){
      break;
    }
  }
  for(var i = N - 1; i >= 0; i--){
    ato += list[i];
    if(sum / 2 <= ato){
      break;
    }
  }
  myout(Math.min(mae - (sum - mae),ato - (sum - ato)));
}
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map( str => parseInt(str, 10) );
    let num = 0;
    for(var i=0;i<N;i++){
        num+=A[i];
    }
    let ans = Infinity;
    let mem = 0;
    for(var i=0;i<N-1;i++){
        mem+=A[i];
        ans=Math.min(ans,Math.abs(num-mem*2));
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
  var inputs = input.split('\n')
  var branch_number = inputs[0]
  var branches = inputs[1].split(' ')
  var result = 0

  var sum = parseInt(branches[0])
  var branch_sum = []
  branch_sum[0] = parseInt(branches[0])
  for (i = 1; i < branch_number; i++) {
    sum += parseInt(branches[i])
    branch_sum[i] = branch_sum[i-1] + parseInt(branches[i])
  }

  var half = sum / 2

  var j = 0
  var flag = false
  var index = 0
  while (!flag) {
    if (Math.abs(branch_sum[j] - half) <= Math.abs(branch_sum[j+1] - half)) {
      index = j
      flag = true
    }
    j++
  }
  // 割れたら終わり
  if (branch_sum[index] === half) {
    console.log(result)
    return
  }

  var center = branch_sum[index]

  var plus = false
  if (center < half) {
    plus = true
  }
  var diff = 0
  while (center !== half) {
    if (plus) {
      diff = Math.ceil(half - center)
      result += diff
      center += diff
      sum += diff
      half = sum / 2
    } else {
      diff = Math.ceil(center - half)
      result += diff
      center -= diff
      sum -= diff
      half = sum / 2
    }
  }

  console.log(result)

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var sum = 0;
  for(var i = 0; i < n; i++){
    sum += a[i];
  }

  var l = 0, r = 0;
  for(var i = 0; i < n; i++){
    if(l < sum/2)l += a[i];
    if(l < sum/2)r += a[i];
  }
  return Math.min(l*2-sum,sum-r*2);
}
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let s = Array(N + 1).fill(0);
    let sum = A.reduce((m,n)=>m+n);
    
    for(let i in A) {
        s[parseInt(i) + 1] = A[i] + s[i];
    }
    
    let costs = Infinity;
    
    for(let i=1; i<A.length; i++) {
        // console.log("A[i-1]" + A[i-1]);
        // console.log("sum - s[i]" + (sum - s[i]));
        
        costs = Math.min(costs, Math.abs(s[i] - (sum - s[i])));
    }

    console.log(costs);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for B - Iron Bar Cutting
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	var temp int
	sum := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		temp += A[i]
		sum[i] = temp
	}

	var flag int
	var min int = 10000000000
	for i := 0; i < N; i++ {
		flag = int(math.Abs(float64(sum[i] - (sum[N-1] - sum[i]))))
		if min > flag {
			min = flag
		}
	}

	fmt.Println(min)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	return n, as
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int, as []int) int {
	sum := 0
	sums := make([]int, len(as)+1)
	for i, a := range as {
		sum += a
		sums[i+1] = sum
	}
	minDiff := math.MaxInt32
	for i := range sums {
		l := sums[i]
		r := sums[len(sums)-1] - sums[i]
		df := abs(l - r)
		if df < minDiff {
			minDiff = df
		}
	}
	return minDiff
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, s int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
		s += as[i]
	}

	var sum int
	ans := math.MaxInt32
	for _, a := range as {
		sum += a
		ans = min(ans, abs(sum-(s-sum)))
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"strings"
)

func main() {
	var n int64
	fmt.Scan(&n)
	aArray := scanNums(n)

	var sumVal int64 = 0
	for _, a := range aArray {
		sumVal += a
	}

	var leftLen int64 = 0
	var rightLen int64 = sumVal
	var leftRightDiff int64 = sumVal

	for _, a := range aArray {
		leftLen += a
		rightLen -= a
		var curDiff int64 = 0
		if leftLen > rightLen {
			curDiff = leftLen - rightLen
		} else {
			curDiff = rightLen - leftLen
		}
		if leftRightDiff > curDiff {
			leftRightDiff = curDiff
		}
	}

	fmt.Println(leftRightDiff)
}

func scanNums(len int64) (nums []int64) {
	var num int64
	var i int64
	for i = 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func splitInput(scanner *bufio.Scanner, sep string) []string {
	scanner.Scan()
	return strings.Split(scanner.Text(), sep)
}
//  [go]
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	sum := 0
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		sum += A[i]
	}

	ans := 9999999999999999
	l := 0
	for i := 0; i < N; i++ {
		l += A[i]
		r := sum - l
		d := abs(r - l)
		if d < ans {
			ans = d
		}
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
//  [ruby]
n = gets.to_i
a = gets.split.map(&:to_i)
l = 0
r = n - 1
diff = a[l] - a[r]
while l + 1 < r do
  if diff < 0
    l += 1
    diff += a[l]
  else
    r -= 1
    diff -= a[r]
  end
end
if diff < 0
  diff2 = diff + a[l + 1] * 2
elsif diff > 0
  diff2 = diff - a[l] * 2
else
  diff2 = 0
end
puts [diff.abs, diff2.abs].min
//  [ruby]
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
r = n-1
l = 0
r_sum = as[-1]
l_sum = as[0]
while l + 1 != r
  if r_sum > l_sum
    l += 1
    l_sum += as[l]
  else
    r -= 1
    r_sum += as[r]
  end
end
puts (r_sum - l_sum).abs
//  [ruby]
N = gets.chomp.to_i
 
input = gets.chomp.split(" ").map(&:to_i)
 
summation = 0
 
input.each do |e|
  summation += e
end
 
border = summation / 2
 
summation2 = 0
number = 0
input.each do |e|
  break if summation2 > border 
  summation2 += e
  number = e
end
 
if summation2 - border > border - (summation2 - number)
	money =  summation - 2 * (summation2 - number)
else
	money = 2 * summation2 - summation
end
 
puts money
//  [ruby]
N = gets.to_i
A = gets.split.map(&:to_i)
pre_a, later_a = 0, A.inject(:+)

p A.inject(A.max) {|n, a|
    pre_a += a
    later_a -= a
    n = [n, (later_a- pre_a).abs].min
}
//  [ruby]
n = gets.to_i
a = gets.split.map(&:to_i)

sum_x = 0
sum_y = 0
x = a.map { |b| sum_x += b; sum_x }
y = a.reverse.map { |b| sum_y += b; sum_y }.reverse

ans = x.last
x.each_index do |i|
  next if i + 1 == n
  ans = [ans, (x[i] - y[i + 1]).abs].min
end

puts ans
//  [ruby]
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

ans = 0
sum = a.inject(:+)

ans = 2020202020

left = 0
right = sum - left
n.times do |i|
  left += a[i]
  right = sum - left
  ans = [ans, (left - right).abs].min
end

puts ans
//  [rust]
use std::io::{BufRead, BufWriter, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    solve(&mut stdin.lock(), &mut BufWriter::new(stdout.lock()));
}

fn solve<R: BufRead, W: Write>(stdin: &mut R, stdout: &mut BufWriter<W>) {
    let n = stdin.gets().parse::<usize>().unwrap();
    let a = stdin.gets().split(' ').take(n)
        .map(|x| x.parse::<i64>().unwrap()).collect::<Vec<_>>();
    let total = a.iter().sum::<i64>();
    let mut min = total;
    let mut cum = 0;
    for i in 0..n {
        cum += a[i];
        let t = (cum * 2 - total).abs();
        min = std::cmp::min(min, t);
    }
    writeln!(stdout, "{}", min).unwrap();
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }
//  [rust]
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        arr: [i64; n],
    }
    let acc: Vec<_> = arr.into_iter().scan(0, |acc, a| {
        *acc += a;
        Some(*acc)
    }).collect();
    let s = *acc.last().unwrap();
    eprintln!("{:?}", acc);
    println!("{}",
        acc.into_iter().fold(i64::MAX, |m, a| min(m, (s - 2 * a).abs()))
    );
}
//  [rust]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let mut a = Vec::with_capacity(n);
    for _ in 0..n {
        let ai: isize = read!();
        a.push(ai);
    }

    let mut s = vec![0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + a[i];
    }

    let mut ans = I_INF;
    for i in 1..n {
        let left = s[i];
        let right = s[n] - s[i];

        ans = ans.min((left - right).abs());
    }

    println!("{}", ans);
}
//  [swift]
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())
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let n=tn(),a=tnn(n),b=[0],s=sum(a)
  for(let i=0;i<n;i++){
    b.push(a[i]+b[i])
  }
  let ans=b[n]
  for(let i=0;i<n;i++){
    ans=min(abs(b[b.length-1]-b[i]-b[i]),ans)
  }
  to(ans)
}
main()
//  [typescript]
{
  const main = (input: string) => {
    const r = reader(input)

    // @ts-ignore
    const _n = r.n()
    const a = r.ns()
    const len = a.reduce((i, j) => i + j, 0)

    let left = 0
    let right = len
    let min = right - left
    a.forEach(v => {
      left += v
      right -= v
      min = Math.min(Math.floor(Math.abs(right - left)), min)
    })
    console.log(min)
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  main(require('fs').readFileSync('/dev/stdin', 'utf8'))
}
//  [python]
N,K = map(int,input().split())
h = list(map(int,input().split()))
count = 0
for i in range(N):
  tmp = h.pop(0)
  if(tmp >= K):
    count += 1
print(str(count))
//  [python]
import numpy as np
n, k = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))
print((a>=k).sum())
//  [python]
NK = input().split()
N = int(NK[0])
K = int(NK[1])
h = list(map(int, input().split()))
i = 0
for j in range(N):
    if h[i] < K:
        h.pop(i)
    else:
        i = i + 1
print(len(h))
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int K = nint();
        int[] h = nints(N);
        
        System.out.println(Arrays.stream(h).filter(i -> i >= K).count());
    }
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }

    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }

    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }

    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    private static long abs(long a, long b) {
        return Math.abs(a - b);
    }
}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int k = sc.nextInt();
        
        int[] h = new int[n];
        
        for(int i = 0; i < n; i++) h[i] = sc.nextInt();
        
        long sum = Arrays.stream(h).filter(x -> x >= k).count();
        
        System.out.println(sum);
    }
}
//  [java]
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> h = new ArrayList<>();

        IntStream.rangeClosed(1, N).forEach(i -> h.add(sc.nextInt()));
        sc.close();

        int answer = (int) h.stream()
                .filter(hi -> hi >= K)
                .count();

        System.out.println(answer);
    }
}
//  [cpp]
#include <bits/stdc++.h>
#include <boost/foreach.hpp>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
#define _GLIBCXX_DEBUG
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
vector<long> Primelist;
//template functions
/////////////////////////
void Prinit(){
long PR=10000001;
vector<long> P(PR,0);
for(long i=2;i*i<PR;i++){
    if(P.at(i)==0){
        long j=i;
      j+=i;
        while(j<PR){
            P.at(j)=1;
             j+=i;         
        }
    }
}

for(long i=2;i*i<PR;i++){//Primelist.size()=446
    if(P.at(i)==0){
        Primelist.push_back(i);
    }
}
}

void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

long Max2(long a,long b){
if(a>b){
    return a;
}else{
    return b;
}
}

long Min2(long a,long b){
if(a>b){
    return b;
}else{
    return a;
}
}


string longtostr(long N){
    string str;
    str=to_string(N);
    return str;
}









/////////////////////////


//Answer


int main() {
Prinit();
long N,K,ans=0;
cin>>N>>K;
vector<long> h(N);
for(long i=0;i<N;i++){
cin>>h.at(i);
if(h.at(i)>=K){
    ans++;
}
}
cout<<ans<<endl;



}
//  [cpp]
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
	int N, K;
    cin >> N >> K;
    vector<int> data(N);
    rep(i, N) cin >> data.at(i);

    int cnt = 0;
    for(int h : data) {
        dump(h);
        if(h >= K) cnt++;
    }

    cout << cnt << endl;
}
//  [cpp]
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;


bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

struct tree {
	queue<lli> leaf;
	lli num;
};

Tree t[200001];

void dfs(lli n, lli num) {
	t[n].num += num;
	while (!t[n].leaf.empty()) {
		dfs(t[n].leaf.front(), t[n].num);
		t[n].leaf.pop();
	}

}
int main() {
	lli n,k,ans=0;
	cin >> n >> k;
	rep0(i,n){
		lli temp;
		cin >> temp;
		if(temp>=k)ans++;
		}
		cout << ans;
}
//  [c]
#include <stdio.h>

int main(void)
{
    int n, k;
    scanf("%d", &n);    scanf("%d", &k);
    int a[n];
    int i = 0;
    int c = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] >= k)
            c++;
    }
    printf("%d", c);
    
    return 0;
}
//  [c]
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

int main(void){
	int n, k, h, ans = 0;

	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &h);
		if (h >= k) {
			ans++;
		}
	}
	printf("%d", ans);
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
	int N, K;
	scanf("%d %d",&N,&K);
	int hight[N];
	for (int i = 0; i < N; i++) {
		scanf("%d",&hight[i]);
	}
	qsort(hight, N, sizeof(int), compare_int);
	int tmp = 0;
	for (tmp = 0; tmp < N; tmp++) {
		if (hight[tmp] >= K) break;
	}
	printf("%d\n",N - tmp);
	return 0;
}
//  [javascript]
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  var list = nextIntArray();
  var output = 0;
  for(var i = 0; i < N; i++){
    if(list[i] >= K){
      output++;
    }
  }
  myout(output);
}
//  [javascript]
const main = input =>{
    const IN = input.split("\n");
    const N = parseInt(IN[0].split(" ")[0]);
    const K = parseInt(IN[0].split(" ")[1]);
    const list = IN[1].split(" ")
    count = 0;

    for(var i=0; i<N; i++){
        if(list[i] >= K){
            count ++;
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = Number(arr[0].split(' ')[1]);
  const b = arr[1].split(' ').map(x => Number(x));
  let count = 0;

  for (let i = 0; i < b.length; i ++) {
    if (b[i] >= a) {
      count ++;
    }
  }
  
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {

	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var count int = 0
	var h int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h)
		if h >= K {
			count++
		}
	}

	fmt.Println(count)
}
//  [go]
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	nums := make([]int, n)

	count := 0
	for i, _ := range nums{
		fmt.Scan(&nums[i])
		if nums[i] >= k{
			count++
		}
	}

	fmt.Println(count)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, k, h, cnt int
	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		if h >= k {
			cnt++
		}
	}
	fmt.Println(cnt)
}
//  [ruby]
n,k=gets.split.map &:to_i
s=gets.split.map &:to_i
s=s.sort.reverse
a=s.bsearch_index{|i|i<k}
if k<=s.min
  puts s.size
elsif k>s.max
  puts 0
else
  puts a
end
//  [ruby]
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

sum = 0
h.each do |x|
  if x >= k
    sum += 1
  end
end

puts sum
//  [ruby]
n,h = gets.split(" ").map(&:to_i)
h_array = gets.split(" ").map(&:to_i)
a_array = []

h_array.each do |i|
  if i >= h
    a_array.push(i)
  end
end

pp a_array.length
//  [rust]
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut k:usize = read!();
    let mut ans:usize = 0;
    for i in 0..n {
        let a:usize = read!();
        if k<=a {
            ans += 1;
        }
    }
    println!("{}",ans);
}
//  [rust]
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut ans = 0;
    for _i in 0..n {
        let h = read::<usize>();
        if h >= k {
            ans += 1;
        }
    }
    println!("{}", ans);
}
//  [rust]
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let k:usize = read();
    let v:Vec<usize> = (0..n).map(|_| read()).collect();

    println!("{}", v.into_iter().filter(|&x| x >= k).count());
}
//  [swift]
import Foundation

var input_num = [String]()
var count:Int = 0

for i in 0..<2 {
  input_num.append(readLine()!)
}

let nk = input_num[0].componentsSeparatedByString(" ")
let n = Int(nk[0])!
let k = Int(nk[1])!

let h = input_num[1].componentsSeparatedByString(" ")
for i in 0..<h.count {
  if Int(h[i]) >= k {
    count += 1
  }
}

print(count)
//  [swift]
import Foundation

var input_num = [String]()
var count:Int = 0

for i in 0..<2 {
  input_num.append(readLine()!)
}

let nk = input_num[0].componentsSeparatedByString(" ")
let n = Int(nk[0])!
let k = Int(nk[1])!

let hList = input_num[1].componentsSeparatedByString(" ")
for i in 0..<hList.count {
  if Int(hList[i]) >= k {
    count += 1
  }
}

print(count)
//  [swift]
let arr1=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let n = arr1[0]
let k = arr1[1]

let h=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let hf = h.filter { $0 >= k }

print( hf.count )
//  [typescript]
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n, k]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const h: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${h.filter(i => i >= k).length}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));
//  [typescript]
import * as fs from 'fs'
const reader = (s: string) =>
  s
    .split('\n')
    .join(' ')
    .split(' ')
    .map(t => parseInt(t, 10))

function Main(input: string) {
  const [_, K, ...h] = reader(input)

  console.log(h.filter(cm => cm >= K).length)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
function main(input) {
    const [n,k] = input.split('\n')[0].split(' ').map(v => parseInt(v, 10));
    const h = input.split('\n')[1].split(' ');
    console.log(h.filter(v => v >= k).length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
import sys
input = sys.stdin.readline

import bisect

def main():
    n = int(input())
    s = []

    for i in range(n):
        a = int(input())
        i = bisect.bisect_left(s, a)
        if len(s) > i and s[i] == a:
            s.remove(a)
        else:
            s.insert(i, a)


    print(len(s))


main()
//  [python]
import bisect
# 操作回数を入力する
N = int(input())
# 言う数字を入力する
list_A = [int(input()) for _ in range(N)]
# 紙の状態を設定する
paper = []
# 
for A in list_A:
    if paper == []:
        paper.append(A)
        continue
    # 紙上のAをニ分探索する
    index = bisect.bisect_left(paper, A)
    if index < len(paper) and paper[index] == A:
        del paper[index]
    else:
        paper.insert(index, A)
# 結果を出力する
print(len(paper))
//  [python]
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    nums = []

    for i in a:
        if len(nums) > 0:
            if i <= nums[-1]:
                ind = bisect.bisect_left(nums, i)
                if nums[ind] == i:
                    nums.pop(ind)
                else:
                    bisect.insort(nums, i)
            else:
                nums.append(i)
        else:
            nums.append(i)
    
    print(len(nums))


if __name__ == "__main__":
    main()
//  [java]
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private final static Scanner sc = new Scanner(System.in);

    /**
     * joisinoお姉ちゃん達が使ってる紙です
     *
     * @author parikkus
     *
     */
    public static class Paper {
        Map<Long, Long> writeNumberCountMap = new HashMap<>();


        public void joisinoCall(Long num) {
            putCountMap(writeNumberCountMap, num);
        }

        public long numberCount() {
            return writeNumberCountMap.values().parallelStream().filter(i -> (i & 1) == 1).count();
        }

        private static void putCountMap(Map<Long, Long> map, Long value) {
            if (map.containsKey(value)) {
                map.put(value, map.get(value) + 1L);
            } else {
                map.put(value, 1L);
            }
        }
    }

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int n = nextInt();
        Paper p = new Paper();

        for (int i = 0; i < n; i++) {
            p.joisinoCall(sc.nextLong());
        }

        out(p.numberCount());
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}
//  [java]
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        System.out.println(IntStream.range(0, scanner.nextInt())
                .boxed()
                .collect(Collectors.groupingBy(i -> scanner.nextInt(), Collectors.reducing(false, i -> true, (a, b) -> a ^ b)))
                .values().stream()
                .filter(Boolean::booleanValue)
                .count());
    }
}
//  [java]
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * お遊び
 *
 * @author s-sugimoto
 */
public class Main {

	/**
	 * 隠蔽
	 */
	private Main() {
	}

	/**
	 * main
	 *
	 * @param args 起動引数
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = scanner.nextInt();

		Map<Integer, Boolean> resultMap = new HashMap<>();
		for (int i = 0; i < count; i++) {
			int input = scanner.nextInt();
			Boolean tmp = resultMap.get(input);
			if (tmp == null) {
				resultMap.put(input, true);
			} else {
				if (tmp) {
					resultMap.put(input, false);
				} else {
					resultMap.put(input, true);
				}
			}
		}

		System.out.println(resultMap.entrySet().stream().map(e -> e.getValue()).filter(e -> e == true).count());
	}

}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  vector<ll> h;

  rep(i, n) {
    ll a;
    cin >> a;

    auto result = find(all(h), a);

    if (result == h.end()) {
      h.push_back(a);
    } else {
      h.erase(result);
    }
  }
  cout << h.size() << endl;
  return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin>>a[i];

    vector<bool> f(1e9,0);
    REP(i,n) f[a[i]-1]=((f[a[i]-1])? 0:1);
    int v=0;
    REP(i,1e9) if(f[i]) v++;

    cout<<v<<endl;

	return 0; 
}
//  [cpp]
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,i,j,sum=0,cnt;
    scanf("%d",&n);
    int num[n];
    for(i=0;i<n;i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    for(i=1;i<n;i++)
    {
        cnt=1;
        if(num[i-1]==num[i])
        {
            for(j=i;j<n;j++)
            {
                if(num[j]==num[i-1])
                    cnt++;
            }
            sum=sum+cnt%2;
            i=i-1+cnt;
        }
        else
            sum++;
        if(i==n-1)sum++;
    }
    printf("%d",sum);
    return 0;
}
//  [c]
#include<stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int ans=N;
  int A[N];
  for (int i = 0; i < N; i++)
  {
    scanf("%d",&A[i]);
    int j=i-1;
    while (A[i]!=A[j]&&j>=0){ j--;}
    if (j<0)
    {
      continue;
    }else
    {
      A[j]=0;A[i]=0;
      ans-=2;
    }
  }
  
  printf("%d",ans);

  return 0;
}