akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *null, *root;

void insert(int key) {
    Node *tmp, *pre, *next;

    next = new Node;
    next->key = key;
    next->left = null;
    next->right = null;
    pre = null;
    tmp = root;

    while (tmp != null) {
        pre = tmp;
        if (next->key < tmp->key)
            tmp = tmp->left;
        else
            tmp = tmp->right;
    }

    next->parent = pre;
    if (pre == null)
        root = next;
    else if (next->key < pre->key)
        pre->left = next;
    else
        pre->right = next;
}

void preorder(Node *node) {
    if (node == null)
        return;
    cout << " " << node->key;

    if (node->left != null)
        preorder(node->left);
    if (node->right != null)
        preorder(node->right);
}
void inorder(Node *node) {
    if (node == null)
        return;

    if (node->left != null)
        inorder(node->left);
    cout << " " << node->key;
    if (node->right != null)
        inorder(node->right);
}

int main() {

    int n;
    cin >> n;

    rep(i, n) {
        string s;
        cin >> s;

        if (s == "insert") {
            int a;
            cin >> a;
            insert(a);
        } else {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 26520
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const input = stdin.split('\n')

const n = Number(input[0])
const b = input[1].split(' ').map(Number)

const ans = () => {
  let a = []

  b.push(Infinity)
  b.push(Infinity)

  for (let i = 0; i < n; i++) {
    if(i === 0) {
      a.push(b[0])
    } else {
      const prevB = b[i - 1]
      const curB = b[i]
      const v = Math.min(curB, prevB)
      a.push(v)
    }
  }

  console.log(a.reduce((p, c) => p + c))
}

ans()


Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

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

    int n;
    cin >> n;
    n--;
    
    map<string, int> mp;
    vec<string> p;
    rep(i, s.length()) rep(j, 5) {
        if (i + j >= s.length()) continue;
        string get = s.substr(i, j + 1);
        if (mp[get]) continue;
        mp[get] = 1;
        p.pb(get);
    }

    sort(p.begin(), p.end());
    cout << p[n] << endl;
    return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>

int main()
{
	int m, n, i, j,k;
	int arr[1000] = { 0 };

	while (1)
	{
		scanf("%d %d", &n, &m);
		if (m == 0 && n == 0)
		{
			break;
		}

		i = 0;
		for (j = 1; j < n;j++)
		{
			for (k = 0; k != m; k++)
			{
				++i;
				if (i > n)
				{
					i %= n;
				}
				if(arr[i])
				{
					--k;
				}
				
			}

			arr[i] = 1;
			//printf("%d:i=%d\n", j, i);
			

		}

		++n;
		for (i = 1; i < n; i++)
		{
			if (arr[i])
			{
				arr[i] = 0;
			}
			else
			{
				printf("%d\n", i);
			}
		}

	}


	return 0;
}


Measured memory_bytes: 600
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, m;

int main(void)
{
	cin>>n>>m;
	cout<<abs(n-2)*abs(m-2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000001;
int n,l,t,x,w,m,ans[maxn],len[maxn],q,c[maxn];
void work(int x,int val)
{
	if(!x)return;
	int pos=upper_bound(len+1,len+m,x)-len-1;
	if(pos==0)c[1]+=val,c[x+1]-=val;
	else ans[pos]+=(x/len[pos])*val,work(x%len[pos],val);
}
signed main()
{
    cin>>n>>q;
    len[++m]=n;
    for(int i=1;i<=q;i++)
    {
    	cin>>x;
    	while(m&&len[m]>=x)m--;	
    	len[++m]=x;
	}
	ans[m]=1;
	for(int i=m;i>=2;i--)
	{
		ans[i-1]+=ans[i]*(len[i]/len[i-1]);
		work(len[i]%len[i-1],ans[i]);
	}
    c[1]+=ans[1],c[len[1]+1]-=ans[1];
    for(int i=1;i<=n;i++)c[i]+=c[i-1],cout<<c[i]<<" ";
    
}
/*
首先排掉没有用的操作，最后就单调增。
对于当前操作x，首先len[x]/len[x-1]下取整*len[x-1]这一段肯定是直接转移的
剩下len[x]%len[x-1]这一段可以二分跳出来。
发现向后转移和倒着扫这件事情非常矛盾，
所以直接转移的部分考虑用数组记录一下，出现的次数。
 

 
 
 
 
*/

Measured memory_bytes: 5988
n = int(input())
monster = list(map(int, input().split()))
yuusya = list(map(int, input().split()))
sub = 0
for i in range(n,0,-1):
  #print("yuusya[i-1]",yuusya[i-1],"monster[i]",monster[i])
  if yuusya[i-1] > monster[i]:
    sub += monster[i]
    yuusya[i-1] -= monster[i]
    monster[i] = 0
  else:
    sub += yuusya[i-1]
    monster[i] -= yuusya[i-1]
    yuusya[i-1] = 0
  if yuusya[i-1] > monster[i-1]:
    sub += monster[i-1]
    yuusya[i-1] -= monster[i-1]
    monster[i-1] = 0
  else:
    sub += yuusya[i-1]
    monster[i-1] -= yuusya[i-1]
    yuusya[i-1] = 0
if yuusya[0] > monster[0]:
  sub+=monster[0]
else:
  sub+=yuusya[0]
print(sub)

Measured memory_bytes: 19284
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    lint T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if(A1 > B1) {
        lint tmp = A1;
        A1 = B1;
        B1 = tmp;
        tmp = A2;
        A2 = B2;
        B2 = tmp;
    }
    if(A2 < B2) {
        cout << 0 << endl;
        return 0;
    }
    lint Ad = T1 * A1 + T2 * A2;
    lint Bd = T1 * B1 + T2 * B2;
    if(Ad == Bd) {
        cout << "infinity" << endl;
        return 0;
    } else if(Ad < Bd) {
        cout << 0 << endl;
        return 0;
    }
    lint ddiff = Ad - Bd;
    lint ddiff2 = T1 * B1 - T1 * A1;
    lint num = ddiff2 / ddiff;
    if(ddiff2 % ddiff == 0) {
        cout << (1+(num-1)*2+1) << endl;        
    } else {
        cout << (1+num*2) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll ans = 0;
  rep(i,n){
    if(a[a[i]-1]==i+1){
      ans++;
    }
  }
  ans /= 2;
  print(ans);
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const ll INF=10000000000000000LL;
ll x,ans=INF;

int main(){

cin>>x;

if(x%11==0){
    ans=2*(x/11);
    cout<<ans<<endl;
    return 0;
}else{
    ans=2*((x/11)+1);
}
if((x+5)%11==0){
    ans=2*(x+5)/11-1;
    cout<<ans<<endl;
    return 0;
}else{
    ans=min(ans,2*((x+5)/11+1)-1);
}

cout<<ans<<endl;

return 0;
 
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc051/tasks/abc051_b
"use strict";
function Main(input) {
  // const [K, S] = input.split(" ").map(Number);
  const params = input.split(" ").map(Number);
  const K = params[0];
  const S = params[1];

  let count = 0;
  for (let x = 0; x <= K; x++) {
    for (let y = 0; y <= K; y++) {
      const z = S - (x + y);
      if (0 <= z && z <= K) {
        count++;
      }
    }
  }
  console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

struct UnionFind{
    vector<int> par;
    int count;
    UnionFind(int n) : par(n, -1), count(0){}
    int Find(int x){return par[x] < 0 ? x : Find(par[x]);}
    int Size(int x){return par[x] < 0 ? -par[x] : Size(par[x]);}
    bool Unite(int x, int y){
        x = Find(x);
        y = Find(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return ++count;
    }
};


signed main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m), b(m);
    vector<int> c(k), d(k);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    for(int i = 0; i < k; ++i){
        cin >> c[i] >> d[i];
        --c[i], --d[i];
    }
    UnionFind uf(n);
    for(int i = 0; i < m; ++i)
        uf.Unite(a[i], b[i]);

    vector<i64> ans(n, -1);
    for(int i = 0; i < n; ++i){
        i64 size = uf.Size(i);
        ans[i] += size;
    }
    for(int i = 0; i < m; ++i){
        --ans[a[i]];
        --ans[b[i]];
    }
    for(int i = 0; i < k; ++i)
        if(uf.Find(c[i]) == uf.Find(d[i])){
            --ans[c[i]];
            --ans[d[i]];
        }
    for(int i = 0; i < n; ++i)
        cout << ans[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 3584
import math
from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
ans=0
cnt=0
for i in range(1,n):
    if a[i]<=a[i-1]:
        cnt+=1
        ans=max(ans,cnt)
    else:
        cnt=0
print(ans)        

Measured memory_bytes: 82624
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N+1];
    int ans = -1;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
        if(a[i] == 1) ans = N-1;
    }
    if(ans == -1){
        cout << ans << endl;
    } else {
        int idx = 1;
        for(int i = 1; i <= N; i++){
            if(a[i] == idx){
                idx++;
            }
        }
        ans = N-idx+1;
        cout << ans << endl;
    }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()

using namespace std;


int main(){
	int x , y , z; cin >> x >> y >> z;
	int k ; cin >> k;
	if(y > x && z > y){
		cout << "Yes\n";
		return 0;
	}
	for(int i = 0 ; i <= 10; i++){
		for(int j = 0 ; j <= 10 ; ++j){
			for(int l = 0 ; l <= 10; ++l){
				if(i + j + l <= k && (x * (1 << i)) < (y *(1 << j)) && (y * (1 << j)) < (z * (1 << l))){
					cout << "Yes\n";
					return 0;
				}
			}
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	string S;
	cin >> S;
	int ans1 = 0;
	int ans2 = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (i % 2 == 0) {
			if (S[i] == '0') {
				ans1++;
			}
		}
		else {
			if (S[i] == '1') {
				ans1++;
			}
		}
	}
	for (int i = 0; i < S.size(); ++i) {
		if (i % 2 == 0) {
			if (S[i] == '1') {
				ans2++;
			}
		}
		else {
			if (S[i] == '0') {
				ans2++;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}



Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
V<int> v[5005];
int a[5005],n,dp[5005][5005][2],ch[5005],maxi=1e18,d[5005][2];
void dfs(int p,int fa){
	for(auto u:v[p])if(u!=fa)dfs(u,p);
	ch[p]=1;
	for(auto u:v[p])if(u!=fa){
		FOR(i,1,ch[p]+ch[u])d[i][0]=d[i][1]=1e18;
		FOR(i,1,ch[p]){
			FOR(j,1,ch[u]+1){
				gmin(d[i+j-1][0],dp[p][i][0]+dp[u][j][0]);
				gmin(d[i+j-1][1],dp[p][i][1]+dp[u][j][0]);
				gmin(d[i+j-1][1],dp[p][i][0]+dp[u][j][1]);
				gmin(d[i+j-1][1],dp[p][i][1]+dp[u][j][1]);
			}
		}
		FOR(i,1,ch[p]+ch[u])dp[p][i][0]=d[i][0],dp[p][i][1]=d[i][1];
		ch[p]+=ch[u];
	} 
	FOR(i,1,ch[p]){
		if(dp[p][i][1]<0)gmin(dp[p][i+1][0],0ll);
		if(dp[p][i][0]<maxi)gmin(dp[p][i+1][0],0ll);
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	FOR(i,1,n)FOR(j,1,n)dp[i][j][0]=dp[i][j][1]=maxi;
	FOR(i,1,n){
		cin>>a[i];
		if(a[i]<0){
			dp[i][1][1]=a[i];
		}else dp[i][1][0]=a[i];
	}
	int x,y;
	rep(i,1,n){
		cin>>x>>y;
		v[x].PB(y);
		v[y].PB(x);
	}
	dfs(1,0);
	FOR(i,1,n){
		if(dp[1][i][0]!=maxi||dp[1][i][1]<0){
			cout<<i-1;RE 0;
		}
	}
	RE 0;
}




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

using namespace std;

int main()
{
    int h,n;
    cin>>h>>n;
    int a,s=0;
    rep(i,n) {cin>>a;s=s+a;}
    
    if(s>=h){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
   
   return 0;
}

Measured memory_bytes: 3532
import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

NM = list(map(int, input().split()))

odd = 1
if (NM[1] > 1):
    odd = permutations_count(NM[1], 2)

even = 1
if (NM[0] > 1):
    even = permutations_count(NM[0], 2)

sum = 0
if (odd > 1):
    sum += int(odd / 2)
if (even > 1):
    sum += int(even / 2)

print(sum)


Measured memory_bytes: 3064
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 200500
#define inf (int)1e9
#define ll long long
#define mm 1000000007
#define eps 1e-9
#define low(x) x&(-x)
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int n=read();
	int op=0;
	deque<int> q;
	rep(i,1,n) {
		int x=read();
		if (!op) q.push_front(x);
		else q.push_back(x);
		op^=1; 
	}
	if (!op) {
		while (!q.empty()){
			int x=q.back(); q.pop_back();
			printf("%d ",x);
		}
	}
	else {
		while (!q.empty()) {
			int x=q.front(); q.pop_front();
			printf("%d ",x);
		}
	}
    return 0;
}

Measured memory_bytes: 2944
N, M = gets.chomp.split(" ").map(&:to_i)
R = Array.new(N+1, 0)
M.times{
  a, b = gets.chomp.split(" ").map(&:to_i)
  R[a] += 1
  R[b] += 1
}

R.shift
puts R.join("\n")


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>

#define ll long long int

using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  ll n;
  ll i,j;
  ll a[10005];
  ll sum=0;

  cin>>n;
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n;i++)
    sum+=a[i];

  cout<<a[0]<<" "<<a[n-1]<<" "<<sum<<endl;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef std::vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef std::vector<string> vs;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef long long ll;
const int inf = 1e9;

template <typename T>
void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>
void print_vv(T v, bool same_line=true){
for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

int main(){
    int n;
    while(cin>>n){
        vi dp(n+1, 1e6);
        vi h(n+1);
        for(int i=1; i<=n; i++)
            cin>>h[i];
        
        for(int i=1; i<=n; i++){
            int c1 = i-1>=0 ? dp[i-1] + abs(h[i] - h[i-1]) : 0;
            int c2 = i-2>=0 ? dp[i-2] + abs(h[i] - h[i-2]) : 0; 
            dp[i] = min(c1,c2);
        }

        cout<<dp[n]<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int N=200005;
using namespace std;
int n,cnt[2],par[2][N];
set<int>vals[2][N];
int F(int ind,int i){
    if(par[ind][i]==i)return i;
    return par[ind][i]=F(ind,par[ind][i]);
}
template <typename T>
std::set<T> getUnion( std::set<T>& a,  std::set<T>& b)
{
  std::set<T> result;
  bool sw=0;
  if(a.size()>b.size()){
    swap(a,b);sw=1;
  }
  for(auto el:a){
    if(b.count(el))result.insert(el);
  }
  if(sw)swap(a,b);
  return result;
}
vector<int>ans(N,0);
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    for(int i=0;i<N;i++){
        par[0][i]=par[1][i]=i;
        vals[0][i]=vals[1][i]={i};
    }
    cin>>n>>cnt[0]>>cnt[1];
    for(int i=0;i<2;i++){
        for(int j=0;j<cnt[i];j++){
            int u,v;cin>>u>>v;
            u=F(i,u);v=F(i,v);
            if(u!=v){
                if(vals[i][u].size()<vals[i][v].size())swap(u,v);
                for(auto el:vals[i][v])vals[i][u].insert(el);
                par[i][v]=u;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(F(0,i)==i){
            set<int>conn;
            for(auto el:vals[0][i]){
                int v=F(1,el);
                //cout<<i<<' '<<v<<endl;
                if(conn.count(v))continue;
                conn.insert(v);
                set<int>S2=getUnion(vals[0][i],vals[1][v]);
                for(auto br:S2)ans[br]+=S2.size();
            }
        }
    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
    return 0;
}


Measured memory_bytes: 54384
n=int(input())
r=[]
cnt=1
for i in range(n):
  x,l=map(int,input().split())
  r.append([x+l,x-l])
r.sort()
#print(r)
migi=r[0][0]
for i in range(1,n):
  if r[i][1]>=migi:
    #print("i,migi",i,migi)
    cnt+=1
    migi=r[i][0]
print(cnt)

Measured memory_bytes: 20108
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N;
    cin>>N;

    int mn=0;
    int ans=0;
    for(int i=0;i<N;i++){
        int A;
        cin>>A;
        if(mn>A){
            ans+=mn-A;
        }
        else{
            mn=A;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define maxn 100005
using namespace std;
int n;
int a[105];
int ans;
signed main()
{
	ios;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n - 2; i++)
	{
		for (int j = i + 1; j <= n - 1; j++)
		{
			for (int k = j + 1; k <= n; k++)
			{
				if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
				{
					ans++;
					//cout << i << ' ' << j << ' ' << k << endl;
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3608
#include<iostream>

using namespace std;

int main(){
  int w,h;

  while(true){
    cin >> w >> h;

    if((w==0) && (h==0))
      break;

    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	if((i==0) || (i==w-1))
	  cout << '#';
	else if((j==0) || (j==h-1))
	  cout << '#';
	else
	  cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void solve(){
    ull n,k;
    cin>>n>>k;
    ull tmp=n%k;
    cout<<min(tmp,k-tmp);
}
void trials(){
    int t;
    for(cin>>t;t--;cout<<endl){
        solve();
    }
}
int main(){
    solve();
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;

		vector<map<int, int>> a( N );
		for( int i = 0; i < N; ++i ) {
			int A;
			cin >> A;
			for( int j = 0; j < A; ++j ) {
				int x, y;
				cin >> x >> y;
				a[i][x-1] = y;
			}
		}

		int ans = 0;
		for( int bt = 1; bt < (1<<N); ++bt ) {
			bool ok = true;
			int cnt = 0;
			for( int i = 0; i < N; ++i ) {
				if( bt & (1<<i) ) {
					for( auto& p: a[i] ) {
						if( p.second && (bt & (1<<p.first)) ) {} // ok
						else if( !p.second && !(bt & (1<<p.first)) ) {} // ok
						else {
							ok = false;
							break;
						}
					}
					cnt += 1;
				}
				if( !ok ) { break; }
			}
			if( ok && ans < cnt ) { ans = cnt; }
		}

		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;

    if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = -1;
    if (a > c) {
        if (a > d) {
            ans = 0;
        }else{
            if (d > b) {
                ans = b - a;
            }else{
                ans = d - a;
            }
        }
    }else{
        if (c > b) {
            ans = 0;
        }else{
            if (b > d) {
                ans = d - c;
            }else{
                ans = b - c;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i<=n; ++i) {
        if (i%3 == 0 || i%5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  long long s; cin >> s;
  if (s <= 1000000000) {
    cout << "0 0 1 0 0 " << s << '\n';
    return 0;
  }
  long long x1_y2 = ceil(sqrt(s));
  long long x2y1 = x1_y2 * x1_y2 - s;
  for (long long x2 = 1; x2 <= 1000000000; ++x2) {
    if (x2y1 % x2 == 0 && x2y1 / x2 <= 1000000000) {
      long long y1 = x2y1 / x2;
      if (x1_y2 == x2 && x1_y2 == y1) continue;
      cout << "0 0 " << x1_y2 << ' ' << y1 << ' ' << x2 << ' ' << x1_y2 << '\n';
      return 0;
    }
  }
  assert(false);
}


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

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        l = max(0, l);
        r = min(N, r);
        int offset = N;
        T resL = def;
        T resR = def;
        while(offset > 0){
            if(l >= r) break;
            if(l&1){ resL = operate(resL, mVal[offset+l-1]); l++; }
            if(r&1){ resR = operate(mVal[offset+r-2], resR); }
            l /= 2;
            r /= 2;
            offset /= 2;
        }
        return operate(resL, resR);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return max(a, b); }
    const int N;
    const T def;
    vector<T> mVal;
};

int main(){
    int N, Q; cin >> N >> Q;
    SegTree<int> seg(N, 0);
    for(int i=0;i<N;i++){
        int a; cin >> a;
        seg.update(i, a);
    }
    for(int i=0;i<Q;i++){
        int t, x, v; cin >> t >> x >> v;
        if(t==1){
            seg.update(x-1, v);
        } else if(t==2){
            cout << seg.get(x-1, v) << endl;
        } else {
            int L = x-1, R = N+1;
            while(R-L > 1){
                int mid = (L+R)/2;
                if(seg.get(x-1, mid) >= v) R = mid;
                else L = mid;
            }
            cout << R << endl;
        }
    }
}

Measured memory_bytes: 5368
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool ch(ll x, ll n) {
	ll res = n;
	for(ll i = x; i >= 1; i--) {
		if(res >= i) {
			res -= i;
		}
	}

	return res == 0;
}

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

	ll l = 0, r = n;
	while(r - l > 1) {
		ll mid = (r + l) / 2;
		if(ch(mid, n)) {
			r = mid;
		} else {
			l = mid;
		}
	}

	ll res = n;
	vector<ll> v;
	for(ll i = l + 1; i >= 1; i--) {
		if(res >= i) {
			v.push_back(i);
			res -= i;
		}
	}

	reverse(v.begin(), v.end());
	rep(i, v.size()) {
		cout << v[i] << endl;
	}

	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  string ab = to_string(a)+to_string(b);
  int AB = stoi(ab);
  bool flag = false;
  for (int i=sqrt(AB); i>0; i--) {
    if(i*i==AB) {
      flag = true;
      break;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	input = parseInt(input, 10)

	console.log(48 - input);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int a[N], i, flag = 0, dif, temp;
    for(i = 0; i < N; i++)cin>>a[i];
    for(i = 0; i < N-1; i++)
    {
        if(a[i] > a[i+1] && i == 0)
        {
            a[i]--;
        }
        else if(a[i] >= a[i+1] && (a[i]-1) >= a[i-1])
        {
            a[i]--;
        }
    }
    for(i = 0; i < N-1; i++)
    {
        if(a[i] > a[i+1]){
            flag = 1;
            break;
        }
    }
    if(flag == 1)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int K, A, B;
	cin >> K >> A >> B;
	string ans = "NG";
	REP(i, A, B+1){
		if(i%K == 0) ans = "OK";
	}
	cout << ans;

}


Measured memory_bytes: 3624
main(){
  int a,b,c,s=0,h=0;
  while(scanf("%d,%d,%d",&a,&b,&c)>0){
    if (a*a+b*b==c*c)s++;
    else if(a==b)h++;
  }
  printf("%d\n%d\n",s,h);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::string s;
  std::cin>>s;
  
  std::string result;
  
  if(s.back()=='s')
  {
    result=s+"es";
  }
  else
  {
    result=s+"s";
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>

int main(){
	int N;
	int array[100];
	int sum=0;
	float ave=0;
	float a=0;
	float b=0;
	int answer=0;
	scanf("%d",&N);
	if(N < 1 || 100 < N) return 1;
	for(int i = 0; i < N; i++){
		scanf("%d",&array[i]);
	}
	for(int i = 0; i < N; i++){
		sum += array[i];
	}
	ave = (float)sum / (float)N;
	a = ((array[0] - ave) >= 0) ? (array[0] - ave) : (ave - array[0]);
	for(int i = 1; i < N; i++){
		b = ((array[i] - ave) >= 0) ? (array[i] - ave) : (ave - array[i]);
		if(a > b){
			a = b;
			answer = i;
		}
	}
	printf("%d",answer);
	return 0;
}

Measured memory_bytes: 128
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

ll x[100010] = {};

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

  int N, K;
  cin >> N >> K;
  REP(i, N) {
    cin >> x[i];
  }

  ll ans = 300000010;
  for (int i = 0; i < N - K + 1; i++) {
    ll mi = x[i];
    ll ma = x[i + K - 1];
    ans = min(abs(ma - mi) + min(abs(mi), abs(ma)), ans);
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> A;
	std::vector<int> Done;
	int maxa = 0;
	for (int i= 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		maxa = std::max(maxa, a);
		A.push_back(a);
	}
	std::sort(A.begin(), A.end());
	bool not_dividable[maxa + 1];
	for (int i = 0; i <= maxa; i++)
		not_dividable[i] = true;
	for (int i = 0; i < n; i++)
	{
		int idx = A.at(i);
		if (not_dividable[idx])
		{
			if (i < n - 1 && A.at(i) == A.at(i + 1))
				not_dividable[idx] = false;
			for (int j = 2 * idx; j <= maxa; j += idx)
				not_dividable[j] = false;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (not_dividable[A.at(i)])
		{
			++ans;
			Done.push_back(A.at(i));
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 6480
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define SIZE 200005
#define INF 100000000000000000LL
 
using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;
 
vector <ll> vec[SIZE];
ll mx[SIZE];
ll ans[SIZE];
 
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int c,v;
		scanf("%d %d",&c,&v);c--;
		vec[c].push_back(v);
	}
	vector <P> vx;
	for(int i=0;i<m;i++)
	{
		sort(vec[i].begin(),vec[i].end(),greater <ll>());
		vx.push_back(P(vec[i][0]+vec[i][1],i));
	}
	sort(vx.begin(),vx.end(),greater <P>());
	for(int i=m-1;i>=0;i--)
	{
		int t=vx[i].second;
		mx[i]=-INF;
		if(vec[t].size()>=3) mx[i]=vec[t][0]+vec[t][1]+vec[t][2];
		if(i+1<m) mx[i]=max(mx[i],mx[i+1]);
	}
	priority_queue <ll> que;
	int to=0,cnt=0;
	ll sum=0,last=INF;
	for(int i=1;i<=n;i++) ans[i]=-INF;
	while(1)
	{
		if(last<INF)
		{
			sum-=last;
			que.push(last);
			last=que.top();
			sum+=last;
			que.pop();
			ans[cnt]=max(ans[cnt],sum);
		}
		if(que.size()>0) ans[cnt+1]=max(ans[cnt+1],sum+que.top());
		if(to<m) ans[cnt+3]=max(ans[cnt+3],sum+mx[to]);
		if(que.size()>0&&to<m)
		{
			ans[cnt+3]=max(ans[cnt+3],sum+que.top()+vx[to].first);
			ans[cnt+4]=max(ans[cnt+4],sum+mx[to]+que.top());
		}
		if(last<INF)
		{
			ans[cnt-1]=max(ans[cnt-1],sum-last);
			if(to<m) ans[cnt+2]=max(ans[cnt+2],sum-last+mx[to]);
		}
		if(que.size()<2)
		{
			if(to==m) break;
			int t=vx[to++].second;
			sum+=vec[t][0]+vec[t][1];
			for(int i=2;i<vec[t].size();i++) que.push(vec[t][i]);
		}
		else
		{
			ll a=que.top();que.pop();
			ll b=que.top();que.pop();
			if(to==m||a+b>vx[to].first)
			{
				sum+=a+b;
				last=min(last,b);
			}
			else
			{
				que.push(a);que.push(b);
				int t=vx[to++].second;
				sum+=vec[t][0]+vec[t][1];
				for(int i=2;i<vec[t].size();i++) que.push(vec[t][i]);
			}
		}
		cnt+=2;
		ans[cnt]=max(ans[cnt],sum);
	}
	for(int i=1;i<=n;i++)
	{
		if(ans[i]<0) puts("-1");
		else printf("%lld\n",ans[i]);
	}
	return 0;
}

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

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

Measured memory_bytes: 1160
n = int(input())
k = int(input())
x = int(input())
y = int(input())

x_sum = 0
if n < k:
  x_sum = n * x
else:
  x_sum = k * x

if n - k > 0:
  y_sum = (n - k) * y
else:
  y_sum = 0
  
print(x_sum + y_sum)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();

  if(s[5]=='0'&&s[6]<='4'){
      cout<<"Heisei"<<endl;
  }else if(s[5]>='1'||s[6]>='5'){
      cout<<"TBD"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b; cin >> a >> b;
    cout << max(a+a-1,max(a+b,b+b-1)) << endl; return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
MOD = 1000000007


def two_power(x):
    if x == 0:
        return 1
    half = two_power(x // 2)
    return half * half * (2 ** (x % 2)) % MOD


M = max(a, b)
inv = [0] * (M + 1)
inv[1] = 1
for i in range(2, M + 1):
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD


def nCk(x, y):
    ans = 1
    for i in range(1, y + 1):
        ans *= (x - i + 1) * inv[i]
        ans %= MOD
    return ans


ans = two_power(n) - nCk(n, a) - nCk(n, b) - 1
print(ans % MOD)


Measured memory_bytes: 10868
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().trim.toInt
  val Array(d, x) = StdIn.readLine().trim.split(" ").map(_.toInt)

  def loop(Ai: Int, a: Int = -1, cnt: Int = -1): Int = if( a*Ai + 1 > d){
    cnt
  } else {
    loop(Ai, a + 1, cnt + 1)
  }
  
  val result = (0 until n).foldLeft(x){ (acc, i) =>
    acc + loop(StdIn.readLine().trim.toInt)
  }

  println(result)
}

Measured memory_bytes: 25424
from collections import deque

n, m = map(int, input().split())
F = [set() for _ in range(3*n)]
for _ in range(m):
  u, v = map(int, input().split())
  u = (u-1)*3
  v = (v-1)*3
  F[u].add(v+1)
  F[u+1].add(v+2)
  F[u+2].add(v)
s, t = map(int, input().split())
s = (s-1)*3
t = (t-1)*3
dist = [-1]*(3*n)
dist[s] = 0
dq = deque([s])
while dq:
  v = dq.popleft()
  for nv in F[v]:
    if dist[nv] != -1:
      continue
    dist[nv] = dist[v]+1
    dq.append(nv)
    if nv == t:
      break
  else:
    continue
  break
print(dist[t]//3)

Measured memory_bytes: 93840
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  double l;
  cin >> l;
  double x = l/3;
  double ans = pow(x, 3);
  printf("%.10f\n", ans);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int>
 
int32_t main(){
    
    string s;
    cin>>s;
    int q;
    cin>>q;
    int cnt=0;
    vector<string> v[2];
    //v[0] these are the characters at the begining
    //v[1] these are the characters at the end
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            cnt++;
        }
        else{
            int pos;
            cin>>pos;
            string ch;
            cin>>ch;
            
            if(cnt%2==0){
                //insert at beg
                if(pos==1){
                    v[0].pb(ch);
                }
                //insert at end
                else{
                    v[1].pb(ch);
                }
                
            }
            else{
                //insert at end
                if(pos==1){
                    v[1].pb(ch);
                }
                //insert at beg
                else{
                    v[0].pb(ch);
                }
            }
        }
        
    }
    string osf="";
    vector<string> res=v[0];
    for(int j=res.size()-1;j>=0;j--){
        osf+=res[j];
    }
    s=osf+s;
    for(auto i:v[1]) s+=i;
    
    if(cnt%2==0) cout<<s<<endl;
    else{
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
}

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

int main()
{
        string s,t;
        cin >> s;
        cin >> t;
        for(int i=0;i<s.size();++i){
                int minc = 0;
                for(int j=i;j<s.size();++j){
                        if(s[minc]<s[j]){
                                minc = j;
                        }
                char tmp = s[i];
                s[i] = s[minc];
                s[minc] = tmp;
                }
        }
        for(int i=0; i<t.size();++i){
                int maxc = 0;
                for(int j=i;j<t.size();++j){
                        if(t[maxc]>t[j]){
                                maxc = j;
                        }
                char tmp = t[i];
                t[i] = t[maxc];
                t[maxc] = tmp;
                }
        }
        if(s<t){
                cout << "Yes\n";
        }else{
                cout << "No\n";
        }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const int maxn = 1e4+5;

bool check(int a){
	if(a >= 1 && a <= 9) return 1;
	return 0;
}

int main(){
	int a,b; cin >> a >> b;
	if(check(a) && check(b)) printf("%d",a*b);
	else printf("-1");
}

Measured memory_bytes: 256
def main():
    n, *h = map(int, open(0).read().split())
    ans = 0
    f = True
    base = 0
    for i, j in zip(h, h[1:]):
        g = i <= j
        if f and not g:
            ans += i - base
        if not f and g:
            base = i
        f = g
    else:
        if f:
            ans += h[-1] - base
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.a();
  var b = o.a();
  var c = o.a();
  var l = o.r(n);
  var d = Array(n).fill(0);
  var ans = 9e9;
  while(f(d,n-1)){
    var sa = 0, sb = 0, sc = 0, mp = 0;
    for(var i = 0; i < n; i++){
      if(d[i] === 1){if(sc)mp += 10;sc += l[i];}
      else if(d[i] === 2){if(sb)mp += 10;sb += l[i];}
      else if(d[i] === 3){if(sa)mp += 10;sa += l[i];}
    }
    if(sa === 0 || sb === 0 || sc === 0)continue;
    var t = Math.abs(c-sc) + Math.abs(b-sb) + Math.abs(a-sa) + mp;
    if(t < ans)ans = t;
  }
  return ans;
  function f(d,x){
    if(d[x] === 3){
      if(x === 0)return false;
      d[x] = 0;
      return f(d,x-1);
    }else d[x]++;
    return true;
  }
}

Measured memory_bytes: 7756
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  float f=0;
  for(int i=0;i<n;i++)
  {
    f+=(double)1/a[i];
  }
  f=1/f;
  cout<<f<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int solve(vector<pair<int, int>>cards) {
	sort(cards.begin(),cards.end());
	bool flush_flag = all_of(cards.begin(), cards.end(), [&](const pair<int, int>&p) {
		return p.second==cards[0].second;
	});
	bool str_flag;
	{
		bool ok=true;
		for (int i = 0; i < 4; ++i) {
			if (cards[i].first + 1 != cards[i + 1].first) {
				ok=false;
			}
			if(cards[0].first==1&&cards[1].first==10&&cards[2].first==11&&cards[3].first==12&&cards[4].first==13)ok=true;
		}
		str_flag=ok;
	}
	if(str_flag&&flush_flag&&cards[0].first==1&&cards[1].first==10)return 9;
	if(str_flag&&flush_flag)return 8;
	if(str_flag)return 4;
	if(flush_flag)return 5;


	map<int,int>mp;
	for (int i = 0; i < 5; ++i) {
		mp[cards[i].first]++;
	}
	vector<int>v;
	for (auto m : mp) {
		v.push_back(m.second);
	}
	sort(v.begin(),v.end(),greater<int>());
	if (v == vector<int>{4, 1})return 7;
	if (v == vector<int>{3, 2})return 6;
	if (v == vector<int>{1, 1, 1, 1, 1})return 0;
	if (v == vector<int>{2, 1, 1, 1})return 1;
	if (v == vector<int>{2, 2, 1})return 2;
	if (v == vector<int>{3, 1, 1})return 3;
}

int main() {
	int N;
	bool flag=false;
	while (cin>>N) {
		if(flag)cout<<endl;
		flag=true;
		vector<vector<int>>costs(4,vector<int>(13));
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 13; ++j) {
				cin>>costs[i][j];
			}
		}
		vector<int>yaku_cost(10);
		for (int i = 0; i < 9; ++i) {
			cin>>yaku_cost[i+1];
		}
		for (int q = 0; q < N; ++q) {
			map<char, int>type_mp{
				{'S',0},
				{'C',1},
				{'H',2},
				{'D',3},
			};
			map<char, int>num_mp{
				{'T',10},
				{'J',11},
				{'Q',12},
				{'K',13},
				{'A',1}
			};

			int sum=0;
			vector<pair<int,int>>cards;
			for (int i = 0; i < 5; ++i) {
				string st;cin>>st;
				int num=isdigit(st[0])?st[0]-'0':num_mp[st[0]];
				int type=type_mp[st[1]];
				sum+=costs[type][num-1];
				cards.emplace_back(num,type);
			}
			int yaku=solve(cards);
			int ans=sum*yaku_cost[yaku];
			cout<<ans<<endl;
		}

	}
	return 0;
} 

Measured memory_bytes: 3128
#ABC061D - Score Attack
#https://atcoder.jp/contests/abc061/tasks/abc061_d

import sys
 
inf = float('inf')
 
n, m = map(int, sys.stdin.readline().split())
abc = []
for _ in range(m):
    a, b, c = map(int, sys.stdin.readline().split())
    abc.append((a-1, b-1, -c))
 
def main():
    dist = [inf] * n
    dist[0] = 0
    for _ in range(n-1):
        for a, b, c in abc:
            dist[b] = min(dist[b], dist[a] + c)
 
    for _ in range(n):
        for a, b, c in abc:
            if dist[a] + c < dist[b]:
                dist[b] = -inf
 
    return -dist[n-1]
 
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

#define N 100

int main(){
	int n,i;
	int sel[N];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&sel[i]);
	}
	int j,minj,tmp,count = 0;
	for(i = 0;i < n -1; i++){
		minj = i;
		for(j = i+1; j< n;j ++){
			if(sel[j] < sel[minj]){
				minj = j;
			}
		}
		if(minj != i){
			tmp = sel[minj];
			sel[minj] = sel[i];
			sel[i] = tmp;
			count++;
		}
	}

	for(i = 0;i < n-1; i++){
		printf("%d ",sel[i]);
	}
	printf("%d\n",sel[i]);
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 2744