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

using namespace std;

using P = pair<int, int>;

int main() {
	ll H, W, N;
	cin >> H >> W >> N;
	map<P, int> mp;
	vector<int> a(N);
	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < N; i++) {
		for (int x = b[i] - 1; x <= b[i] + 1; x++) {
			for (int y = a[i] - 1; y <= a[i] + 1; y++) {
				if ((x < 1) || (x > W) || (y < 1) || (y > H)) continue;

				mp[P(x, y)]++;
			}
		}
	}

	vector<ll> res(10, 0);
	for (auto it = mp.begin(); it != mp.end(); it++) {
		int x = it->first.first, y = it->first.second;
		if ((x <= 1) || (x >= W) || (y <= 1) || (y >= H)) continue;

		res[it->second]++;
	}

	ll psum = 0;
	for (int i = 1; i < res.size(); i++) {
		psum += res[i];
	}
	res[0] = (H - 2) * (W - 2) - psum;

	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

void solve(){
  int N; cin>>N;
  ll a[N]; CINA(a,N);
  ll ans = 0LL;
  ll h = a[0];
  for(int i=1;i<N;++i){
    if(h<=a[i]){
      h = a[i];
    }else{
      ans += (h-a[i]);
    }
  }
  cout << ans << "\n";
}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}

Measured memory_bytes: 5188
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            m = 0
            if i-1 >= 0 and j-1 >= 0:
                if s[i-1][j-1] == '#':
                    m += 1
            if i-1 >= 0:
                if s[i-1][j] == '#':
                    m += 1
            if i-1 >= 0 and j+1 < w:
                if s[i-1][j+1] == '#':
                    m += 1
            if j-1 >= 0:
                if s[i][j-1] == '#':
                    m += 1
            if j+1 < w:
                if s[i][j+1] == '#':
                    m += 1
            if i+1 < h and j-1 >= 0:
                if s[i+1][j-1] == '#':
                    m += 1
            if i+1 < h:
                if s[i+1][j] == '#':
                    m += 1
            if i+1 < h and j+1 < w:
                if s[i+1][j+1] == '#':
                    m += 1
            s[i][j] = str(m)
for i in range(h):
    z = list(s[i])
    print(''.join(z))

Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int main(int argc, char *argv[])
{
  string ri("qwertasdfgzxcvb");
  string in;
  while(cin >> in && in!="#"){
    int ans = 0;
    bool ini=
      ri.find(in[0]) == string::npos;
    rep(i,SZ(in)-1){
      bool np=
        ri.find(in[i+1]) == string::npos;
      if(np!=ini) ++ ans;
      ini=np;
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

  int n, m, x;
  cin >> n >> m >> x;
  int a[m+1];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  a[m] = x;
  sort(a, a+m+1);
  for (int i = 0; i < m+1; i++) {
    if (a[i] == x) {
      cout << min(i, m-i) << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  ll h[100010];
  ll min=2000000000;
  rep(i,n)cin>>h[i];
  sort(h,h+n,greater<int>());
  // rep(i,n)cout<<h[i]<<endl;
  rep(i,n-k+1){
    ll tmp=h[i]-h[i+k-1];
    if(tmp<min){
      min=tmp;
    }
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 4348
import math

N,K=map(int,input().split())

p = 0
N_inv = 1.0/N

for ii in range(1,N+1):
    if K > ii:
        #print('exp')
        exp_n = math.ceil(math.log(K/ii,2))
        p = p + N_inv * (0.5)**exp_n
        #print(ii,exp_n,p)
    else:
        p = p + N_inv
        #print(ii,N_inv2,p)

print(p)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#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 <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;
    int ans = 0;
    int count = 0;
    rep(i, S. size()) {
        if (S.at(i) == 'a') {
            if (ans < A+B) {
                ans++;
                cout << "Yes" << endl;
                continue;
            }
        }
        if (S.at(i) == 'b') {
            if (ans < A + B && count < B) {
                ans++;
                count++;
                cout << "Yes" << endl;
                continue;
            }
        }
        cout << "No" << endl;
    }
}

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

int main() {
    string S; cin >> S;
    string T = "AKIHABARA";
    rep(a, 0, 2) rep(b, 0, 2) rep(c, 0, 2) rep(d, 0, 2) {
        string tmp;
        rep(i, 0, T.size()) {
            if(a && i == 0) continue;
            if(b && i == 4) continue;
            if(c && i == 6) continue;
            if(d && i == 8) continue;
            tmp += T[i];
        }
        if(tmp == S) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(5);
    FOR(i, 0, 5){
        cin >> A.at(i);
    }

    ll bottleneck = A[0];
    ll bottleneck_index = 0;
    FOR(i, 1, 5){
        if(A[i]<bottleneck){
            bottleneck = A[i];
            bottleneck_index = i;
        }
    }

    ll num;
    if(N%bottleneck==0){
        num = N / bottleneck;
    }else{
        num = N / bottleneck + 1;
    }

    ll ans = num + 4;
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define sz(x) int(x.size())

using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int a, b;
    
    cin >> a >> b;
    
    if(b==1)cout << "0" << endl;
    else{
        int res = 1;
        b-=a;
        while(b>0){
            b-=(a-1);
            res++;
        }
        
        cout << res << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)

using namespace std;

int main(){
	int x;
	cin >> x;
	if(x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

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

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

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

int main(){
  
 int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c >= 22){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	int p[n];
	REP(i,n) cin >> p[i];
	int ans = 0;
	for(int i = 1; i < n - 1; i++){
		if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1])) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// author: Saman Mahdanian
#include <iostream>

using namespace std;
const int N = 1e6 + 10;
const int L = 32;

int n, cnt[L + 10];

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

	cin >> n;
	int grand = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		grand ^= a;
		int lb = __builtin_popcount(a ^ (a - 1)) - 1;
		if (lb >= 0)
			cnt[lb]++;
	}

	int ans = 0;
	for (int i = L; ~i; i--) 
		if (((grand * 1LL) >> i) & 1LL) {
			if (cnt[i] == 0) {
				cout << -1 << endl;
				return 0;
			} else {
				grand ^= (1LL << (i + 1)) - 1;
				ans ++;
			}
		}
	cout << ans << endl;
}

// SamMHD :: Apr10-2019 :: Another Code BEFORE Marhale2!!...

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    # N = int(input())
    # s = input()
    a, b = map(int, input().split())
    # a = list(map(int, input().split()))
    # a = [int(input()) for i in range(N)]
    if (a+b)&1 == 1:
        print("IMPOSSIBLE")
    else:
        print((a+b)//2)

if __name__ == "__main__":
    main()

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int32_t main()
{
    IOS
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}



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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve() {
    int h1, m1, h2, m2, period;
    cin >> h1 >> m1 >> h2 >> m2 >> period;
    int a = h1 * 60 + m1;
    int b = h2 * 60 + m2;
    int duration = b - a;
    // cout << "duration: " << duration << endl;
    if (duration < period)
        return 0;
    return duration - period;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstdio>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef long long ll;
const int N=1e5+5;

    int n,m,t;
    int fa[N];
    int i,j,k;
struct point
{
    int x,y,id;
}p[N];
struct Edge
{
    int u,v,valu;
    bool const operator<(const Edge &b)
    const{
        return valu<b.valu;
    }
}edge[N];
int Find(int son)
{
    return son==fa[son] ? son : fa[son]=Find(fa[son]);
}
bool Union(int x,int y)
{
    x=Find(x),y=Find(y);
    if(x==y) return 1;
    else{
        fa[y]=x;
        return 0;
    }
}
bool cmpx(point &a,point &b){
    return a.x<b.x;
}
bool cmpy(point &a,point &b){
    return a.y<b.y;
}
int main()
{
    cin.tie(0);istream::sync_with_stdio(false);
    while(cin>>n){
        for(i=1;i<=n;i++) fa[i]=i;

        for(i=1;i<=n;i++){
            cin>>p[i].x>>p[i].y;
            p[i].id=i;
        }

        int num=0;
        sort(p+1,p+1+n,cmpx);//尽量以x之间的距离为经费建路
        for(i=1;i<n;i++){
            edge[++num].u=p[i].id;
            edge[num].v=p[i+1].id;
            edge[num].valu=min(abs(p[i].x-p[i+1].x),abs(p[i].y-p[i+1].y));
        }
        sort(p+1,p+1+n,cmpy);//尽量以y之间的距离为经费建路
        for(i=1;i<n;i++){
            edge[++num].u=p[i].id;
            edge[num].v=p[i+1].id;
            edge[num].valu=min(abs(p[i].x-p[i+1].x),abs(p[i].y-p[i+1].y));
        }

        stable_sort(edge+1,edge+1+num);
        int ans=0,cnt=0;
        for(i=1;i<=num;i++){
            if(0==Union(edge[i].u,edge[i].v)){//若u，v两点还未连接
                ans+=edge[i].valu;
                cnt++;
            }
            if(cnt==n-1) break;//建路数达到联通所有城市
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,k;
	cin>>n>>k;
	vi t(n);
	rep(i,k)t[n-1-i]=1;
	vi in(n);
	rep(i,n)cin>>in[i];
	ll out=INF;
	do{
		ll sum=0;
		int ma=0;
		rep(i,n){
			if(t[i]){
				if(ma<in[i]){
					ma=in[i];
				}else{
					sum+=ma+1-in[i];
					ma++;
				}
			}else{
				ma=max(ma,in[i]);
			}
		}
		out=min(out,sum);
	}while(next_permutation(all(t)));
	cout<<out<<endl;
}











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


int main()
{
    int N;
    std::cin >> N;
    for (int t = 0; t < N; t++) {
        std::string a;
        std::cin >> a;
        std::set<std::string> s;
        int size = a.size();
        std::string x, rx, ry, y;
        s.insert(a);
        for (int i = 1; i < size; i++) {
            x = rx = a.substr(0, i);
            y = ry = a.substr(i);
            s.insert(y+x);
            std::reverse(rx.begin(), rx.end());
            std::reverse(ry.begin(), ry.end());
            if (i > 1 && i < size-1) { s.insert(ry+rx); s.insert(rx+ry); }
            if (i > 1) { s.insert(rx+y); s.insert(y+rx); }
            if (i < size -1) { s.insert(x+ry); s.insert(ry+x); }
        }
        std::cout << s.size() << std::endl;
    }
    return 0;
}



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

int main() {
	string a, b;
	cin>>a>>b;
	int n = a.length();
	vector<vector<int>> v(n, vector<int>(26));
	vector<int> t(26, -1);
	for (int i = n-1; i >= 0; i--) {
		int j = a[i];
		j -= 97;
		t[j] = i;
		v[i] = t;
	}
	int ci = 0;
	long long an = 0;
	int fl = 1;
	for (int i = 0; i < b.length();) {
		int j = b[i];
		j -= 97;
		if (v[ci][j] == -1 && ci == 0) {
			fl = 0;
			break;
		}
		if (v[ci][j] == -1) {
			an += n - ci;
			ci = 0;
			continue;
		}
		int cc = v[ci][j];
		an += cc - ci + 1;
		ci = cc + 1;
		if (ci == n) ci = 0;
		i++;
	}
	if (fl == 0) cout<<-1<<endl;
	else cout<<an<<endl;
	return 0;
}

Measured memory_bytes: 13696
#include<stdio.h>

int main(){
		int n,i,j,f=0;
		long long sum=0,a[100000],b[100000];
		scanf("%d",&n);
		for(i=0;i<n;i++){
				scanf("%lld",&a[i]);
		}for(i=0;i<n;i++){
				scanf("%lld",&b[i]);
		}
		long long tmp=0,tmpp=0;
		for(i=0;i<n;i++){
				if(b[i]>a[i])tmp+=(b[i]-a[i])/2;
				if(a[i]>b[i])tmpp+=a[i]-b[i];
		}
		if(tmp>=tmpp)puts("Yes");
		else puts("No");
		return 0;
}



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

int main(){
  long long n,t;
  cin >> n >> t;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long ans = 0;
  for(int i = 0; i < n-1; i++){
    ans += min(a[i+1]-a[i],t);
  }
  cout << ans+t << endl;
}

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

using namespace std;

static const int kModulo = 1000 * 1000 * 1000 + 7;

int solve(const vector<int64_t>& S, int64_t A, int64_t B) {
    if (A < B)
        swap(A, B);
    int N = S.size();
    for (int i = 1; i + 1 < N; ++i)
        if (S[i + 1] - S[i - 1] < B)
            return 0;
    vector<int> dp(N, 0);
    vector<int> last_small(N, 0), next_small(N, N - 1);
    for (int i = 1; i < N; ++i) {
        if (S[i] - S[i - 1] < B)
            last_small[i] = i;
        else
            last_small[i] = last_small[i - 1];
    }
    for (int i = N - 2; i >= 0; --i)
        if (S[i + 1] - S[i] < B)
            next_small[i] = i;
        else
            next_small[i] = next_small[i + 1];

    for (int i = 0; i < N; ++i)
        if (i == 0 || last_small[i - 1] == 0)
            dp[i] = 1;

    vector<int> partial(N, 0);
    int j = 0;
    partial[0] = dp[0];
    for (int i = 1; i < N; ++i) {
        while (S[i] - S[j + 1] >= A)
            ++j;
        if (S[i] - S[j] >= A && last_small[i - 1] <= j + 1) {
            int up_to = last_small[i - 1] - 1;
            dp[i] = (dp[i] + partial[j] - (up_to > 0 ? partial[up_to - 1] : 0)) % kModulo;
            if (dp[i] < 0)
                dp[i] += kModulo;
        }
        partial[i] = (partial[i - 1] + dp[i]) % kModulo;
    }

    int answer = 0;
    for (int i = 0; i < N; ++i)
        if (i == N - 1 || next_small[i + 1] == N - 1)
            answer = (answer + dp[i]) % kModulo;
    if (next_small[0] == N - 1)
        answer = (answer + 1) % kModulo;
    return answer;
}

int main() {
    ios::sync_with_stdio(false);

    int N;
    int64_t A, B;
    cin >> N >> A >> B;

    vector<int64_t> S(N);
    for (int i = 0; i < N; ++i)
        cin >> S[i];

    cout << solve(S, A, B) << "\n";
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

using ll = long long;

int bitcout(int bitmap)
{
    int tmp = bitmap;
    int count = 0;
    while (tmp) {
        if (tmp & 1) {
            count++;
        }
        tmp = tmp >> 1;
    }
    return count;
}

int main()
{
    int n;
    cin >> n;
    vector< vector<pair<int, int> > > x(n);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        for (int j = 0; j < tmp; j++) {
            pair<int, int> p;
            cin >> p.first >> p.second;
            x[i].push_back(p);
        }
    }

    bool isUso = false;
    int result = 0;
    // bitが1なら正直者
    for (int bitmap = 0; bitmap < pow(2, n); bitmap++) {
        for (int person = 0; person < n; person++) {
            bool isSyoujiki = (bitmap & (1 << person)) != 0 ? true : false;
            if (isSyoujiki) {
                for (int i = 0; i < x[person].size(); i++) {
                    pair<int, int> info = x[person][i];
                    int kotae = (bitmap & (1 << (info.first - 1))) != 0 ? 1 /*true*/ : 0;
                    if (info.second != kotae) {
                        isUso = true;
                        break;
                    }
                }
            }
            if (isUso) break;
        }
        if (!isUso) {
            result = max(result, bitcout(bitmap));
        }
        isUso = false;
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#print("input the number of syllables: ")
A, B, C  = map(int, input().split())
if A and B and C >= 1:
        if A and B and C <= 10:
             if A == 5 and B == 5 and C == 7: print('YES')
             elif A == 5 and B == 7 and C == 5: print('YES')
             elif A == 7 and B == 5 and C == 5: print('YES')
             else:
                 print('NO')




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

int main()
{
	ll l, r; cin >> l >> r;

	if (2020 <= r - l) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 2018;
	for (ll i = l; i < r ; i++) {		
		for (ll j = l + 1; j <= r; j++) {
			ans = min(ans, i * j % 2019);
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,T,a,b;
    cin>>N>>T;
    int mini=INT_MAX;
    for(int i = 0 ; i < N ;i++){
        cin>>a>>b;
        if(b<=T){
            mini=min(mini,a);
        }
    }
    if(mini==INT_MAX){
        cout<<"TLE"<<endl;
    }else{
        cout<<mini<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#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 rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int mdeg[114];
vector<int> es[114];

void CalcMaxDeg(int v, int p, int d) {
  int cnt = 0;
  for (int u : es[v]) {
    if (u == p) continue;
    CalcMaxDeg(u, v, d+1);
    cnt++;
  }
  MX(mdeg[d], cnt);
}

vector<int> CalcMaxDepth(int v, int p) {
  vector<int> ret;
  for (int u : es[v]) {
    if (u == p) continue;
    auto res = CalcMaxDepth(u, v);
    if (ret.size() < res.size()) ret.swap(res);
  }
  ret.eb(v);
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    es[a].eb(b);
    es[b].eb(a);
  }

  auto res1 = CalcMaxDepth(0, 0);
  auto res2 = CalcMaxDepth(res1.front(), res1.front());
  int l = res2.size();
  int ans1 = (l+1)/2;
  using ULL = unsigned long long;
  ULL ans2 = 1ULL << 63;
  if (l%2) {
    int r = res2[l/2];
    for (int v : es[r]) {
      fill(mdeg, mdeg+N+1, 1);
      CalcMaxDeg(v, r, 0);
      CalcMaxDeg(r, v, 0);
      ULL cand = 2;
      rep(i, N+1) {
        cand *= mdeg[i];
      }
      MN(ans2, cand);
    }
    fill(mdeg, mdeg+N+1, 1);
    CalcMaxDeg(r, r, 0);
    ULL cand = 1;
    rep(i, N+1) {
      cand *= mdeg[i];
    }
    MN(ans2, cand);
  } else {
    int u = res2[l/2];
    int v = res2[l/2-1];
    fill(mdeg, mdeg+N+1, 1);
    CalcMaxDeg(u, v, 0);
    CalcMaxDeg(v, u, 0);
    ULL cand = 2;
    rep(i, N+1) {
      cand *= mdeg[i];
    }
    MN(ans2, cand);
  }
  cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long mod=1e9+7;

typedef pair<int, int> P;

vector<pair<long long int,long long int> > G[101];
vector<long long int> dist(101,1e18);

void dijkstra(long long int s,long long int g){
  bool f=true;
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0;i<101;i++){
    dist[i]=1e18;
  }
  dist[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    long long int v=p.second;
    long long int d=p.first;
    if(dist[v]<d)continue;
    for(int i=0;i<G[v].size();i++){
      long long int d2=d+G[v][i].second;
      if(dist[G[v][i].first]>d2){
        dist[G[v][i].first]=d2;
        que.push(P(dist[G[v][i].first],G[v][i].first));
      }
    }
  }
}

int main(){
  long long n,m;
  cin>>n>>m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> c(m);
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(make_pair(b[i],c[i]));
    G[b[i]].push_back(make_pair(a[i],c[i]));
  }
  int ans=0;
  for(int i=0;i<m;i++){
    dijkstra(a[i],b[i]);
    if(dist[b[i]]!=c[i])ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    if (h1 > h2) h2 += 24;
    int Min = (h2 * 60 + m2) - (h1 * 60 + m1);
    cout << Min - k << endl;
}

Measured memory_bytes: 3636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()

ans = 0
for a in range(1, N):
	ans += (N-1)//a

print(ans)

Measured memory_bytes: 9904
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 420000
using namespace std;
int Next[N],h[N],v[N],l[N],f[N],tot,n;
int add(int x,int y){
	tot++;
	Next[tot]=h[x];
	v[tot]=y;
	h[x]=tot;
}
int dfs(int x,int fa){
	for(int i=h[x];i;i=Next[i]){
		if(v[i]==fa)continue;
		dfs(v[i],x);
	}
	tot=0;
	for(int i=h[x];i;i=Next[i])if(v[i]!=fa)l[++tot]=f[v[i]];
	sort(l+1,l+1+tot);
	for(int i=1;i<=tot;i++)f[x]=max(f[x],l[i]+(tot-i+1));
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int x;
		scanf("%d",&x);
		add(i,x);
		add(x,i);
	}
	dfs(1,0);
//	for(int i=1;i<=5;i++)printf("%d ",f[i]);
//	printf("\n");
	printf("%d\n",f[1]);
}

Measured memory_bytes: 11520
fun main(args: Array<String>) {
    var (a, b, k) = readLine()!!.split(" ").map { it.toInt() }
    var i = 0
    var d = Math.min(a, b) + 1
    while (k != 0) {
        d--
        if (a % d == 0 && b % d == 0) {
            k--
        }
    }
    println(d)
}

Measured memory_bytes: 37884
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

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 (int 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);}

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

ll conv[51][51];

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

  ll n,a,b;
  std::cin>>n>>a>>b;

  rep(i,1,51){
    conv[i][1]=i;
    rep(j,2,i+1){
      conv[i][j]=conv[i][j-1]*(i+1-j)/j;
    }
  }

  std::vector<ll> v(n);
  rep(i,0,n)std::cin>>v[i];
  std::sort(all(v),std::greater<ll>());

  double sum=0;

  rep(i,0,a)sum+=v[i];
  sum/=a;

  std::cout<<std::setprecision(10)<<std::fixed<<sum<<"\n";

  if(v[0]==v[a-1]){
    ll now=a-1;
    while(now<n&&v[now]==v[0])now++;

    ll ans=0;
    rep(i,a,std::min(b+1,now+1))ans+=conv[now][i];
    std::cout<<ans;
  }else{
    ll start=0;
    while(v[start]!=v[a-1])start++;
    ll last=a-1;
    while(v[last]==v[a-1])last++;

    std::cout<<conv[last-start][a-start];
  }

  return 0;
}






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

class Dice {
public:
  int face[7];

  void roll(int p) {
    int w;
    if (p == 1) {
      w = face[1]; face[1] = face[2]; face[2] = face[6]; face[6] = face[5]; face[5] = w;
    } else if (p == 2) {
      w = face[1]; face[1] = face[4]; face[4] = face[6]; face[6] = face[3]; face[3] = w;
    } else {
      w = face[2]; face[2] = face[3]; face[3] = face[5]; face[5] = face[4]; face[4] = w;
    }
  }

  void find_top(int t) {
    if (face[1] == t) return;
    for (int i = 0; i < 3; i++) {
      roll(1);
      if (face[1] == t) return;
    }
    for (int i = 0; i < 3; i++) {
      roll(2);
      if (face[1] == t) return;
    }
  }

  void find_front(int f) {
    if (face[2] == f) return;
    for (int i = 0; i < 3; i++) {
      roll(3);
      if (face[2] == f) return;  
    }    
  }
};

bool same(Dice d1, Dice d2) {
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 4; j++) {
      bool check = true;
      for (int k = 1; k <= 6; k++) {
        if (d1.face[k] != d2.face[k]) {
          check = false;
          break;
        }
      }
      if (check) return true;
      d1.roll(3);
    }
    if (i < 3) {
      d1.roll(1);
    }
    else if (i == 3) {
      d1.roll(2);
    }
    else {
      d1.roll(2);
      d1.roll(2);
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  
  Dice d[110];
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= 6; j++)
      cin >> d[i].face[j];

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (same(d[i], d[j])) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;  
  return 0;
}


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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;

ll  qpow(ll x,ll n)
{
     ll sum=1;
     while(n){
        if(n&1)  sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
     }
     return sum;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll all=qpow(10,n);
    if(n==1) cout<<0<<endl;
    else{
        ll zero=qpow(9,n)*2%mod;
        ll qu=qpow(8,n);
        cout<<(all-zero+qu+mod)%mod;
    }
     return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>

constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr int LONGINF = 1005000000000000000;
using namespace std;


int main() {
	long long n; cin >> n;
	long long x[87];
	x[0] = 2;
	x[1] = 1;

	for (int i = 2; i <= n; i++) {
		x[i] = x[i - 1] + x[i - 2];
	}

	cout << x[n] << endl;





}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    Int N,K;cin >> N >> K;
    while(1){
        if(N>=0&&N>=K){
            N-=K*(N/K);
        }else if(N>=0&&K>=N&&K-N<=N){
            N=K-N;
        }else{
            break;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int i,j;
	char c[3][3];
	for(i=0; i<3; i++)
	{
		for(j=0; j<=3; j++)
		{
			scanf("%c",&c[i][j]);
		}
	}
	for(i=0; i<3; i++)
	{
		for(j=0; j<=3; j++)
		{
			if(i==j)
				printf("%c",c[i][j]);
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

const int MAXN=5e5;
const int MAXD=1e9;
int N, Q, D;
vector<int> d, A, B;

int main(int argc, char *argv[])
{
    cin >> N >> D;
    A.resize(N+1);
    B.resize(N+2);
    d.resize(N+1);
    
    A[0] = D;
    FOR1(i,1,N+1) {
        cin >> d[i];
        if (d[i] < 2*A[i-1])
            A[i] = abs(A[i-1]-d[i]);
        else
            A[i] = A[i-1];
    }
    
    B[N+1] = 1;
    for (int i = N; i > 0; i--) {
        if (2*B[i+1] <= d[i])
            B[i] = B[i+1];
        else
            B[i] = B[i+1] + d[i];
    }

    cin >> Q;
    FOR(i,Q) {
        int q;
        cin >> q;
        if (A[q-1] >= B[q+1])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    
    return 0;
}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int result = 0;
    rep(a, A+1) rep(b, B+1) rep(c, C+1) {
        if (500 * a + 100 * b + 50 * c == X) ++result;
    }
    cout << result << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
int x,y,t[20][20],a,b,cnt;
void func(int x,int y)
{
	if(x==a&&y==b) cnt++;
	else{
		if(x+1<=a&&t[y][x+1]!=1) func(x+1,y);
		if(y+1<=b&&t[y+1][x]!=1) func(x,y+1);
	}
}
int main(void)
{
	int n,i,j;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0) break;
		scanf("%d",&n);
		for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				t[i][j]=0;
			}
		}
		for(i=1;i<=n;i++){
			scanf("%d%d",&x,&y);
			t[y][x]=1;
		}
		cnt=0;
		func(1,1);
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2592
import random
import time
t_start = time.time()

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]

def calc_score(day, contest, score, last):
  t_last = last[:]
  t_last[contest] = day + 1

  contest_score = s[day][contest]
  score += contest_score

  dis = 0
  for i in range(26):
    dis += c[i] * ((day + 1) - t_last[i])
  score -= dis

  return score


score = 0
last = [0 for i in range(26)]
for day in range(d):
  t_score = 0
  for each_contest in range(26):
    each_t_score = calc_score(day, each_contest, score, last)
    if each_t_score > t_score:
      t_score = each_t_score
      contest = each_contest

  score = t_score
  last[contest] = day + 1

  print(contest + 1)

Measured memory_bytes: 84060
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define mp make_pair
#define frab(i, a, b) for (int i = a; i < b; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll MAX = 1e12;
const ll INF = 1e17;
const ld EPS = 1e-9;
const int M = 1e2 + 12;
const int N = 3e5 + 10;

void solve() {

}

ll a[N];

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("mines.in", "r", stdin);
    //freopen("mines.out", "w", stdout);
    int n;
    cin >> n;
    fr(i, n)
        cin >> a[i];
    ll s = accumulate(a, a + n, 0ll);
    ll ans = INF;
    ll p = 0;
    frab(i, 0, n - 1) {
        p += a[i];
        ans = min(ans, abs(p - (s - p)));
    }
    cout << ans;

}


Measured memory_bytes: 1792
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    string O, E;
    cin >> O;
    cin >> E;
    
    string pass="";

    for(int i = 0; i < E.size(); i++)
    {
        /* code */
        pass += O[i];
        pass += E[i];

        if (i == E.size()-1 and O.size() != E.size())
        {
            pass += O[i+1];
        }
    }

    cout << pass << endl;
    
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

struct DSU {
    vector<int> parents;

    DSU(int n) {
        parents.resize(n+1);
        for(int i = 1; i <= n; ++i) parents[i] = i;
    }

    int root(int i) {
        while(parents[i] != i) {
            parents[i] = parents[parents[i]];
            i = parents[i];
        }
        return i;
    }

    bool find(int a, int b) {
        return root(a) == root(b);
    }

    void join(int a, int b) {
        int root_a = root(a);
        int root_b = root(b);
        if(root_a == root_b) return;
        parents[root_a] = parents[root_b];
    }

    int numComps() {
        unordered_set<int> nums;
        for(int i = 1; i < (int)parents.size(); ++i) {
            nums.insert(root(i));
        }
        return nums.size();
    }
};


int32_t main() {

    int n; cin >> n;
    vector<int> x(n+1), y(n+1);
    for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i];

    int ans = n;
    
    for(int i = 1; i <= n; ++i) {
        for(int j = i+1; j <= n; ++j) {
            int p = x[i] - x[j], q = y[i] - y[j];
            DSU dsu(n);
            for(int a = 1; a <= n; ++a) {
                for(int b = a+1; b <= n; ++b) {
                    if((p == x[a]-x[b] && q == y[a]-y[b]) ||
                       (p == x[b]-x[a] && q == y[b]-y[a]))
                        dsu.join(a, b);
                }
            }

            int cand = dsu.numComps();
            ans = min(ans, cand);
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int

	fmt.Scan(&a)
	fmt.Scan(&b)

	fmt.Println(solve(a, b))
}

func solve(a, b int) int {
	if (b-1)%(a-1) == 0 {
		return (b - 1) / (a - 1)
	} else {
		return (b-1)/(a-1) + 1
	}
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    sort(p.begin(),p.end());
    int total = 0;
    rep(i,k) total += p[i];
    cout << total << endl;
}

Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	a--
	if c < d {
		c, d = d, c
	}

	x := lcm(c, d)

	toA := a - a/c - a/d + a/x
	toB := b - b/c - b/d + b/x

	fmt.Println(toB - toA)
}

func lcm(c, d int) int {
	return c / gcd(c, d) * d
}

func gcd(c, d int) int {
	if c%d == 0 {
		return d
	} else {
		return gcd(d, c%d)
	}
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
#符号が同じ場合、累積和的な感じでいける。
#全部負か全部正しかない。
#全部正の場合は、一番おっきいやつを一番左に足し、左から累積和
#全部負の場合は、一番ちっさいやつを右に足し、右から累積和
#また、負と正が両方含まれている場合は、どっちかに統一する
ans = []
if max(a) * min(a) < 0:
    if abs(max(a)) > abs(min(a)):
        for i in range(n):
            if i != a.index(max(a)):
                ans.append([a.index(max(a))+1, i+1])
                a[i] += max(a)
    else:
        for i in range(n):
            if i != a.index(min(a)):
                ans.append([a.index(min(a))+1, i+1])
                a[i] += min(a)
if max(a) > 0:
    #全部正
    for i in range(1,n):
        ans.append([i,i+1])
else:
    #全部負
    for i in range(n-1,0,-1):
        ans.append([i+1,i])
print(len(ans))
for i in range(len(ans)):
    print("{} {}".format(*ans[i]))


Measured memory_bytes: 38384
// 2018/12/09 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		int a[10000];
		int sum = 0;
		for(int i=0; i<n; i++){
			cin >> a[i];
			sum += a[i];
		}

		int ave = sum/n;
		int cnt = 0;

		for(int i=0; i<n; i++){
			if(a[i]<=ave){
				cnt++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
bitset<4000001>dp;
int n,a[2003],sum;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
	dp[0]=1;
	for(int i=0;i<n;i++)
		dp|=(dp<<a[i]);
	for(int i=0;i<=4000000;i++)
		if(dp[i]&&i*2>=sum){
			cout<<i;
			return 0;
		}
}

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

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

  set<int> sunuke;
  rep(i, n) sunuke.insert(i + 1);

  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      sunuke.erase(a);
    }
  }

  int ans = sunuke.size();
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;


int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(k >= a + b){
        cout << a - (k - a - b) << endl;
    }else if(k < a){
        cout << k << endl;
    }else{
        cout << a << endl;
    }
}




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

int main() {
    int H1,H2,K1,K2,A,B,C,D;
    cin >> H1 >> H2 >> K1 >> K2 >> A >> B >> C >> D;
    int hiro,ken;
    hiro = A*H1 + B*H2 + C*(H1/10) + D*(H2/20);
    ken = A*K1 + B*K2 + C*(K1/10) + D*(K2/20);

    if(hiro > ken) cout << "hiroshi" << endl;
    else if(hiro < ken) cout << "kenjiro" << endl;
    else cout << "even" << endl;
}


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n;
	cin >> n;
	int count = 0;
	ll sum = 0;
	ll mini = 1000000000;
	ll a;
	for(int i = 0; i < n; i++){
		cin >> a;
		sum += abs(a);
		mini = min(mini,abs(a));
		if(a < 0)count++;
	}
	if(count % 2)cout << sum - 2 * mini << endl;
	else cout << sum << endl;
	return 0; 
}


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

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init,tail...)
    return move(vector<decltype(rec)>(s, rec));
#undef rec
}

const int inf = 1e9;

struct Solver {
    int N;
    vector<int> W;
    vector<vector<int>> dp;

    Solver(int N) : N(N) {
        W.resize(N);
        for(int &e : W) cin >> e;
        dp = make_v(-1, N + 10, N + 10);
    }

    int calc(int l, int r) {
        if(r - l < 2) return 0;
        if(dp[l][r] != -1) return dp[l][r];
        int ret = calc(l + 1, r);
        for(int i = l + 1; i < r; i++) {
            if(abs(W[l] - W[i]) > 1) continue;
            int rec = calc(l + 1, i);
            if(rec < i - (l + 1)) continue;
            int tmp = 2 + rec + calc(i + 1, r);
            ret = max(ret, tmp);
        }
        return dp[l][r] = ret;
    }

    int solve() {
        return calc(0, N);
    }
};

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;
    cout << Solver(N).solve() << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3396