akhauriyash/Code-Regression huggingface dataset:
// J'aime
// Chemise Blanche

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

#define int long long

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

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int x; cin >> x;
  int ans = 1, t = x;
  while (t % 360) t += x, ans++;
  cout << ans << '\n';
}

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


Measured memory_bytes: 3596
using System;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] tmpInput = Console.ReadLine().Split(' ');
            int[] a = Array.ConvertAll(tmpInput, int.Parse);

            var leftIndex = 0;
            long leftLength = 0;
            var rightIndex = a.Length - 1;
            long rightLength = 0;
            for(;;){
                if(leftLength < rightLength){
                    leftLength += a[leftIndex];
                    leftIndex++;
                }else{
                    rightLength += a[rightIndex];
                    rightIndex--;
                }

                if(leftIndex == rightIndex){
                    if(leftLength < rightLength){
                        leftLength += a[leftIndex];
                    }else{
                        rightLength += a[rightIndex];
                    }
                    break;
                }
            }
            var ans = Math.Abs(leftLength - rightLength);
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 34640
#include<bits/stdc++.h>
using namespace std;
long long n,k,ans=0,x,xx,c;
int main(){
	scanf("%lld%lld",&n,&k);
	for(int i=k+1;i<=n;i++){
		x = (i-k) * (n/i);
		xx = 0;
//		printf("%d ",x);
		if(n % i > 0){
			if(k == 0){
				c = 1;
			}
			else{
				c = k;
			}
			xx = (n % i) - c +1;
			if(xx < 0){
				xx = 0;
			}
		}
		x += xx;
		ans += x;
//		printf("%d %d %d\n",i,x,ans);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

int w,h;
int ret;
char f[32][32];
bool visited[32][32];
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};

int main(){
	while(cin >> w >> h){
		if(!(h|w)) break;
		int x, y;
		deque<pair<int,int> > q;
		fill((char *)f, (char *)f+32*32, '#');
		fill((bool *)visited, (bool *)visited+32*32, false);
		ret = 0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> f[i][j];
				if(f[i][j] == '@'){
						q.push_back(make_pair(i,j));
				}
			}
		}
		while(!q.empty()){
			x = q.front().first;
			y = q.front().second;
			q.pop_front();
			visited[x][y] = true;
			ret++;
			for(int i=0;i<4;i++){
				if(f[x+dx[i]][y+dy[i]] == '.' &&
				   visited[x+dx[i]][y+dy[i]] == false &&
				find(q.begin(),q.end(),make_pair(x+dx[i], y+dy[i])) == q.end()){
					q.push_back(make_pair(x+dx[i], y+dy[i]));
				}
			}
		}
		
		cout << ret << endl;
	}
	
}

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

int bubbleSort(int a[], int N){
    int sw = 0;
    bool flag = 1;
    for(int i = 1; flag; i++){
        flag = 0;
        for(int j = N-1; j >= i; j--){
            if(a[j-1] > a[j]){
                swap(a[j], a[j-1]);
                sw++;
                flag = 1;
            }
        }
    }

    rep(i, N){
        if(i != 0){
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    return sw;
}

int main(){
    int N, a[100], ans;
    cin >> N;
    rep(i, N){
        cin >> a[i];
    }
    ans = bubbleSort(a, N);
    cout << ans << endl;     
}


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

int main(){
  int n,m,count;
  count=0;
  vector<int > v;
  int a[1000]={0};
  cin>>n>>m;
  while(n>0){
    n-=2*m+1;
    count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[]
for i in range(h):
  c+=[list(input())]
d=[[0 for i in range(w)]for j in range(h)]
d[0][0]=1
for i in range(1,w):
  d[0][i]=d[0][i-1]*(c[0][i]=='.')
for i in range(1,h):
  d[i][0]=d[i-1][0]*(c[i][0]=='.')
for i in range(1,h):
  for j in range(1,w):
    d[i][j]=(d[i][j-1]+d[i-1][j])*(c[i][j]=='.')
print(d[-1][-1]%(10**9+7))

Measured memory_bytes: 166388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
const ld pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int m, k; cin >> m >> k;

    if ((1 << m) <= k) {
        cout << "-1\n";
        return 0;
    }

    deque<int> ans;
    if (k == 0) {
        FOR(i, 0, 1 << m)FOR(j, 0, 2)ans.push_back(i);
    }
    else {
        int a = -1, b = -1;
        FOR(i, 0, 1 << m)if (i != k && (i ^ k) != i && (i ^ k) != k && (i ^ k) < (1 << m)) {
            a = i;
            b = i ^ k;
            break;
        }
        if (a == -1) {
            cout << "-1\n";
            return 0;
        }
        ans = { a,b };
        FOR(i, 0, 1 << m)if (i != a && i != b && i != k) {
            ans.push_front(i);
            ans.push_back(i);
        }
        ans.push_front(k);
        ans.push_back(k);
        ans.push_back(b);
        ans.push_back(a);
    }

    FOR(i, 0, 1 << (m + 1))cout << ans[i] << ENDL(i, 1 << (m + 1));

}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, f[51][51], fac[51], ifac[51];
int main() {
	scanf("%d", &n);
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
		ifac[i] = i == 1 ? 1 : mod - 1ll * (mod / i) * ifac[mod % i] % mod;
	}
	for (int i = 1; i <= n; ++i) ifac[i] = 1ll * ifac[i - 1] * ifac[i] % mod;
	f[1][0] = f[1][1] = 1;
	for (int i = 1; i < n; ++i)
		for (int j = 0; j <= i; ++j)
			for (int k = 0; k + i <= n; ++k)
				for (int l = 0; l + i + k <= n; ++l)
					if (k + l >= j && (k + l - j) % 2 == 0 && (k || l)) {
						(f[i + k + l][abs(j + (k + l - j) / 2 - l)] += 1ll * f[i][j] * ifac[k] % mod * ifac[l] % mod) %= mod;
					}
	printf("%lld", 1ll * f[n][0] * fac[n] % mod);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
 
const int MAXN=2e5+5,INF=0x7f7f7f7f;
int n;
int a[MAXN];
char s[MAXN];
 
inline int chr_idx(char c){return c-'a';}
 
template<class T>
long long mge_sort(T a[],int l,int r){
	static T tmp[MAXN];
	if(l==r) return 0;
	int mid=l+r>>1;
	long long ret=mge_sort(a,l,mid)+mge_sort(a,mid+1,r);
	int lp=l,rp=mid+1,cur=l-1;
	while(lp<=mid && rp<=r){
		if(a[lp]<=a[rp]) tmp[++cur]=a[lp++];
		else{
			ret+=mid-lp+1;
			tmp[++cur]=a[rp++];
		}
	}
	while(lp<=mid) tmp[++cur]=a[lp++];
	while(rp<=r) tmp[++cur]=a[rp++];
	memcpy(a+l,tmp+l,(r-l+1)*sizeof(T));
	return ret;
}
 
inline void deal(){
	static int fir_pos[26],last_pos[26],pre[MAXN],nex[MAXN];
	static bool use[MAXN];
	for(int i=n;i;--i){
		nex[i]=fir_pos[chr_idx(s[i])];
		fir_pos[chr_idx(s[i])]=i;
	}
	for(int i=1;i<=n;++i){
		pre[i]=last_pos[chr_idx(s[i])];
		last_pos[chr_idx(s[i])]=i;
	}
	for(int i=0;i<26;++i){
		if(!fir_pos[i]) continue;
		for(int l=fir_pos[i],r=last_pos[i];r;l=nex[l],r=pre[r])
			a[n-l+1]=r;
	}
}
 
inline bool spj(){
	static int cnt[26];
	for(int i=1;i<=n;++i)
		++cnt[chr_idx(s[i])];
	int tot=0;
	for(int i=0;i<26;++i){
		if(cnt[i]&1) ++tot;
	}
	return tot==(n&1);
}
 
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(!spj()){
		printf("-1");
		return 0;
	}
	deal();
	printf("%lld",mge_sort(a,1,n)>>1);
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

static long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(void){
    ll X, Y;
    COMinit();
    cin>>X>>Y;
    if((2*Y-X)<0 || ((2*Y-X)%3 != 0) || (2*X-Y)<0 || ((2*X-Y)%3 != 0)){
        cout<<0<<endl;
    } else{
        ll k =(2*Y-X)/3;
        ll l = (2*X-Y)/3;
        //cout<<k <<" " << l <<endl;
        cout<<COM(k+l, k) <<endl;
    }
    return 0;
}


Measured memory_bytes: 119808
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
    for a in lst:
         fl.append(int(a))
for a in range(101):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/


typedef long long ll;
int N, A, B, H[101010];
//---------------------------------------------------------------------------------------------------
bool check(ll x) {
    ll c = 0;
    rep(i, 0, N) {
        ll h = 1LL * H[i] - 1LL * x * B;
        if (h <= 0) continue;
        c += h / A;
        if (h % A) c++;
    }
    return c <= x;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B;
    A -= B;
    rep(i, 0, N) cin >> H[i];

    int ng = 0, ok = 1010101010;
    while (ng + 1 != ok) {
        int x = (ng + ok) / 2;
        if (check(x)) ok = x;
        else ng = x;
    }
    cout << ok << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
ll  mod = 1000000007;

ll n = 1000005;
vector<bool> prime;
unordered_map<ll, bool> primesquare;
ll a[1000005];

void SieveOfEratosthenes() 
{
    prime[1] = false; 

    for (ll p = 2; p * p <= n; p++) { 
        if (prime[p] == true) { 
            for (ll i = p * 2; i <= n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    ll j = 0; 
    for (ll p = 2; p <= n; p++) { 
        if (prime[p]) { 
            a[j] = p; 
            primesquare[p * p] = true; 
            j++; 
        } 
    } 
} 
  
ll cd_c(ll k) 
{ 
    if (k == 1) 
        return 1; 
  
    ll ans = 1; 
    for (ll i = 0;; i++) { 
        if (a[i] * a[i] * a[i] > k) 
            break; 
  
        int cnt = 1; // cnt is power of prime a[i] in n. 
        while (k % a[i] == 0) // if a[i] is a factor of n 
        { 
            k = k / a[i]; 
            cnt = cnt + 1; // incrementing power 
        } 
        ans = ans * cnt; 
    } 

    if (prime[k]) 
        ans = ans * 2; 
    else if (primesquare[k]) 
        ans = ans * 3; 
    else if (k != 1) 
        ans = ans * 4; 
  
    return ans; // Total divisors 
} 


int main()
{
    cin >> n;
    prime.resize(1000005, true);
    SieveOfEratosthenes();

    long long ans = 0;
    for(ll i = 1 ; i < n; i++)
    {
        ans += cd_c( n - i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 10852
import sys

n = int(input())
minv = int(input())
maxv = -1000000000

for r in map(int,sys.stdin.readlines()):
  m = r-minv
  if maxv < m < 0:
    maxv = m
    minv = r
  elif maxv < m:
    maxv = m
  elif m < 0:
    minv = r

print(maxv)

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

string s;

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>s;
    if(s.size()==2){
        cout<<s<<"\n";
    }else {
        rrep(i,0,3){
            cout<<s[i];
        }
        cout<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    cout << (n <= m && s == t.substr(0, n) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3636
#include<stdio.h>


void insertion(int x[], int n, int g);
void shell(int x[], int n);
#define a 10000000
int cnt;
int main(void){

	int n, i;
	int x[a];

	scanf("%d", &n);
	for(i = 0;i<n;i++){
		scanf("%d", &x[i]);
	}
	shell(x, n);
	printf("%d\n", cnt);
	for(i = 0;i<n;i++){
		printf("%d\n", x[i]);
	}
			//printf("%d", x[n-1]);

	return 0;

}

void insertion(int x[], int n, int g){
	int i, j,v;
	for(i = g;i<n;i++){
		v = x[i];
		j = i-g;
		while(j>=0 && x[j] >v){
			x[j+g] = x[j];
			j = j-g;
			cnt++;
		}
		x[j+g] = v;
	}
}

void shell(int x[], int n){
	int i;
	
	int m = 0;
	int g[1000000];
	g[0] =1;
	for(m=1;3*g[m-1]+1 <=n;m++){
		g[m] = 3*g[m-1]+1;
	}
	printf("%d\n", m);
	cnt =0;
	for(i=m-1;i>0;i--){
		printf("%d ", g[i]);
		insertion(x, n, g[i]);
	}

	printf("%d\n", g[0]);
	insertion(x, n, g[0]);
	
	//printf("\n");

}


Measured memory_bytes: 5612
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v,adj[100005];
ll pr[100005],d[100005];

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

ll dfs(ll node)
{
	if(pr[node])
		return d[node];
	pr[node]=1;
	ll m=0,i;
	for(i=0;i<adj[node].size();i++)
		m=max(m,dfs(adj[node][i]));
	d[node]=1+m;
	return d[node];
}

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

	ll n,i,m,j,k,x,y,a,b;
	string s;
	
	cin >> n >> m;
	for(i=0;i<m;i++)
	{
		cin >> x >> y;
		adj[x].pb(y);
	}
	m=0;
	for(i=1;i<=n;i++)
	{
		if(!pr[i])
			x=dfs(i);
		m=max(m,d[i]);
	}
	cout << m-1;
	return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
int solve(vector<vector<int>> &arr, int n)
{
//     if( n == 1)
//         return *max_element(arr[0].begin(), arr[0].end());
    
    vector< vector<int> > dp(n, vector<int>(3,0) );
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    
    for(int i = 1; i < n; i++)
    {
        dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][0]);
    }
    // for(int i = 0; i < n; i++)
    // {
    //     for(int j = 0; j < 3; j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    return max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}
int main() {
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(3,0));
    
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 3; j++)
            cin >> arr[i][j];
    cout << solve(arr, n);
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) {
        ll tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b;
        ab[i] = make_pair(tmp_a, tmp_b);
    }
    sort(ab.begin(), ab.end());
    cout << ( ab[0].first - 1 ) + ( ab[ab.size()-1].first - ab[0].first + 1 ) + ab[ab.size()-1].second << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

#define abs(x) ( (x) > 0 ? (x) : -(x) )
using namespace std;

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

    cout << ( (abs(B - A) <= D && abs(C - B) <= D) || abs(C - A) <= D ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL m,k;
  cin >> m >> k;
  LL pm = 1;
  REP(i,m) pm *= 2;
  if(k >= pm) {
    cout << -1 << endl;
    return 0;
  }
  if(k == 1 && m == 1) {
    cout << -1 << endl;
    return 0;
  }
  if(k == 0) {
    REP(i, pm-1) {
      cout << i << " " << i << " ";
    }
    cout << pm-1 << " " << pm-1 << endl;
    return 0;
  }
  REP(i, pm) {
    if(i != k) cout << i << " ";
  }
  cout << k << " ";
  for(int i = pm-1; i>=0; --i) {
    if(i != k) cout << i << " ";
  }
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	ll a[50],t = 0;
	cin>>n;
	for(int i = 0; i < n; i++)
	cin>>a[i];
	while(1)
	{
		sort(a,a+n);
		if(a[n-1] < n)	break;
		ll s = a[n-1] / n;
		a[n-1] = a[n-1] % n;
		for(int i = 0; i < n-1; i++)
		{
			a[i] += s;
		}
		t += s; 
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct Card {
	char suit;
	int value;
};
void printAns(int arr[], int len) {
	using std::cout;
	using std::endl;
	for (int i = 0; i < len; i++)
	{
		if (i)
			cout << " ";
		cout << arr[i];
	}
	cout << endl;
}
void printAns(Card arr[], int len) {
	using std::cout;
	using std::endl;
	for (int i = 0; i < len; i++)
	{
		if (i)
			cout << " ";
		cout << arr[i].suit<<arr[i].value;
	}
	cout << endl;
}
void judgeAns(Card arr[], Card ans[],int len) {
	for (int i = 0; i < len; i++) {
		if(arr[i].suit !=ans[i].suit){
			cout << "Not stable\n";
			return;
		}
	}
	cout << "Stable\n";
}
int main() {
	int len;
	cin >> len;
	//normal input
	/*int* arr = new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	*/

	//card input
	Card* poker = new Card[len];
	Card* judge = new Card[len];
	for (int i = 0; i < len; i++) {
		cin >> poker[i].suit >> poker[i].value;
		judge[i] = poker[i];
	}
	//insertion sort
	/* for (int i = 0; i < len - 1; i++) {
		printAns(arr, len);
		for (int j = i + 1; j > 0; j--) {
			if (arr[j - 1] > arr[j])
				swap(arr[j - 1], arr[j]);
		}
	}
	printAns(arr, len);*/

	//bubble sort
	/*int step = 0;
	for (int i = 0; i < len - 1; i++) {
		for (int j = len - 1; j > i; j--) {
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;*/

	//brush sort (switch time is the same as buble sort)
	/*int step = 0;
	for (int i = 0; i < len - 1 ; i++) {
		if (arr[i] > arr[i + 1]) {
			swap(arr[i], arr[i + 1]);
			step++;
		}
		for(int j=i;j>0;j--){
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;*/

	//selection sort
	/*int t = 0;
	for (int i = 0; i < len - 1; i++) {
		int minp = i;
		for(int j = i+1;j<len;j++)
			if (arr[j] < arr[minp]) 
				minp = j;
		if (minp != i) {
			swap(arr[i], arr[minp]);
			t++;
		}
	}
	printAns(arr, len);
	cout << t << endl;*/

	//judge a stable sort
	for (int i = 0; i < len - 1; i++) {
		for (int j = len - 1; j > 0; j--) {
			if (poker[j].value < poker[j - 1].value)
				swap(poker[j], poker[j - 1]);
		}
	}
	printAns(poker, len);
	cout << "Stable\n";
	for (int i = 0; i < len - 1; i++) {
		int minp = i;
		for (int j = i + 1; j < len; j++)
			if (judge[j].value < judge[minp].value)
				minp = j;
		if(minp!=i)
			swap(judge[i], judge[minp]);
	}
	printAns(judge, len);
	judgeAns(judge, poker, len);
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  scanf("%d",&n);
  int a[n];
  REP(i,n) scanf("%d",&a[i]);
  int cnt = 0;
  REP(i,n) if(i+1 != a[i]) cnt++;
  if(cnt > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
  
}

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

// #define NDEBUG
#include<assert.h>
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, d;
  ll x, y;
  cin >> n >> d;
  int res = 0;
  rep(i, n) {
    cin >> x >> y;
    if(sqrt(x * x + y * y) <= d) res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<iostream>
using namespace std;
 
int main(){

  int a, b, c, d, e;
  int ans=0;

  cin>>a>>b>>c>>d>>e;

  if(a<0){
    ans-=c*a;
    a=0;
  }
  if(a==0) ans+=d;
  ans+=(b-a)*e;

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

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX 1000000000
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;
vector<vector<int>> graph;
vector<vector<bool>> reached;

int main(){
    string S,T;
    cin >> S >> T;
    int ts = -1;

    for(int i=S.size()-T.size();i>=0;i--){
        for(int j=0;j<T.size();j++){
            if(S[i+j] != T[j] && S[i+j] != '?'){
                break;
            }
            if(j == T.size()-1){
                ts = i;
            }
        }
        if(ts != -1){
            break;
        }
    }

    if(ts == -1){
        cout << "UNRESTORABLE" << endl;
    }
    else{
        for(int i=0;i<T.size();i++){
            S[ts+i] = T[i];
        }
        for(int i=0;i<S.size();i++){
            if(S[i]=='?'){
                cout << 'a';
            }else{
                cout << S[i];
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

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

	void solve(Scanner sc) {
		int n = sc.nextInt();
		List<Integer> list = new LinkedList<Integer>();

		if (n % 2 == 0) {
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				if (i % 2 != 0) {
					list.add(0, a);
				} else {
					list.add(a);
				}
			}
		} else {
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				if (i % 2 == 0) {
					list.add(0, a);
				} else {
					list.add(a);
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i : list) {
			sb.append(i);
			sb.append(" ");
		}
		System.out.println(sb.substring(0, sb.length() - 1));
	}
}


Measured memory_bytes: 100348
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<numeric>
using namespace std;


using ll = int64_t;

/// <summary>
/// GCDを計算します
/// </summary>
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
	if (a < b) {
		NumType tmp = a;
		a = b;
		b = tmp;
	}

	NumType r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

/// <summary>
/// 約数を数えます
/// </summary>
template <typename NumType>
NumType cntDivisor(const NumType& num) {
	NumType cnt = 0;
	for (NumType i = 1; i * i <= num; ++i) {
		if (num % i == 0) {
			cnt++;
			if (i * i != num) cnt++;
		}
	}

	return cnt;
}

template<typename TypeInt>
TypeInt L_C_M(TypeInt a, TypeInt b) {
	if (a == 0 && b == 0) {
		return 0;
	}
	return a * b / calcGCD<ll>(a, b);
}

/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"


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

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

	ll N;
	cin >> N;

	vector<pair<ll, ll>> work(N);

	for (ll i = 0; i < N; ++i) {
		cin >> work[i].second >> work[i].first;
	}
	sort(work.begin(), work.end());

	ll ans = 0;

	for (ll i = 0; i < N; ++i) {
		ans += work[i].second;
		if (ans > work[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 3456
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(A[i] % 2 != 0) {
				continue;
			}
			if(A[i] % 3 == 0 || A[i] % 5 == 0) {
				continue;
			}
			out.println("DENIED");
			return;
		}
		out.println("APPROVED");
	}
}


Measured memory_bytes: 23636
#include<iostream>
using namespace std;
int main(){
	long double ax[100],ay[100],bx[100],by[100],cx[100],cy[100],dx[100],dy[100];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>ax[i]>>ay[i]>>bx[i]>>by[i]>>cx[i]>>cy[i]>>dx[i]>>dy[i];
	}
	for(int i=0;i<n;i++){
		long double A=0,B=0;
		A=(by[i]-ay[i])/(bx[i]-ax[i]);
		B=(dy[i]-cy[i])/(dx[i]-cx[i]);
		if(A==B){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 3232
import sys
input=sys.stdin.readline
from collections import deque
n=int(input())
Edges=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    u-=1; v-=1
    w%=2
    Edges[u].append((v,w))
    Edges[v].append((u,w))
Dist=[0]*n
Visited=[False]*n
q=deque()
q.append((0,0))
while q:
    fr,dist=q.popleft()
    for to,d in Edges[fr]:
        if not Visited[to]:
            q.append((to,dist+d))
            Dist[to]=dist+d
            Visited[to]=True
for i in range(n):
    print(Dist[i]%2)

Measured memory_bytes: 69168
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

ll p[1000005];
int t[1000005];

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 1; i < n; i++){
        if(i % 2) p[i] = 0;
        else p[i] = p[i / 2] + 1;
    }
    bool f = true;
    for(int i = 0; i < n; i++){
        if(s[i] == '2') f = false;
    }
    if(f){
        for(int i = 0; i < n - 1; i++) t[i] = abs(s[i + 1] - s[i]);
        int e;
        if(n == 2) e = t[0];
        else e = (t[0] + t[n - 2]) % 4;
        int b = p[n - 2];
        for(int i = 1; i < n - 2; i++){
            if(b == 0) e = (e + t[i]) % 4;
            b += p[n - 2 - i] - p[i + 1];
        }
        cout << e << endl;
    }
    else{
        int e = ((s[0] - '0') + (s[n - 1] - '0')) % 2;
        int b = p[n - 1];
        for(int i = 1; i < n - 1; i++){
            if(b == 0) e = (e + (s[i] - '0')) % 2;
            b += p[n - 1 - i] - p[i + 1];
        }
        cout << e << endl;
    }
}

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

using namespace std;

int main(){

  int a,b,c;

  cin >> a >> b >> c;

  int max3 = max(a,(max(b,c)));

  int dev = abs(a-max3) + abs(b-max3) + abs(c-max3);

  if(dev%2 == 0){
    cout << dev/2 << endl;
  }
  else{
    cout << (dev/2)+2 << endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int n = ri();
	int a[n];
	FOR(i,n) a[i] = ri();
	
	int* ptr = a;
	int cur = *ptr;
	int res = 0;
	while(ptr < a+n) {
		int cnt = 0;
		while(*(++ptr) == cur) cnt++;
		res += (cnt+1)/2;
		cur = *ptr;
	}
	
	wi(res);	
	return 0;
}


Measured memory_bytes: 128
datas =$stdin.read.split("\n")
n = datas[0].to_i
datas = datas[1].split(" ")
datas.map! do |x|
  x.to_i
end
puts datas.join(" ")
for i in 1..n - 1 do
  v = datas[i]
  j = i - 1
  while j >= 0 && datas[j] > v do
    datas[j + 1] = datas[j]
    j -= 1
  end
  datas[j + 1] = v
  puts datas.join(" ")
end




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

using namespace std;

int main()
{
    int n;
    unsigned long long int sum=0;
    vector<unsigned long long int>vec;
    cin>>n;
    vec.resize(n);
    for(int m=0;m<vec.size();++m)cin>>vec.at(m);
    for(int m=0;m<vec.size();++m){
        if(vec.at(m)%2!=0){
            cout<<sum<<endl;return 0;
        }
    }
    while(1){
        ++sum;
        for(int m=0;m<vec.size();++m){
            vec.at(m)/=2;
            if(vec.at(m)%2!=0){
                cout<<sum<<endl;return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = iss()
    M = ['a', 'i', 'u', 'e', 'o']
    print('vowel' if N in M else 'consonant')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> cntl(N + 1);
    for(int i = 0; i < N; i++){
        if(S[i] == 'E') cntl[i + 1] = cntl[i] + 1;
        else cntl[i + 1] = cntl[i];
    }
    int ans = 1e9;
    for(int i = 0; i < N; i++){
        int t = i - cntl[i] +  (cntl[N] - cntl[i + 1]);
        ans = min(ans, t);
    }
    cout << ans << endl;
}

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

const int N = 18;
int n, a[1 << N], b[1 << N];

inline void check(int x, int y) {
	if(a[y] > a[x]) b[x] = max(a[x], b[y]), a[x] = a[y];
	else if(a[y] > b[x]) b[x] = a[y]; 
} 

int main() {
	cin >> n;
	for(int i = 0; i < 1 << n; ++i) cin >> a[i];
	for(int k = 0; k < n; ++k)
		for(int i = 0; i < 1 << n; ++i)	
			if(i >> k & 1) check(i, i ^ (1 << k));
	for(int i = 0, ans = 0; i < 1 << n; ++i) {
		ans = max(ans, a[i] + b[i]);
		if(i) printf("%d\n", ans);
	}
	return 0;
} 

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }

bool isprime(long long int val) {
 if (val <= 1)return false;
 for (long long int i = 2; i*i <= val; i++) {
   if (val%i == 0LL)return false;
 }
 return true;//ç´ æ•°
}

int main(int argc, char const *argv[]) {
  int x;
  cin >> x;
  while(!isprime(x)) x++;
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Measured memory_bytes: 115560
//Δ
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 1e5+15;
const LL inf = 1e18+N;
int n,e,t,a[N];
LL dp[N];
int main()
{
	int i,x;
	LL y,z;
	scanf("%d%d%d",&n,&e,&t);
	for(i=1;i<=n;i=i+1)
		scanf("%d",a+i);
	a[0]=0,a[n+1]=e;
	dp[1]=0;
	x=1;
	y=inf;
	for(i=1;i<=n;i=i+1){
		while(2*(a[i]-a[x])>t){
			y=min(y,dp[x]-2*a[x]);
			x++;
		}
		dp[i+1]=min(dp[x]+t,y+2*a[i]);
		//cout<<i+1<<' '<<x<<' '<<dp[i+1]<<endl;
	}
	cout<<dp[n+1]+e<<endl;
	return 0;
}
/*
2 1000000000 1000000000
1 999999999
*/

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

int main(){

  int n;
  
  cin >> n;
  
  rep(i,10){
    rep(j,10){
      if(i * j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
    
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

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

    long n = sc.nextLong();
    long k = sc.nextLong();
    
    long buf = n / k;
    long ans = Math.min(Math.abs((-1) * k * buf + n), Math.abs((-1) * k * (buf + 1) + n));

    System.out.println(ans);
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
using namespace std;
string Data;

int main(void)
{
	cin >> Data;

	bool A= Data.substr(2, 1)== Data.substr(3, 1);
	bool B = Data.substr(4, 1) == Data.substr(5, 1);

	if (A&&B)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main() {
	int n, k, ans;
 
	cin >> n >> k;
 
	int b = n - k;
 
	ans = b / (k - 1);
 
	if (b % (k - 1)) {
		ans++;
	}
 
	cout << ans + 1 << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const int DX[25]={0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2};
const int DY[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};
int n,m;
int x,y,enx,eny,goal;
bool g[1005][1005];
int graph[1005][1005];
bool vis[1005][1005],used[500005];
vpii ver[500005];
int dis[500005]={0};
int k=0;
ll ans=0;
bool infield(int a,int b){
	return a>=0&&b>=0&&a<n&&b<m;
}
void bfs1(int a,int b){
	queue<pii >q;
	q.push(mp(a,b));
	while(!q.empty()){
		int _x=q.front().fi,_y=q.front().se;
		q.pop();
		vis[_x][_y]=1;
		graph[_x][_y]=k;
		ver[k].pb(mp(_x,_y));
		REP(i,4){
			if((!vis[_x+dx[i]][_y+dy[i]])&&g[_x+dx[i]][_y+dy[i]]&&infield(_x+dx[i],_y+dy[i])){
				vis[_x+dx[i]][_y+dy[i]]=1;
				q.push(mp(_x+dx[i],_y+dy[i]));
			}
		}
	}
}
void bfs2(int pos){
	queue<int>q;
	used[pos]=1;
	q.push(pos);
	while(!q.empty()){
		int a=q.front();
		q.pop();
		REP(i,(int)ver[a].size()){
			int _x=ver[a][i].fi,_y=ver[a][i].se;
			REP(j,25){
				if(g[_x+DX[j]][_y+DY[j]]&&infield(_x+DX[j],_y+DY[j])){
					if(graph[_x+DX[j]][_y+DY[j]]!=a&&!used[graph[_x+DX[j]][_y+DY[j]]]){
						q.push(graph[_x+DX[j]][_y+DY[j]]);
						used[graph[_x+DX[j]][_y+DY[j]]]=1;
						dis[graph[_x+DX[j]][_y+DY[j]]]=dis[a]+1;
					}
				}
			}
		}
	}
}
int main(void){
	cin>>n>>m>>x>>y>>enx>>eny;
	x--,y--,enx--,eny--;
	REP(i,n)REP(j,m)graph[i][j]=-1;
	REP(i,n)REP(j,m){
		char c;
		cin>>c;
		if(c=='.'){
			g[i][j]=1;
		} 
		else{
			g[i][j]=0;
		}
	}
	REP(i,n)REP(j,m){
		if(!vis[i][j]&&g[i][j]){
			bfs1(i,j);
			k++;
		}
	}
	memset(vis,false,sizeof(vis));
	goal=graph[enx][eny];
	if(goal==graph[x][y]){
		cout<<0;
		return 0;
	}
	bfs2(graph[x][y]);
	if(dis[goal]==0)cout<<-1;
	else cout<<dis[goal];
	return 0;
}

Measured memory_bytes: 28080
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <atcoder/all>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;


int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) cin >> b[i];

	vector<int> c = convolution<MODD>(a, b);
	
	for (auto ans : c) cout << ans << " ";
	cout << endl;
	return 0;
}



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

int main() {
    
    int ans = 700;
    string str;
    cin >> str;
    for (int i=0;i<=2;i++){
        if (str.at(i) == 'o'){
            ans += 100;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=0

for i in range(N-1):
    ans+=abs(A[i]-A[i+1])

ans+=abs(A[0])+abs(A[N-1])


print(ans-abs(0-A[0])-abs(A[0]-A[1])+abs(0-A[1]))

for j in range(1,N-1):
    print(ans-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])+abs(A[j-1]-A[j+1]))

print(ans-abs(A[N-2]-A[N-1])-abs(A[N-1]-0)+abs(A[N-2]-0))


Measured memory_bytes: 20560
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    X = []
    Y = []
    H = []
    si = -1
    for i in range(N):
        x, y, h = map(int, input().split())
        X.append(x)
        Y.append(y)
        H.append(h)
        if h > 0:
            si = i

    for cx in range(0, 101):
        for cy in range(0, 101):
            h = H[si] + abs(X[si] - cx) + abs(Y[si] - cy)
            ok = True
            for i in range(N):
                if H[i] != max(h - abs(X[i] - cx) - abs(Y[i] - cy), 0):
                    ok = False
                    break
            if ok:
                return print(cx, cy, h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42988
from itertools import combinations
import numpy as np
ans = -1

N, M, X = map(int, input().split())
A = np.ndarray(shape=(N, M), dtype=int)
C = np.ndarray(shape=(N, ), dtype=int)
ans = []
costs = []
money = []
for i in range(N):
    inp = list(map(int, input().split()))
    C[i] = inp[0]
    A[i] = inp[1:]
for r in range(N):
    for c in combinations(range(N), r + 1):
        if min(np.sum(A[list(c)], axis=0)) >= X:
            costs.append(np.sum(C[list(c)]))
if len(costs) == 0:
    print(-1)
else:
    print(min(costs))

Measured memory_bytes: 27328
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, m, p = LI()
    edg = [[] for i in range(n)]
    for _ in range(m):
        a, b, c = LI_()
        c += 1
        edg[a].append((b, c))
    dp = [-inf] * n
    dp[0] = 0
    for j in range(n):
        for i in range(n):
            score = dp[i]
            for e, s in edg[i]:
                if dp[e] < score + s - p:
                    dp[e] = score + s - p
    ans = dp[:]
    for j in range(n):
        for i in range(n):
            score = dp[i]
            for e, s in edg[i]:
                if dp[e] < score + s - p:
                    dp[e] = inf
    if ans[-1] != dp[-1]:
        print(-1)
    else:
        print(abs(max(ans[-1],0)))
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 77596