akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;

int n;
vector<int> g[MAXN], w[MAXN];
vector<int> seen, sum;
int centroid = -1;

void dfsCentroid(int node) {
    seen[node] = 1;
    sum[node] = 1;
    
    bool bad = false;

    int sz = g[node].size();
    for(int i = 0; i < sz; ++i) {
        int to = g[node][i];
        if(seen[to])
            continue;
        dfsCentroid(to);
        sum[node] += sum[to];
        if(sum[to] > n / 2)
            bad = true;
    }

    if(n - sum[node] > n / 2)
        bad = true;

    if(not bad) {
        centroid = node;
    }
}

void dfsSolve(int node, long long depth, int son, vector<long long> &h, vector<int> &whose) {
    seen[node] = 1;
    h[node] = depth;
    if(son != -1)
        whose[node] = son;

    int sz = g[node].size();

    for(int i = 0; i < sz; ++i) {
        int to = g[node][i];
        if(seen[to])
            continue;
        int new_son = son;
        if(centroid == node)
            new_son = i;
        dfsSolve(to, depth + w[node][i], new_son, h, whose);
    }
}

int main() {
    //ifstream cin("d.in");
    cin >> n;
    
    seen = vector<int> (n, 0);

    for(int i = 0; i < n - 1; ++i) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
    }
    
    sum = vector<int> (n, 0);

    dfsCentroid(0);

    vector<long long> height(n, 0);
    vector<int> whose(n, -1);
    seen = vector<int> (n, 0);
    dfsSolve(centroid, 0, -1, height, whose);
    
    int maxx = 0;
    vector<int> cnt(n, 0);

    for(int i = 0; i < n; ++i) {
        if(whose[i] >= 0) {
            cnt[whose[i]] += 1;
            maxx = max(cnt[whose[i]], maxx);
        }
    }
    
    long long min_depth = 1e16;

    if(n % 2 == 0 and maxx == n / 2) {
        for(int i = 0; i < n; ++i)
            if(whose[i] >= 0 and cnt[whose[i]] == maxx)
                min_depth = min(min_depth, height[i]);
    } else {
        for(int i = 0; i < n; ++i)
            if(i != centroid)
                min_depth = min(min_depth, height[i]);
    }

    long long ans = 0;

    for(int i = 0; i < n; ++i) {
        ans += 2 * height[i];
        //cerr << i << " " << height[i] << "\n";
    }

    ans -= min_depth;
    cout << ans << "\n";
}

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

using namespace std;

int main()
{
	int N;
	vector<int> a(100);
	int alice, bob;
	alice = bob = 0;

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

	sort(a.begin(), a.end(), greater<int>());

	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0)
			alice += a[i];
		else
			bob += a[i];
	}
	
	cout << alice - bob << endl;

	return 0;
}

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

using namespace std;

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}
 
template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}

template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}

int main(){
    const int n = read<int>();
    
    vector<vector<int64_t>> mat;
    mat.reserve(n);
    
    times_do(n, [&](){
        mat.push_back(reads<int64_t>(n));
    });

    int64_t total = 0;

    for(int i = 0; i < n; ++i)
    for(int j = (i+1); j < n; ++j)
    {
        bool is_needed = true;
        for(int k = 0; k < n; ++k)
        {
            if(k == i || k == j) continue;
            int64_t d = mat[i][j] - (mat[i][k] + mat[k][j]);
            if(d > 0)
            {
                cout << "-1\n";
                return 0;
            }
            else if(d == 0)
            {
                is_needed = false;
            }
        }
        if(is_needed)
            total += mat[i][j];
    }
    cout << total << '\n';

    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, m;
  cin >> n >> m;
  vector<char> res(n, 0);
  for (int i = 1; i <= m; i++) {
    int s; char c;
    cin >> s >> c;
    s--;
    if (res[s] == 0) res[s] = c;
    else if (res[s] != c) {
      cout << -1 << '\n';
      return;
    }
  }
  if (n > 1) {
    if (res[0] == '0') {
      cout << -1 << '\n';
      return;
    }
    if (res[0] == 0) {
      res[0] = '1';
    }
  }
  for (auto &i : res) {
    if (i == 0) cout << '0';
    else cout << i;
  }
  cout << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


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

using namespace std;

int main()
{
  int n, x[100], y[100], h[100];
  cin >> n;
  int tx, ty, th = -1;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] > 0)
    {
      tx = x[i];
      ty = y[i];
      th = h[i];
    }
  }
  for (int cx = 0; cx <= 100; cx++)
    for (int cy = 0; cy <= 100; cy++)
    {
      if (th == -1)
      {
        
      }
      else
      {
        int hh = max(th + abs(cx - tx) + abs(cy - ty), 0);
        bool ok = true;
        for (int i = 0; i < n; i++)
          if (max(hh - abs(cx - x[i]) - abs(cy - y[i]), 0) != h[i])
            ok = false;
        if (ok)
        {
          cout << cx << " " << cy << " " << hh << endl;
          return 0;
        }
      }
    }

  return 0;
}


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

int main () 
{
    int n;
    std::cin >> n;
    
    int a[n];
    for (int i = 0; i < n; i++) 
    {
        std::cin >> a[i];
    }
    
    sort(a, a+n);
    long int sum = 0;
    
    for (int i = 0; i < n; i++) 
    {
        sum += a[i];
    }
    
    std::cout << a[0] << " " << a[n-1] << " " << sum << std::endl;
    
    return 0;
}


Measured memory_bytes: 3140
#include<cstdio>
void rotatez(int *dice) {
	int tmp = dice[1];
	dice[1] = dice[2];
	dice[2] = dice[4];
	dice[4] = dice[3];
	dice[3] = tmp;
}
void rotatex(int *dice) {
	int tmp = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = tmp;
}
void rotatey(int *dice) {
	int tmp = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = tmp;
}
bool equaldice(int *dice1, int *dice2) {
	for (int i = 0; i < 6; i++) {
		if (dice1[i] != dice2[i])return false;
	}
	return true;
}
bool samedice(int *dice1, int *dice2) {
	int i,j;
	for (i = 0; i < 4; i++) {
		if (equaldice(dice1, dice2))return true;
		rotatez(dice2);
	}
	rotatex(dice2);
	for (j = 0; j < 4; j++) {
		for (i = 0; i < 4; i++) {
			if (equaldice(dice1, dice2))return true;
			rotatez(dice2);
		}
		rotatey(dice2);
	}
	rotatex(dice2);
	for (i = 0; i < 4; i++) {
		if (equaldice(dice1, dice2))return true;
		rotatez(dice2);
	}
	return false;	
}
int main() {
	int dice[2][6], i, j;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 6; j++) {
			scanf("%d", &dice[i][j]);
		}
	}
	if (samedice(dice[0], dice[1]))printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 2616
N = int(input())
BA = BX = XA = ans = 0
for _ in range(N):
    s = input()
    for i in range(len(s)-1):
        if s[i:i+2] == "AB":
            ans += 1
    if s[0] == "B" and s[-1] == "A":
        BA += 1
    elif s[0] == "B":
        BX += 1
    elif s[-1] == "A":
        XA += 1
ans += min(BX, XA) + (BA if (BX+XA) else max(BA-1, 0))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
int xr=0,yr=1e9;
int res=0;
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		xr=max(xr,x);
		yr=min(yr,y);
	}
	cout <<max(0,yr-xr+1);
	return 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)
x << 0
x.sort!

res = 10 ** 14
cur = x.bsearch_index {|y| y >= 0 }

k.step(n) do |i|
  if cur < i - k || cur > i
    next
  end

  dist = [res]
  dist << x[i].abs + (x[i] - x[i - k]).abs
  dist << x[i - k].abs + (x[i] - x[i - k]).abs
  res = dist.min
end
puts res

Measured memory_bytes: 23024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 1e5 + 50;
const int MOD = 1e9 + 7;
int x[MAXN];

inline int add(int x, int y) { x += y; if(x >= MOD) x -= MOD; return x; }
inline int mul(int x, int y) { return 1ll * x * y % MOD; }

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
		scanf("%d", &x[i]);
	int ans = 1;
	int loc = 1;
	for(int i = 1; i <= N; i++) {
		if(x[i] < loc) {
			ans = mul(ans, loc / 2 + 1);
		}
		else
			loc += 2;
	}
	loc /= 2;
	for(int i = 1; i <= loc; i++)
		ans = mul(ans, i);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 764
//##MohK
//10/2/2020 .... 10,28
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    set<char>x;
    int c=a.size();
    for(int i=0;i<a.size();i++){
        x.insert(a[i]);
    }
    if(a.size()==x.size()){
        cout<<"yes"<<endl;
    }
    else cout<<"no"<<endl;


return 0;
}


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

using namespace std;


/*
    FILE *f=fopen("data.txt","w");
    fprintf(f,);
    fclose(f);
*/

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)
#define scan(a) scanf("%d",&a)
#define scanll(a) scanf("%lld",&a)
#define print(a) printf("%d\n",a)
#define printll(a) printf("%lld\n",a)
#define stll(a) stoll(a,nullptr,10)
#define PII pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define EL printf("\n")
#define ff first
#define ss second

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll a,b;
    cin>>a>>b;
    b=b*2;
    if(a<=b)
        cout<<0<<endl;
    else cout<<a-b<<endl;

}






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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n,m; cin >> n >> m;
    if(n == 0) break;

    vi h(n+1), w(m+1);
    h[0] = w[0] = 0;
    rep(i,n) cin >> h[i+1];
    rep(i,m) cin >> w[i+1];

    rep(i,n) h[i+1] += h[i];
    rep(i,m) w[i+1] += w[i];

    map<int,int> mph, mpw;
    rep(i,n) rep(j,n-i)
      mph[h[j + i + 1] - h[j]]++;
    rep(i,m) rep(j,m-i)
      mpw[w[j + i + 1] - w[j]]++;

    int ans = 0;
    for(auto x : mph){
      auto y = mpw.find(x.fst);
      if(y != mpw.end()) ans += x.snd * y->snd;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 38784
#include <bits/stdc++.h>
#define int long long
#define get djsiuao
using namespace std;

const int mod = 1000000007;
int n;
int dp[4014][4014];
int get[4014][4014];
int a[200005], b[200005];
int ans=0;

int binpow(int n, int k)
{
	int ans=1, cac=n;
	while(k)
	{
		if(k%2==1)
		{
			ans*=cac;
			ans%=mod;
		}
		cac=cac*cac;
		cac%=mod;
		k/=2;
	}
//	cout<<ans;
	return ans;
}

signed main()
{
//	cout<<binpow(2, mod-2);
	cin>>n;
	dp[1][1]=1;
	for(int i=1; i<=4003; i++)
	{
		for(int j=1; j<=4003; j++)
		{
			dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=mod;
		}
	}
	for(int i=1; i<=n; i++)
	{
		cin>>a[i]>>b[i];
		ans+=(mod-dp[a[i]*2+1][b[i]*2+1]);
		ans%=mod;
	}
	memset(dp, 0, sizeof(dp));
	for(int i=1; i<=n; i++)
	{
		dp[2002-a[i]][2002-b[i]]++;
		get[2002+a[i]][2002+b[i]]++;
	}
	for(int i=1; i<=4010; i++)
	{
		for(int j=1; j<=4010; j++)
		{
			dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=mod;
			ans+=get[i][j]*dp[i][j];
			ans%=mod;
		}
	}
	cout<<(ans*binpow(2, mod-2))%mod;
}

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

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

int main(){
  long long n;
  cin >> n;
  string ans="";
  long long k=1;
  long long div;
  while(true){
    div = pow(2,k);
    if(n%div == 0){
      ans = "0"+ans;
    }
    else{
      ans = "1"+ans;
      n -= pow(-2,k-1);
    }
    k += 1;
    if (n == 0) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

        return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func permutations(n int) []int {
	var helper func([]int, int)
	res := []int{}
	arr := make([]int, n)
	for i := 1; i <= n; i++ {
		arr[i-1] = i
	}
	// fmt.Printf("arr:%+v", arr)

	helper = func(arr []int, n int) {
		if n == 1 {
			// tmp := make([]int, len(arr))
			// copy(tmp, arr)
			tmp := 0
			for i := 0; i < len(arr); i++ {
				tmp = tmp*10 + arr[i]
			}
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func getidx(all []int, target int) int {
	for i := 0; i < len(all); i++ {
		if target == all[i] {
			return i
		}
	}
	return 0
}

func C(n int, p int, q int) int {
	r := 0
	all := permutations(n)
	sort.Ints(all)
	// fmt.Printf("all: %v\n", all)
	// fmt.Printf("%v\n", all)
	a := getidx(all, p)
	b := getidx(all, q)
	// fmt.Printf("a:%d, b:%d\n", a, b)
	if a > b {
		r = a - b
	} else {
		r = b - a
	}
	return r
}

func main() {
	var n int
	var p int
	var q int
	var t int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &t)
		p = p*10 + t
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &t)
		q = q*10 + t
	}

	r := C(n, p, q)
	fmt.Printf("%d\n", r)
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

long long Max = -INF;

int main(){
    int W, H, N; cin >> W >> H >> N;
    bool Map[W][H];
    memset(Map, false, sizeof(Map));

    for(int i = 0; i < N; i++){
        int x, y, a; cin >> x >> y >> a;
        if(a == 1){
            for(int j = 0; j < x; j++){
                for(int k = 0; k < H; k++) Map[j][k] = true;
            }
        }
        else if(a == 2){
            for(int j = x; j < W; j++){
                for(int k = 0; k < H; k++) Map[j][k] = true;
            }
        }
        else if(a == 3){
            for(int j = 0; j < W; j++){
                for(int k = 0; k < y; k++) Map[j][k] = true;
            }
        }
        else {
            for(int j = 0; j < W; j++){
                for(int k = y; k < H; k++) Map[j][k] = true;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < W; i++){
        for(int j = 0; j < H; j++)if(Map[i][j])ans++;
    }
    cout << H*W - ans << endl;
}

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

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll ans = 0;
    for(int i=1;i<n;i++){
        if(a[i] < a[i-1]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
    if(abs(a-b) <= k && abs(a-c) <= k && abs(a-d) <= k && abs(a-e) <= k && abs(b-c) <= k && abs(b-d) <= k && abs(b-e) <= k && abs(c - d) <= k && abs(c-e) <= k && abs(d-e) <= k) OUT("Yay!");
    else OUT(":(");

    return 0;
}

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

int main() {

    int n;

    cin >> n;

    int ans = 5000000;

    while(n--){
        int a;

        cin >> a;

        int count = 0;
        while(a%2 == 0){
            a/=2;
            count++;
        }

        ans = min(ans,count);

    }

    cout << ans << endl;

    return 0;
}

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

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

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}




using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    
    int n = s.size(),m = t.size();

    vector<vector<int>> dp(3100,vector<int> (3100));

    for(int i = 0;i<=n;i++){
        for(int j=0; j<=m;j++){
            if(i == 0 || j == 0){
                dp[0][0] = 0;
                continue;
            }

            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]){
                dp[i][j] = max(dp[i-1][j-1]+1 , dp[i][j]);
            }
             
        }
       
    }

    string ans = "";
    while (n > 0 && m >0){
        if(dp[n][m] == dp[n-1][m]) n--;
        else if(dp[n][m] == dp[n][m-1]) m--;
        else {
            ans += s[n-1];
            n--; m--;
        } 
    }
    REVERSE(ans);
    cout<< ans <<endl;
}





Measured memory_bytes: 40940
#include <stdio.h>
#define NOT_FOUND -1

int binarySearch(int *,int );

int n,q;

int main(){
  int i,x=0,z;
  int s[100000],t[50000];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
 
  scanf("%d",&q);

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

  for(i=0;i<q;i++){
    z = binarySearch(s,t[i]);
    if(z != NOT_FOUND) x++;
  }

  printf("%d\n",x);
  
  return 0;
}

int binarySearch(int *s,int t)
{
  int left,right,mid;
  
  left = 0;
  right = n;
  while(left < right){
    mid = (left + right) / 2;
    if(s[mid] == t) return mid;
    else if(t < s[mid]) right = mid;
    else left = mid + 1;
  }
  return NOT_FOUND;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
 
 
 
 
 
int main() {
 
 int A=0,B=0;
  
  int n,m;
  cin>>n;
  
  int a[n];
  for(int i=0;i<n;i++)
      cin>>a[i];
  
     sort(a, a+n);
     reverse(a,a+n);
  
      for(int i=0;i<n;i++)
      {
         if(i%2==0)
         {
           A+=a[i];
         }
         else{
           B+=a[i];
         }
      }
  
  
   cout<<A-B<<endl;
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/22/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int H,W,K; cin>>H>>W>>K;
  vector<string> choco(H); for(auto& l : choco) cin>>l;
  vector<vector<int>> acc(H, vector<int>(W, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i > 0) acc[i][j] = acc[i-1][j];
      if (i > 0 and j > 0) acc[i][j] -= acc[i-1][j-1];
      if (j > 0) acc[i][j] += acc[i][j-1];
      acc[i][j] += choco[i][j]=='1';
    }
  }
  auto sum = [&](int x0, int y0, int x1, int y1) {
    auto res = acc[x1][y1];
    if (x0 > 0)
      res -= acc[x0-1][y1];
    if (y0 > 0)
      res -= acc[x1][y0-1];
    if (x0 > 0 and y0 > 0)
      res += acc[x0-1][y0-1];
    return res;
  };

  int ans = (H-1)+(W-1);
  for (int i = 0; i < (1<<(H-1)); i++) {
    vector<int> vl={0};
    for (int k = 0; k < H-1; k++) {
      if (i&(1<<k)) {
        vl.push_back(k+1);
      }
    }
    vl.push_back(H);
    int d = vl.size()-2;
    auto solve = [&](int left, int right) {
      for (int k = 0; k < vl.size()-1; k++) {
        if (sum(vl[k], left, vl[k+1]-1, right-1) > K)
          return false;
      }
      return true;
    };
    int l = 0;
    for (int r = 0; r <= W; r++) {
      if (not solve(l, r)) {
        l = r-1;
        if (not solve(l, r)) {
          d = ans;
          break;
        }
        d++;
      }
    }
    ans = min(ans, d);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k;
	cin >> k;
	if(k%10==9||(k/10)%10==9){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    if(__builtin_popcountll(N) == 1)return 0 & puts("No");
    puts("Yes\n1 2");
    for(unsigned long i = 2; i < N; i += 2)cout << i << " " << i + 1 << "\n" << i + 1 << " " << N + 1 << "\n" << N + 1 << " " << N + i << "\n" << N + i << " " << N + i + 1 << endl;
    if(N % 2 == 0)cout << N << " " << N + (N & -N) << "\n" << ((N & -N) ^ 1 ^ N) << " " << 2 * N << endl;
    return 0;
}

Measured memory_bytes: 2816
a,c,b,d = map(int,input().split())
 
def cmald(a,b,c,d):
  while True:
    b-=c
    if b<=0:
      print("Yes")
      return 
    a-=d
    if a<=0:
      print("No")
      return 
    
cmald(a,b,c,d)

Measured memory_bytes: 61624
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> loop;
    loop.push_back(0);
    vector<int> visited(n, 0);
    int idx = 0;
    int now = 0;
    ll cnt = k;
    while(cnt > 0){
        //cout << now << endl;
        int next = a[now];
        if(visited[next] > 0){
            idx = next;
            cnt = 1;
            break;
        }
        loop.push_back(next);
        visited[next]++;
        now = next;
        cnt--;
    }

    if(cnt == 0){
        cout << now + 1 << endl;
        return 0;
    }

    reverse(all(loop));
    cnt = 0;
    while(loop.back() != idx){
        cnt++;
        loop.pop_back();
    }

    reverse(all(loop));

    k -= cnt;

    ll m = k % loop.size();

    cout << loop[m] + 1 << endl;
}


Measured memory_bytes: 6664
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main(){
	int N,M;
	cin>>N>>M;
	int k;
	int tmp;
	vector<int>s;
	vector<int>p;
	for(int i=0;i<M;++i){
		cin>>k;
		int tmp1=0;
		for(int j=0;j<k;++j){
			cin>>tmp;
			tmp1+=pow(2,tmp-1);
		}
		s.push_back(tmp1);
	}
	for(int i=0;i<M;++i){
		cin>>tmp;
		p.push_back(tmp);
	}
	/*
	for(int i=0;i<s.size();++i){
		cout<<s[i]<<endl;
	}
	*/
	int ans=0;
	for(int i=0;i<pow(2,N);++i){
		//cout<<i<<endl;
		int tmp3;
		bool yey=true;
		for(int j=0;j<s.size();++j){
			int tmp2=0;
			tmp3 = i&s[j];
			for(int l=1;l<=N;++l){
				if(tmp3>=pow(2,N-l)){
					tmp2++;
					tmp3 -= pow(2,N-l);
				}
			}
			//cout<<tmp2<<endl;
			if(tmp2%2!=p[j]){
				yey=false;
				break;
			}
		}
		if(yey==true){
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
bool kaibun(string s){
    string r = s;
    reverse(r.begin(),r.end());
    
    bool kaibun = true;
    for(int i =0; i<(s.size()/2)+1; i++){
        if(r[i] != s[i]){
            kaibun = false;
            return kaibun;
        }
    } 
    return kaibun;
}

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

    bool ans = false;
    ans = kaibun(s);
    if(ans){
        string s2;
        rep(i,(s.size()-1)/2){
            s2 += s[i];
        }
        ans = kaibun(s2);
    }
    if(ans){
        string s3;
        repr(i,(s.size()+3)/2-1,s.size()){
            s3 += s[i];
        }
        ans = kaibun(s3);
    }
    if(ans)cout << "Yes" << endl;
    else cout <<"No" << endl;

}

Measured memory_bytes: 256
int main(void)
{
    char c;
    int i;
    int ctr = 0;
    
    for(i=0; i<4; i++)
    {
        scanf("%c", &c);
        
        if(c == '+')
            ctr++;
        else
            ctr--;
    }
    
    printf("%d\n", ctr);

    //system("pause");
    
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var (
		N int
		s string
	)
	fmt.Scan(&N)
	nakami := make(map[string]int, N+10)

	for i := 0; i < N; i++ {
		fmt.Scan(&s)
		nakami[s] = i
	}
	fmt.Println(len(nakami))

}

Measured memory_bytes: 17772
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<int> a(30,0);
	for(long i=0;i<s.size();i++){
		int code=(int)s[i]-(int)'a';
		a[code]++;
	}
	
	for(int i=0;i<30;i++){
		if(i==26){
			cout << "None" << endl;
			return 0;
		}
		if(a[i]==0){
			char ans=i+'a';
			cout << ans << endl;
			return 0;
		}
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  long long int n;
  cin>>n;
  long long int arr[(n+1)];
  long long int c[n];
  memset(arr,0,sizeof(arr));
  for(int i =0;i<n;i++)
  { 
    cin>>c[i];
    arr[(c[i])]++;
  }
  long long int ans =0;
  for(int i =1;i<=n;i++)
  {
    ans += (arr[i]*(arr[i]-1))/2; 
  }
  long long int k;long long int val;
  for(int i =0;i<n;i++)
  {
       k = arr[c[i]];
      val= ans-(k*(k-1))/2;
      val+= ((k-1)*(k-2))/2;
    cout<<val<<endl;
  }
}


Measured memory_bytes: 5760
//************************
//*  Date: 2018.8.3      *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

double k;
string s;

int main()
{
	cin>>s>>k;
	rep(i,s.size())
	{
		if(s[i]!='1'&&(double)(i+1)<=k)
		{
			cout<<s[i]<<endl;
			rt0;
		}
	}
	cout<<1<<endl;
	rt0;
}

Measured memory_bytes: 256
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimize("02")
using namespace std;
using ll =long long ;
const ll maxn=1e5+5;
ll n,a[maxn],ans;
map <ll,ll> mp;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]=i;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if((abs(i-mp[a[i]]))%2==1){
			ans++;
		}
	}
	cout<<ans/2;
}


Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e4+10,INF=0x3f3f3f3f;
int h,n,a,b,dp[N];
int main()
{
	scanf("%d%d",&h,&n);
	memset(dp,INF,sizeof dp);
	dp[0]=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		for(int j=a;j<N;++j)
		dp[j]=min(dp[j],dp[j-a]+b);
	}
	int ans=INF;
	for(int i=h;i<N;++i)
	ans=min(ans,dp[i]);
	printf("%d\n",ans);
	return 0;
} 

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

//BEGIN CUT HERE
template <typename T>
T isPrime(T x){
    if(x <= 1) {
        // 0，1は素数じゃない
        return 0;
    } else if (x == 2) {
        // 2は素数
        return 1;
    } else if (x%2 == 0) {
        // 偶数は除く
        return 0;
    } else {
        // 偶数は２で割り切れるため除く
        for(T i = 3; i*i <= x; i+=2) {
            if(x%i == 0) return 0;
        }
        return 1;
    }
}
//END CUT HERE

// verified AOJ: ALDS1_1_C
int main() {
    ll N, num, sum = 0;
    cin >> N;
    
    for (int i = 0; i < N; ++i) {
        cin >> num;
        sum += isPrime(num);
    }
    
    cout << sum << "\n";
    
    return 0;
}



Measured memory_bytes: 3080
n, m, k = map(int, input().split())
li = []
for t in range(n):
    li.append(list(map(int, input().split())))
price_list = []
for bit in range(1, 2**n):
    index_list = []
    for i in range(n):
        if bit & 1<<i:
            index_list.append(i)

    c = 0
    for t in range(1,m+1):
        s = 0
        for i in index_list:
            s += li[i][t]
        if s >= k:
            c += 1

    if c == m:
        p = 0
        for i in index_list:
            p += li[i][0]
        price_list.append(p)

if len(price_list):
    print(min(price_list))
else:
    print('-1')
        


Measured memory_bytes: 9300
import sys

N = int(input())
p = list(map(int, input().split()))
checker = p.pop(0)
l = []
for pp in p:
    if checker > pp:
        l.append(pp)
    checker = pp
    
if len(l) == 0:
    print('YES')
    sys.exit()    
    
if len(l) == 2:
    temp_p = p[:]
    temp_p[p.index(l[0])] = l[1]
    temp_p[p.index(l[1])] = l[0]
    checker = temp_p.pop(0)
    for pp in temp_p:
        if pp < checker:
            print('NO')
            sys.exit()
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int s(int n) {
    if (n == 0) return 0;
    return n % 10 + s(n / 10);
}

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

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    total = sum(A)
    right = [0] * N
    left = [0] * N

    left[0] = A[0]
    for i in range(N - 1):
        left[i + 1] = A[i + 1] + left[i]

    right[N - 1] = A[N - 1]
    for i in range(N - 1, 0, -1):
        right[i - 1] += A[i - 1] + right[i]
    
    mi = float("inf")
    for i in range(N - 1):
        mi = min(mi, abs(left[i] - right[i + 1]))
    
    print(mi)


if __name__ == '__main__':
    main()



Measured memory_bytes: 32012
# 入力
a_I, a_O, a_T, a_J, a_L, a_S, a_Z = map(int, input().split())

# 使用するテトロミノはI, O, J, L型のみ
R = ((a_I % 2 + a_J % 2 + a_L % 2) >= 2) and min(a_I, a_J, a_L) >= 1
ans = a_O + 2 * ((a_I - R) // 2) + 2 * ((a_J - R) // 2) + \
    2 * ((a_L - R) // 2) + 3 * R

# 出力
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
	string s;
	cin>>s;
	int a=1001;
	int b=1001;
	REP(i,s.size()){
	    if(s[i]=='C'){
	       a=i;
	       break;
	    }
	}
	REP(i,s.size()){
	    if(s[i]=='F'){
	       b=i;
	    }
	}
	if(a<b&&a<200&&b<200){
	   cout<<"Yes"<<endl;
	}else{
           cout<<"No"<<endl;
        }
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;


#define ll                  long long
#define scl(n)              scanf("%lld",&n)
#define scll(n, m)              scanf("%lld%lld",&n, &m)
#define scc(c)	            scanf("%c",&c)
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
#define pfl(x)              printf("%lld\n",x)
#define pb                  push_back
#define debug               cout<<"I am here"<<endl;
#define pno                 cout<<"No"<<endl
#define pys                 cout<<"Yes"<<endl
#define tcas(i,t)           for(ll i=1;i<=t;i++)
#define all(x) 	            (x).begin(), (x).end()
#define pr                  pair<ll, ll>
#define ff                  first
#define ss                  second

#define l(s)                s.size()
#define asort(a)            sort(a,a+n)
#define dsort(a)            sort(a,a+n,greater<int>())
#define vasort(v)           sort(v.begin(), v.end());
#define vdsort(v)           sort(v.begin(), v.end(),greater<int>());
#define uniquee(x)          x.erase(unique(x.begin(), x.end()),x.end())
#define pn                  printf("\n")
#define el                  cout<<endl
#define md                  1000000007
#define inf                 9e18
#define ps                  cout<<" ";
#define Pai                  acos(-1.0)
#define mem(a,i)            memset(a, i, sizeof(a))
#define pcas(i)             cout<<"Case "<<i<<": "<<endl;
#define fast 	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define N 200006

char ans[5];
ll v[5];

bool pal(string s)
{
    string t = s;
    reverse(all(t));
    return s == t;
}
int main()
{
     ll i , j , n, m;
     string s, t, u;
    cin>>s,t=s.substr(0,(s.size()-1)/2),u=s.substr((s.size()+1)/2);

    if(t==u )pys;
    else pno;

    //cout<<t<<" "<<u<<endl;
return 0;
}

/// **************************Before submit****************************

///    ****Please check all base case output  and printing " YES or NO " ***
///    *check for integer overflow,array bounds
///    *check for n=1




Measured memory_bytes: 3636
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    for (int row_a = 0; row_a <= H; row_a++) {
        int row_w_a = H - row_a;
        for (int col_b = 0; col_b <= W; col_b++) {
            int col_h_b = W - col_b;
            if (A * row_a + (W - A) * row_w_a == B * col_b + (H - B) * col_h_b) {
                vector<string> ans(H, string(W, '0'));
                typedef pair<int, int> pii;
                vector<pii> col_list;
                for (int i = 0; i < W; i++) {
                    int left = i < col_b ? B : H - B; 
                    col_list.push_back(pii(-left, i));
                }
                for (int i = 0; i < H; i++) {
                    int left = i < row_a ? A : W - A;
                    sort(col_list.begin(), col_list.end());
                    for (int j = 0; j < left; j++) {
                        ans[i][col_list[j].second] = '1';
                        col_list[j].first += 1;
                    }
                }

                for (int i = 0; i < H; i++) {
                    cout << ans[i] << endl;
                }
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 2304
//TODO
//#include "debug.h"
#include <iostream>
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 12

int n, m;
char g[MAXN][MAXN+1];
char t[MAXN+1];

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	for (int i=0; i<n; i++)
		scanf("%s", g[i]);
	return 1;
}

void init() {
}

string col_str(int j) {
	for (int i=0; i<n; i++) t[i] = g[i][j];
	t[n] = '\0';
	return string(t);
}

int check() {
	multiset<string> ss;
	for (int j=0; j<m; j++) ss.insert(col_str(j));
	int first = 1;
	while (ss.size()>0) {
		auto p = ss.begin();
		string s = *p, r = s;
		reverse(r.begin(), r.end());
		ss.erase(p);
		auto q = ss.find(r);
		if (q==ss.end()) {
			if (m%2==0) return 0;
			if (!first || r != s) return 0;
			first = 0;
		}
		else ss.erase(q);
	}
	//for (int i=0; i<n; i++) printf("%s\n", g[i]);
	return 1;
}

void swap_str(int i, int j) {
	if (i==j) return;
	strcpy(t, g[i]);
	strcpy(g[i], g[j]);
	strcpy(g[j], t);
}

int srch(int p) {
	if (p==n/2) {
		return check();
	}
	int q = n-1-p;
	for (int i=p+1; i<=q; i++) {
		swap_str(i,q);
		if (srch(p+1)) return 1;
		swap_str(i,q);
	}
	return 0;
}

int solve() {
	if (n%2) {
		int mid = n/2;
		for (int i=0; i<n; i++) {
			swap_str(i,mid);
			if (srch(0)) return 1;
			swap_str(i,mid);
		}
		return 0;
	}
	else return srch(0);
}

void output(int ans) {
	printf("%s\n", ans? "YES":"NO");
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
	}
}




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

using namespace std;

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

    int cnt=0;

    for(int i=0;i<s.length()-2;i++){
        if(s.substr(i,3)=="ABC"){
            cnt+=1;
        }
    }
    cout << cnt << endl;
}

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

int main(){
	int N, x[370], y[370], b[370], p[370], a[370];

	cin>>N;

	for(int i = 0; i < N; i++){
		cin>>x[i]>>y[i]>>b[i]>>p[i];
		if(b[i] >= 5 && p[i] >= 2){
			a[i] = (x[i] * b[i] + y[i] * p[i]) * (8.0/10.0);
		}else if((x[i] * b[i] + y[i] * 2) * (8.0/10.0) < x[i] * b[i] + y[i] * p[i] && p[i] < 2 && b[i] >= 5){
			a[i] = (x[i] * b[i] + y[i] * 2) * (8.0/10.0);
		} else if((x[i] * 5 + y[i] * p[i]) * (8.0/10.0) < x[i] * b[i] + y[i] * p[i] && b[i] < 5 && p[i] >= 2){
			a[i] = (x[i] * 5 + y[i] * p[i]) * (8.0/10.0);
		} else{
			a[i] = x[i] * b[i] + y[i] * p[i];
		}
	}

	for(int i = 0; i < N; i++){
		cout<<a[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2020;
const LL S=1e10;

void GG(){
	puts("-1");
	exit(0);
}

LL lens[N];

void solve(LL l,LL cx,LL cy,LL x,LL y){
	LL len=lens[l];
	// cerr<<endl<<len<<"\t"<<cx<<'\t'<<cy<<'\t'<<x<<"\t"<<y<<endl;
	if(l==0){
		assert(cx==x);
		assert(cy==y);
		return;
	}
	LL dx=x-cx,dy=y-cy;
	if(dx+dy>0){
		if(dx-dy>0){//R
			putchar('R');
			solve(l-1,cx+len,cy,x,y);
		}else{//U
			putchar('U');
			solve(l-1,cx,cy+len,x,y);
		}
	}else{
		if(dx-dy>0){//D
			putchar('D');
			solve(l-1,cx,cy-len,x,y);
		}else{//L
			putchar('L');
			solve(l-1,cx-len,cy,x,y);
		}
	}
}

LL x[N],y[N];


int main(){
	int n;
	scanf("%d",&n);
	LL mr=0;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		mr=max(mr,abs(x[i])+abs(y[i]))+10;
	}
	int v=(x[0]+y[0])&1;
	for(int i=1;i<n;i++){
		if(((x[i]+y[i])&1)!=v)GG();
	}
	int m=1;
	lens[m]=1;
	LL rg=0;
	while(rg<mr){
		LL len=rg+1;
		rg=len*2-1;
		lens[++m]=len;
	}
	reverse(lens+1,lens+m+1);
	printf("%d\n",v?m+1:m);
	if(v)printf("1 ");
	for(int i=1;i<=m;i++){
		printf("%lld ",lens[i]);
	}
	printf("\n");
	reverse(lens+1,lens+m+1);
	for(int i=0;i<n;i++){
		if(v)printf("R");
		solve(m,0+v,0,x[i],y[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
X,K,D=input().split(' ')
x,k,d=abs(int(X)),int(K),int(D)

x_par=x%d
x_num=int((x-x_par)/d)

s=0
if x_num<=k:
  x_div=x-x_num*d
  k-=x_num
  if k%2==0:
    s=abs(x_div)
  else:
    s=x_div-d
else:
  s=x-d*k
print(abs(s))

Measured memory_bytes: 9196
n,a,b=map(int,input().split())
s=input()
ta=0
tb=0
for i in range(n):
    if s[i]=="c":
        print("No")
    elif s[i]=="a":
        if ta+tb<a+b:
            print("Yes")
            ta+=1
        else:
            print("No")
    elif s[i]=="b":
        if ta+tb<a+b and tb<b:
            print("Yes")
            tb+=1
        else:
            print("No")

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

long long a[100005];
long long n,minv=1e9+7,total=0;

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		if (abs(a[i])<minv)  minv=abs(a[i]);
		total+=abs(a[i]);
	}
	for (int i=1;i<=n-1;i++)
	{
		if (a[i]<0)
		{
			a[i]=-a[i];
			a[i+1]=-a[i+1];
		}
	}
	if (a[n]<0)  cout<<total-minv*2<<endl;
	else cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 1024