akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define mod 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)


struct Modcomb{
  std::vector<long long int>fac;  //$B3,>h(B
  std::vector<long long int>finv; //$B3,>h$N5U85(B
  std::vector<long long int>inv;  //$B5U85(B

  //nCr=n!/r!(n-r)!
  Modcomb(int max){
    fac.resize(max+1,0);
    finv.resize(max+1,0);
    inv.resize(max+1,0);
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<=max;i++){
      fac[i]=(fac[i-1]*i%mod)%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }

  long long int slove(int n,int r){
    if(n<r)return 0;
    if(n<0||r<0)return 0;
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod;
  }
};

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

  int n,k;
  cin>>n>>k;

  ll ans=0;
  Modcomb comb(n);
  if(n<=k)k=n-1;
  for(int i=0;i<=k;i++){
    ans=(ans+(((comb.slove(n,i)*comb.fac[n-1])%MOD*comb.finv[i])%MOD*comb.finv[n-i-1])%MOD)%MOD;
    ans%=MOD;
  }
  cout<<ans%MOD<<endl;

  return 0;
}


Measured memory_bytes: 4992
n, k = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
INF = 10 ** 9

def sign(x):
    return int(x >= 0)

ans = INF
for i in range(n - k + 1):
    p = k + i - 1
    if sign(x[i]) == sign(x[p]):
        t = max(abs(x[i]), abs(x[p]))
    else:
        t = min(-x[i] * 2 + x[p], -x[i] + x[p] * 2)
    if t < ans:
        ans = t

print(ans)

Measured memory_bytes: 14252
def examA():
    N = I()
    H = LI()
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
        if i<N-2:
            dp[i + 2] = min(dp[i + 2], dp[i]+abs(H[i + 2] - H[i]))
    ans = dp[-1]
    print(ans)
    return

def examB():
    N, K = LI()
    H = LI()
    dp = [inf]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1,K+1):
            if i+k>=N:
                break
            if dp[i+k]>dp[i]+abs(H[i+k]-H[i]):
                dp[i+k] = dp[i]+abs(H[i+k]-H[i])
    ans = dp[-1]
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 54000
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
      //取得
	  int N = sc.nextInt();
      if(N%1000==0){
        System.out.println(0);
      }else{
        System.out.println(1000-(N%1000));
      }
    } 
}

Measured memory_bytes: 35812
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
	ll n, s, ans;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s;
		cout << "Case " << i + 1 << ":" << endl;
		for (int j = 0; j < 10; j++){
			s = s*s;
			s %= 1000000;
			s /= 100;
			cout << s << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

ll ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default : return -1;
	}
}

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

	ll s = S.length();
	mat dp(s , vec(13, 0));

	if (S[0] == '?') {
		REP(i, 10) {
			dp[0][i] = 1;
		}
	}
	else {
		ll Sz = ctoi(S[0]);
		dp[0][Sz] = 1;
	}

	FOR(i, 1, s) {
		if (S[i] == '?') {
			REP(j, 13) {
				REP(k, 10) {
					dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
				}
			}
		} else {
			ll Si = ctoi(S[i]);
			REP(j, 13) {
				dp[i][(j * 10 + Si) % 13] += dp[i - 1][j];
			}
		}
		REP(j, 13) {
			dp[i][j] %= mod;
		}
	}

	cout << dp[s - 1][5] % mod << endl;

	return 0;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, m; cin >> n >> m;
    vector<int> A(n, 0);
    REP(i, m){
        int tmp;
        cin >> tmp;
        A[tmp - 1]++;
        cin >> tmp;
        A[tmp - 1]++;
    }
    REP(i, n){
        cout << A[i] << endl;
    }
}

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

using namespace std;

typedef pair<int, int> pii;

int N;
vector<pii> squares;

void solve() {
	int maxx = 0, minx = 0, maxy = 0, miny = 0;
	squares.assign(N, make_pair(0, 0));
	
	for (int i = 1; i < N; i++) {
		int n, d; cin >> n >> d;
		
		pii p = squares[n];
		
		if (d == 0) squares[i] = make_pair(p.first - 1, p.second);
		if (d == 1) squares[i] = make_pair(p.first, p.second - 1);
		if (d == 2) squares[i] = make_pair(p.first + 1, p.second);
		if (d == 3)	squares[i] = make_pair(p.first, p.second + 1);
		
		maxx = max(maxx, squares[i].first);
		minx = min(minx, squares[i].first);
		maxy = max(maxy, squares[i].second);
		miny = min(miny, squares[i].second);
	}
	
	int w = maxx - minx + 1, h = maxy - miny + 1;
	cout << w << " " << h << endl;
}

int main() {
	while (1) {
		cin >> N; if (N == 0) break;
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1192
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

// 最大要素数 問題の制約次第でいじってください
#define MAX_E 10000
#define MAX_V 1010

// 頂点fromから頂点toへのコストcostの辺
struct edge{
    int from,to;
    int cost;
};

edge es[MAX_E];

vector<bool> n(MAX_V,false);

int d[MAX_V];
int V,E;

// trueなら負の閉路が存在する
bool find_negative_loop(){
    //memset(d,0,sizeof(d));

    for(int i=0;i<V;i++){
        for(int j=0;j<E;j++){
            edge e=es[j];
            if(d[e.from]==INF) continue;
            if(d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                n[e.to]=true;
                // n回目にも更新があるなら負の閉路が存在する
                if(i==V-1) return true;
            }
            if(n[e.from]) n[e.to]=true;
        }
    }
    return false;
}

// s番目の頂点から各頂点への最短経路を求める
void shortest_path(int s){
    for(int i=0;i<V;i++) d[i]=INF;
    d[s]=0;
    /*while(true)*/rep(i,V-1){
        //bool update=false;
        for(int i=0;i<E;i++){
            edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                //update=true;
            }
        }
        //if(!update) break;
    }
}

signed main(){
    io();
    in(V,E);
    rep(i,E){
        int a,b,c;
        in(a,b,c);
        a--;b--;c*=-1;
        edge e={a,b,c};
        es[i]=e;
        //show(es[i].from,es[i].to,es[i].cost);
    }
    shortest_path(0);
    find_negative_loop();
    if(n[V-1]){
        out("inf");
        return 0;
    }

    out(-d[V-1]);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int divceil(int a, int b) {
	return (a + b - 1) / b;
}

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

	int K, P;
	cin >> K >> P;
	VI D(K);
	REP(i, K)cin >> D[i];

	REP(i, P) {
		int N, X, M;
		cin >> N >> X >> M;

		int L = X, E = 0;
		REP(i, K) {
			int num = divceil(N - 1 - i, K);
			L += (D[i] % M)*num;
			if (D[i] % M == 0)E += num;
		}
		int ans = (N - 1) - (L / M - X / M) - E;
		cout << ans << endl;
	}



	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>

const int N = 11;

int n, m;
char s[N][N];

bool solve() {
	if (s[0][0] != '#') return false;
	int cnt = 1;	
	int x, y;
	x = 0, y = 0;
	while (x + 1 < n || y + 1 < m) {
		if (x + 1 < n && s[x + 1][y] == '#') {
			x++;
		} else if (y + 1 < m && s[x][y + 1] == '#') {
			y++;
		} else {
			return false;
		}
		cnt++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i][j] == '#') cnt--;
		}
	}
	return cnt == 0;
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	printf("%s\n", solve() ? "Possible" : "Impossible");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int a,b,c,d;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b>>c>>d;
		if(b*b+c*c==d*d||c*c+d*d==b*b||d*d+b*b==c*c){
			cout <<"YES"<<endl;
		}else{
			cout <<"NO"<<endl;
		}
	}
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

using Tup = tuple<ll, ll, ll>;
using Graph = vector<vector<Tup>>;

ll N, M, S;
Graph g;
Vl C, D;
vector<Vl> cost;


int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    cin >> N >> M >> S;
    g.resize(N);
    C.resize(N);
    D.resize(N);

    for (ll i = 0; i < M; i++) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        g[u].emplace_back(v, a, b);
        g[v].emplace_back(u, a, b);
    }

    for (ll i = 0; i < N; i++) {
        cin >> C[i] >> D[i];
    }


    cost.assign(N, Vl(2510, L_INF));

    priority_queue<Tup, vector<Tup>, greater<Tup>> q;  // time, idx, silver
    if (S > 2500) S = 2500;
    q.emplace(0, 0, S);
    cost[0][S] = 0;

    while (!q.empty()) {
        auto [t, idx, s] = q.top();
        q.pop();
        if (t > cost[idx][s]) continue;

        {
            ll nt = t + D[idx];
            ll ns = s + C[idx];
            if (ns > 2500) ns = 2500;
            if (nt < cost[idx][ns]) {
                q.emplace(nt, idx, ns);
                cost[idx][ns] = nt;
            }
        }

        for (const auto& [to, a, b] : g[idx]) {
            ll nt = t + b;
            ll ns = s - a;
            if (ns < 0) continue;
            if (nt >= cost[to][ns]) continue;
            q.emplace(nt, to, ns);
            cost[to][ns] = nt;
        }
    }

    Vl ans(N, L_INF);
    for (ll i = 0; i < N; i++) {
        for (ll c = 0; c <= 2500; c++) {
            ans[i] = min(ans[i], cost[i][c]);
        }
    }

    for (ll i = 1; i < N; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 7344
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> heights;
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    heights.push_back(temp);
  }
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(heights[1] - heights[0]);
  for(int i = 2; i < n; i++){
    dp[i] = min(dp[i - 1] + abs(heights[i] - heights[i - 1]), dp[i - 2] + abs(heights[i] - heights[i-2]));
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1144
a,b,c=map(int,input().split())

cnt=0
t=[]
while True:
	if a%2!=0 or b%2!=0 or c%2!=0:
		print(cnt)
		break
	cnt+=1
	a,b,c=b//2+c//2, a//2+c//2, a//2+b/2
	if [a,b,c] not in t:t.append([a,b,c])
	else:
		print(-1)
		break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
typedef long long ll;

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

  cout << (n * (n + 1)) / 2 << endl;
  return 0;
}

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

int ary[2][210];
int K[1010];
int main(){
	int I,O,N,M;
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>K[i];
	}
	for(int i=1;i<=2*N;i++){
		ary[0][i]=i;
	}
	I=0;O=1;
	for(int i=0;i<M;i++){
		if(K[i]!=0)for(int j=1;j<=2*N;j++){
			if(K[i]+j<=2*N)ary[O][j]=ary[I][K[i]+j];
			else ary[O][j]=ary[I][K[i]+j-2*N];
		}
		else{
			for(int j=1;j<=2*N;j+=2){
				ary[O][j]=ary[I][(j+1)/2];
			}
			for(int j=2;j<=2*N;j+=2){
				ary[O][j]=ary[I][N+j/2];
			}
		}
		swap(I,O);
	}
	for(int i=1;i<=2*N;i++){
		cout<<ary[I][i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,a[100005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)if(a[i]>=m){
		puts("Possible");
		for(int j=1;j<i;j++)printf("%d\n",j);
		for(int j=n-1;j>=i;j--)printf("%d\n",j);
		return 0;
	}
	for(int i=1;i<n;i++)if(a[i]+a[i+1]>=m){
			puts("Possible");
			for(int j=1;j<i;j++)printf("%d\n",j);
			for(int j=n-1;j>=i;j--)printf("%d\n",j);
			return 0;
		}
	puts("Impossible");
}

Measured memory_bytes: 1152
s = input()
m1 = {0 : 0, 1 : 0}
m2 = {0 : 0, 1 : 0}
for c in s[::2]:
    m1[int(c)] += 1
for c in s[1::2]:
    m2[int(c)] += 1
print(min(m1[0] + m2[1], m1[1] + m2[0]))

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define loop(i, a, b) for(int i = a; i < b; i++)
#define pool(i, a, b) for(int i = a; i > b; i--)
#define pb push_back

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

int main()
{
	int n, k;
	fastIO
	scanf("%d%d", &n, &k);
	vector <int> a(n);
	for(int& x : a)
		scanf("%d", &x);
	vector <bool> dp(k + 1);
	loop(stones, 0, k + 1)
	for(int x : a)
	{
		if(stones >= x && !dp[stones - x])
			dp[stones] = true;
	}

	puts(dp[k] ? "First" : "Second"); 	 	

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(void){
  long long sum=0,t,s,p;
  int n;

  scanf("%d %lld %lld",&n,&t,&p);

  for(int i=0;i<n-1;i++){
    scanf("%lld",&s);
    if(s-p>=t)
      sum+=t;
    else
      sum+=s-p;
    p = s;
  }
  sum+=t;

  printf("%lld\n",sum);

  return 0;
}



Measured memory_bytes: 128
n = int(input())
x = list(map(int, input().split()))

ans = 10**10
for i in range(min(x),max(x)+1):
    temp = 0
    for j in range(n):
        temp += (x[j]-i)**2
    ans = min(ans,temp)
if ans == 10**10:
        print(0)
        exit()
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n),b(n);
  rep(i,0,n){
    a[i]=1+25000*i;
    b[i]=1+25000*(n-1-i);
  }

  rep(i,0,n){
    ll p;
    std::cin>>p;
    p--;
    b[p]+=i;
  }

  for(const auto& e:a)std::cout<<e<<" ";
  std::cout<<"\n";


  for(const auto& e:b)std::cout<<e<<" ";
  std::cout<<"\n";

  return 0;
}

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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; i++) {
    int sum = findSumOfDigits(i);
    if (sum >= A && sum <= B) {
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
def Main():
    n = int(input())
    a = input()
    b = input()
    x = 0
    y = 0
    for i in range(len(a)):
        if a[i] == b[x]:
            x += 1
            y += 1

    print(len(a[0:n - y]) + len(b))

if __name__ == '__main__':
    Main()

Measured memory_bytes: 3064
import bisect
import copy
N,M=map(int,input().split())
A=list(map(int,input().split()))
cards=[list(map(int,input().split())) for _ in range(M)]
cards2=copy.deepcopy(cards)
"""累積和+bisect
cards.sort(key=lambda x:x[1],reverse=True)
A.sort()
tmpsum=[0]*(N+1)
allsum=sum(A)
buf=0
id=0
l=0
r=0
for i in range(N):
    buf=buf+A[i]
    tmpsum[i+1]=buf
#print(cards,A,tmpsum)
i=0
while (r<N)and(i<M):
    l=r
    r=min(r+cards[i][0],N)
    #print(l,r)
    if A[min(r,N-1)]<cards[i][1]:
        allsum=allsum-(tmpsum[r]-tmpsum[l])+cards[i][1]*(r-l)#cards[i][0]
    elif A[l]>=cards[i][1]:#A[r]=>cards[i][1]
        break
    else:#A[r]=>cards[i][1],A[l]<cards[i][1]
        id=bisect.bisect_left(A,cards[i][1])
        allsum=allsum-(tmpsum[id]-tmpsum[l])+cards[i][1]*(id-l)
        break
    i=i+1
print(allsum)
"""
#このひらめきが欲しい(A[i]を1枚のA[i]カードとみなしてカード全てから貪欲)
for i in range(N):
    cards2.append([1,A[i]])

cards2.sort(key=lambda x:x[1],reverse=True)
i=0
su=0
#print(cards2)
while N>0:
    if cards2[i][0]>N:
        su=su+N*cards2[i][1]
        N=0
    else:
        su=su+cards2[i][0]*cards2[i][1]
        N=N-cards2[i][0]
    i=i+1
print(su)


Measured memory_bytes: 127492
#include<bits/stdc++.h>
#define int long long int
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define inf 10000000000001
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(auto i=s;i<n;i++)
#define rloop(i,n,b) for(auto i=n-1;i>=b;i--)
using namespace std;

signed main()
{
	fastio(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	loop(i,0,n) cin>>a[i];
	int dp[k+1][n+1];
	init(dp,0);
	//no of ways for n=1, fill upto a[0], is 1.
	loop(i,0,k+1)
	{
		if(i<=a[0]) dp[i][1] = 1;
		else dp[i][1] = 0;
		// use dp[k][0] as prefix array
		if(i==0) dp[i][0] = dp[i][1];
		else dp[i][0] = (dp[i-1][0] + dp[i][1])%mod;
	}

	

	// dp[k][n] = sum(dp[k-ai][n-1]) ; ai E [0,min(k,an)].
	for(int N=2;N<=n;N++)
	{
		for(int K=0;K<=k;K++)
		{
			if(a[N-1]<K)
			{
				// bug(K);
				dp[K][N] = (dp[K][0] - dp[K-a[N-1]-1][0] + mod)%mod; 
			}
			else dp[K][N] = dp[K][0]%mod;
		}
		// update prefix array
		for(int K=0;K<=k;K++)
		{
			if(K==0) dp[K][0] = dp[K][N]%mod;
			else dp[K][0] = (dp[K-1][0] + dp[K][N])%mod;
		}

		// bug("DP");
		// loop(i,0,k+1)
		// {
		// 	loop(j,0,n+1) cout<<dp[i][j]<<" ";
		// 	cout<<endl;
		// }
	}



	// ans = dp[k][n]
	cout<<dp[k][n]%mod<<endl;
	return 0;	
}


Measured memory_bytes: 79104
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 2 "main.cpp"
int main(){
	int D,T,S;
	std::cin>>D>>T>>S;
	if(D<=T*S)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
using namespace std;
int N;
double p[3000];
double dp[3000][3000];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> p[i];

    dp[0][0] = 1;
    for (int i= 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }
    double ans = 0.0;
    for (int i = (N+1)/2; i <= N; i++) ans += dp[N][i];
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 68864
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int h,w;
int q;
char buf[2005][2005];
int sum[2005][2005];
int adjR[2005][2005],adjC[2005][2005];
int main(){
  cin>>h>>w>>q;
  REP(i,h){
    scanf("%s",buf[i]);
    REP(j,w) sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+(buf[i][j]-'0');
  }
  REP(i,h) REP(j,w-1){
    adjR[i+1][j+1]=adjR[i+1][j]+adjR[i][j+1]-adjR[i][j];
    if(buf[i][j]==buf[i][j+1] && buf[i][j]=='1') ++adjR[i+1][j+1];
  }
  REP(i,h-1) REP(j,w){
    adjC[i+1][j+1]=adjC[i+1][j]+adjC[i][j+1]-adjC[i][j];
    if(buf[i][j]==buf[i+1][j] && buf[i][j]=='1') ++adjC[i+1][j+1];
  }
  auto get=[&](int A[2005][2005],int t,int b,int l,int r){
    return A[b][r]-A[b][l]-A[t][r]+A[t][l];
  };
  REP(i,q){
    int t,b,l,r;scanf("%d%d%d%d",&t,&l,&b,&r);--t;--l;

    int res=get(sum,t,b,l,r)-get(adjR,t,b,l,r-1)-get(adjC,t,b-1,l,r);
    printf("%d\n",res);
  }
  return 0;
}





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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = long long;
using vint = vector<int>;

void Main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)cin >> s[i];

    rep(i, n)sort(ALL(s[i]));
    sort(ALL(s));

    ll ans = 0;
    rep(i, n) {
        ll cur_count = 0;
        for (int j = i + 1; j < n; ++j) {
            if (s[i] == s[j]) {
                ++cur_count;
            }
            else {
                break;
            }
        }
        ans += ((cur_count * (cur_count + 1)) / 2);
        i += (cur_count);
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define ll long long
#define Add_Speed ios_base::sync_with_stdio(0);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define f first
#define sz size()
#define s second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define inf INT_MAX
//#define int ll
                                                                                                                                            
using namespace std;

const int maxn = (int)1e5 + 100;
const int mod = (int)1e6 + 3;    

int n, a[maxn], pr[maxn], suf[maxn];
int main () {
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  n++;
  for(int i = 1; i <= n; ++i){
    pr[i] = pr[i - 1] + abs(a[i] - a[i - 1]);
  }

  for(int i = 1; i < n; i++){
    cout << pr[n] - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i + 1] - a[i - 1]) << " ";
  }                                                                    

}

Measured memory_bytes: 2048
/*
Author : N_o_o_B
Created : December 03 2019 22:56:57 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n;
    cin >> n;
    vi a(n);
    ll sum=0;
    fori(i,n) {cin >> a[i];sum+=a[i];}
    int mean = sum/n;
    ll ans1 = 0,ans2=0;
    fori(i,n){
        ans1 += pow(mean-a[i],2);
        ans2 += pow(mean+1-a[i],2);
    }

    cout << min(ans1,ans2) << endl;


    time_taken();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> vec(N,0);

  for(int i=0;i<N;i++) cin>>vec[i];

  sort(vec.begin(),vec.end());

  cout<<vec[N-1]-vec[0]<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
  

using namespace std;
int main() {
  int a;
  cin >> a;
  int b[a];
  for(int i = 0;i<a;i++)cin >> b[i];
  int ans = 0;
  for(int i = 0;i<a-2;i++){
    if(b[i]>b[i+1]&&b[i+2]<b[i+1])ans++;
    if(b[i]<b[i+1]&&b[i+2]>b[i+1])ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    long long n, a[5];
    cin >> n;
    rep(i, 5) cin >> a[i];

    long long min_ = 1e15;
    rep(i, 5) min_ = min(min_, a[i]);
    long long groups = ceil((double)n / min_);
    cout << 4 + groups;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
cin>>n;
ll ruiseki[n+1];
ll w;
ruiseki[0]=0;
for(ll i=0;i<n;i++){
    cin>>w;
    ruiseki[i+1]=ruiseki[i]+w;
}
ll ans=infll;
for(int i=0;i<=n;i++){
    chmin(ans,(ll)fabs(ruiseki[i]-(ruiseki[n]-ruiseki[i])));
}
cout<<ans<<endl;
}










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

#define INF 0x3f3f3f3f
#define MOD 10000

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

int sum, n;

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

	cin >> n;
	for (int i = 0; i < n; i++) {
		int r, l;
		cin >> l >> r;
		sum += r - l + 1;
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    
dp=[[-1]*(W+1) for i in range(N+1)]
for i in range(W+1):
    dp[0][i]=0
for i in range(N):
    for j in range(W+1):
        if j-w[i]<0:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i])
print(dp[N][W])

Measured memory_bytes: 120172
#include<stdio.h>
int main()
{
    int m,n,p;
    scanf("%d%d%d",&m,&n,&p);
    if(m==5&&n==7&&p==5)
    printf("YES\n");
    else if(m==5&& n==5&&p==7)
        printf("YES\n");
    else if(m==7&&n==5&&p==5)
        printf("YES\n");
    else
    printf("NO\n");
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[5] = {0,0,1,-1,0};
int dj[5] = {1,-1,0,0,0};

int main(){
    map<char,int> act;
    act['5'] = 4;
    act['8'] = 3;
    act['6'] = 0;
    act['4'] = 1;
    act['2'] = 2;
    int h, w;
    while(cin >> h >> w, h+w){
        int si, sj, gi, gj;
        char mat[h][w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mat[i][j];
                if(mat[i][j] == 'A')    si = i, sj = j;
                if(mat[i][j] == 'B')    gi = i, gj = j;
            }
        }
        vector<vector<int>> step(h, vector<int>(w, 1<<30));
        queue<pair<int, pair<int,int>>> q;
        q.push({0, {si, sj}});
        int maxstep;
        while(!q.empty()){
            auto p = q.front(); q.pop();
            int cost = p.first, i = p.second.first, j = p.second.second;
            if(step[i][j] <= cost)  continue;
            step[i][j] = cost;
            maxstep = cost;
            for(int k = 0; k < 4; k++){
                int ni = i+di[k], nj = j+dj[k];
                if(inRange(ni, 0, h) && inRange(nj, 0, w) && mat[ni][nj] != '#' && cost+1 < step[ni][nj]){
                    q.push({cost+1, {ni, nj}});
                }
            }
        }
        string s;
        cin >> s;
        int slen = s.length();
        int last = 0, turn = 0;
        vector<vector<bool>> ghost(h, vector<bool>(w, 0));
        bool meet = false;
        while(turn < maxstep+5 || turn-last < slen){
            int ngi = gi+di[act[s[turn%slen]]], ngj = gj+dj[act[s[turn%slen]]];
            if(!inRange(ngi, 0, h) || !inRange(ngj, 0, w))  ngi = gi, ngj = gj;
            gi = ngi, gj = ngj;
            if(!ghost[gi][gj]){
                last = turn+1;
                ghost[gi][gj] = true;
            }
            turn++;
            if(step[gi][gj] <= turn){
                cout << turn << " " << gi << " " << gj << endl;
                meet = true;
                break;
            }
        }

        if(!meet){
            cout << "impossible" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3076
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque, defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    N = input()
    if int(N[-1]) == 2 or int(N[-1]) == 4 or int(N[-1]) == 5 or int(N[-1]) == 7 or int(N[-1]) == 9:
        print('hon')
    elif int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 :
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main()


Measured memory_bytes: 65356
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<Integer, Integer> map = new HashMap<>();
    for(int i = 0; i < n; i++) {
      int num = sc.nextInt();
      map.put(num, map.getOrDefault(num, 0) + 1);
    }
    int num = 0;
    for(Map.Entry<Integer, Integer> entry: map.entrySet()) {
      int key = entry.getKey();
      int count = entry.getValue();
      if (count < key) {
        num += count;
        continue;
      }
      num += Math.min(count, count - key);
    }
    System.out.println(num);
  }
}


Measured memory_bytes: 63396
#include<bits/stdc++.h>
typedef long long ll;
const int MN=104,MV=1004;
int N,W;
ll dp[MV*MN];
int main() {
    scanf("%d%d",&N,&W);
    memset(dp,0x3f,sizeof dp);
    dp[0]=0;
    for(int i=0,w,v;i<N;++i) {
        scanf("%d%d",&w,&v);
        for(int j=MV*MN-1;j>=v;--j)
            dp[j]=std::min(dp[j],dp[j-v]+w);
    }
    for(int i=MV*MN-1;i>=0;--i)
        if(dp[i]<=W){
            printf("%d\n",i);
            return 0;
        }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

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

  if (N == 1)
    cout << "Hello World" << endl;
  else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> w(N);
  for(int i=0;i<N-1;i++){
    int A;
    cin>>A;
    w.at(A-1)+=1;
  }
  for(int i=0;i<N;i++)
  	cout<<w.at(i)<<endl;
  return 0;
}

Measured memory_bytes: 4044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

signed main(){
	ll n;
	cin>>n;
	ll ans=0;
	vector<ll>a(n+1),b(n);
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n){
		ans+=min(a[i],b[i]);
		if(a[i]<b[i]){
			ll cmp=a[i+1];
			a[i+1]-=b[i]-a[i];
			if(a[i+1]<0)a[i+1]=0;
			ans+=cmp-a[i+1];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792