akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main() {
    using namespace std;
    char S[1001];
    int w;
    cin >> S >> w;

    for(int i = 0; S[i] != '\0'; i++) {
        if(i % w == 0) {
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
d = []
a = []
for i in range(1,k+1):
    d.append(int(input()))
    a_temp = list(map(int,input().split()))
    a.append(a_temp)

num = []
    
for i in range(n):
    cnt = 0
    for j in range(k):
        if i+1 in a[j]:
            cnt += 1
    if cnt == 0:
        num.append(i)
print(len(num))

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;

int main() {
    string o, e;
    cin >> o >> e;

    for (int i = 0; i < o.length(); i++) {
        cout << o[i];
        if (i < e.length()) {
            cout << e[i];
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int[] A;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            A = new int[N];
            for (int i = 0; i < A.length; i++) {
                A[i] = sc.nextInt();
            }
        }

        int max = 0;
        int nextMax = 1;
        for (int i = 0; i < A.length; i++) {
            if (A[i] == nextMax) {
                max++;
                nextMax++;
            }
        }
        if (max == 0) {
            System.out.println(-1);
        } else {
            System.out.println(N - max);
        }
    }
}


Measured memory_bytes: 83284
#include <bits/stdc++.h>
using namespace std;

int f(int h[], int n)
{
    int ret = 0;
    int divide = 1;
    for (int i = 0; i < n; i++) {
        if (h[i] > 0) {
            h[i]--;
            if (divide) {
                ret++;
                divide = 0;
            }
        } else {
            divide = 1;
        }
    }

    return ret;
}

int main()
{
    int n;
    cin >> n;

    int h[n];
    int min = 0;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    int ans = 0;
    while (1) {
        int a = f(h, n);
        ans += a;

        if (a == 0) {
            break;
        }
    };

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by zzt on 17-2-18.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long m = scanner.nextLong();

        if (n*2>=m)
            System.out.println(m/2);
        else {
            long r = m-n*2;
            System.out.println(n+r/4);
        }
    }
}

Measured memory_bytes: 22740
n,m=map(int,input().split())
l = [list(input().split()) for i in range(m)]
ans=[0]*n
for i in range(m):
    if l[i][1]=="AC":
        if ans[int(l[i][0])-1]==0:
            ans[int(l[i][0])-1]+=0.5
        if ans[int(l[i][0])-1]<0:
            ans[int(l[i][0])-1]=ans[int(l[i][0])-1]*(-1)
    else:
        if ans[int(l[i][0])-1]<=0:
            ans[int(l[i][0])-1]-=1
ac=0
wa=0
for i in range(n):
    if ans[i]>0:
        ac+=1
        if ans[i]!=0.5:
          wa+=ans[i]
print(ac,wa)
    

Measured memory_bytes: 34204
#include<bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	for (int i=0; i<100000; i++) {
		int j=i*1.08;
		if (j==n) {
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<":(\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

long long powx(int k)
{
    long long t=1;
    for(int i=1;i<=k;i++) t*=10;
    return t;
}
int main()
{
    int a,b;
    cin>>a>>b;
    long long m=0;
    int k=max(a,b), p=min(a,b);
    for(int i=0;i<k;i++){
        m+=p*powx(i);
    }
    cout<<m;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
	int n, m;
	cin >> n;
	vector<int>t(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		int p, x;
		cin >> p >> x;
		cout << sum - t[p - 1] + x << endl;;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	cout << min(a, b) + min(c, d) << '\n';
    return 0;
}


Measured memory_bytes: 256
import bisect
from heapq import heappush as hpush 
from heapq import heappushpop as hpushpop 

Q=int(input())

que=list(map(int,input().split()))
b=que[2]
l,r=[-que[1]],[que[1]]
a=0
tmp=que[1]
j=1
for i in range(Q-1):
    que=list(map(int,input().split()))
    if que[0]==1:
        j+=1
        b+=que[2]
        q1=que[1]
        if j%2==0:
            if q1<-l[0]:
                hpushpop(l,-q1)
            else:
                hpushpop(r,q1)

        else:
            if q1<-l[0]:
                hpush(l,-q1)
                hpush(r,-l[0])
            else:
                hpush(r,q1)
                hpush(l,-r[0])
        

        if -l[0]!=r[0]: a+=abs(tmp-q1)
        else: a+=abs(tmp-q1)-abs(-l[0]-tmp)
        tmp=-l[0]

    elif que[0]==2:
        print(tmp,a+b)

Measured memory_bytes: 11188
//AtCoder B - Some Sums
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N,A,B;
    cin>>N>>A>>B;
    ll ans=0;
    auto check_keta = [&](ll n){
        ll kw=0;
        while(n > 0){
            kw += n%10;
            n /= 10;
        }
        return (kw>=A&&kw<=B);
    };
    for(ll i=1;i<=N;++i){
        if (check_keta(i)) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

signed main(){
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    
    int c1 = 0; // 国内の通過者
    int c2 = 0; // 海外の通過者
    for (int i = 0; i < n; ++i){
        if (s[i] == 'c'){
            cout << "No" << endl;
        }
        else if (s[i] == 'a'){
            if (c1 + c2 < a + b){
                ++c1;
                cout << "Yes" << endl;
            }
            else
                cout << "No" << endl;
        }
        else{
            if (c1 + c2 < a + b && c2 < b){
                ++c2;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	string o,e,ans;
	cin>>o>>e;
	rep(i,o.size()){
		if(i==e.size()) ans=ans+o[i];
		else ans=ans+o[i]+e[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    if (a<b){
        rep(i,b) cout << a;
        cout << endl;
    }
    else if (a>b){
        rep(i,a) cout << b;
        cout << endl;
    }
    else {
        rep(i,a) cout << b;
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
 
	int n,m;
	cin >> n >> m;
	int towns[n];
	int a,b;
	for(int i = 0;i<n;i++){
		towns[i] = 0;
	}
	for(int i = 0;i<m;i++){
		cin >> a >> b;
		a--;
		b--;
		towns[a]++;
		towns[b]++;
	}
	for(int i = 0;i<n;i++){
		cout << towns[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}


const int limit = 51;
int n,m;
bool vec[limit][limit];
bool vis[limit];

void DFS(int x){
    if(vis[x]) return;

    vis[x] = true;

    REP(i,n){
        if(vec[i][x]){
            DFS(i);
        }
    }
}
using namespace std;
int main(){
    int n;
    cin >> n;

    int a[2][n];
    int dp[2][n];


    REP(i,2){
        REP(j,n){
            cin >> a[i][j];
        }
    }
    

    dp[0][0] = a[0][0];
    dp[1][0] = a[0][0] + a[1][0];

    FOR(i,1,n){
        dp[0][i] = dp[0][i-1] + a[0][i];
        dp[1][i] = max(dp[1][i-1], dp[0][i]) + a[1][i];
    }

    cout << dp[1][n-1] <<endl;
}

Measured memory_bytes: 256
def partition(a, p, r)
	x = a[r]
	i = p-1
	p.upto(r-1) do |j|
		if a[j] <= x
			i += 1
			a[i], a[j] = a[j], a[i]
		end
	end
	a[i+1], a[r] = a[r], a[i+1]
	return i+1
end

n = gets.to_i
a = gets.split.map &:to_i

q = partition(a, 0, n - 1)
a[q] = "[" + a[q].to_s + "]"
puts a.join(" ")

Measured memory_bytes: 17172
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[101][100010];

int max_weight(int w, int n, int *wt, int *val){
    if(w == 0 or n==0)
        return 0;
    if(dp[n][w]!=-1)
        return dp[n][w];
    if(wt[n-1] > w)
        return max_weight(w,n-1,wt,val);
    dp[n][w] = max(max_weight(w,n-1,wt,val), val[n-1] + max_weight(w-wt[n-1], n-1, wt, val));
    return dp[n][w];
    
}

signed main()
{
    int n,w;
    cin>>n>>w;
    int values[n],weights[n];
    for(int i=0;i<n;i++)
        cin>>weights[i]>>values[i];
    for(int i=0;i<101;i++){
        for(int j=0;j<100010;j++)
            dp[i][j] = -1;
    }
    cout<<max_weight(w,n,weights,values);
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  int s;
  cin >> s;
  if(s == 25)
    cout << "Christmas" << endl;
  else if(s == 24)
    cout << "Christmas Eve" << endl;
  else if(s == 23)
    cout << "Christmas Eve Eve" << endl;
  else if(s == 22)
    cout << "Christmas Eve Eve Eve" << endl;
  
}

Measured memory_bytes: 3632
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

int n;

void input() {
    RI(n);
}

void solve() {
    int cur=1;

    REP(i, n) {
        int a; RI(a);
        if(a==cur) {
            cur++;
        }
    }
    if(cur-1==0) {
        printf("-1\n");
    } else {
        printf("%d\n", n-cur+1);
    }
}

int main( int argc, char *argv[] ) {
    input(); solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=1e5+10;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

int N,X;

int main(){
    //freopen("","r",stdin);
    N=rd(),X=rd();
    int now=0,ans=1;
    for(int i=1;i<=N;i++){
    	now+=rd();
    	if(now>X) break;
    	ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int X = scan.nextInt();
        int Y = scan.nextInt();

        int ans = 1000000000;
        for(int i = 0;i <= 2*(X+Y);i++){
           int ABpizza = i;
           int Apizza = 0;
           int Bpizza = 0;
           if(X - i/2>=0){ Apizza = X - i/2;}
           if(Y - i/2>=0){ Bpizza = Y - i/2;}
           ans = Math.min(ans,Apizza*A+Bpizza*B+ABpizza*C);
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=1145141919810364364;

int gcd(int x,int y){
    if(x<y) swap(x,y); //常にx>=y
    //ユークリッドの互除法
    if(!(x%y)) return y;
    else return gcd(y,x%y);
}

int main(){
	int n,k; cin>>n>>k;
	int g,m; cin>>g; m=g;
	rep(i,n-1){
		int a; cin>>a;
		g=gcd(g,a);
		m=max(m,a);
	}
	// cout<<g<<" "<<m<<endl;
	if(k<=m&&k%g==0) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll bit[10000000];
ll mini = 1;

ll sum(ll i) {
	ll s = 0;
	while(i > 0) {
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x) {
	while(i <= mini) {
		bit[i] += x;
		i += i & -i;
	}
}

int main(void) {
	ll n, k;
	cin>>n>>k;
	vector<ll> a(n);
	REP(i, n) cin>>a[i];
	REP(i, n) a[i] -= k;
	vector<P> b(n);
	REP(i, n) {
		if(i == 0) b[i].first = a[i];
		else b[i].first = b[i - 1].first + a[i];
		b[i].second = i;
	}
	sort(ALL(b));
	vector<ll> c(n);
	for(ll i = n - 1; i >= 0; --i) {
		if(i == n - 1) c[b[i].second] = mini;
		else if(b[i].first == b[i + 1].first) {
			c[b[i].second] = mini;
		} else {
			++mini;
			c[b[i].second] = mini;
		}
	}
	ll anshoge = 0;
	REP(i, n) {
		if(b[i].first >= 0) ++anshoge;
	}
	ll ans = 0;
	REP(i, n) {
		ans +=sum(c[n - 1 - i]);
		add(c[n - 1 - i], (ll)1);
	}
	ans += anshoge;
	cout<<ans<<endl;
}



Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b;
  cin >> a >> b;
  cout << b + (b - a) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int64_t N;
	cin >> N;
	vector<int64_t> A(N);
	vector<int64_t> flag(N, 0);
	vector<int64_t> count(N, 0);
	//vector<int> counter(N, 0);
	int64_t counter = 0;
	

	for (int64_t i = 0; i < N; i++)
	{
		cin >> A[i];
		flag[A[i] - 1] += 1;
	}

	for (int64_t i = 0; i < N; i++)
	{
		count[i] = flag[i] * (flag[i] - 1) / 2;
		counter += count[i];
	}

	for (int64_t k = 0; k < N; k++)
	{
		cout << counter - count[A[k] - 1] + (flag[A[k] - 1] - 1) * (flag[A[k] - 1] - 2) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];
    sort(l.begin(), l.end(), greater<ll>());
    ll tmp=0;
    rep(i,n-1) tmp+=l[i+1];
    if(l[0]<tmp) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))

inf = 10000000000

dp = [inf] * N
dp[0] = 0

for i in range(1, N):
    #mindp_i = inf

    for jump in range(1, K + 1):
        if i - jump >= 0:
            dp[i] = min(dp[i], dp[i - jump] + abs(h[i] - h[i - jump]))

            #dpcand = dp[i - jump] + abs(h[i] - h[i - jump])
            #print(dpcand)
            #if dpcand < mindp_i:
            #    mindp_i = dpcand

    #dp[i] = mindp_i

print(dp[N-1])

Measured memory_bytes: 84604
#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct calc_bridge_and_articulation{
    const int size;
    vector<vector<int>> graph;
    vector<bool> used_v;
    vector<vector<bool>> used_e;
    vector<int> ord,lowlink,articulations;
    vector<pair<int,int>> bridges;

    calc_bridge_and_articulation(const vector<vector<int>> &graph):graph(graph),size(graph.size()){
        used_v.resize(size);
        used_e.resize(size);
        rep(i,0,size) used_e[i].resize(size);
        ord.resize(size);
        lowlink.resize(size);
        int k;
        rep(i,0,size) if(!used_v[i]) dfs(i,-1,k);
    }

    void dfs(int v,int p,int &k){ //v???????????¨???p=-1
        used_v[v]=true;
        ord[v]=lowlink[v]=k++;

        bool is_articulation=false;
        int count=0;
        for(int u:graph[v]){
            if(!used_v[u]){
                ++count;
                used_e[v][u]=true;
                dfs(u,v,k);
                lowlink[v]=min(lowlink[v],lowlink[u]);

                if(ord[v]<lowlink[u]) bridges.push_back(make_pair(min(v,u),max(v,u)));
                if(p!=-1 and ord[v]<=lowlink[u]) is_articulation=true;
            }else if(!used_e[u][v]) lowlink[v]=min(lowlink[v],ord[u]);
        }

        if(p==-1 and count>1) is_articulation=true;
        if(is_articulation) articulations.push_back(v);
    }
};

void solve(){
    int size_v,size_e;
    cin >> size_v >> size_e;
    vector<vector<int>> graph(size_v);
    rep(i,0,size_e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    calc_bridge_and_articulation cba(graph);
    auto ans=cba.articulations;
    sort(ans.begin(),ans.end());
    rep(i,0,ans.size()) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 17804
#include <cstdio>
const int N=2e5+5;
int a[N],mid,l,r,n,ans=0;
inline bool get(int x){return !(x<=mid);}
inline bool check(){
	for (int i=1;i<n;i++){
		if (get(a[n+i-1])==get(a[n+i])) return get(a[n+i]);
		if (get(a[n-i+1])==get(a[n-i])) return get(a[n-i]);
	}return get(a[1]);
}
int main () {
	scanf ("%d",&n);
	for (int i=1;i<(n*2);i++) scanf ("%d",&a[i]);
	l=1,r=(n*2)-1;
	while (l<=r){
		mid=(l+r)>>1;
		if (check()) l=mid+1;
		else r=mid-1;
	}
	printf ("%d",r+1);
	return 0;
}

Measured memory_bytes: 1024
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll sum1 = a*x+b*y;
	for(int i=1;i<=max(x,y);i++){
		ll sum2 = 2*i;
		ll sum3 = c*sum2+(a*max(0,x-i))+(b*max(0,y-i));
		sum1 = min(sum3,sum1);
	}
	cout<<sum1<<endl;
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Long[] array = new Long[6];
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		List<String> list_s= new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list_t= new ArrayList<String>(Arrays.asList(t.split("")));
		String answer ="";
		for(int i=0;n>i;i++) {
			answer=answer+list_s.get(i);
			answer=answer+list_t.get(i);
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;

int main() {
  
  string s, t;
  
  cin >> s >> t;
  
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


using mint = modint998244353;

struct S{
  mint a;
  int size;
};
struct F{
  mint a, b;
};

S op(S l, S r){return S{l.a + r.a, l.size + r.size};}
S e(){return S{0,0};}
S mapping(F l, S r){return S{r.a * l.a + r.size * l.b, r.size};}
F composition(F l, F r){return F{r.a * l.a, r.b * l.a + l.b};}
F id(){return F{1, 0};}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;
  vector<S> A(N);
  rep(i,N){
    int a;
    cin >> a;
    A.at(i) = {a, 1};
  }

  lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
  rep(_,Q){
    int q;
    cin >> q;
    if(q == 0){
      int l,r,b,c;
      cin >> l >> r >> b >> c;
      seg.apply(l, r, F{b, c});
    }
    else if(q == 1){
      int l,r;
      cin >> l >> r;
      cout << seg.prod(l, r).a.val() << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 19208
#include  <iostream>
#include  <vector>

using namespace std;

typedef long long ll;
const int E = static_cast <int> (1e9 + 7);

int main()
{
	int n, m;
	cin >> n >> m;
	vector <ll> dp(n + 5, -1);
	dp[0] = 1;
	dp[1] = 1;
	dp[2] = 2;
	for (int i = 0; i < m; i++) {
		int tmp;
		cin >> tmp;
		dp[tmp] = 0;
	}
	if (dp[1] == 0 && dp[2] != 0)  dp[2] = 1;;
	for (int i = 3; i <= n; i++) {
		if (dp[i] == -1) {
			dp[i] = (dp[i - 1] + dp[i - 2]) % E;
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    priority_queue<ll> que;
    rep(i, n) {
        ll a;
        cin >> a;
        que.push(a);
    }

    rep(i, m) {
        ll t = que.top();
        que.pop();
        que.push(t/2);
    }

    ll res = 0;
    while(!que.empty()) {
        res += que.top();
        que.pop();
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 1400
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int a[N];
int b[N];
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);



bool check (int x) {
	ordered_set < pair < int, int > > q;
	ll ans = 0;
	q.insert({0, 0});
	for (int i = 1; i <= n; ++i) {
		b[i] = b[i-1];
		if (a[i] >= x) b[i]++;
		else b[i]--;
		ans += q.order_of_key({b[i], n+1});
  		q.insert({b[i], i});
	}
	ll overall = n * (ll)(n+1) / 2;

	return ans * 2 >= overall;
}

int main () {
	scanf("%d", &n);
	vector < int > val;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		val.pb(a[i]);
	}
	sort(every(val));
	val.resize(unique(every(val)) - val.begin());

	int l = 0, r = sz(val);
	while (r - l > 1) {
		int md = (l + r) >> 1;
		if (check(val[md])) {
			l = md;
		} else {
			r = md;
		} 
	}

	printf("%d\n", val[l]);

	return Accepted;
}

// B...a

Measured memory_bytes: 11384
n = int(input())
s = []
c = 0
check = [0,0,0]
for i in range(n):
  s.append(input())
  c+=s[i].count("AB")
  if s[i][0] == 'B' and s[i][-1] == 'A':
    check[0]+=1
  elif s[i][0] == 'B':
    check[1]+=1
  elif s[i][-1] == 'A':
    check[2]+=1
    
if check[0] == 0:
  c+=min(check[1],check[2])
elif check[1] + check[2] == 0:
  c+=check[0]-1
else:
  c+=check[0]+min(check[1],check[2])
print(c)   

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 300;
const int inf = (1<<20);
int cap[N][N];
int flow[N][N];
bool vis[N];

int fordFulkerson(int n,int s,int t,int now,int fl){
  if (now == t)return fl;
  if (vis[now])return 0;
  vis[now]=true;
  int tmp=0;
  rep(i,n){
    int &next=i;
    if (cap[now][i] - flow[now][i] > 0){
      tmp=fordFulkerson(n,s,t,next,min(fl,cap[now][i]-flow[now][i]));
      if (tmp != 0){
	flow[now][next]+=tmp;
	flow[next][now]=-flow[now][next];
	return tmp;
      }
    }
  }
  return 0;
}

int maxFlow(int n,int s,int t){
  int tmp=0,ret=0;
  rep(i,n)vis[i]=false;
  while((tmp = fordFulkerson(n,s,t,s,inf)) != 0){
    ret+=tmp;
    rep(i,n)vis[i]=false;
  }
  return ret;
}

bool edge[N][N];
int num[N][N];
main(){
  int n,m;
  while(cin>>n>>m){
    rep(i,n)rep(j,n)flow[i][j]=0,cap[i][j]=0,edge[i][j]=false,num[i][j]=-1;
    rep(i,m){
      int a,b;
      cin>>a>>b;
      a--;b--;
      edge[a][b]=true;
      num[a][b]=num[b][a]=i+1;
      cap[a][b]=cap[b][a]=1;
    }
    int s,t;
    cin>>s>>t;
    s--;t--;
    int ans=maxFlow(n,s,t);
    cout << ans << endl;
    int cnt=0;
    rep(i,n)rep(j,n)if (flow[i][j] > 0 && !edge[i][j])cnt++;
    cout << cnt << endl;
    rep(i,n)rep(j,n)if (flow[i][j] > 0 && !edge[i][j])cout << num[i][j] << endl;
#ifdef DEBUG
    cout <<"end" << endl;
#endif    
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 200200;
const long double PI = acos(-1);

ll n, m, k;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> x >> n;

    set<int> st, nt;

    for (int i=0; i<n; i++){
        int aux;
        cin >> aux;
        st.insert(aux);
    }

    for (int i=0; i<=110; i++){
        if (!st.count(i)) nt.insert(i);
    }

    auto pos = nt.lower_bound(x);

    if (nt.empty()){
        cout << x << endl;
    }
    else if (nt.begin() == pos){
        cout << *pos << endl;
    }
    else {
        auto npos = prev(pos);
        cout << (abs(*npos - x) <= abs(*pos - x)? *npos : *pos) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

public class Digits
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var list = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToList();
        var max = list.Max();
        var min = list.Min();
        var results = new List<int>();
        for (int i = min; i <= max; i++)
        {
            results.Add(Enumerable.Range(0, list.Count).Select(x => (list[x] - i) * (list[x] - i)).Sum());
        }
        Console.WriteLine(results.Min());
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sc(t) scanf("%d",&t)
#define sc3(t,u,v) scanf("%d %d %d",&t,&u,&v)
#define sc2(t,u) scanf("%d %d",&t,&u)
#define scL(t) scanf("%lld",&t)
#define scL3(t,u,v) scanf("%lld %lld %lld",&t,&u,&v)
#define scL2(t,u) scanf("%lld %lld",&t,&u)
#define mem(a,i) memset(a,i,sizeof a)
#define fr(i,n) for(int i=0;i<n;i++)
#define fr1(i,n) for(int i=1;i<=n;i++)
#define itr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define inf 10000007
#define endd printf("\n")
#define MAXX 100007
///unsigned int isprime[(MAXX>>6)+2];
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
#define check(i) (isprime[i>>6] & (1<<((i>>1)&31)))
#define sett(i) (isprime[i>>6] |= (1<<((i>>1)&31)))
#define eps 1e-6

int h[MAXX],dp[MAXX];

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

    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> h[i];
    dp[0] = 0;
    for(int i=1;i<n;i++){
        dp[i] = INT_MAX;
        for(int j=1;j<=k;j++){
            if(i-j>=0){
                dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]));
            }
            else break;
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a;
  a=N/100;
  if(a==7){
    cout << "Yes" << endl;
    return 0;
  }
  N=N-a*100;
  a=N/10;
  if(a==7){
    cout << "Yes" << endl;
    return 0;
  }
  N=N-a*10;
  a=N;
  if(a==7){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;

int main(){
    int k=0,n=0,dmax=0,i=0;
    cin >> k >> n;
    int a[n]={0},d[n]={0};
    for (i=0;i<n;i++){
        cin >> a[i];
    }
    d[0]=a[0] + k - a[n-1];
    for (i=1;i<n;i++){
        d[i]=a[i]-a[i-1];
    }
    dmax = d[0];
    for (i=1;i<n;i++){
        if (dmax <= d[i]) {
            dmax =d[i];
       }
    }
    cout << k-dmax << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>


int main(void)
{
	char a[100+2], b[100+2];
	int r;

	while(scanf("%s%s", a, b)==2)
	{
		r=strlen(a)-strlen(b);
		if(r==0)
		{
			r=strcmp(a, b);
		}
		if(r>0) printf("GREATER\n");
		if(r<0) printf("LESS\n");
		if(r==0) printf("EQUAL\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    ll L, R;
    cin >> L >> R;

    ll ans = 1e9;
    for(ll i = L; i <= min(R - 1, L + 2019); ++i) {
        for(ll j = i + 1; j <= min(R, i + 1 + 2019); ++j) {
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	for (int n = 0;n<=1000;++n) {
		if (A==n*8/100&&B==n*10/100) {
			cout <<n<<endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i += 2) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
from scipy.sparse import*
n,*a=map(int,open(0).read().split())
c=[1]*~-n
print('FSennunkeec'[sum(g>h for g,h in zip(*csgraph.dijkstra(csr_matrix((c,(a[::2],a[1::2])),[n+1]*2),0,[1,n])))*2>=n::2])

Measured memory_bytes: 34508
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
         int a =sc.nextInt();
         int b =sc.nextInt();
         System.out.println(""+(a*b)+" "+(2*(a+b))+"");
         sc.close();
    }
}


Measured memory_bytes: 26200
fun main(args:Array<String>?): Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val runner = Array(n){
            val (d, v) = readLine()!!.trim().split(' ').map(String::toLong)
            Pair(d, v)
        }
        val time = runner.fold(1L){time, (d, v) ->
            val a = d / gcd(d, v)
            time * a / gcd(time, a)
        }
        val g = runner.map{(d, v) -> time * v / d}.reduce(::gcd)
        for ((d, v) in runner){
            println(time * v / d / g)
        }
    }
}
tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) a else gcd(b, a % b)
}


Measured memory_bytes: 39584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll pr[200500];
void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		pr[i + 1] = x + pr[i];
	}
	ll ans = LONG_MAX;
	for (int i = 1; i <= n - 1; i++) {
		ans = min(ans, abs(pr[i] - pr[n] + pr[i]));
	}
	cout << ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    s[k - 1] = s[k - 1] + 32;
    cout << s << endl;
	return 0; 
} 

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;


void solve();

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

void solve(){
    ll n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];

    ll ans=0;
    map<ll,ll> mp;
    rep(i,n){
        ans+=mp[i-a[i]];
        ++mp[a[i]+i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 27400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <bitset>
#include <string>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <deque>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef pair<int, int> P;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};

int w, h, k;

int mw[100005] = { 0 };
int dp[100005] = { 0 };
int res = INF;

int main() {
	cin >> w >> h >> k;
	for (int i = 0; i < k; i++) {
		int x, y;
		cin >> x >> y;
		mw[x] = max(mw[x], y);
	}
	for (int i = w - 2; i >= 0; i--) {
		//out(mw[i]);
		dp[i] = max(dp[i + 1], mw[i + 1]);
		//out(dp[i]);
	}
	for (int i = 0; i < w; i++) {
		res = min(res, i + dp[i]);
	}
	out(res);
	return 0;
}


Measured memory_bytes: 3880
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp;
  auto cnt = new int[](3);
  foreach (e; s) {
    cnt[e-'a']++;
  }
  if (abs(cnt[0]-cnt[1]) < 2 && abs(cnt[1]-cnt[2]) < 2 && abs(cnt[0]-cnt[2]) < 2) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


Measured memory_bytes: 508
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int x,a,b;
scanf("%d\n%d\n%d\n",&x,&a,&b);
int c;
c=x-a;
x=c%b;
printf("%d",x);
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=1000000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;


int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {  
           string s;
           cin>>s;
           if(s[2]==s[3] && s[4]==s[5])
           cout<<"Yes"<<endl;
           else
           cout<<"No"<<endl;	
      }

      return 0;     
}

/*
 TIPS(FOR ME):
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/


Measured memory_bytes: 256
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(n):
  p=c
  A=list(map(int,input().split()))
  for j in range(m):
    p+=A[j]*B[j]
  if p>0:count+=1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

string S, T;
int dp[3010][3010];

int main() {
  cin >> S >> T;

  rep(i, 0, S.size()) rep(j, 0, T.size()) {
    if (S[i] == T[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
    chmax(dp[i+1][j+1], dp[i+1][j]);
    chmax(dp[i+1][j+1], dp[i][j+1]);
  }

  string res = "";
  int i = S.size(), j = T.size();
  while (i >0 && j > 0) {
    // (i-1, j) -> (i, j)
    if (dp[i][j] == dp[i-1][j]) i--;
    // (i, j-1) -> (i, j)
    else if (dp[i][j] == dp[i][j-1]) j--;
    // (i-1, j-1) -> (i, j)
    else {
      res = S[i-1] + res;
      i--; j--;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

const int mod=1000000007;

//N=(m+1)*x (m>x)
//8*1,4*2
//36*1,18*2,12*3,9*4,x6*6

std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n&&n/i-i!=1)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> a=enum_div(n);
    sort(a.begin(),a.end());
    ll ans=0;
    for(auto it=upper_bound(a.begin(),a.end(),sqrt(n));it!=a.end();++it){
        ans+=(*it)-1;
    }
    cout<<(n==2?0:ans)<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
signed main(){
	int ans=0,x;
  	cin>>x;

  	if(x%5 != 0)
      ans+=100;
  	if(x%10 > 4)
      ans+=100;
  	ans+=((x%100-x%10)/10)*200;
  	if(ans <= x)
      cout<<1<<endl;
  	else	
      cout<<0<<endl;
	return(0);
}

Measured memory_bytes: 256