akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
	int i,n,m,sum=0;
  string s;
  cin>>n>>m;
  vector<int> vec(n);
  for(i=0;i<n;i++) cin>>vec.at(i);
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(i=0;i<n;i++) sum += vec.at(i);
 if(vec.at(m-1)*4*m >=sum) s={"Yes"}; 
  else s={"No"};
  cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

void solve(ll N, ll W, vll v, vll w){
    //* complete search on the first half and record
    ll N2 = N/2;
    vector<pll> rec;
    rep(S, 1<<N2){
        ll sw=0, sv=0;
        rep(j, N2){
            if((S >> j) & 1 ) { //* Set S has 1 in j-th position from right
                sw += w[j];
                sv += v[j];
            }
        }
        rec.push_back(pll(sw, sv));
    }
    //* remove to make sure w <= w'  <==>  v <= v'
    sort(rec.begin(), rec.end());
    ll m=1;
    for(ll S=1; S < 1<<N2; S++){
        if(rec[m-1].second < rec[S].second){
            rec[m] = rec[S];
            m++;
        }
    }
    //* complete search for the rest half
    ll res = 0;
    rep(S, 1<<(N-N2)){
        ll sw = 0, sv=0;
        rep(j, N-N2){
            if(S >> j & 1){
                sw += w[N2+j];
                sv += v[N2+j];
            }
        }
        if(sw <= W){
            ll tv = (lower_bound(rec.begin(), rec.begin()+m, make_pair(W-sw, INF))-1) ->second;
            res = max(res, sv + tv);
        }
    }
    cout << res << endl;


}

int main(){
    ll N, W;
    cin >> N >> W;
    vll v(N), w(N);
    rep(i, N){
        scanf("%lld", &v[i]);
        scanf("%lld", &w[i]);
    }
    solve(N, W, move(v), move(w));
    return 0;
}


Measured memory_bytes: 19524
#include <cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n,a[105],x,ans=0;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=100;i++)
        if(a[i]) ans++;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    int x,a,b;
    while (scanf("%d %d %d",&x,&a,&b)!=EOF)
    {
        if((b-a)>x) printf("dangerous\n");
        else
        {
            if((b-a)<=x&&b>a)
                printf("safe\n");
            else
                printf("delicious\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    lint n, k, q;
    cin >> n >> k >> q;

    vector<lint> p(n, k - q);
    rep(i, q){
        lint a;
        cin >> a;
        ++p[a - 1];
    }

    rep(i, n){
        if(p[i] <= 0LL){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
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;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m) {
        ll p;
        cin >> p;
        sum += p;
    }
    if (sum%(n+1) == 0) {
        cout << sum/(n+1) << endl;
    } else {
        cout << sum/(n+1) + 1 << endl;
    }
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 305  //check the limits, man
int ad[N][N],ar[N][N];
int main()
{
    int n,m,k,l,a,x,i,j;
    in3(n,m,k);
    string str;
    vi v(n,0);
    rep(i,n)
    {
        cin >> str;
        rep(j,m)
            if(str[j]=='#')ad[i][j]=1,v[i]++;
    }
    l=0,i=0,k=1;
    while(i<n)
    {
        l=i;
        while(i<n && v[i]==0)
            i++;
        if(i==n)
            break;
        a=0;
        rep(j,m)
        {
            lp(x,l,i+1)
                ar[x][j]=(k-(a==v[i]));
            if(ad[i][j])
                k++,a++;
        }
        i++;
    }
    if(ar[n-1][0]==0)
    {
        rep(j,m)
        {
            lp(x,l,n)
                ar[x][j]=ar[l-1][j];
        }
    }
    rep(i,n)
    {
        rep(j,m)
            pr(ar[i][j]);
        lin;
    }

}





Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll N, M, v, p;
    cin>>N>>M>>v>>p;
    vl as(N);
    cin>>as;
    sort(rng(as));
    reverse(rng(as));

    ll mi = N;
    rep(i, N) if (as[i] + M < as[p - 1]) {
        mi = i;
        break;
    }
    ll l = p - 1;
    ll r = mi;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        ll s = 0;
        s += M * (p - 1 + N - m);
        for (int i = p - 1; i < m; ++i) {
            s += as[m] + M - as[i];
        }
        if (s >= M * v) l = m;
        else r = m;
    }
    cout<<l + 1<<endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int maxa = 0;
  rep(i,n){
    cin >> a[i];
    maxa = max(maxa,a[i]);
  }
  int b = maxa;
  int res;
  rep(i,n){
    if(b == a[i]) continue;
    if(min(abs(a[i]-maxa/2),abs(a[i]-(maxa+1)/2))<b){
      b = min(abs(a[i]-maxa/2),abs(a[i]-(maxa+1)/2));
      res = a[i];
    }
  }
  cout << maxa << ' ' << res << endl;
}

Measured memory_bytes: 640
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int n, d[55];
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) scanf("%d", &d[i]);
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), N = ip[0], H = ip[1], W = ip[2];
	ulong cnt;
	foreach(i; 0..N) {
		auto ip2 = readAs!(int[]), A = ip2[0], B = ip2[1];
		if(A >= H && B >= W) cnt++;
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 508
n, y = map(int, input().split())
ans = ("-1 -1 -1")
for i in range(n + 1):
    for j in range(n + 1):
        k = int((y - 10000 * i - 5000 * j) / 1000)
        if i + j + k == n and k >= 0:
            ans = ("{} {} {}".format(i, j, k))
            break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int n;

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		int A=0,B=0;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			if(a>b) A+=(a+b);
			else{
				if(a<b) B+=(a+b);
				else{
					A+=a;
					B+=b;
				}
			}
		}
		cout<<A<<' '<<B<<endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n)
	{
		cin >> d[i];
	}
	ll ans = 0;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define NMAX 1001
#define limit 1000000007

using namespace std;

int mat[NMAX][NMAX], w, h, DP[NMAX][NMAX], cnt[NMAX];

void read(){
    char c;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> c;
            switch(c){
                case '.': mat[i][j] = 1;
                        break;
                case '#': mat[i][j] = -1;
                        break;
            }
        }
    }

}


void solve(){

    DP[1][1] = 1;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if((i != 1 || j != 1) && mat[i][j] != -1){

                DP[i][j] = (DP[i-1][j] + DP[i][j-1]) % limit;
              //  cout << i << " " << j <<" " << DP[i][j]<<  '\n';
            }
        }
    }

    cout << DP[h][w];




}

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

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, m, a, b, dis[100001], mx, in[100001];
vector<int> adj[100001];

void bfs(int src) {
    queue<int> q;
    q.push(src);

    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int ch : adj[p]) {
            in[ch]--;
            if (dis[p]+1 > dis[ch]) {
                dis[ch] = dis[p]+1;

            }
            if (in[ch]==0) {
                q.push(ch);
            }
        }
    }

}
int main()
{
    IOS
    //bfreopen("balalance.in", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        a--;
        b--;
        adj[a].emplace_back(b);
        in[b]++;
    }
    for (int i = 0; i < n; ++i) {
        if (!in[i] && !dis[i]) {
            bfs(i);
        }
    }
    for (int i = 0; i < n; ++i) {
        mx = max(mx, dis[i]);
    }
    cout << mx << endl;

    return 0;
}


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

using namespace std;

int h, w, n;
char org_c[35][35], c[35][35];

void copy(char src[35][35], char dest[35][35])
{
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			dest[x][y] = src[x][y];
		}
	}
}

void fall()
{
	char t[35][35];
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			t[x][y] = '.';
		}
	}
	for(int x = 1; x <= w; x++){
		int cnt = 0;
		for(int y = 1; y <= h; y++){
			if(c[x][y] == '.') cnt++;
			else t[x][y-cnt] = c[x][y];
		}
	}
	copy(t, c);
}

bool erase()
{
	bool used[35][35];
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			used[x][y] = false;
		}
	}
	for(int x = 1; x <= w; x++){
		int cnt = 0; char pre = '#';
		for(int y = 1; y <= h+1; y++){
			if(c[x][y] != '.' && c[x][y] == pre) cnt++;
			else{
				if(cnt >= n){
					for(int i = 1; i <= cnt; i++) used[x][y-i] = true;
				}
				if(c[x][y] == '.') cnt = 0;
				else cnt = 1;
			}
			pre = c[x][y];
		}
	}
	for(int y = 1; y <= h; y++){
		int cnt = 0; char pre = '#';
		for(int x = 1; x <= w+1; x++){
			if(c[x][y] != '.' && c[x][y] == pre) cnt++;
			else{
				if(cnt >= n){
					for(int i = 1; i <= cnt; i++) used[x-i][y] = true;
				}
				if(c[x][y] == '.') cnt = 0;
				else cnt = 1;
			}
			pre = c[x][y];
		}
	}
	int cnt = 0;
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			if(used[x][y]) c[x][y] = '.', cnt++;
		}
	}
	return cnt > 0;
}

bool check()
{
	bool flag = true;
	while(flag){
		fall();
		flag = erase();
	}
	int cnt = 0;
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			if(c[x][y] != '.') cnt++;
		}
	}
	return cnt == 0;
}

int main(void)
{
	cin >> h >> w >> n;
	for(int y = h; y >= 1; y--){
		for(int x = 1; x <= w; x++){
			cin >> org_c[x][y];
		}
	}
	
	for(int x = 1; x < w; x++){
		for(int y = 1; y <= h; y++){
			copy(org_c, c);
			swap(c[x][y], c[x+1][y]);
			if(check()){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
	static int MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		long total = power(2, n, MOD);
		total = (total + MOD - combination(n, a, MOD)) % MOD;
		total = (total + MOD - combination(n, b, MOD)) % MOD;

		System.out.println(total - 1);
	}

	static int power(int base, int exp, int mod) {
		long res = 1;
		int first = base % mod;
		int cnt = exp == 0 ? 0 : firstBitPos(exp) + 1;
		while ( cnt >= 0 ) {
			res = (res * res) % mod;
			if ( ((exp >> cnt) & 1) != 0 ) {
				res = (res * first) % mod;
			}
			cnt--;
		}
		return (int) res;
	}

	// 最大公約数と、ax + by = gcdを満たすx,yを計算する
	static int[] xgcd(int a, int b) {
		int x0 = 1;
		int y0 = 0;
		int x1 = 0;
		int y1 = 1;
		while ( b != 0 ) {
			int q = a / b;
			int tmp = b;
			b = a % b;
			a = tmp;

			tmp = x1;
			x1 = x0 - q * x1;
			x0 = tmp;

			tmp = y1;
			y1 = y0 - q * y1;
			y0 = tmp;
		}
		return new int[] {a, x0, y0};
	}

	// 逆元
	static int modInv(int a, int mod) {
		int[] xgcd = xgcd(a, mod);
		return (xgcd[1] + mod) % mod;
	}

	// 二項係数
	static int combination(int n, int a, int mod) {
		int aa = Math.min(a, n - a);
		long ret = 1;
		for ( int i = 0 ; i < aa ; i++ ) {
			ret = (ret * (n - i)) % mod;
			ret = (ret * modInv(i + 1, mod)) % mod;
		}
		return (int) ret;
	}

	static int firstBitPos(int num) {
		int x = num | (num >> 1);
		x |= x >> 2;
		x |= x >> 4;
		x |= x >> 8;
		x |= x >> 16;
		return countBits(x);
	}

	static int countBits(int num) {
		int cnt = (num & 0x55555555) + (num >> 1 & 0x55555555);
		cnt = (cnt & 0x33333333) + (cnt >> 2 & 0x33333333);
		cnt = (cnt & 0x0f0f0f0f) + (cnt >> 4 & 0x0f0f0f0f);
		cnt = (cnt & 0x00ff00ff) + (cnt >> 8 & 0x00ff00ff);
		return (cnt & 0x0000ffff) + (cnt >> 16 & 0x0000ffff);
	}
}


Measured memory_bytes: 25812
#include <bits/stdc++.h>
#define INF (1e9)
using namespace std;


int calc(string s){
  vector<int> v;
  for(int i=0;i<s.size();i++){
    int n = (int)v.size()-1;
    if(s[i]=='+')v.push_back(0);
    if(s[i]=='-')v.push_back(1);
    if(s[i]=='(')v.push_back(0),v.push_back(0);
    if(s[i]==')'){
      if(v.size()<3)continue;
      v[n-2]+=v[n-1]? -v[n]:v[n];
      v.pop_back(),v.pop_back();
    }

    if(isdigit(s[i])){
      int num=s[i]-'0';
      if(v.size()>=2){
	v[n-1]+=v[n]? -num:num;
	v.pop_back();
      }
      else v.push_back(num);
    }
  }
  return v[0];
}


bool check(string s){
  if(s[0]!='(')return 0;
  int i=1,c=1;
  while(c)c+=(s[i]=='(')-(s[i++]==')');
  return i==(int)s.size();
}


map<string,int> mem[2];
int dfs(string s,int f){
  while(check(s))s=s.substr(1,s.size()-2);
  if(s.size()==1) return s[0]-'0';
  if(mem[f].count(s))return mem[f][s];
  
  int n=s.size(),res=calc(s),d=0;
  for(int i=0;i<n;i++) if(s[i]=='+'||s[i]=='-')d++;
  for(int i=0,c=0,cnt=0;i<n;i++,cnt++,d--){
    while(i<n){
      while(s[i]=='('||s[i]==')')c+=(s[i]=='(')-(s[i]==')'),i++;
      if(s[i]=='+'||s[i]=='-') break;
      i++;
    }
    if(i>=n)break;
    if(cnt&&s[i-2]=='(')continue;
    if(d!=1&&s[i+2]==')')continue;
    string a=s.substr(0,i),b=s.substr(i+1,n-i-1);
    int t=c,ch=s[i];
    while(t--)a+=')',b='('+b;
    int mxa=dfs(a,0),mna=dfs(a,1);
    int mxb=dfs(b,0),mnb=dfs(b,1);
    if(f==0&&ch=='+') res=max(res, mxa+mxb);
    if(f==0&&ch=='-') res=max(res, mxa-mnb);
    if(f==1&&ch=='+') res=min(res, mna+mnb);
    if(f==1&&ch=='-') res=min(res, mna-mxb);
  }
  return mem[f][s]=res;
}




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

  cout <<dfs(S,0)<<endl;
  return 0;
}

Measured memory_bytes: 4672
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a, b;
		
		a = sc.nextInt();
		b = sc.nextInt();
		
		System.out.printf("%d %d %.5f\n", a / b, a % b, (double)a / b);
	}
}

Measured memory_bytes: 26492
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;


int main(int argc, char const *argv[]) {
    int dist[100010];
    REP(i,100010) dist[i] = -1;
    int n;
    cin >> n;
    queue<int> q;
    q.push(0);
    dist[0] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for (int pow6 = 1; v + pow6 <= n; pow6 *= 6) {
            if (dist[v + pow6] == -1) {
                dist[v + pow6] = dist[v] + 1;
                q.push(v + pow6);
            }
        }
        for (int pow9 = 1; v + pow9 <= n; pow9 *= 9) {
            if (dist[v + pow9] == -1) {
                dist[v + pow9] = dist[v] + 1;
                q.push(v + pow9);
            }
        }
    }
    cout << dist[n] << std::endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int ans=INT_MAX;
  for(int i=0;i+t.length()<=s.length();i++)
  {
  	int c=0;
    for(int j=0;j<t.length();j++) if(t[j]!=s[i+j]) c++;
    ans=min(ans,c);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

const int MAX_N = 1001;
int f[MAX_N+1] = {2,3};

struct Union_Find{
  vector<int> par,rank;
  
  void init(int n){
    par.resize(n); rank.resize(n);
    for(int i = 0 ; i < n ; i ++){
      par[i] = i;
      rank[i] = 0;
    }
  }
  
  int find(int s){
    if(par[s] == s)return s;
    return par[s] = find(par[s]);
  }

  void unite(int x,int y){
    int a = find(x),  b = find(y);
    if(a==b)return ;
    if(rank[a] < rank[b]) par[a] = b;
    else{
      par[a] = b;
      if(rank[a] == rank[b]){
	rank[b]++;
      }
    }
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }

  bool size(int x,int y){
    return par.size();
  }
};

void fib_init(){
  loop(i,2,MAX_N+1){
    f[i] = (f[i-1] + f[i-2])%MAX_N;
  }
}

void solve(){
  fib_init();
  
  int V,D;
  while(cin>>V>>D){
    Union_Find uf;
    uf.init(V);
    int memo[MAX_N+1] = {0};
    rep(i,V){
      loop(j,i+1,V){
	if(abs(f[i]-f[j])<D){
	  uf.unite(i,j);
	}
      }
    }
    int ans = 0;
    rep(i,V){
      int root = uf.find(i);
      if(memo[root]==0){
	memo[root]=1;
	ans ++;
      }
    }
    cout<<ans<<endl;
    
  }
}

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

Measured memory_bytes: 1208
S = int(input())
MOD = 10**9 + 7

# dp = [[0 for _ in range(S+1)]  for _ in range(S+1)]# dp[i][j] : i以下の整数のみでjを構成する方法
# # dp[0][0] = 1
# # dp[0][n] = 0
# # dp[k >= n][n] = dp[n][n]
# # dp[n][n] = dp[n-1][n] + 1
# # dp[k][n] = dp[k-1][n] + dp[k][n-k]

# for i in range(S+1):
#     for j in range(S+1):
#         if i == 0 and j == 0:
#             dp[i][j] = 1
#         elif i == 0 and j != 0:
#             dp[i][j] = 0
#         elif i > j:
#             dp[i][j] = dp[j][j]
#         elif i == j:
#             dp[i][j] = dp[i-1][j] + 1
#         else:
#             dp[i][j] = dp[i-1][j] + dp[i][j-i]

# print(dp)

dp = [0 for _ in range(S+1)] # dp[i] : 3以上の整数のみでiを構成する方法
for i in range(3, S+1):
    dp[i] = sum(dp[:i-2])
    dp[i] += 1
    dp[i] %= MOD

print(dp[S])

Measured memory_bytes: 9180
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
if (s[0]==s[1] and s[1]==s[2]) or (s[1]==s[2] and s[2]==s[3]):
    print("Yes")
else:
    print("No")
    
    
    
    


Measured memory_bytes: 9256
#include <stdio.h>

int main(void) {
	int a,b,c;
	int n;
	int count;
	while(!feof(stdin)) {
		scanf("%d",&n);
		if(feof(stdin))break;
		count=0;
		for(a=0;a<=9;a++) {
			for(b=0;b<=9;b++) {
				for(c=0;c<=9;c++) {
					if(a+b+c>=n-9 && a+b+c<=n)count++;
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
def ABC67_B():
    N, K = LI()
    L = LI()
    L.sort(reverse=True)
    ans = sum(L[:K])
    print(ans)
    return

def ABC100_C():
    def factorization_2(n):
        arr = defaultdict(int)
        temp = n
        i = 2
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
        if temp != 1:
            arr[temp] = 1
        if arr == []:
            arr[n] = 1
        return arr[2]
    N = I()
    A = LI()
    ans = 0
    for a in A:
        ans += factorization_2(a)
    print(ans)
    return

def ARC68_C():
    X = I()
    ans = 0
    ans += 2*(X//11)
    rest = X%11
    if rest>0:
        ans += 1
    if rest>=7:
        ans += 1
    print(ans)
    return

def ABC49_C():
    S = SI()
    T = {"maerd","remaerd","esare","resare"}
    stack = ""
    for s in S[::-1]:
        stack += s
        if stack in T:
            stack = ""
    if stack:
        print("NO")
    else:
        print("YES")
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    ABC49_C()

"""

"""

Measured memory_bytes: 4380
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
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);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	n--;
	int a[n];
	forci(0,n)	cin>>a[i];
	int sum=0;
	forci(0,n-1){
		sum+=min(a[i],a[i+1]);
	}
	cout<<sum+a[0]+a[n-1]<<endl;


}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
from collections import deque
n, d, a = map(int, input().split())
dat = [list(map(int, input().split())) for _ in range(n)]
dat.sort()
use = deque()
give = 0
cnt = 0
for i in range(n):
    # dat[i][0]未満のuse消費
    while len(use) > 0 and use[0][0] < dat[i][0]:
        give -= use.popleft()[1]
    # dat[i][1] - giveが残HPなので、[dat[i][0], dat[i][0]+2d]に爆撃して殺す
    if dat[i][1] - give > 0:
        add = (dat[i][1] - give + a - 1) // a   # add回爆撃
        cnt += add
        use.append([dat[i][0] + 2 * d, add * a])
        give += add * a
print(cnt)
        

Measured memory_bytes: 89432
n = int(input())
pre = [int(i) for i in input().split()]
ans = 0
for i in range(1, n - 1) :
    if pre[i-1] < pre[i] < pre[i+1] or pre[i-1] > pre[i] > pre[i + 1]:
        ans += 1
print(ans)


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

#define Triangle(s1,s2,s3) if(s1*s1+s2*s2==s3*s3)
using namespace std;

int main()
{
	int n;
	int h[3];
	vector<int> side;
	int i;
	
	cin >> n;
	
	for(i=0;i<n;i++)
	{
		side.clear();
		
		for(int j=0;j<3;j++)
		{
			cin >> h[j];
			side.push_back(h[j]);
		}
		
		sort(side.begin(),side.end());
		
		Triangle(side[0],side[1],side[2])
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int sum = 0,sum2 = 0,tmp;
	for (int i = 0; i < 4; i++){
		cin >> tmp;
		sum += tmp;
	}
	for (int i = 0; i < 4; i++){
		cin >> tmp;
		sum2 += tmp;
	}
	cout << max(sum,sum2) <<endl;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,Q,K;
int A,B,C;

void solve() {
    cin>>A>>B>>C>>K;
    int ans = 0;
    while(B<=A) {
        B *= 2;
        ans++;
    }
    while(C<=B) {
        C *= 2;
        ans++;
    }
    cout << (ans <= K ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3660
from math import sqrt
n, d = map(int, input().split())
xs = [tuple(map(int, input().split())) for _ in range(n)][::-1]

ans = 0

for i in range(n-1):
    xi = xs.pop()
    
    for xj in xs:
        o2 = [(y-z)**2 for y,z in zip(xi, xj)]
        o = sqrt(sum(o2))
        
        if o//1 == o:
            ans += 1

print(ans)

Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp.to!(wchar[]);

    int cost;
    foreach_reverse (c; S[1..$]) {
        if (c == 'E') ++cost;
    }
    auto min_cost = cost;
    for (int p = 1; p < N; ++p) {
        if (S[p] == 'E') --cost;
        if (S[p-1] == 'W') ++cost;
        min_cost = min(cost, min_cost);
    }
    writeln(min_cost);
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	int x, ans;
  	cin >> x;
  	for(int i = 360/x; i <= 360; i++){
    	if((x*i)%360 ==  0){
        	cout << i << "\n";
          	break;
        }
    }
}

Measured memory_bytes: 3644
import math

n = int(input())
c = -1
sum_ = 0
for i in range(n):
    a, b = map(int, input().split())
    sum_ += a
    if a > b:
        if c == -1:
            c = b
        if b < c:
            c = b
if c == -1:
    print(0)
else:
    print(sum_ - c)


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

ll N;
ll Q,K;
ll tmp_x,tmp_y;

struct edge {
    ll to;
    ll cost;
};

std::vector<edge> edges[100000];
ll dist[100000];

void dfs(int v, int p , ll cost) {
    dist[v]=cost;
    for (auto& e : edges[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, cost + e.cost);
    }
}

int main() {
    std::cin >> N;
    for (int i = 0; i < N-1; i++) {
        ll a,b,c;
        std::cin >>a>>b>>c;
        a--;
        b--;
        
        edges[a].push_back({b,c});
        edges[b].push_back({a,c});
    }
    std::cin >> Q>>K;
    dfs(K-1,-1,0);
    for (int i = 0; i < Q; i++) {
        std::cin >> tmp_x>>tmp_y;
        std::cout << dist[tmp_x-1]+dist[tmp_y-1] << std::endl;
    }
    
}


Measured memory_bytes: 14336
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

const int MAXN = 100002;
int n, a[MAXN], ans[MAXN];

int main()
{
    read(n);
    for (int i = 1; i <= n; ++i) read(a[i]);
    for (int i = 1; i <= n; ++i)
        ans[1] += a[i] * pow(-1, i + 1);
    for (int i = 2; i <= n; ++i)
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 4808
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

struct Q {
    Int v, l, ind, add;
    Q(Int v, Int l, Int ind, Int add) : v(v), l(l), ind(ind), add(add) {}
};

#define mid 9
vector<Q> queries[1 << 18];
Int W[1 << 18], V[1 << 18];
Int dp[1 << (mid + 1)][110000];
Int ans[110000];

Int calc(Int v, Int l, Int add = 0)
{
    if (l < 0)
        return 0;
    if (v == 1 || ((1 << mid) <= v && v < (1 << (mid + 1)))) {
        return dp[v][l] + add;
    }
    else {
        return max(calc(v / 2, l - W[v], add + V[v]), calc(v / 2, l, add));
    }
}

void solve(Int v)
{
    if (v >= (1 << (mid + 1)))
        return;
    Int p = v / 2;
    for (Int i = 0; i < 110000; i++) {
        dp[v][i] = dp[p][i];
        if (i - W[v] >= 0) {
            dp[v][i] = max(dp[v][i], dp[p][i - W[v]] + V[v]);
        }
    }
    solve(v * 2);
    solve(v * 2 + 1);
}

int main()
{
    Int n, q;
    cin >> n;
    for (Int i = 1; i <= n; i++) {
        cin >> V[i] >> W[i];
    }
    solve(1);
    cin >> q;
    for (Int i = 0; i < q; i++) {
        Int v, l;
        cin >> v >> l;
        cout << calc(v, l) << endl;
    }
    return 0;
}

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

using namespace std;

template<typename T> inline T gcd(T a, T b) {
  return __gcd(a, b);
}

template<typename T> inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}

template<typename T> inline T floor(T a, T b) {
  return a - a % b;
}

template<typename T> inline T ceil(T a, T b) {
  return floor(a + b - 1, b);
}

template<typename T> inline T round(T a, T b) {
  return floor(a + b / 2);
}

int main() {
  int n;
  cin >> n;
  int k = 100000;
  for (int i = 0; i < n; ++i) {
    k = ceil(k * 105 / 100, 1000);
  }
  cout << k << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

inline void InitRand()
{
    srand((unsigned int)time(NULL));
}

int main() {
    InitRand();
    int D; cin >> D;
    veci C(26);
    vecveci S(D,veci(26));
    veci T(D);
    REP(i,26) cin >> C[i];
    REP(i,D) REP(j,26) cin >> S[i][j];
    REP(i,D) {
        T[i] = rand()%26;
    }
    int M; M = 1e5;
    veci B(M),Q(M);
    REP(i,M) {
        B[i] = rand()%D;
        Q[i] = rand()%26;
    }

    veci last_d(26);
    ll old_ans = 0;
    REP(i,D) {
        int d = i+1;
        last_d[T[i]] = d;
        old_ans += S[i][T[i]];
        REP(j,26) {
            old_ans -= C[j]*(d-last_d[j]);
        }
    }

    REP(i,M) {
        int old_p = T[B[i]];
        T[B[i]] = Q[i];
        ll score = 0;
        veci last(26);
        REP(j,D) {
            int d = j+1;
            last[T[j]] = d;
            score += S[j][T[j]];
            REP(k,26) {
                score -= C[k]*(d-last[k]);
            }
        }
        if(old_ans < score) {
            old_ans = score;
        }
        else {
            T[B[i]] = old_p;
        }
    }
    REP(i,D) cout << T[i]+1 << endl;
}

Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k,l; string s; string sp;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	cin >> n >> l;
	vector<string> str(n);
	for (int i = 0; i < n; i++) {
		cin >> str[i];
	}
	sort(str.begin(), str.end());
	rep(i, n) {
		cout << str[i];
	}
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInteger

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

combSum :: Integer -> Integer -> Integer -> Integer
combSum n k i
  | k > n = 0
  | k == 0 || k == n = 1 + combSum n (k + i) i
  | k == 1 || k == n - 1 = n + combSum n (k + i) i
  | k >= n `div` 2 = (product [(k + 1) .. n]) `div` (product [1 .. (n - k)]) + combSum n (k + i) i
  | otherwise = (product [(n - k + 1) .. n]) `div` (product [1 .. k]) + combSum n (k + i) i

main = do
  [n, p] <- getIntList
  as <- getIntList
  let as' = map (\a -> a `mod` 2) as
  let o = length (filter (== 1) as')
  let e = length as - o
  let eSum = combSum (fromIntegral e) 0 1
  let oSum
        | p == 0 = combSum (fromIntegral o) 0 2
        | p == 1 = combSum (fromIntegral o) 1 2
  print $ eSum * oSum


Measured memory_bytes: 4052
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = Integer.parseInt(scan.next());
		int b = Integer.parseInt(scan.next());
		int c = Integer.parseInt(scan.next());
		scan.close();
		int count=0;	
		for(int i=1;i<=c;i++){
			if(c%i==0)
				if(i>=a&&i<=b)
					count++;
		}
		System.out.println(count);
		
	}

}

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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int money = 500 * i + 100 * j + 50 * k;
                if (money == X) ans++;
            }
        }
    }

    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    string s;
    ll k;
    cin >> s >> k;

    int cnt = 0;
    char ans;
    rep(i, s.size()){
        if(s[i] == '1') {
            cnt++;
        }else{
            ans = s[i];
            break;
        }
    }

    if(cnt >= k){
        cout << 1 << endl;
    }else{
        cout << ans << endl;
    }


    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1010;
const int inf = 1e9;

int n,m,k;
int g[maxn][maxn];

int getr(int mask, int i) {
    int r = 0;
    for (int j=0; j<i; j++) {
	if (mask>>j&1) {
	    r++;
	}
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m>>k;
    
    for (int i=0; i<n; i++) {
	string buf; cin>>buf;
	for (int j=0; j<m; j++) {
	    g[i][j] = buf[j]-'0';
	}
    }

    int ans = inf;

    for (int mask=0; mask<((1<<n)-1); mask++) {
	vector<int> rows(n, 0);
	int cuts = __builtin_popcount(mask);
	bool fail = false;
	
	for (int j=0; j<m; j++) {
	    for (int i=0; i<n; i++) {
		int r = getr(mask,i);
		rows[r] += g[i][j];
	    }

	    if (*max_element(rows.begin(), rows.end()) > k) {
		cuts++;
		rows = vector<int>(n, 0);
		for (int i=0; i<n; i++) {
		    int r = getr(mask,i);
		    rows[r] += g[i][j];
		}

		//impossible even after cutting
		if (*max_element(rows.begin(), rows.end()) > k) {
		    fail = true;
		}
	    }
	}

	//cout<<bitset<2>(mask)<<": "<<cuts<<endl;

	if (!fail) {
	    ans = min(ans, cuts);
	}
    }


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


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < 4; i++){
    if(s.at(i) == '+')
      ans++;
    else
      ans--;
  }    
  cout << ans << endl;
}

Measured memory_bytes: 256