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

using namespace std;
#define ll long long
const int maxn=2e5+5;
ll ans[maxn];
int a[maxn];
map<int,int>mp;
map<int,int>mp1;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    ll sum=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ll x=it->first;
        ll y=it->second;
        if(y>=2&&mp1[x]==0)
        {
            mp1[x]=1;
            sum+=y*(y-1)/2;
        }
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ll x=it->first;
        ll y=it->second;
        y--;
        if(ans[x]==0)
        {
            ans[x]=sum;
            if(y==1)
            {
                ans[x]--;
            }
            else if(y>1)
            {
                ans[x]-=(y+1)*y/2;
                ans[x]+=y*(y-1)/2;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(ans[a[i]]!=0)
        {
            cout<<ans[a[i]]<<'\n';
        }
        else
            cout<<0<<'\n';
    }













}



Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{    
    int a,b;
    cin >> a >> b;

    stringstream ss;
    int h = 0;
    int w = 100;
    int ra = a-1;
    int rb = b-1;
    rep(i,25)
    {
        rep(j,50)
        {
            if(j%2==0 && rb>0)
            {
                ss << "#";
                rb--;
            }
            else
                ss << ".";
        }

        rep(j,50)
        {
            if(j%2==1 && ra>0)
            {
                ss << ".";
                ra--;
            }
            else
                ss << "#";
        }

        ss << endl;
        rep(j,50) ss << ".";
        rep(j,50) ss << "#";
        ss << endl;

        h += 2;
        if(ra<=0 && rb<=0) break;
    }

    cout << h << " " << w << endl << ss.str();
    return 0;
}

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

int main() {int N;
  cin>>N;
  string S[N];
  int t[N];
  int i=0;
  while(i<N){cin >> S[i] >> t[i];
            i++;}
string x;
  cin>>x;
  int sum=0;
for(int j=0;j<N;j++){
  if(x==S[j]){
    for(int k=j+1;k<N;k++){sum +=t[k];}
  	break;	}
	}
cout<<sum<<endl;  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
#define N 100010
int par[N];
int rnk[N];
int weight[N];

void init(int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        weight[i] = 1;
        rnk[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rnk[x] < rnk[y]){
        weight[find(y)] += weight[find(x)];
        par[x] = y;
    }
    else{
        weight[find(x)] += weight[find(y)];
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x,int y){
    return find(x) == find(y);
}
signed main(){
    int n,m;
    cin >> n >> m;
    pair<int,int> p[m];
    rep(i,m){
        int a,b;
        cin >> a >> b;
        p[i] = MP(a-1,b-1);
    }
    vector<int> ans(m);
    init(n);
    ans[m-1] = n*(n-1)/2;
    for(int i = m-2;i >= 0;i--){
        // cerr << "i:" << i << " ";
        // rep(j,n)cerr << weight[j] << " ";
        // cerr << endl;
        if(same(p[i+1].fi,p[i+1].se)){
            ans[i] = ans[i+1];
            continue;
        }
        int x = weight[find(p[i+1].fi)];
        int y = weight[find(p[i+1].se)];
        ans[i] = ans[i+1] - x*y;
        unite(p[i+1].se,p[i+1].fi);
    }   
    // rep(j,n)cerr << weight[j] << " ";
    //     cerr << endl;
    rep(i,m)cout << ans[i] << endl;
    


    return 0;   
}


// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc059.contest.atcoder.jp/tasks/arc059_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 6016
n = int(input())
a = list(map(int, list(input().split(" "))))
dif = [0] * n
itr = sum(a)/sum(list(range(n+1)))

if itr != int(itr):
	print("NO")
	exit()
 
count = 0
for i in range(n-1):
	dif[i] = a[i+1]-a[i]
	temp = (itr - dif[i])/n
	if temp < 0 or temp != int(temp):
		print("NO")
		exit()
	count += temp

if count > itr:
	print("NO")
	exit()

print("YES")

Measured memory_bytes: 15244
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef pair<int, int> P;

/** Problem2262 : Stopping Problem **/
vector<string> b;
bool vis[4][20][20][16];
int R, C;

bool solve(int d, int x, int y, int m)
{
	while (1) {
		char c = b[y][x];
		
		if (c == '<')
			d = 3;
		else if (c == '>')
			d = 1;
		else if (c == '^')
			d = 0;
		else if (c == 'v')
			d = 2;
		
		else if (c == '_') {
			if (m == 0)
				d = 1;
			else
				d = 3;
		}
		
		else if (c == '|') {
			if (m == 0)
				d = 2;
			else
				d = 0;
		}
		
		else if (c == '.')
			;
		
		else if (c == '@')
			return true;
		
		else if (isdigit(c)) {
			m = c-'0';
		}
		
		else if (c == '+') {
			m++; if (m==16) m=0;
		}
		
		else if (c == '-') {
			m--; if (m<0) m=15;
		}
		
		else if (c == '?') {
			rep(i, 4) {
				int nx = x+dx[i], ny = y+dy[i];
				nx = (x+C)%C;
				ny = (y+R)%R;
				
				if (vis[i][nx][ny][m]) continue;
				vis[i][nx][ny][m] = true;
				
				if (solve(i, nx, ny, m))
					return true;
			}
		}
		
		x += dx[d], y += dy[d];
		x = (x+C)%C;
		y = (y+R)%R;
		
		if (vis[d][x][y][m])
			return false;
		vis[d][x][y][m] = true;
	}
}

int main()
{
	cin>>R>>C;
	b.resize(R);
	rep(i, R) cin>>b[i];
	
	memset(vis, 0, sizeof(vis));
	vis[0][1][0][0] = true;
	cout << (solve(1, 0, 0, 0)?"YES":"NO") << endl;
}

Measured memory_bytes: 1420
from collections import defaultdict


class Solution:
    def main(self):
        N = int(input())
        self.hashmap = defaultdict(set)
        for i in range(N-1):
            u, v, w = map(int, input().split())
            self.hashmap[u-1].add((v-1, w))
            self.hashmap[v-1].add((u-1, w))
        # print(self.hashmap)
        self.colors = [None] * N
        for i in range(N):
            stack = [(i, 0)]
            while stack:
                idx, color = stack.pop()
                if self.colors[idx] == None:
                    self.colors[idx] = color
                    for node, weight in self.hashmap[idx]:
                        if weight % 2 == 0:
                            stack.append((node, color))
                        else:
                            stack.append((node, 1 ^ color))
        for i in range(N):
            print(self.colors[i])

    def dfs(self, i, color):
        if self.colors[i] is None:
            self.colors[i] = color
            for node, weight in self.hashmap[i]:
                if weight % 2 == 0:
                    self.dfs(node, color)
                else:
                    self.dfs(node, 1 ^ color)


if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 59208
#if 1

#include <bits/stdc++.h>
using namespace std;

int cnt[20];

inline int pcnt(int n)
{
    int ccnt = 0;
    for(int i = 19;i > 0;i--)
    {
        for(;n >= cnt[i];n -= cnt[i]) ccnt++;
    }
    return ccnt;
}
int main()
{
    int L;
    scanf("%d",&L);
    cnt[1] = 1;
    for(int i = 2;i <= 19;i++) cnt[i] = cnt[i-1] << 1;
    printf("20 %d\n",36 + pcnt(L));
    for(int i = 1;i <= 18;i++)
    {
        printf("%d %d %d\n",i,i+1,0);
        printf("%d %d %d\n",i,i+1,cnt[i]);
    }
    for(int i = 19;i > 0;i--)
    {
        for(;L >= cnt[i];)
        {
            L -= cnt[i],
            printf("%d %d %d\n",i,20,L);
        }
    }
    return 0;
}

#endif // 1++

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll n,h,w;
    cin >> n >> h >> w;
    ll ans = 0;
    for(ll i = 0;i < n;i++)
    {
        ll a,b;
        cin >> a >> b;
        if(a >= h && b >= w)
        {
            ans++;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
long long a[200005];
long long x[200005], y[200005];

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%lld%lld",&x[i],&y[i]);
    long long ans = 0;
    for(int i = 1; i <= n; i++) a[i] = x[i]+y[i];
    std::sort(a+1,a+1+n);
    long long cur = a[n]-a[1];
    if(ans<cur) ans = cur;
    for(int i = 1; i <= n; i++) a[i] = x[i]-y[i];
    std::sort(a+1,a+1+n);
    cur = a[n]-a[1];
    if(ans<cur) ans = cur;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6424
package main

import "fmt"

func main() {
	var k, s, ans int
	fmt.Scan(&k, &s)
	for i := 0; i <= k; i++ {
		for j := 0; j <= k; j++ {
			if 0 <= s-(i+j) && s-(i+j) <= k {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n){
       REP(i, n) par[i] = -1;
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    int size(int x){
        return (-par[root(x)]);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(x > y) swap(x, y);
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(int x){
        REP(i, x) cout << par[i] << " ";
        cout << endl;
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    REP(i, m){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    int ans = 0;
    REP(i, m){
        UnionFind UF(n);
        REP(j, m){
            if(i == j) continue;
            UF.unite(A[j], B[j]);
        }
        REP(j, n){
            if(UF.size(j) != n){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int maxS = 1e5 + 7;
pair<ll, ll> arr[maxS];
ll DP[2][maxS];
ll MAX = 1e5 + 7;
int main() {
    fastio();

    ll N, W;
    cin >> N >> W;
    for(int i = 0;i < N;i ++) {
        cin >> arr[i].first >> arr[i].second;
    }
    for(int i = 0;i < MAX;i ++) {
        DP[0][i] = -1;
    }
    DP[0][0] = 0;
    DP[0][arr[0].second] = arr[0].first;
    int a = 1, b = 0;
    for(int i = 1;i < N;i ++) {
        for(int j = 0;j < MAX;j ++) {
            DP[a][j] = DP[b][j];
            if(j-arr[i].second >= 0) {
                if(DP[b][j-arr[i].second] >= 0) {
                    if(DP[a][j] == -1) {
                        DP[a][j] = DP[b][j-arr[i].second] + arr[i].first;
                    } else {
                        DP[a][j] = min(DP[b][j-arr[i].second] + arr[i].first, DP[a][j]);
                    }
                }
            }
        }
        swap(a, b);
    }
    
    ll MAX_ = 0;
    for(int i = 0;i < MAX;i ++) {
        if(DP[b][i] <= W && DP[b][i] >= 0) {
            MAX_ = i;
            // cout << i << " " << DP[b][i] << "\n";
        }
    }
    cout << MAX_ << "\n";
}

Measured memory_bytes: 1920
import math

N, D = [int(i) for i in input().split()]
data = [list(map(int, input().split())) for _ in range(N)]

t = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      lsti = data[i]
      lstj = data[j]
      dist = 0
      for k in range(D):
        ik = lsti[k]
        ij = lstj[k]
        dist += (ik - ij)**2
      dist = math.sqrt(dist)
      if int(dist) - dist == 0:
        t += 1
        
print(t)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

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

  vector<int> h(n);
  REP(i, n) cin >> h[i];
  int len = 0;
  int ans = 0;
  REP(i, n-1){
    if(h[i] >= h[i+1]){
      len++;
    }else{
      chmax(ans, len);
      len = 0;
    }
  }
  chmax(ans, len);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
int main() {
	int na,nb;
	long long int S[10000],T[10000];
	cin >> na;
	int count = 0;
	for (int i = 0;i < na;i++) {
		cin >> S[i];
	}
	cin >> nb;
	for (int i = 0;i < nb;i++) {
		cin >> T[i];
	}
	int j = 0;
	int i = 0;
		while (j<nb) {
				if (S[i] != T[j]) {
					i++;
				}
				if (S[i] == T[j]) {
					i = 0;
					j++;
					count++;
				}
				if (i == na - 1) {
					j++;
					i = 0;
				}
			}

		cout << count << endl;
 
}

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


int main()
{
    int n;
    cin >> n;
    vector<int> b;
    for (int i = 0; i < n - 1; i++) {
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }

    long long int res = 0;
    res += b[0];
    res += b[n - 2];
    for (int i = 0; i < n - 2; i++) {
        int a = min(b[i], b[i + 1]);
        res += a;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll now = 0;
    FOR(i,1,2000000) {
        now = (now * 10 + 7) % n;
        if (now == 0) {
            cout << i;
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


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

using namespace std;

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

int main(){
   
   int n,m,t[200],p[200],x[200],tmp[200];
   cin >> n;
   rep(i,n) cin >> t[i], tmp[i] = t[i];
   cin >> m;
   rep(i,m) cin >> p[i] >> x[i];

   rep(i,m){
      int id = p[i];
      t[id - 1] = x[i];
      int sum = 0;
      rep(j,n){
         sum += t[j];
      }
      cout << sum << endl;
      t[id - 1] = tmp[id - 1];
   }

   return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
ll ans = 1000000000000LL;
int n, a[3];
vll l;

void f(vector<int> &v) {
  ll sub = 0;
  ll cnt[4] = {0}, b[4] = {0};
  for (int i = 0; i < n; i++) {
    cnt[v[i]]++;
    b[v[i]] += l[i];
  }
  for (int i = 0; i < 3; i++) {
    if (cnt[i] == 0)
      return;
    sub += (cnt[i] - 1) * 10;
    sub += abs(a[i] - b[i]);
  }
  ans = min(ans, sub);
}

void dfs(int i, vector<int> &v) {
  if (i == n) {
    f(v);
    return;
  }
  for (int j = 0; j < 4; j++) {
    v[i] = j;
    dfs(i + 1, v);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a[0] >> a[1] >> a[2];
  l.resize(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  vector<int> v(n);
  dfs(0, v);
  cout << ans << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    long long B = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B ^= A[i];
    }
    for (int i = 0; i < N; ++i) cout << (B^A[i]) << endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
pair<int,long long> cal(int num,long long ct){
	if(ct==1){
		return {num,0};
	}else{
		auto tmp = cal(num,ct/2);
		int curr = tmp.first * 2;
		pair<int,long long> res = make_pair(0,0L);
		res.second += tmp.second*2;
        res.second = res.second+1;
		while(curr>=10){
			curr = curr/10 + curr%10;
			res.second = res.second+1;
		}
		if(ct%2==0){
			res.first = curr;
			return res;
		}else{
			curr += num;
            res.second = res.second+1;
			while(curr>=10){
				curr = curr/10 + curr%10;
				res.second = res.second+1;
			}
			res.first = curr;
			return res;
		}

	}
	return {0,0};
}
int main(){
  //auto tmp = cal(8,5);
  //cout<<tmp.first<<" "<<tmp.second<<endl;
  
	int m;cin>>m;
	vector<int> arr(m);
	long long res = 0;
	for(int i=0;i<m;++i){
		int num;
		long long ct;
		cin>>num>>ct;
		auto tmp = cal(num,ct);
		arr[i]=tmp.first;
		res += tmp.second;
	}
    
	int lst = arr[0];
	for(int i=1;i<m;++i){
		int curr = arr[i] + lst;
        res++;
		while(curr>=10){
			curr = curr/10 + curr%10;
			res++;
		}
		lst = curr;
	}
    cout<<res<<endl;
    
	return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];

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

    if (v[2] == v[1] + v[0])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
	
	return 0;
}


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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;

// ll ac(vector<ll> vec){
//     ll a=0;
//     for (auto k:vec) a+=abs(k);

//     return a;
// }


int main(){
    int N,M;
    ll r=0;
    cin >> N >> M;

    vector<vector<ll> > v(N,vector<ll> (3));
    vector<ll> v2(N);

    for (int i=0;i<N;++i){
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    for (int i=0;i<2;++i){
        for (int j=0;j<2;++j){
            for (int k=0;k<2;++k){
                for (int ii=0;ii<N;++ii){
                    v2[ii] = (v[ii][0]*pow(-1,i) + v[ii][1]*pow(-1,j) + v[ii][2]*pow(-1,k));
                }
                sort(v2.rbegin(), v2.rend());
                r = max(accumulate(v2.begin(),v2.begin()+M,(ll) 0),r);
            }
        }
    }
    cout << r << endl;



    //vector<vector<vector<ll>>> dp(N,vector<vector<ll>> (M+1,vector<ll> (3,0)));


    // dp[0][1] = v[0];

    // for (int i=1;i<N;++i){
    //     for (int j=1;j<=M;++j){
    //         ll d=0;
    //         for (int k=0;k<3;++k) {
    //             d += abs(dp[i-1][j-1][k] + v[i][k]);
    //         }
    //         //cout << d << endl;
    //         if (d>ac(dp[i-1][j])) dp[i][j] = {dp[i-1][j-1][0]+v[i][0], dp[i-1][j-1][1]+v[i][1], dp[i-1][j-1][2]+v[i][2]};
    //         else dp[i][j] = dp[i-1][j];
    //     }
    // }

    // for (int i=0;i<N;++i){
    //     for (int j=0;j<=M;++j){
    //         for (auto k:dp[i][j]){
    //             cout << k << " ";
    //         }
    //         cout << endl;
    //     }
    // }


    // for (auto i:dp[N-1][M])r+=abs(i);

    // cout << r << endl;
  }


Measured memory_bytes: 256
n = gets.to_i
n_arr = []
arr = []
(1..n).each do |v|
  if v.even?
    n_arr << v
  end
end

n_arr.each do |v|
  cnt = 0
  while v % 2 == 0
    v /= 2
    cnt +=1
  end
  arr << cnt
end

if n == 1
  puts 1
else
  puts n_arr[arr.index(arr.max)]
end


Measured memory_bytes: 1788
h, w = map(int, input().split())
result = []

while (h and w):
    result.append((h, w))
    h, w = map(int, input().split())

for item in result:
    h = item[0]
    w = item[1]
    for i in range(0, h):
        for j in range(0, w):
            if ((i + j) % 2 == 0):
                print('#', end = '')
            else :
                print('.', end = '')
        print()
    print()


Measured memory_bytes: 7004
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll a,b,c,d,e,f,g,h,n,m;
vector<list<ll> >adj(1000001);
vector<bool>v(1000001);
vector<bool>col(1000001);
vector<ll>val(1000001,0);
ll grid[1000][1000];
char in[1000][1000];
void hello(ll x){
    v[x]=true;
    for(auto i=adj[x].begin();i!=adj[x].end();i++){
        if(col[*i]){val[x]=(val[x]+val[*i])%mod;continue;}
        if(!v[*i]){
            if(*i==e){val[x]=1;continue;}
            hello(*i);
            val[x]=(val[x]+val[*i])%mod;
        }
    }
    v[x]=false;
    col[x]=true;
}
int main()
{
    c=1;
    scanf("%lld %lld",&a,&b);
    getchar();
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            grid[i][j]=c++;
            scanf("%c",&in[i][j]);
        }
        if(i!=a-1)getchar();
    }
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            if(in[i][j]=='#')continue;
            if(i!=a-1&&in[i+1][j]=='.')adj[grid[i][j]].push_back(grid[i+1][j]);
            if(j!=b-1&&in[i][j+1]=='.')adj[grid[i][j]].push_back(grid[i][j+1]);
        }
    }
    e=grid[a-1][b-1];
    d=0;
    hello(1);
    printf("%lld\n",val[1]);
    return 0;
}


Measured memory_bytes: 95232
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        A = map(int, input().split())

        odd_cnt = 0
        for a in A:
            if a % 2 == 1:
                odd_cnt += 1
        print('YES' if odd_cnt % 2 == 0 else 'NO')


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

int main() {
    int n, temp = 1;
    cin >> n;
    while((temp + 1) * (temp + 1) <= n) {
        temp++;
    }
    int ans = temp * temp;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
const long long INF = 1LL << 60;
using namespace std;
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; }

ll dp[100010];
ll h[100010];
int main() {
    int n;
    cin >> n;
    rep(i,n) cin >> h[i];
    rep(i,100010)dp[i] = INF;
    dp[0]=0;
    for(int i = 0; i < n; ++i) {
        chmin(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		double w = in.nextDouble();

		if (w <= 48) {
			out.println("light fly");
		} else if (w <= 51) {
			out.println("fly");
		} else if (w <= 54) {
			out.println("bantam");
		} else if (w <= 57) {
			out.println("feather");
		} else if (w <= 60) {
			out.println("light");
		} else if (w <= 64) {
			out.println("light welter");
		} else if (w <= 69) {
			out.println("welter");
		} else if (w <= 75) {
			out.println("light middle");
		} else if (w <= 81) {
			out.println("middle");
		} else if (w <= 91) {
			out.println("light heavy");
		} else {
			out.println("heavy");
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 27924
def sum_digit(n) :
    max_sum = 999999
    for n1 in range(1, n) :
        n2 = n - n1

        l_n1 = []
        l_n2 = []
        l_n1 = list(map(int, list(str(n1))))
        l_n2 = list(map(int, list(str(n2))))
        l_n1.append(0)
        l_n2.append(0)
       
        res = sum(l_n1) + sum(l_n2)
        if res < max_sum :
            max_sum = res
            tmp_n1 = l_n1
            tmp_n2 = l_n2
            
    return max_sum

n = int(input())
print(sum_digit(n))

Measured memory_bytes: 3064
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N=I()
    A=LLIN(N)
    d=deepcopy(A)
    warshall_floyd(d, N)

    edge = []
    for i in range(N):
        for j in range(i+1,N):
            edge.append((A[i][j],i,j))
    edge.sort()

    ans = 0
    for a,i,j in edge:
        if d[i][j]<a:
            print(-1)
            return
        need = True
        for k in range(N):
            if k in (i,j):
                continue
            if a==d[i][k]+d[k][j]:
                need = False
                break
        if need:
            ans += a
    print(ans)
        
if __name__ == '__main__':
    main()

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

using ll = long long;

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

  vector<int> B(N+1, 0);

  for (int i = 0; i < N; i++) {
    if(S[i]=='#') B[i+1] = B[i] + 1;
    else B[i+1] = B[i];
  }

  int ans = 10000000;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, B[i]+((N-i)-(B[N]-B[i])));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1412
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String n = sc.next();

		int A = Integer.parseInt(n.substring(0,1));
		int B = Integer.parseInt(n.substring(1,2));;
		int C = Integer.parseInt(n.substring(2,3));;
		int D = Integer.parseInt(n.substring(3,4));;

		boolean op1[] = {true,false};
		boolean op2[] = {true,false};
		boolean op3[] = {true,false};

		int cal1 = 0;
		int cal2 = 0;
		int ans = 0;

		boolean op[] = new boolean[3];

		calc:for (int i = 0; i < 2; i++) {
			if (op1[i]) {
				cal1 = A+B;
			} else {
				cal1 = A-B;
			}
			for (int j = 0; j < 2; j++) {
				if (op2[j]) {
					cal2 = cal1+C;
				} else {
					cal2 = cal1-C;
				}
				for (int k = 0; k < 2; k++) {
					if (op3[k]) {
						ans = cal2+D;
					} else {
						ans = cal2-D;
					}
					if (ans == 7) {
						op[0] = op1[i];
						op[1] = op2[j];
						op[2] = op3[k];
						break calc;
					}
				}
			}
		}
		String s[] = new String[3];
		for (int i = 0; i < 3; i++) {
			if (op[i]) {
				s[i] = "+";
			} else {
				s[i] = "-";
			}
		}
		System.out.println(A+s[0]+B+s[1]+C+s[2]+D+"=7");
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int H,W;cin>>H>>W;
    string A[H][W];
    REP(i,H){
        REP(j,W){
            cin>>A[i][j];
            if(A[i][j]=="snuke"){
                cout<<(char)('A'+j)<<i+1<<endl;
            }
        }
    }
}

Measured memory_bytes: 256
use proconio::input;
use std::cmp::{max, min};

const MAX_L: usize = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        ul: [(usize, usize); q],
    }
    let dp = make_dp(&vw);
    for (u, l) in ul {
        println!("{}", calc(&dp, &vw, u - 1, l));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push({
        let w = vw[0].1 as usize;
        (0..=MAX_L)
        .map(|i| if i < w { 0 } else { vw[0].0 })
        .collect()
    });

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1 as usize;
                let v = if i < w { 0 } else { dp[p][i - w] + vw[c].0 };
                max(dp[p][i], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    dp: &Vec<Vec<u32>>,
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: usize,
) -> u32 {
    if u < dp.len() {
        dp[u][l]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1 as usize;
        let pv1 = calc(dp, vw, p, l);
        let pv2 = if l < w { 0 } else { calc(dp, vw, p, l - w) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 410968
#include <unistd.h>

char ibuf[2000010];
char *ibufe = ibuf-1;

extern inline void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
}

int read_uint(){
  int x=0;
  while(*(++ibufe) <'0');
  do {
    x *= 10;
    x += *ibufe-'0';
  } while(*(++ibufe) >='0');

  return x;
}

char buf[40];
char *bufe = buf;

void write_uintln(long long int x){
  int i;
  static char tmp[23];
  if(x==0){
    *bufe++ = '0';
    *bufe++ = '\n';
    return;
  }

  for(i=0; x; i++){
    tmp[i] = '0' + x % 10;
    x /= 10;
  }
  for(i--; i >= 0; i--){
    *bufe++ = tmp[i];
  }
  *bufe++ = '\n';
}

extern inline void writeall(){
  int k, t = 0;
  while((k=write(STDOUT_FILENO, buf+t, bufe-buf-t))>0) t += k;
}


int n;
int A[200000];

inline void swap(int *a, int *b){
  int z;
  z = *a;
  *a = *b;
  *b = z;
}

int median(int *A, int n){
  int ll = 0;
  int rr = n;
  const int k = n/2;
  while(ll + 1 < rr){
    int l, r, pivot;
    swap(A+ll, A+(ll+rr)/2);
    pivot = A[ll];
    l = ll+1;
    r = rr-1;
    while(1){
      while(A[l] < pivot) l++;
      while(A[r] > pivot) r--;
      if(l >= r) break;
      swap(A+l++, A+r--);
    }
    swap(A+ll, A+l-1);
    if(k == l-1) return pivot;
    else if(k < l-1) rr = l-1;
    else ll = l;
  }
  return A[ll];
}

int main(){
  int i, m;
  long long int r;
  readall();
  n = read_uint();
  for(i=0;i<n;i++){
    A[i] = read_uint()-(i+1);
  }
  m = median(A, n);
  r = 0;
  for(i=0;A[i] < m;i++) r += m - A[i];
  for(;i<n;i++) r += A[i] - m;
  write_uintln(r);
  writeall();
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    double x = 0, y = 0, r = M_PI/2.0;
    int a, b;
    char delim;
    while (cin >> a >> delim >> b, a||b) {
        x += a * cos(r);
        y += a * sin(r);
        r -= b * M_PI / 180.0;
    }
    cout << (int)x << "\n";
    cout << (int)y << "\n";

    return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n;
    cin >> n;
    int cc = 0;
    int max = 0;
    rep(i,n){
        int h;
        cin >> h;
        if(max<=h){
            max = h;
            cc++;
        }
    }
    cout<<cc<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include <algorithm>
using namespace std;
int a,b[200000],c,d[200000],f,g;
int main(){

	cin>>a;

	//sort(b,b);

	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	cin>>c;
	for(int i=0;i<c;i++){
		cin>>d[i];
	}
	sort(b,b+a);
	sort(d,d+c);
	for(int i=0;i<a;i++){
		if(b[i]==d[f]){
			f++;
		}
	}
	if(f==c){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

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


int main()
{
	int N=0,K=0,h[100000];


	scanf("%d %d", &N, &K);

	int i;

	for(i=0;i<N;i++){
		scanf("%d", &h[i]);
	}



	qsort(h,N,sizeof(int),compare_int);
	
	int min = h[N-1];
	
	for(i=0;i<=N-K;i++){

		if(h[i+K-1]-h[i]<min){
			min = h[i+K-1]-h[i];
		}

	}

	printf("%d", min);


	return 0;
}


Measured memory_bytes: 892
n = int(input())
a = map(int, input().split())

divided = []
divided_1 = []
divided_2 = []

def count_divide(i):
  count = 0
  while True:
    if i % 2 == 0:
      i = int(i / 2)
      count += 1
    else:
      return count

for ai in a:
  c = count_divide(ai)
  if c == 0:
    divided.append(c)
  elif c == 1:
    divided_1.append(c)
  else:
    divided_2.append(c)

l_1 = len(divided)
l_2 = len(divided_1)
l_4 = len(divided_2)

if l_2 == 0:
  if l_1 <= l_4 + 1:
    print('Yes')
  else:
    print('No')
  exit(0)

if l_1 <= l_4:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 11436
n = int(input())
play_list = [0, 0, 0]

for i in range(n):
    a, b, c = [ int(v) for v in input().split() ]
    play_list[0], play_list[1], play_list[2] = a + max(play_list[1], play_list[2]), b + max(play_list[2], play_list[0]), c + max(play_list[0], play_list[1])
print(max(play_list))


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

int main () {
 int a,b;
 cin>>a>>b;
  if(a>b){
    for(int i=0;i<a;i++){
      cout<<b;
    }
  } else{
    for(int j=0;j<b;j++){
      cout<<a;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

using namespace std;
int n, k;

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

  cin >> n >> k;
  int x = 0;
  for (int i = 1; (i<=n) && x < k;i+=2) {
    x++;
  }
  if (x == k) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    string S;
    cin >> S;
    int L=S.length();
    L--;
    if(L%2==1) L--;
    while(!(S.substr(0,L/2)==S.substr(L/2,L/2))) L-=2;
    cout << L << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = [0] * (N+1)

for i in range(K):
    d = int(input())
    if d > 0:
        a = list(map(int, input().split()))
        for v in a:
            x[v] += 1

# print(a)

c = 0
for i in range(1, N+1, 1):
    if x[i] == 0:
        c += 1

print(c)

Measured memory_bytes: 9092
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int tmp = 0;
        if (A < B) {
            tmp = B;
            B = A;
            A = tmp;
        }
        long num = 0;
        for (int b = 1; b <= B; b++){
            num = num + A;
            if (num % B == 0) {
                System.out.println(num);
                System.exit(0);
            }
        }
    }
}



Measured memory_bytes: 22356
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;


int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int a[100][3];
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    int l, r, d, u;
    l = 0;
    r = w;
    d = 0;
    u = h;
    for (int i = 0; i < n; i++) {
        if (a[i][2] == 1) {
            l = max(a[i][0], l);
        }
        else if (a[i][2] == 2) {
            r = min(a[i][0], r);
        }
        else if (a[i][2] == 3) {
            d = max(a[i][1], d);
        }
        else if (a[i][2] == 4) {
            u = min(a[i][1], u);
        }
        if (r <= l || u <= d) {
            break;
        }
    }
    if (l < r && d < u) {
        cout << (r - l) * (u - d) << endl;
    }
    else {
        cout << 0 << endl;
    }
   
}

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

#define ll long long

using namespace std;

int main(){
    int n, a, i;
    ll s = 0, news, count1 = 0, count2 = 0;

    cin >> n;
    vector<ll> as(n);

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

    i = 0;
    s = 0;
    while(i < n){
        news = as[i] + s;
        if(news > -1){
            s -= news + 1;
            count1 += news + 1;
        }
        if(++i >= n) break;

        news = as[i] + s;
        if(news < 1){
            s += 1 - news;
            count1 += 1 - news;
        }
        i++;
    }

    i = 0;
    s = 0;
    while(i < n){
        news = as[i] + s;
        if(news < 1){
            s += 1 - news;
            count2 += 1 - news;
        }
        if(++i >= n) break;

        news = as[i] + s;
        if(news > -1){
            s -= news + 1;
            count2 += news + 1;
        }
        i++;
    }

    cout << (count1 < count2 ? count1 : count2) << endl;
}

Measured memory_bytes: 4052
/* -----KAUN_MEET--------*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
int mod = 1000000007;
#define P get<0>
#define D get<1>
#define T get<2>
#define C get<3>
#define PB push_back
#define MP make_pair
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define F first
#define S second
#define gcd __gcd
#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void __print(int x)
{
    cerr << x;
}
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename Th, typename V>
void __print(const pair<Th, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename Th>
void __print(const Th &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif
void binary_rock()
{
    int n;
    cin >> n;
    int i, j, k, l;
    // int ans[3][n];
    vector<vector<int>> ans(n);
    vector<int> a(n), b(n), c(n);
    for (i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < 3; j++)
        {
            // cin>>k;
            k = 0;
            ans[i].PB(k);
        }
    }

    ans[0][0] = a[0];
    ans[0][1] = b[0];
    ans[0][2] = c[0];

    for (i = 1; i < n; i++)
    {
        ans[i][0] = a[i] + (max(ans[i - 1][1], ans[i - 1][2]));
        ans[i][1] = b[i] + (max(ans[i - 1][0], ans[i - 1][2]));
        ans[i][2] = c[i] + (max(ans[i - 1][1], ans[i - 1][0]));
    }
    cout << max(ans[n - 1][0], max(ans[n - 1][1], ans[n - 1][2])) << endl;

    // int ans[]
}

signed main()
{
    fastio
        clock_t t1 = clock();

    int t = 1;
    // cin >> t;
    while (t--)
    {
        binary_rock();
    }

    clock_t t2 = clock();
    // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;
    // cout << CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <stdbool.h>
bool is_include_three(int x)
{
    while (x)
    {
        if (x % 10 == 3)
        {
            return true;
        }
        else
        {
            x /= 10;
        }
    }
    return false;
}
void call(int n)
{
    for (int i = 1; i <= n; i++)
    {
        //3の倍数か３が含まれていれば表示
        // is_multiple_three(i);
        if (i % 3 == 0 || is_include_three(i))
        {
            printf(" %d", i);
        }
    }
    printf("\n");
}
int main(void)
{
    int n;
    scanf("%d", &n);
    call(n);
    return 0;
}


Measured memory_bytes: 2756
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if(A+B >= C){
		cout << "Yes" << endl;
	}else{
		cout << "No"<< endl;
	}
	return 0;
}

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

signed main() {
  int k,x;
  cin >> k >> x;
  int l = max(x-(k-1), -1000000);
  int r = min(x+(k-1), 1000000);
  for(int i=l; i<=r; i++) {
    cout << i << (i==r ? "\n" : " ");
  }
}


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

int main() {
	int N;
	int K;
	int q;
	int q11;
	int q22;
	long long p;
	long long p1;
	long long p2;
	long long p3;
	long long p4;
   
	cin >> N >> K;
	int a[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
    sort(a, a + (N), greater<int>());  // a[0:N] を大きい順にソート
  	if (K==1){
		cin >> a[0];
 		p=1000000007;
      	p+=a[0];
		p=p%1000000007;
		cout << p << endl;
      return 0;
    }
	if (((K%2)==1)&&(a[0]<=0)){
		p=1;
		for(int i=0;i<K;i++){
			p*=a[i];
			p=p%1000000007;
		}
		p+=1000000007;
		p=p%1000000007;
		cout << p << endl;
		return 0;
	}
	q=0;
	q11=(K%2);
	q22=N-1;
	for(int i=(K%2);i<K;i++){
		if(a[q11]>-a[q22]) {
			q11++;
		} else {
			q22--;
			q++;
		}
	}
 	if ((q%2)==1){
 		p1=a[q11-1];
		p2=a[q11];
		p3=a[q22];
		p4=a[q22+1];
		if(p1*p2<p3*p4) {
			q11--;
			q22--;
		} else {
			q11++;
			q22++;
		}
	}
  	p=1;
	while (q11 > 0) {
		q11--;
		p*=a[q11];
		p=p%1000000007;
	}
	while (q22 < N-1) {
		q22++;
		p*=a[q22];
		p=p%1000000007;
	}
	p+=1000000007;
	p=p%1000000007;
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 4424
N, L = map(int, input().split())
if L >= 0:
    print ((N - 1)*(2 * L + N) // 2)
elif N + L - 1 < 0:
    print((N - 1)*(2 * L + N - 2) // 2)
else:
    print(N * (2 * L + N - 1) // 2)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){
    return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}

int main(void){
    ll n,i,min=INF;
    scanf("%lld",&n);
    ll a[n],sum[n];
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i==0) sum[i]=a[i];
        else sum[i]=sum[i-1]+a[i];
    }
    // for(i=0;i<n-1;i++){
    //     printf("%lld ",sum[i]);
    // }
    for(i=0;i<n-1;i++){
        // ll x=sum[n-1]-sum[i],y;
        min=min2(min,ABS(sum[n-1]-sum[i]-sum[i]) );
    }

    printf("%lld\n",min);
    return 0;
}


Measured memory_bytes: 3328