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

typedef complex<double> P;
typedef pair<double, P> C;
vector<C> circles;
#define FST first
#define SND second
typedef pair<P, P> S;
#define EPS (1e-5)

double dot(P a, P b) {
  return a.real()*b.real()+a.imag()*b.imag();
}

double cross(P a, P b) {
  return a.real()*b.imag()-a.imag()*b.real();
}

double distanceLP(S s, P a) {
  // d = |y||sin(th)| = |x||y|sin(th)/|x| = |cross(x, y)|/|x|
  return abs(cross(s.SND-s.FST, a-s.FST)) / abs(s.SND-s.FST);
}

double distanceSP(S s, P a) {
  // 2ベクトルのなす角が鈍角なら端点と１点との距離を返す
  if (dot(s.SND-s.FST, a-s.FST) < EPS) return abs(a-s.FST);
  if (dot(s.FST-s.SND, a-s.SND) < EPS) return abs(a-s.SND);
  
  return distanceLP(s, a);
}

int main() {
  int N;
  while(cin >> N && N) {
    circles.clear();
    circles.resize(N);
    for(int i=0; i<N; i++) {
      int x, y, r;
      cin >> x >> y >> r;
      circles[i] = C(r, P(x, y));
    }
    int Q; cin >> Q;
    while(Q--) {
      int x, y;
      cin >> x >> y; P taro(x, y);
      cin >> x >> y; P ogre(x, y);
      for(int i=0; i<N; i++) {
	if(distanceSP(S(taro, ogre), circles[i].SND) < circles[i].FST + EPS) {
	  if(   !(abs(circles[i].SND-taro) < circles[i].FST + EPS)
	     || !(abs(circles[i].SND-ogre) < circles[i].FST + EPS)) {
	    cout << "Safe" << endl;
	    goto EXIT;
	  }
	}
      }
      
      cout << "Danger" << endl;
      
    EXIT:;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1212
fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map { it.toInt() }
    
    // v1 -> v2なる長さdの辺があるとき、(v1, (v2, d))
    val edges = mutableMapOf<Int, MutableList<Pair<Int, Int>>>()

    for (i in 1..m) {
        val (l, r, d) = readInputLine().split(" ").map { it.toInt() }
        
        val e1 = edges.get(l) ?: mutableListOf<Pair<Int, Int>>()
        val e2 = edges.get(r) ?: mutableListOf<Pair<Int, Int>>()
        
        e1.add(Pair(r, d))
        e2.add(Pair(l, -d))
        
        edges.put(l, e1)
        edges.put(r, e2)
    }
    
    val tested = BooleanArray(n + 1)
    val pos = IntArray(n + 1)
    
    for (i in 1..n) {
        if (tested[i]) {
            continue
        }
        if (!dfs(i, edges, tested, pos)) {
            println("No")
            return
        }
    }
    println("Yes")
}

fun readInputLine(): String {
    return readLine()!!
}

fun dfs(i: Int, edge: Map<Int, List<Pair<Int, Int>>>, tested: BooleanArray, pos: IntArray): Boolean {
    tested[i] = true
    for ((v, d) in edge.get(i) ?: emptyList()) {
        if (tested[v]) {
            if (pos[v] - pos[i] != d) {
                return false
            }
        } else {
            pos[v] = pos[i] + d
            if (!dfs(v, edge, tested, pos)) {
                return false
            }
        }
    }
    
    return true
}


Measured memory_bytes: 146424
h,w,k = map(int,input().split())
c = []
for i in range(0,h):
    c.append(input())
def white(c,r,co):
    count = 0
    for i in range(0,h):
        for j in range(0,w):
            if r[i] != 0 and co[j] != 0 and c[i][j] == "#":
                count += 1            
    return count
import itertools
listr = list(itertools.product([0,1],repeat = h))
listc = list(itertools.product([0,1],repeat = w))
ans = 0
for i in range(0,2**h):
    for j in range(0,2**w):
        if white(c,listr[i],listc[j]) == k:
            ans += 1
print(ans)

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// 約数の列挙
vector<ll> divisor(ll n)
{
	vector<ll> res;

	for (ll i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			res.push_back(i);
			if (i != n / i)
				res.push_back(n / i);
		}
	}

	return res;
}

vector<ll> d;
int main()
{
	ll N, A, B;
	int Ac, Bc;
	Ac = Bc = 1;

	cin >> N;

	d = divisor(N);
	sort(d.begin(), d.end());

	if (d.size() % 2 == 0)
	{
		A = d[(int)(d.size() / 2) - 1];
		B = d[(int)(d.size() / 2)];
	}
	else
	{
		A = B = d[(int)(floor(d.size() / 2))];
	}

	while (true)
	{
		if (A / 10 > 0)
		{
			Ac++;
			A = (int)(A / 10);
		}
		else
			break;
	}
	while(true)
	{
		if (B / 10 > 0)
		{
			Bc++;
			B = (int)(B / 10);
		}
		else
			break;
	}

	cout << Bc << endl;

	return 0;
}

Measured memory_bytes: 256
def com(x,y):
    a=1
    b=1
    y=min(y,x-y)
    for i in range(x,x-y,-1):
        a*=i
    for i in range(1,y+1):
        b*=i
    return a//b

n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
from collections import Counter
c=Counter(b)
d=list(c.items())
ans=0
for t in d:
    if t[0]==0:
        ans+=com(t[1]+1,2)
    elif t[1]>1:
        ans+=com(t[1],2)
print(ans)

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<int> b(n), c(n);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i == j) continue;
            if(a[i] > a[j]) {
                ++c[i];
                if(i < j) ++b[i];
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        ans += (ll)b[i] * k % MOD + (ll)k * (k - 1) / 2 % MOD * c[i] % MOD;
        ans %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > contact[51];
bool u[51]={false};
void dfs(int a,int b)
{
	u[a]=true;
	for(int i=0;i<contact[a].size();i++)
	{
		if(!u[contact[a][i].first]&&contact[a][i].second!=b)
		{
			dfs(contact[a][i].first,b);
		}
	}
	return;
}
int main()
{
	int m,n;
	cin>>n>>m;
	int a[51],b[51];
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		contact[a[i]].push_back(make_pair(b[i],i+1));
		contact[b[i]].push_back(make_pair(a[i],i+1));
	}
	int ans=0;
	bool is=true;
	for(int j=1;j<=m;j++)
	{
		is=true;
		dfs(1,j);
		for(int k=1;k<=n;k++)
		{
			if(u[k]==false)
			{
				is=false;
				break;
			}
		}
		if(is)
		{
			ans++;
		}
		memset(u,false,sizeof(u));
	}
	cout<<m-ans;
	return 0;
}

Measured memory_bytes: 256
Y, M, D = map(int, input().split("/"))

if Y < 2019:
    print("Heisei")
    exit()
if Y == 2019 :
    if M <= 4:
        print("Heisei")
        exit()
    if M == 4:
        if D <= 30:
            print("Heisei")
            exit()

print("TBD")

Measured memory_bytes: 3060
//
// Created by yjq on 2019/11/7.
//

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int maxn = 2e5 + 10;
int n, a[maxn], r[maxn];

int c[maxn];

const int cmp(const int i, const int j) {
    return a[i] < a[j];
}

inline int lb(int x) { return x & -x; }

int read(int x) {
    int tot = 0;
    for (; x; x -= lb(x))tot += c[x];
    return tot;
}

void add(int x, int num) {
    for (; x <= n; x += lb(x))c[x] += num;
}

int main() {
    __;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        r[i] = i;
    }
    sort(r + 1, r + 1 + n, cmp);
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        int x = r[i];
        int left = 1, right = x;
        while (left < right) {
            int mid = (left + right) >> 1;
            if (read(x) - read(mid - 1) == 0)right = mid;
            else left = mid + 1;
        }
        ll t1 = x - left + 1;
        left = x, right = n;
        while (left < right) {
            int mid = (left + right + 1) >> 1;
            if (read(mid) - read(x) == 0)left = mid;
            else right = mid - 1;
        }
        ll t2 = right - x + 1;
        ans += t1 * t2 * a[x];
        add(x, 1);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int A , B ;
	string s;
	
	cin>>A>>B>>s;
	int t = s.size();
	
	if( (A+B+1) !=t || s[A]!='-' ){
		cout<<"No"<<endl;
		return 0;
	}
	else{
		for( int i=0 ; i<t ; i++ ){
			if(i==A )
				continue;
			if( s[i]>='0' && s[i]<='9' )
				continue;
			else{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int cntE = 0;
    REP(i, n) if (a[i] % 2 == 0) cntE++;

    cout << pow(3, n) - pow(2, cntE) << '\n';
    return 0;
}

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


int main()
{
	int n;
	cin>>n;
	int arr[n+10];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(int i=n-1;i>0;i--)
	{
		if(arr[i-1]-arr[i]>1)
		{
			cout<<"No";
			return 0;
		}
		else
		{
			if(arr[i-1]>arr[i])
				arr[i-1]--;
		}
	}
	for(int i=0;i<n-1;i++)
	{
		if(arr[i]>arr[i+1])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const ll maxn = 1e6 + 5;
ll a,b,c,t,n,m,ans = INF,d,e,f;
ll num1[maxn],num2[maxn];
string str;
int main()
{
    cin >> a >> b >> m;
    for(int i = 1; i <= a; i++)
        cin >> num1[i];
    for(int i = 1; i <= b; i++)
        cin >> num2[i];
    for(int i = 1; i <= m; i++)
    {
        cin >> d >> e >> f;
        ans = min(ans,num1[d] + num2[e] - f);
    }
    sort(num1 + 1,num1 + a + 1);
    sort(num2 + 1,num2 + b + 1);
    ans = min(ans,num1[1] + num2[1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef long long lli;

const lli W = 17;
lli ten[W];
lli begin[W];

lli getA(string a, string b) {
  int n = a.size();
  for(int i = n-1, t = 1; i >= 0; --i) {
    if(a[i] == 'X') break;
    int d = (a[i]-'0') + t;
    a[i] = '0' + d % 10;
    t = d / 10;
  }
  for(int i = n-1; i >= 0; --i) {
    if(a[i] == 'X' && b[i] == 'X') {
      if(i == 0) a[i] = '1';
      else a[i] = '0';
    } else if(a[i] == 'X') {
      a[i] = b[i];
    } else if(b[i] == 'X') {
      //a[i] = a[i];
    } else if(a[i] == b[i]) {
      //a[i] = a[i];
    } else {
      return -1LL;
    }
  }
  return atoll(a.c_str()) - 1LL;
}

string toString(lli x) {
  stringstream ss;
  ss << x;
  string res;
  ss >> res;
  return res;
}

lli getPos(lli x) {
  if(x == 0) return 0;
  lli digits = 0;
  lli t = x;
  while(t) {
    ++digits;
    t /= 10;
  }
  lli dist = x - ten[digits-1];
  return begin[digits-1] + dist * digits;
}

int main() {
  // init
  ten[0] = 1;
  for(int i = 1; i < W; ++i) {
    ten[i] = ten[i-1] * 10LL;
  }
  begin[0] = 1;
  for(int i = 1; i < W; ++i) {
    begin[i] = begin[i-1] + i * (ten[i] - ten[i-1]);
  }

  string s;
  while(cin >> s && s != "#") {
    int N = s.size();
    vector<lli> as;
    vector<lli> bs;
    for(int m = 1; m <= N; ++m) {
      for(int L = m; L < W; ++L) {
        as.push_back(ten[L]-1LL);
        bs.push_back(L-m);

        string a = s.substr(0, m);
        string b = s.substr(m, min((int)s.size()-m, L));
        while(a.size() < L) a.insert(0, "X");
        while(b.size() < L) b += 'X';
        if(a[0] == '0' || b[0] == '0') continue;
        lli A = getA(a, b);
        if(A != -1LL) {
          as.push_back(A);
          bs.push_back(L-m);
        }
      }
    }

    lli res = 10000000000000001LL;
    for(int i = 0; i < as.size(); ++i) {
      string t;
      lli na = as[i];
      while((int)t.size()-bs[i] < (int)s.size()) {
        t += toString(na++);
      }
      if(t.substr(bs[i], s.size()) == s) {
        res = min(res, getPos(as[i]) + bs[i]);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
N,X=map(int,input().split())

a,p=[1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        if X>0:
            return 1
        else:
            return 0
    elif X==1:
        return 0
    elif X<=1+a[N-1]:
        return f(N-1,X-1)
    elif X==2+a[N-1]:
        return p[N-1]+1
    elif 2+a[N-1]<X<=2+2*a[N-1]:
        return p[N-1]+1+f(N-1,X-2-a[N-1])
    else:
        return 2*p[N-1]+1

print(f(N,X))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll N, M;
ll x[1010], y[1010], z[1010];
ll ans = 0;
ll t[1010];

int main() {
	cin >> N >> M;
	repi(i, 0, N) {
		cin >> x[i] >> y[i] >> z[i];
	}

	repi(I, 0, 2) {
		repi(J, 0, 2) {
			repi(K, 0, 2) {
				repi(i, 0, N) {
					ll tx, ty, tz;
					if (I == 0) {
						tx = x[i];
					}
					else {
						tx = -x[i];
					}

					if (J == 0) {
						ty = y[i];
					}
					else {
						ty = -y[i];
					}

					if (K == 0) {
						tz = z[i];
					}
					else {
						tz = -z[i];
					}

					t[i] = tx + ty + tz;
				}
				sort(t, t + N);
				ll tsum = 0;
				repi(i, 0, M) {
					tsum += t[N - 1 - i];
				}
				ans = max(ans, tsum);
			}
		}
	}

	wrln(ans);
	
	return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for _ in range(M):
        BC.append(tuple(map(int, input().split())))
    BC.sort(key=lambda x: x[1])
    vs = []; jtmp = 0
    for i in range(M):
        tmp = BC.pop()
        jtmp += tmp[0]
        if jtmp > N:
            vs.extend([tmp[1]]*(N-(jtmp-tmp[0])))
            break
        else:
            vs.extend([tmp[1]]*tmp[0])
    
    A.sort(reverse=True)
    vs.sort()
    ans = 0
    for _ in range(N):
        tmpA = A.pop()
        if len(vs) > 0:
            tmpC = vs.pop()
        else:
            tmpC = 0
        ans += tmpA*(tmpA>=tmpC) + tmpC*(tmpA<tmpC)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 22960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<(n);++i)
const ll MOD=1e9+7;
//const ll MOD=998244353;

struct LowestCommonAncestor{
    int n,h;
    vector<vector<int>> G,par;
    vector<int> dep;
    LowestCommonAncestor(int n):n(n),G(n),dep(n){
        h=1;
        while((1<<h)<=n) ++h;
        par.assign(h,vector<int>(n,-1));
    }
    void add_edge(int u,int v){
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    void dfs(int v,int p,int d){
        par[0][v]=p;
        dep[v]=d;
        for (int u:G[v]){
            if (u!=p) dfs(u,v,d+1);
        }
    }
    void build(int r=0){
        dfs(r,-1,0);
        for (int k=0;k<h-1;++k) for (int v=0;v<n;++v){
            if (par[k][v]>=0) par[k+1][v]=par[k][par[k][v]];
        }
    }
    int lca(int u,int v){
        if (dep[u]>dep[v]) swap(u,v);
        for (int k=0;k<h;++k){
            if ((dep[v]-dep[u])&1<<k) v=par[k][v];
        }
        if (u==v) return u;
        for (int k=h-1;k>=0;--k){
            if (par[k][u]!=par[k][v]) u=par[k][u],v=par[k][v];
        }
        return par[0][u];
    }
    int distance(int u,int v){
        return dep[u]+dep[v]-dep[lca(u,v)]*2;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    LowestCommonAncestor LCA(n);
    rep(i,n){
        int k; cin >> k;
        rep(j,k){
            int c; cin >> c;
            LCA.add_edge(i,c);
        }
    }
    LCA.build();
    int q; cin >> q;
    rep(i,q){
        int u,v; cin >> u >> v;
        cout << LCA.lca(u,v) << endl;
    }
}


Measured memory_bytes: 18372
#include<bits/stdc++.h>
using namespace std;
char a[100050],b[100050];
int c[128],nx[100050][26],mp[26];
int main()
{
	cin>>(a+1)>>(b+1);
	int n=strlen(a+1);
	int m=strlen(b+1);
	for(int i=1;i<=n;i++)c[a[i]]++;
	for(int i=1;i<=m;i++)if(!c[b[i]])return puts("-1"),0;
	for(int i=1;i<=n;i++)a[i]-='a';
	for(int i=1;i<=m;i++)b[i]-='a';
	for(int i=0;i<26;i++)mp[i]=n+1;
	for(int i=n;i>=0;i--)
	{
		for(int j=0;j<26;j++)nx[i][j]=mp[j];
		mp[a[i]]=i;
	}
	long long ans=0;
	int now=0;
	for(int i=1;i<=m;i++)
	{
		if(nx[now][b[i]]==n+1)
		{
			ans+=n-now;
			now=0;
		}
		ans+=nx[now][b[i]]-now;
		now=nx[now][b[i]];
	}
	cout<<ans;
}

Measured memory_bytes: 10624
#include<iostream>
using namespace std;
long long ans=0;
long long n;
void div(long long a)
{
	while(a%2==0)
	{
		a/=2;
		ans++;
	}
}
int main()
{
	cin>>n;
	for(long long i=1,a;i<=n;i++)
	{
		cin>>a;
		div(a);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//测试标程正确性，无意抄袭
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
string f[15];
 
bool forbid[15][15][15][15];
 
bool rec(int mask,vector<P>mch,bool ok){
	int yet = -1;
	for(int i=0;i<n;i++){
		if(!((mask>>i)&1)){
			yet = i; break;
		}
	}
	if(yet != -1){
		vector<int>zan;
		for(int i=yet+1;i<n;i++){
			if(!((mask>>i)&1)){
				zan.pb(i);
			}
		}
		{
			for(int i=0;i<zan.size();i++){
				int newmask = mask+(1<<yet)+(1<<zan[i]);
				mch.pb(mp(yet,zan[i]));
				if(rec(newmask,mch,ok)) return true;
				mch.pop_back();
			}
		}
		if(ok){
			int newmask = mask+(1<<yet);
			mch.pb(mp(yet,yet));
			if(rec(newmask,mch,false)) return true;
		}
		return false;
	}
	else{
		bool bad[15][15]={};
		for(int i=0;i<mch.size();i++){
			int a = mch[i].fi,b = mch[i].sc;
			for(int c=0;c<m;c++) for(int d=0;d<m;d++) bad[c][d] |= forbid[a][b][c][d];
		}
		bool okk[(1<<12)]={};
		okk[0] = true;
		for(int i=0;i<(1<<m);i++){
			if(okk[i] == false) continue;
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if( ((i>>j)&1) || ((i>>k)&1) ) continue;
					if(bad[j][k]) continue;
					if(__builtin_popcount(i) != m-1 && j==k) continue;
					okk[i | (1<<j) | (1<<k)] = true;
				}
			}
		}
		return okk[(1<<m)-1];
	}
}
int main(){
	cin>>n>>m;
	rep(i,n){
		cin>>f[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int a=0;a<m;a++){
				for(int b=0;b<m;b++){
					if(f[i][a] == f[j][b] && f[i][b] == f[j][a]);
					else{
						forbid[i][j][a][b] = true;
					}
				}
			}
		}
	}
	bool flag = rec(0,vector<P>(),n%2);
	puts(flag?"YES":"NO");
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
p = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():

    def combination(n, r, p):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n-r] % p

    N = 10 ** 6  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

    x, y = nm()

    if (x + y) % 3 != 0:
        print(0)
        exit()
    
    n = (2*y - x) // 3 # (X, Y) -> (X+1, Y+2) 
    m = (2*x - y) // 3 # (X, Y) -> (X+2, Y+1) 

    if n < 0 or m < 0:
        print(0)
        exit()

    print(combination(n+m, n, p))

if __name__ == '__main__':
    main()


Measured memory_bytes: 127572
using System;

class Program
{
    static void Main(string[] args)
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int n = input[0];
        int m = input[1];
        int[] ans = new int[n];
        int[] tmp;

        for (int i = 0; i < n; i++)
        {
            ans[i] = 0;
        }

        for (int i = 0; i < m; i++)
        {
            tmp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            ans[tmp[0] - 1]++;
            ans[tmp[1] - 1]++;
        }

        foreach (int i in ans)
        {
            Console.WriteLine(i);
        }

    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

int main(){
    int n ,m ;
    cin >> n >> m ;
    int a ;
    for (size_t i = 0; i < m; i++)
    {
        cin >> a ;
        n -= a ;
    }
    if (n < 0)
    {
        n = -1 ;
    }
    cout << n << endl ;
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;



int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int h,w;
    cin >>h>>w;
    vector<vector<int>> g(h,vector<int>(w));
    vector<vector<int>> ansv;

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >>g[i][j];
        }
    }

    for (int i = 0; i < h-1; i++){
        for (int j = 0; j < w; j++){
            if(g[i][j]%2==1){
                --g[i][j];
                ++g[i+1][j];

                vector<int> eans(4);
                eans[0]=i+1;
                eans[1]=j+1;
                eans[2]=i+2;
                eans[3]=j+1;

                ansv.emplace_back(eans);
                ++ans;

            }
        }
    }

    for (int j = 0; j < w-1; j++){
        if(g[h-1][j]%2==1){
                --g[h-1][j];
                ++g[h-1][j+1];
                
                vector<int> eans(4);
                eans[0]=h;
                eans[1]=j+1;
                eans[2]=h;
                eans[3]=j+2;

                ansv.emplace_back(eans);
                ++ans;

        }
    }
    
    
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    for(auto v:ansv){
        cout << v[0] <<" " <<v[1] <<" " <<v[2] <<" " <<v[3] <<endl;
    }

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

using namespace std;

int main(){

  string s;
  cin>>s;
  long long int count=0;

  for(int i=0; i<s.size()-1; i++){
    if(s[i]!=s[i+1]){
      count+=1;
    }
  }

  cout<<count<<endl;
}


Measured memory_bytes: 3748
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
    	Scanner scn = new Scanner(System.in);
    	int a = scn.nextInt();
      	int[] x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      	System.out.println(x[a-1]);
    }
}


Measured memory_bytes: 21588
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=1000010, Mod=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,m,fac[N+10],inv[N+10];
inline int ksc(int x,int p) { int res=1; for(;p;p>>=1, x=x*x%Mod) if(p&1ll) res=res*x%Mod; return res; }
inline int C(int x,int y) { if(x<y) return 0; return fac[x]*inv[x-y]%Mod*inv[y]%Mod; }
inline int A(int x,int y) { if(x<y) return 0; return fac[x]*inv[x-y]%Mod; }
signed main()
{
    n=read(), m=read();
    fac[0]=1;
    for(ri int i=1;i<=N;i++) fac[i]=fac[i-1]*i%Mod;
    inv[N]=ksc(fac[N],Mod-2);
    for(ri int i=N;i;i--) inv[i-1]=inv[i]*i%Mod;    
    int res=0;
    for(ri int i=0;i<=n;i++) res=(res+((i&1ll)?-1:1)*C(n,i)*A(m-i,n-i)%Mod+Mod)%Mod;
    res=res*A(m,n)%Mod;
    printf("%lld\n",res);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    string S[3];
    ll c = 0;
    cin >> S[0] >> S[1] >> S[2];
    while(!S[c].empty()) {
        ll temp = S[c][0] - 'a';
        S[c].erase(0, 1);
        c = temp;
    }
    cout << (char)('A' + c) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int a, b;
    cin >> a >> b;
    if (a <= 8 and b <= 8)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/dp_m

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = in.nextInt();
        }
        if(k==0) {
            out.println(1);
            return;
        }
        long[][] dp = new long[n+1][k+1];
        dp[0][0] = 1;
        long[][] p = new long[2][k+1];
        for(int i=0; i<=k; i++) {
            p[0][i] = 1;
        }
        // show("", dp[0], p[0]);
        for(int i=1; i<=n; i++) {
            for(int j=0; j<=k; j++) {
                int l = (i+1)%2;
                int x = Math.min(j, a[i]);
                dp[i][j] = p[l][j] - (j-x-1>=0 ? p[l][j-x-1] : 0);
                dp[i][j] = (dp[i][j]%MOD + MOD) %MOD;
                p[i%2][j] = (dp[i][j] + (j-1>=0?p[i%2][j-1]:0))%MOD;
            }
            // show("", dp[i], p[i%2]);
        }
        long rs = dp[n][k];
        out.println(rs%MOD);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 127200
import math
n = int(input())
ls = [0 for i in range(n)]
r = math.ceil(math.sqrt(n))

for x in range(1, r + 1):
    for y in range(1, r + 1):
        for z in range(1, r + 1):
            k = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if k <= n:
                ls[k - 1] += 1

for i in range(n):
    print(ls[i])


Measured memory_bytes: 9296
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for (iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  string s[10];
  s[0]="0111111";
  s[1]="0000110";
  s[2]="1011011";
  s[3]="1001111";
  s[4]="1100110";
  s[5]="1101101";
  s[6]="1111101";
  s[7]="0100111";
  s[8]="1111111";
  s[9]="1101111";
  
  int n;
  while(cin >> n && n!=-1) {
    string t="0000000";
    rep(j,n) {
      int x;
      cin >> x;
      rep(i,7) cout << !(t[i]==s[x][i]);
      cout << endl;
      t=s[x];
    }
  }
  return 0;
}


Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

  int ans;

  int dp[1000000];

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int a,b,x,y,z;
    cin >> x >> y >> z >> a >> b;

    int k = min(a,b);
    // trace5(x,y,z,a,b);
    // trace2(k*a+k*b,2*z*k);
    ans += min({k*x+k*y,2*z*k});

    //trace1(ans);
    int aa = max(a,b);

    a -= k;
    b -= k;

    ans += a*x + b*y;

   

    cout << min(ans,2*z*aa);

    return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, a, b;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
long long MOD = 1e9 + 7;
constexpr ll INF = 1e17;

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == s[i + 1]) {
            ans++;
        }
    }

    int max = n - 1;
    ans = std::min(max, ans + k * 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    int cnt = 0;
    ll num = INF;
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        if(A[i]<0) cnt++;
        num = min(num,abs(A[i]));
        sum += abs(A[i]);
    }
    if(cnt%2==0){
        cout << sum << endl;
    }else{
        cout << sum-num*2 << endl;
    }
    return 0;
}

Measured memory_bytes: 4056
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int INF = INT_MAX / 2;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct segment_tree {
	int n; vector<i_i> v;
	segment_tree(int _n = 1) {
		for (n = 1; n < _n; n *= 2);
		v = vector<i_i>(n * 2 - 1, i_i(-1, -1));
	}
	void set(int i, int x) {
		int k = i + n - 1;
		v[k] = i_i(x, i);
		while (k > 0) {
			k = (k - 1) / 2;
			v[k] = max(v[k * 2 + 1], v[k * 2 + 2]);
		}
	}
	i_i _get(int i, int j, int k, int l, int r) {
		if (r <= i || j <= l) return i_i(-1, -1);
		if (i <= l && r <= j) return v[k];
		i_i vl = _get(i, j, k * 2 + 1, l, (l + r) / 2);
		i_i vr = _get(i, j, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
	i_i get(int i, int j) { return _get(i, j, 0, 0, n); }
};

int N, K;
segment_tree st;
priority_queue<int> pq;
bool added[500000];

void f(int l) {
	int i = st.get(l, min(N, l + K)).second;
	if (i == -1) return;
	if (!added[i] && st.get(max(0, i - K + 1), min(N, i + K)).second == i) {
		pq.push(i), added[i] = true;
	}
}

int main() {
	cin >> N >> K;
	vector<int> a(N);
	for (int& x: a) scanf("%d", &x), x--;
	st = segment_tree(N);
	for (int i = 0; i < N; i++)
		st.set(i, a[i]);
	for (int l = 0; l < N; l += K) f(l);
	vector<int> ans(N);
	for (int t = N - 1; t >= 0; t--) {
		int i = pq.top(); pq.pop();
		ans[i] = t;
		st.set(i, -1);
		int l = i / K;
		f(l * K);
		if (l - 1 >= 0) f((l - 1) * K);
		if (l + 1 < (N + K - 1) / K) f((l + 1) * K);
	}
	for (int& x: ans) printf("%d\n", x + 1);
}


Measured memory_bytes: 18288
n = int(input())
p = list(map(int, input().split()))

a = [20001 * i for i in range(1, n + 1)]
b = [20001 * (n - i + 1) for i in range(1, n + 1)]

num = 0
for e in p:
    e -= 1
    b[e] += num
    num += 1

print(*a)
print(*b)


Measured memory_bytes: 6300
n = int(input())
dp = [[0]*3 for i in range(n)]
for i in range(n):
    if i == 0:
        a,b,c = map(int,input().split())
        dp[0] = [a,b,c]
    else:
        a,b,c = map(int,input().split())
        dp[i][0] = max(dp[i-1][1]+a, dp[i-1][2]+a)
        dp[i][1] = max(dp[i-1][0]+b, dp[i-1][2]+b)
        dp[i][2] = max(dp[i-1][0]+c, dp[i-1][1]+c)
print(max(dp[-1]))

Measured memory_bytes: 22816
import copy
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 10**9*15
for i in range(2**(N-1)):#2番~N番からK-1個選ぶ
    B = copy.copy(A)
    count = 0
    bit = 0
    for j in range(N-1):#A[1]~A[N-1]の内、選ばれるものの数
        bit = bit + (1&(i>>j))
    if(bit == K-1):#K-1個選ぶ
        for k in range(N-1):
            if(i>>k&1):
                if max(B[0:k+1]) >= B[k+1]:#シフト量+2番のビルが1番:B[0]~シフト量+1番:B[k]のビルより高く
                    dif =max(B[0:k+1])-B[k+1]+1
                    B[k+1] += dif#シフト量+2番目のビルを伸ばす
                    count += dif#コストをプラス
        ans = min(ans,count)
print(ans)
           


Measured memory_bytes: 9276
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	ll N; cin >> N;
	vector<ll> v( N );
	ll total = 0;
	rep( i, N )
	{
		cin >> v[i];
		total += v[i];
	}

	vector<ll> ans( N );
	ans[0] = total;
	for ( int i = 1; i < N; i += 2 )
	{
		ans[0] -= 2 * v[i];
	}

	for ( int i = 1; i < N; ++i )
	{
		ans[i] = 2 * v[i - 1] - ans[i - 1];
	}

	arep( it, ans )
		cout << it << " ";
	cout << endl;

	return ( 0 );
}


Measured memory_bytes: 2944
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int main(){
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<pair<int,int>> A;
  int i = 0;
  while(i < N){
    int j = i;
    while(i < N && S[i] ==S[j]) i++;
    A.pb({S[j] - '0',i-j});
  }
  vector<int> T(A.size()+1);
  for(int i = 0; i < A.size();i++) T[i+1] = T[i] + A[i].second;
  int ans = 0;
  for(int i = 0; i < A.size();i++){
    if(A[i].first == 0){
      int j = min<int>(A.size(),i+2*K);
      ans = max(ans,T[j]-T[i]);
    }else{
      int j = min<int>(A.size(),i+2*K+1);
      ans = max(ans,T[j] - T[i]);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1652
A, B, C, D = map(int, input().split())
takaq, takamod = divmod(C, B)
aoq, aomod = divmod(A, D)
if takaq < aoq:
    print('Yes')
elif takaq == aoq:
    if takamod > 0 and aomod == 0:
        print('No')
    else:
        print('Yes')
else:
    if takamod == 0 and aomod > 0:
        print('Yes')
    else:
        print('No')

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = (int)s.size();
    int count = 0;
    for (int i = 0; i < n; ++i) {
        count += s[i] == t[i];
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=(1<<18)+5,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,H,p[MAXN],tag[MAXN],ans,S[MAXN],iS[MAXN];
inline void Ins(int x,int Sum){Sum=1ll*Sum*S[p[x]]%Mod;for(int t=p[x];t;t>>=1)tag[t]=(tag[t]+Sum)%Mod;}
inline void Del(int x,int Sum){Sum=1ll*Sum*S[p[x]]%Mod;for(int t=p[x];t;t>>=1)tag[t]=(tag[t]-Sum+Mod)%Mod;}
inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
void Solve(int x,int l,int r){
	if(l==r){Ins(l,S[x]);return;}int mid=l+r>>1;
	Solve(x<<1,l,mid);
	Rep(i,mid+1,r){
		int Sum=1ll*S[i]*iS[x]%Mod*iS[x>>1]%Mod*p[i]%Mod;
		for(int t=p[i]>>1,las=0;t;t>>=1)Sum=1ll*Sum*t%Mod,ans=(ans+1ll*Sum*(tag[t<<1]+tag[t<<1|1]-las)%Mod*iS[t])%Mod,las=tag[t];
	}Rep(i,l,mid)Del(i,S[i]);
	Solve(x<<1|1,mid+1,r);
	Rep(i,l,mid)Ins(i,S[i]);
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	H=read();iS[0]=S[0]=1;
	Rep(i,1,(1<<H)-1)S[i]=1ll*S[i>>1]*i%Mod,iS[i]=Fp(S[i],Mod-2);
	Rep(i,(1<<H-1),(1<<H)-1)p[i]=read()+(1<<H-1)-1;
	Solve(1,1<<H-1,(1<<H)-1),cout<<ans<<'\n';
	return 0;
}




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

/*おかしい？
void cmin(int x, int y) {
  x=min(x, y);
  return;
}
*/

int main() {
  int N;
  int INF=1000000000;
  cin >> N;
  vector<int> h(N);
  vector<int> d(N);
  
  for (int i=0; i<N; i++) {
    cin >> h.at(i);
  }
  
  
  for (int i=0; i<N; i++) {
    d.at(i)=INF;
  }
  
  d.at(0)=0;
  
  for (int i=1; i<N; i++) {
    d.at(i)=min(d.at(i), d.at(i-1)+abs(h.at(i)-h.at(i-1)));
    if (i>1) {
      d.at(i)=min(d.at(i), d.at(i-2)+abs(h.at(i)-h.at(i-2)));
    }
  }
  
  cout << d.at(N-1) << endl;
  
}


Measured memory_bytes: 1024