akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    int a = N%10;
    if(a == 3) {
        cout << "bon" << endl;
    } else if(a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}

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

string AffineCipher(string s, int a, int b){
	for (int i = 0; i < s.size(); ++i){
		if (s[i] >= 'a' && s[i] <= 'z')
			s[i] = (a*(s[i] - 'a') + b) % 26 + 'a';
	}
	return s;
}

string DeAffine(string s, int a, int b){
	int t;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] >= 'a' && s[i] <= 'z'){
			t = (((s[i] - 'a') - b) * a);
			while(t<0)
				t+=26;
			s[i] = t % 26 + 'a';
		}
	}

	return s;

}

int main(){
	int n, b;
	int a[12] = { 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25 };
	string s,t;
	string key1, key2;
	cin >> n;cin.ignore();

	for (int j = 0; j < n; ++j){
		
		getline(cin,s);
		
		for (int i = 0; i < 12;++i){

			for (b = 1; b <= 26; ++b){
				
				t = DeAffine(s,a[11-i],b);
				
				if (t.find("this") != -1 || t.find("that") != -1){
					cout << t << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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 RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int N;
string S;
int shortcut(string s1,string s2){
    int i=0;
    int cnt=S.size();
    while(i<S.size()-1){
        if(S[i]==s1[0]&&S[i+1]==s1[1]){
            cnt--;i++;
        }else if(S[i]==s2[0]&&S[i+1]==s2[1]){
            cnt--;i++;
        }
        i++;
    }
    return cnt;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<b*a/2<<endl;
}


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

using namespace std;

class SegmentTree{
private:
    int n;
    vector<int> t;
    
    int combine(int a, int b){
        return a+b;
    }
public:
    SegmentTree(vector<int>& v){                                         // build tree
        n = v.size();
        t.assign(n << 1, 0);
        
        for (int i=0; i<n; i++) t[n+i] = v[i];
        for (int i=n-1; i>0; i--) t[i] = combine(t[i<<1], t[i<<1|1]);
    }
    void modify(int p, int val){                                        // set v[p] = val
        for (t[p+=n]+=val; p>>=1; ) t[p] = combine(t[p<<1],t[p<<1|1]);
    }
    int query(int l, int r){                                            // query in range v[l,r)
        int res = 0;
        for (l+=n, r+=n; l<r; l>>=1, r>>=1){
            if (l&1) res = combine(res,t[l++]);
            if (r&1) res = combine(res,t[--r]);
        }
        return res;
    }
};

int main(){

    ios_base::sync_with_stdio(false);

    /*
     * Input Format (0-base indexing)
     * N = array size
     * Q = number of operation
     */

    // client program for demo

    int N, Q;
    cin >> N >> Q;

    vector<int> v; v.assign(N,0);

    SegmentTree st(v);

    for (int i=0; i<Q; i++){
        int op;
        cin >> op;

        if (op == 0){                       // modify v[p] to val
            int p, val;
            cin >> p >> val; p--;

            st.modify(p,val);
        }
        if (op == 1){                       // query sum of a[l,r]
            int l, r;
            cin >> l >> r; l--; r--;

            cout << st.query(l,r+1) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<double> p(N, 0);
  vector<double> pp(N, 0);
  REP(i, N){
    double tmp; cin >> tmp;
    p[i] = (tmp + 1) / 2;
    if(i == 0){
      pp[i] = p[i];
    }else{
      pp[i] = pp[i-1] + p[i];
    }
  }
  double ans = pp[K-1];
  for(int i = K; i < N; i++){
    ans = max(ans, pp[i] - pp[i-K]);
  }
  cout << fixed << setprecision(11) << ans << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100
#define MAXW 10000
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

int dp[MAXN+1][MAXW+1];
int n, W;
int w[MAXN+1], v[MAXN+1];

int knapsack(int i, int j) {
    if (dp[i][j] >= 0) {
        return dp[i][j];
    }

    int res;

    if (i == n) {
        res = 0;
    } else if (j < w[i]) {
        res = knapsack(i+1, j);
    } else {
        res = max(knapsack(i+1, j), knapsack(i+1, j-w[i])+v[i]);
    }

    return dp[i][j] =res;

}

int main() {

    cin >> n >> W;
    memset(dp, -1, sizeof(dp));

    rep(i, n) {
        cin >> v[i] >> w[i];
    }
    cout << knapsack(0, W)  << endl;
/*
    rep(i, n) {
        rep(j, W) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
*/

}




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

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

    int a[4];
    string s;
    cin >> s;
    rep(i, 4) {
        a[i] = (s[i] - '0');
    }

    for(int i = 0; i < (1 << 3); ++i) {
        int sum = a[0];
        string tmp;
        tmp += (char)(a[0] + '0');
        for(int j = 0; j < 3; ++j) {
            if(i >> j & 1) {
                sum += a[j+1];
                tmp += '+';
                tmp += (char)(a[j+1] + '0');
            }
            else {
                sum -= a[j+1];
                tmp += '-';
                tmp += (char)(a[j+1] + '0');
            }
        }
        if(sum == 7) {
            tmp += "=7";
            cout << tmp << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	string S;
	cin >> S;

	ll ans = 0;

	ll size = S.length();
	
	vll N(size);
	
	for (ll i = 0; i < size; i++) {
		N[i] = ll(S[i]) - 48;
	}

	ll time = 0;

	for (ll bit = 0; bit < (1<<size-1) ; bit++) {

		ll local = 0;
		for (ll i = 0; i < size-1; i++) {

			local *= 10;
			local += N[i];

			if ((bit >> (size - 2 - i)) & 1) {
				ans += local;
				local = 0;

				if (i == size - 2) {

					ans += local + N[i + 1];
					local = 0;
				}
			}
			else {
				if (i == size - 2) {
					local *= 10;
					ans += local + N[i + 1];
					local = 0;
				}
			}



		}
		time++;
	}

	if (size == 1) {
		cout << S;
		return 0;
	}

	cout << ans << endl;





}



Measured memory_bytes: 256
N = int(input())
s = list(list(input()) for _ in range(N))

for i in range(N):
    s[i].sort()

s.sort()

a = 0
answer = 0

for i in range(N-1):
    for j in range(10):
        if s[i][j] != s[i+1][j]:
            a = 0
            break
        elif j == 9:
            a += 1
            answer += a

print(answer)


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

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	vector<int> x;
	
	x.push_back(a);
	x.push_back(b);
	x.push_back(c);
	sort(x.begin(), x.end());
	int count = 1;
	for (int i = 0; i < x.size() -1; i++)
	{
		if (x[i] == x[i+1])
		{
			count++;
		}
	}
	if (count == 3)
	{
		cout << "No";
	}
	else if (count == 2)
	{
		cout << "Yes";
	}
	else cout << "No";
	return 0;
}


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

using namespace std;

int main()
{
    int A, B, C;

    cin >> A >> B >> C;

    if(A < C && C < B){
        cout << "Yes" << endl;
    }
    else if(B < C && C < A){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]

y = 0
x = 0

goal_y = H - 1
goal_x = W - 1

counts = 0
for item in inputs:
    counts += item.count('#')

if counts != (H + W - 1):
    print('Impossible')
else:
    for _ in range(H + W - 2):
        if x + 1 < W and inputs[y][x + 1] == '#':
            x += 1
        elif y + 1 < H and inputs[y + 1][x] == '#':
            y += 1
    print('Possible' if y == goal_y and x == goal_x else 'Impossible')

Measured memory_bytes: 3064
//AZ@RK2019
//I know it wll accepted in first go! 
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 2e5+7;
int h,w,n,a,l,c = 1;
vector<int> v,line;
int main(){
	cin >> h >> w >> n;
	for (int i = 1;i <= n;i++){
		cin >> a;
		while(a--){
			v.push_back(i);
		} 
	}
	//solve;
	while(h--){
		if (c == 1){
			for (int i = 1;i <= w;i++){
				cout << v.back() << " ";
				v.pop_back();
			}
			c *= -1;
			cout << endl;
		}
		else if(c == -1){
			for (int i = w;i > 0;i--){
				line.push_back(v.back());
				v.pop_back();
			}
			while(line.size()){
				cout << line.back() << " ";
				line.pop_back();
			}
			line.clear();
			c *= -1;
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            int n,m;
            cin >> n >> m;
            int sum = 0;
            for(int i = 0; i < m; i++)
            {
                int x;
                cin >> x;
                sum += x;
            }
            if(sum > n)
                cout << -1 << endl;
            else 
                cout << n - sum << endl;




           return 0;
        }
          

Measured memory_bytes: 3656
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
change_a = [i for i in range(3) if a[i] < b[i]]
change_b = [i for i in range(3) if a[i] > b[i]]
if len(change_a) == 0:
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    i = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += i * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = n
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
  else:      
    tmp = n
    for i in range(5001):
      for j in range(5001):
        m = n
        m -= i * b[change_b[0]]
        if m < 0:
          break
        m -= j * b[change_b[1]]
        if m < 0:
          break
        k = m // b[change_b[2]]
        m = m % b[change_b[2]]
        m += i * a[change_b[0]] + j * a[change_b[1]] + k * a[change_b[2]]
        tmp = max(tmp, m)
    print(tmp)
elif len(change_a) == 1:
  i = n // a[change_a[0]]
  n = n % a[change_a[0]]
  n += i * b[change_a[0]]
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    i = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += i * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = n
    for i in range(n // b[change_b[0]] + 1):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
elif len(change_a) == 2:
  tmp = n
  for i in range(5001):
    m = n
    m -= i * a[change_a[0]]
    if m < 0:
      break
    j = m // a[change_a[1]]
    m = m % a[change_a[1]]
    m += i * b[change_a[0]] + j * b[change_a[1]]
    tmp = max(tmp, m)
  n = tmp
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    i = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += i * a[change_b[0]]
    print(n)
else:    
  tmp = n
  for i in range(5001):
    for j in range(5001):
      m = n
      m -= i * a[change_a[0]]
      if m < 0:
        break
      m -= j * a[change_a[1]]
      if m < 0:
        break
      k = m // a[change_a[2]]
      m = m % a[change_a[2]]
      m += i * b[change_a[0]] + j * b[change_a[1]] + k * b[change_a[2]]
      tmp = max(tmp, m)
  print(tmp)


Measured memory_bytes: 41436
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

vector<pair<ll ,ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p; 
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {

    ll n;
    cin >> n;

    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    vector<pair<ll, ll>> prime = prime_factorize(n);

    ll cnt = 0;

    for(auto a : prime) {
        ll tmp = a.second;
        ll i = 1;
        while (i <= tmp) {
            tmp -= i;
            i++;
            cnt++;
        }
    }

    cout << cnt << endl;

return 0;
}

Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int h, w, a, b; cin >> h >> w >> a >> b;
	char x = '0', y = '1';
	for (int i = 0; i < h; i++) {
		if (i == b) swap(x, y);
		cout << string(a, x) << string(w - a, y) << '\n';
	}
	return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

int main() {
  ll n, d;
  cin >> n >> d;

  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;

    if (sqrt(x * x + y * y) <= (double)d) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

ll n, m;
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> m; 
    ll p = min(n, m/2);
    n -= p, m -= p*2;

    cout << p + m/4 << endl;
    return 0;
}


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

using namespace std;

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

int s[10004];
vector<int> c[1003];

int main(){
    int n,m;
    while(cin >> n >> m){
        if( n == 0) return 0;
        rep(i, m){
            int k;
            cin >> s[i] >> k;
            c[i].clear();
            rep(j, k){
                int C;
                cin >> C;
                --C;
                c[i].push_back(C);
            }
        }
        int ret = 0;
        rep(i, n){
            int ma = 0;
            int x[10004];
            rep(j, n) x[j] = 0;
            rep(j, m){
                bool f = false;
                for(int z:c[j]){
                    f |= z == i;
                }
                if(f) ma+=s[j];
                else if(c[j].size() == 1){
                    x[c[j][0]] += s[j];
                }
            }
            int mi = ma;
            rep(j, n){
                if(i == j) continue;
                mi = min(mi, x[j]);
            }
//            cout << "# " << i+1 << " " << ma << " " << mi << endl;
            ret = max(ret, ma - mi + 1 );
        }
        cout << ret << endl;
    }
}


Measured memory_bytes: 4516
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll D, N; cin >> D >> N;
  if (N == 100) N+=1;
  REP(i, D) N *= 100;
  cout << N << endl;
  return 0;
}

Measured memory_bytes: 256
T=list(input())
if len(T)==1:
  print('D')
  exit()
if T[0]=='?' and T[1]=='D':
  T[0]='P'
elif T[0]=='?' and T[1]=='?':
  T[0]='P'
elif T[0]=='?' and T[1]=='P':
  T[0]='D'
for i in range(1,len(T)-1):
  if T[i]=='?' and T[i-1]=='P':
    T[i]='D'
  elif T[i]=='?' and T[i+1]=='D':
    T[i]='P'
  elif T[i]=='?' and T[i+1]=='P':
    T[i]='D'
  elif T[i]=='?' and T[i+1]=='?':
    T[i]='P'
if T[-1]=='?':
  T[-1]='D'
  
print(''.join(T))

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

using namespace std;

#define ll long long

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    int num = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (v[i] + v[j] > v[k]) {
                    if (v[j] + v[k] > v[i]) {
                        if (v[i] + v[k] > v[j]) {
                            num++;
                        }
                    } else {
                        i = n;
                    }
                }
            }
        }
    }
    cout << num << "\n";
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

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

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m,x,y;
	cin >> n >> m;
	vb visited(n,false);
	vll sum(n,1);
	visited[0]=true;
	rep(i,m){
		cin >> x >> y;
		x--;
		y--;
		if(visited[x]) visited[y]=true;
		if(sum[x]==1) visited[x]=false;
		sum[x]--;
		sum[y]++;
	}
	ll ans=0;
	rep(i,n){
		if(visited[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
from __future__ import division

n = input()
a = map(int, raw_input().strip().split())

dp = [[[0 for i in xrange(n + 1)] for j in xrange(n + 1)] for k in xrange(n + 1)]

r = [0, 0, 0, 0]
for ai in a: r[ai] += 1

for r3 in xrange(n + 1):
    for r2 in xrange(n + 1):
        for r1 in xrange(n + 1):
            if r1 == r2 and r2 == r3 and r3 == 0: continue
            if r1 + r2 + r3 > n: break
            s = r1 + r2 + r3
            dp[r1][r2][r3] = n / s
            if r1 >= 1: dp[r1][r2][r3] += ((r1 * dp[r1 - 1][r2][r3]) / s)
            if r2 >= 1: dp[r1][r2][r3] += ((r2 * dp[r1 + 1][r2 - 1][r3]) / (s))
            if r3 >= 1: dp[r1][r2][r3] += ((r3 * dp[r1][r2 + 1][r3 - 1]) / (s))
            
ans = dp[r[1]][r[2]][r[3]]
print "{0:.10f}".format(ans)

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

#define int long long

const int N = 5e3 + 10, INF = 1e15 + 10;
int n, A, B, ans = INF, ar[N], dp[N];

int32_t main() {
	cin >> n >> A >> B;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	
	for (int i = 0; i < n; i++) 
		for (int j = 0; j < i; j++)
			if (ar[j] > ar[i])
				dp[i] += A;
			else
				dp[i] += B;
	
	for (int i = 1; i < n; i++) {
		int sum = 0;
		for (int j = i - 1; j >= 0; j--) {
			if (ar[j] < ar[i])
				dp[i] = min(dp[i], dp[j] + sum);
			
			if (ar[j] > ar[i])
				sum += A;
			else
				sum += B;
		}
	}
	
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = i + 1; j < n; j++)
			if (ar[j] < ar[i])
				sum += B;
			else
				sum += A;
		ans = min(ans, sum + dp[i]);
	}
	cout << ans;
}

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

using namespace std;

unsigned long long h, w;

int main()
{
  	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);

	cin >> h >> w;

	if (h == 1 || w == 1)
        cout << 1;
	else if (w % 2 == 0)
        cout << (w / 2) * h;
    else
        cout << ((w - 1) / 2) * h + (h + 1) / 2;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <utility>
#define NMAX 100000
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n";
#define prin4(arg1,arg2,arg3,arg4) cout<<arg1<<" "<<arg2<<" "<<arg3<<" "<<arg4<<"\n";
#define scan(arg) cin>>arg;
using namespace std;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pi;
typedef pair<pi,pi> pii;
typedef vector<pii> vpii;
int h,w;
int a[501][501];
vpii vec;
int main(){
	scan(h);scan(w);
	rep1(i,h){
		rep1(j,w){
			scan(a[i][j]);
		}
	}
	int res=0;
	rep1(i,h){
		rep1(j,w-1){
			if(a[i][j]%2==1){
				vec.push_back(pii(pi(i,j),pi(i,j+1)));
				a[i][j+1]++;
			}
		}
	}
	rep1(i,h-1){
		if(a[i][w]%2==1){
			vec.push_back(pii(pi(i,w),pi(i+1,w)));
			a[i+1][w]++;
		}
	}
	prin(vec.size());
	rep(i,vec.size()){
		prin4(vec[i].first.first,vec[i].first.second,vec[i].second.first,vec[i].second.second);
	}
	
		
	return 0;
}


Measured memory_bytes: 5232
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P,int>PP;
typedef vector<vector<int>>mat;

int amida[63][100006];

int x[100006];
int a[100006];
int fin[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> x[i];
	int m, k; cin >> m >> k;
	rep(i, m) {
		cin >> a[i]; a[i]--;
	}

	rep(i, n)amida[0][i] = i;
	rep(i,m) {
		swap(amida[0][a[i]], amida[0][a[i] - 1]);
	}
	for (int i = 0; i < 62; i++) {
		rep(j, n) {
			amida[i + 1][j] = amida[i][amida[i][j]];
		}
	}
	rep(i, n)fin[i] = i;
	rep(i, 63) {
		if (k&(1ll << i)) {
			rep(j, n) {
				fin[j] = amida[i][fin[j]];
			}
		}
	}
	int cnt = x[0];
	cout << cnt<<endl;
	rep(i, n - 1) {
		cnt += x[fin[i] + 1] - x[fin[i]];
		cout << cnt << endl;
	}
}

Measured memory_bytes: 52864
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = ni();
		int[] a = new int[n];
		int s = 0;
		String ss = "";

		for (int i = 0; i < n; i++) {
			a[i] = ni();
			s = s ^ a[i];
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(s ^ a[i]).append(" ");
		}

		out(sb.toString().trim());

	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

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

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 61456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int ans = 0, now = 1e9;
	rep(i, n - 1) {
		if (abs(a[i] * 2 - a[n - 1]) < now) {
			now = abs(a[i] * 2 - a[n - 1]);
			ans = a[i];
		}
	}
	cout << a[n - 1] << " " << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <string.h>
#include <fstream>

using namespace std;

#define MAXN 11

int n, m, s, e, d, total;
int c[MAXN][MAXN];
int dir[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};
int ans[MAXN * MAXN];
bool ok;

int change(char ch)
{
    switch(ch)
    {
        case 'L': return 0;
        case 'U': return 1;
        case 'R': return 2;
        case 'D': return 3;
    }
}

char changetwo(int x)
{
    switch(x)
    {
        case 0: return 'L';
        case 1: return 'U';
        case 2: return 'R';
        case 3: return 'D';
    }
}

void dfs(int x, int y, int len, int di)
{
    if (len == total)
    {
        ok = true;
        return ;
    }

    if (ok)
    {
        return ;
    }

    for (int i = 3; i < 6; i++)
    {
        for (int k = 1; k <= 10; k++)
        {
            int xt = x + dir[(i + di) % 4][0] * k, yt = y + dir[(i + di) % 4][1] * k;

            if (xt >= 0 && xt < n && yt >= 0 && yt < m && !ok)
            {
                if (c[xt][yt] == 1)
                {
                    ans[len] = (i + di) % 4;
                    len++;
                    c[xt][yt] = 0;
                    dfs(xt, yt, len, (i + di) % 4);

                    len--;
                    c[xt][yt] = 1;
                    break;
                }
            }
        }
    }
}

void solve()
{
    dfs(s, e, 0, d);

    for (int i = 0; i < total; i++)
    {
        cout << changetwo(ans[i]);
    }
    cout << endl;
}

void input()
{
    char ch;

    while (cin >> n >> m)
    {
        total = 0;
        ok = false;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cin >> ch;
                if (ch == '.')
                {
                    c[i][j] = 0;
                }
                else if (ch == 'o')
                {
                    total++;
                    c[i][j] = 1;
                }
                else
                {
                    d = change(ch);
                    s = i, e = j;
                    c[i][j] = 0;
                }
            }
        }

        solve();
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    input();
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC") ac++;
    else if (s == "WA") wa++;
    else if (s == "TLE") tle++;
    else if (s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

Measured memory_bytes: 3628
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
a,b,h = IR(3)
print(((a+b)*h)//2)
#B

#C

#D
"""
h,w,n = LI()
dp = [0 for i in range(10)]
dp[0] = (h-2)*(w-2)
q = defaultdict(int)
for i in range(n):
    a,b = LI()
    a -= 1
    b -= 1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 0 < a+i < h-1 and 0 < b+j < w-1:
                q[(a+i)*w+b+j] += 1
                dp[q[(a+i)*w+b+j]] += 1
                dp[q[(a+i)*w+b+j]-1] -= 1
for i in dp:
    print(i)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include <iostream> 
#include <math.h> 
using namespace std;  
int e,x;
int min_mum = 0;

int solve (){
	min_mum = e;
	for (int z=0; z<=ceil(pow(e, 1.0/3)); ++z){
		for (int y=0; y<=ceil(sqrt(e - z*z*z)); ++y){
			x = e- z*z*z - y*y;
			if (x+y+z < min_mum && x>=0){
				min_mum = x+y+z;
			}	 
		}
	}
	return min_mum;
	
}

int main()  
{     
	while (cin >> e && e > 0){
		cout << solve() << endl;
	}        
	
	return 0;  
}  

Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define max(a,b) ((a)<(b)?(b):(a))
#define swap(a,b) a^=b^=a^=b 
#define lb(x) ((x)&(-(x)))
#define inf 0x3f3f3f3f
#define N 200010
using namespace std;
typedef long long ll;
int n,a[N];
ll s[N],ans=0x3f3f3f3f3f3f3f3fll;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
	}
	for(int i=1;i<n;i++)ans=min(ans,abs(s[n]-s[i]-s[i]));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
if __name__ == "__main__":
    N = int(input())
    V = N
    dp = []
    for i in range(N):
        dp.append(list(map(int,input().split())))
    edge = [[True]*N for _ in range(N)]
    for k in range(V):
        for i in range(V):
            for j in range(V):
                a = dp[i][j]
                b = dp[i][k]+dp[k][j]
                if a > b:
                    print(-1)
                    exit(0)
                elif a == b and k != i and k != j:
                    edge[i][j] = False
                    edge[j][i] = False
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if edge[i][j]:
                ans += dp[i][j]
    print(ans)

Measured memory_bytes: 75456
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        label:
        var sp = ReadLine().Split();
        var list = new List<string>();
        int a = Parse(sp[0]);
        int b = Parse(sp[1]);
        if (a == 1)
        {
            while (0 < b)
            {
                int count = Min(50, b);
                b -= count;
                list.Add(string.Concat(Enumerable.Repeat(".#", count)) + new string('.', 100 - 2 * count));
                list.Add(new string('.', 100));
            }
        }
        else if (b == 1)
        {
            while (0 < a)
            {
                int count = Min(50, a);
                a -= count;
                list.Add(string.Concat(Enumerable.Repeat("#.", count)) + new string('#', 100 - 2 * count));
                list.Add(new string('#', 100));
            }
        }
        else
        {
            while (1 < a)
            {
                int count = Min(50, a - 1);
                a -= count;
                list.Add(string.Concat(Enumerable.Repeat(".#", count)) + new string('#', 100 - 2 * count));
                list.Add(new string('#', 100));
            }
            while (1 < b)
            {
                int count = Min(50, b - 1);
                b -= count;
                list.Add(new string('.', 100));
                list.Add(string.Concat(Enumerable.Repeat(".#", count)) + new string('.', 100 - 2 * count));
            }
        }
        WriteLine($"{list.Count} 100");
        foreach (var line in list) WriteLine(line);
    }
}


Measured memory_bytes: 13268
h,w,K=map(int,input().split())
s=[]
for i in range(h):
    s.append(input())

ans=float("inf")
for i in range(2**(h-1)):
    cut=[]
    linecount=0
    for j in range(h-1):
        if (i>>j)%2==1:
            cut.append(j)
    counter=[0]*(len(cut)+1)
    for j in range(w):
        ncounter=[0]*(len(cut)+1)
        area=0
        flag=False
        for k in range(h):
            ncounter[area]+=int(s[k][j])
            if counter[area]+ncounter[area]>K:
                if ncounter[area]>K:
                    linecount=float("inf")
                flag=True
            if k in cut:
                area+=1
        if flag:
            counter=ncounter[:]
            linecount+=1
        else:
            for l in range(len(cut)+1):
                counter[l]+=ncounter[l]
    ans=min(ans,linecount+len(cut))
print(ans)
        





Measured memory_bytes: 46556
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


int d;
int s[365][26];
int c[26];

int calc(vector<int> &v) {
	int sum = 0;
	int las[26]; rep(i, 26)las[i] = -1;
	

	int dec = 0;

	int aldec = 0;

	rep(i, d) {
		if (las[v[i]] >= 0) {
			aldec -= c[v[i]] * (i - las[v[i]]);
		}
		else {
			dec += c[v[i]];
		}

		sum += s[i][v[i]];
		las[v[i]] = i;




		sum -= aldec;
		aldec += dec;
	}
	return max(sum, 0);
}

void query(vector<int> v) {
	rep(i, d) {
		cout << v[i] + 1 << "\n";
	}
}
void solve() {
	cin >> d;
	rep(i, 26)cin >> c[i];
	rep(i, d)rep(j, 26)cin >> s[i][j];

	//init_answer
	vector<int> v;
	int las[26]; rep(j, 26)las[j] = -1;
	int sum = 0;

	rep(i, d) {
		int ma = -mod;
		int chk = -1;
		rep(j, 26) {
			int ad = s[i][j];
			if (las[j] >= 0) {
				ad += c[j] * (i - las[j]);
			}
			if (ma < ad) {
				ma = ad;
				chk = j;
			}
		}
		v.push_back(chk);
		las[chk] = i;

		sum += s[i][chk];
		rep(j, 26)if (las[j] >= 0) {
			sum -= c[j] * (i - las[j]);
		}
	}

	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> ud(0, d - 1);
	vector<int> alt = v;


	int cur=sum;
	rep(i, 30000) {
		int id = ud(mt);
		rep(j, 26) {
			if (j == v[id])continue;
			alt[id] = j;
			int val = calc(alt);
			if (cur < val) {
				v=alt;
				cur = val;
			}
		}
      alt=v;
	}

	query(v);
}


signed main() {
	solve();
		return 0;
}


Measured memory_bytes: 3648
n = int(input())
a = []
for _ in range(n):
    title, dur = input().split()
    a.append((title, int(dur)))
sleep = input().rstrip()

ret = 0
for i, (title, _) in enumerate(a):
    if sleep == title:
        for j in range(i + 1, n):
            ret += a[j][1]
print(ret)

Measured memory_bytes: 3064
N = int(input())
A = [0]+[int(x) for x in input().split()]
res = [0]*(N+1)
sum_res = 0
for i in range(N):
    # 今見てるところ
    k = N-i
    tmp = 0
    for j in range(k,N+1,k):
       	tmp += res[j]
    res[k] = A[k] ^ tmp%2
    sum_res += res[k]
 
print(sum_res)
print(' '.join([str(i) for i,x in enumerate(res) if x==1]))

Measured memory_bytes: 14764