akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD;
}

ll fastpow(ll x, ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
/*struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.ff.ff == b.ff.ff) {
      return a.ff.ss < b.ff.ss;
    }
    return a.ff.ff <b.ff.ff;
  }
};*/
inline int ask(int x, int y){
	cout<<"?"<<" "<<x<<" "<<y<<"\n"<<flush; 
	int ret; cin>>ret; 
	if(ret == -1)exit(0); 
	return ret; 
}

int main(int argc, char** argv)
{
  sws ;  
  cout<<setprecision(20); 
 // tcase
  {
  ll s=0 ;
  ll n ;
  cin>>n ;
  ll a[n] ;
  map<ll,ll>mp ;
  forn(i,n)
  {
  cin>>a[i] ;
  mp[a[i]]++ ;
  s+=a[i];
  }
  ll x=0 ;
  forn(i,n)
  x=(x^a[i]) ;
  forn(i,n)
  cout<<(x^a[i])<<" ";
  }
  
  return 0 ;
}

Measured memory_bytes: 17544
require 'pp'

n = gets.chomp!.to_i
h_n = gets.chomp!.split(" ").map(&:to_i)

max = 0
now = h_n[0]

now_max = 0
1.upto(n-1) do |i|
    if now >= h_n[i]
        now_max += 1
    else
        now_max = 0
    end
    
    now = h_n[i]

    if max < now_max
        max = now_max
    end
end

puts max


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

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    vector<int> wleft(n), rright(n);
    int cnt = 0, cnt2=0;
    for(int i=0;i<n;i++) {
        if(s[i] == 'W') cnt++;
        wleft[i] = cnt;
    }
    for(int i=n-1;i>=0;i--) {
        if(s[i] == 'R') cnt2++;
        rright[i] = cnt2;
    }
    int res = min(cnt, n-cnt);
    for(int i=0;i<n;i++) {
        int w = i==0 ? 0 : wleft[i-1];
        int r = i==n-1 ? 0 : rright[i+1];
        int cost = min(w,r) + abs(w-r);
        res = min(res, cost);
    }
    cout << res;
}


Measured memory_bytes: 5192
//2018年  3月 22日 木曜日 16:49:17 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string str[2];

void solve() {
	cin >> N;
	ll res = 1;
	rep(i, 0, 2) cin >> str[i];
	int i = 0, type = -1;
	while(i < N) {
		if(str[0][i] == str[1][i]) {
			if(type == -1) {
				MUL(res, 3);
			}
			else if(type == 0) {
				MUL(res, 2);
			}
			else if(type == 1) {
				MUL(res, 1);
			}
			type = 0; i++;
		}
		else {
			if(type == -1) {
				MUL(res, 6);
			}
			else if(type == 0) {
				MUL(res, 2);
			}
			else if(type == 1) {
				MUL(res, 3);
			}
			type = 1; i += 2;
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, d[55], cnt[15];
signed main() {
	cin >> n;
	cnt[0] = 1;
	rep(i, n) {
		cin >> d[i];
		cnt[d[i]]++;
	}
	if (n > 24) {
		cout << 0 << endl; return 0;
	}
	else if (n > 12) {
		if (cnt[0] > 1 || cnt[12] > 1) {
			cout << 0 << endl; return 0;
		}
		REP(i, 12) {
			if (cnt[i] > 2) {
				cout << 0 << endl; return 0;
			}
		}
		cout << 1 << endl; return 0;
	}
	int ma = 0;
	rep(i, 1 << n) {
		vector<int>v;
		rep(j, n) {
			if (i >> j & 1)v.push_back(d[j]);
			else v.push_back(24 - d[j]);
		}
		v.push_back(0); v.push_back(24);
		sort(all(v));
		int ans = 24;
		rep(i, v.size() - 1) {
			chmin(ans, v[i + 1] - v[i]);
		}
		chmax(ma, ans);
	}
	cout << ma << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int k,n;
  scanf("%d %d",&k,&n);
  int a[n],b[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  b[0]=k+a[0]-a[n-1];
  int temp = b[0];
  for(int i=1;i<n;i++){
    b[i] = a[i]-a[i-1];
  }
  for(int i =0;i<n;i++){
    if (temp < b[i]){
      temp = b[i];
    }
  }
  printf("%d",k-temp);
  return 0;

}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#define VMAX 10000


int main(){
   unsigned short *A, *B;
   int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

   A = malloc(sizeof(short)*n+1);
   B = malloc(sizeof(short)*n+1);



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

  for(i = 0; i < VMAX+1; i++){
    C[i] = 0;
  }

  for(i = 0 ;i < n;i++){
    C[A[i]]++;
  }

  for(i = 1; i < VMAX+1; i++){
    C[i] = C[i] + C[i-1];
  }

  for(i = n-1; i >= 0; i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
  }


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

  return 0;
}



Measured memory_bytes: 9712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<pair<int,int>> p(m);
    for(int i=0;i<m;i++){
        int a,b;cin >> a >> b;
        a--,b--;
        p[i]={a,b};
    }
    sort(p.begin(),p.end(),greater<pair<int,int>>());
    int t=n+1;
    int ans=0;
    for(int i=0;i<m;i++){
        if(t>=p[i].second){
            ans++;
            t=p[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
s = set()
for i in range(n):
  q = list(map(int, input().split()))
  if q[0]==0:
    s.add(q[1])
    print(len(s))
  elif q[0]==1:
    if q[1] in s:
      print(1)
    else:
      print(0)
  else:
    if q[1] in s:
      s.remove(q[1])


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

#include <string.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_S = 100000;
char S[MAX_S + 1];

void solve(const int N) {
    vector<int> dist(N);

    int prev = 0;
    int cur = 1;
    char dir = 'R';
    while (cur <= N) {
        if (S[cur] != dir || cur == N) {
            for (int i = prev; i < cur; i++) {
                if (dir == 'R') {
                    dist[i] = cur - i - 1;
                } else {
                    dist[i] = -1 * (i - prev + 1);
                }
            }
            dir = S[cur];
            prev = cur;
        }
        cur++;
    }

    // for (int i = 0; i < N; i++) {
    //     cout << dist[i] << " ";
    // }
    // cout << endl;

    vector<int> count(N, 0);
    for (int i = 0; i < N; i++) {
        if (abs(dist[i]) % 2 == 0) {
            count[i + dist[i]]++;
        } else {
            count[i + dist[i] + 1]++;
        }
    }

    cout << count[0];
    for (int i = 1; i < N; i++) {
        cout << " " << count[i];
    }
    cout << endl;
}

int main(void) {
    cin >> S;
    int N = strlen(S);

    solve(N);

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
//int a[100005],b[i][30];
int32_t main() {
	/*int t;
	cin>>t;
	while(t--)
	{
		int n,i,j,k;
		cin>>n;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			for(j=0;j<=26;j++)
				b[i][j]=b[i][j-1];
			b[i][a[i]]++;
		}*/
	string s;
	cin>>s;
	map<char ,int> mp;
	for(auto c:s)
	{
		if(mp[c]==1)
		{	cout<<"no\n";
			return 0;
		}
		mp[c]++;
	}
	cout<<"yes\n";
		
		
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    char s[123];
    Scs(s);
    s[3] = 0;
    printf ("%s\n", s );



    return 0;
}



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

int main(){
    int N, i;
    int a[10250];
    int ans_tmp = 0;
    int ans = 0;
    cin >> N;

    for (i=0; i < N; i++){
        cin >> a[i];
        }
    for (i=0; i < N; i++){
        while (1){
            if(a[i]%2 == 0){
                a[i] = a[i]/2;
                ans_tmp++;}
            else
                break;
            }

        ans = ans+ans_tmp;
        ans_tmp = 0;
        }


    cout << ans << endl;
    }


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

using namespace std;

int n, k, x[200005], ans = 1, cnt;
bool g;
set<int> s;

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", x + i);
		if (i && x[i] > x[i - 1])
			cnt++;
		if (i - k >= 0 && x[i - k + 1] > x[i - k])
			cnt--;
		// printf("cnt=%d k-1=%d %d\n", cnt, k - 1, x[i]);
		s.insert(x[i]);
		if (i >= k) {
			if (x[i] != *s.rbegin() || x[i - k] != *s.begin()) {
				if (cnt != k - 1 || !g) {
					ans++;
					// printf("%d\n", x[i]);
				}
			}
			s.erase(x[i - k]);
		}
		if (cnt == k - 1)
			g = 1;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n;
    cin>>n;
    vector<ll>a(5,0);
    rep(i,0,n){
        string s;
        cin>>s;
        if(s[0]=='M'){
            a[0]++;
        }
        if(s[0]=='A'){
            a[1]++;
        }
        if(s[0]=='R'){
            a[2]++;
        }
        if(s[0]=='C'){
            a[3]++;
        }
        if(s[0]=='H'){
            a[4]++;
        }
    }
    ll ans=0;
    rep(i,0,3) {
        rep(j,i+1,4) {
            rep(k,j+1,5) {
                ans += a[i]*a[j]*a[k];
            }    
        }
    }
    cout<<ans<<endl;
    
    
}


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

A.sort()

MAXN = 10**5+10
p = 10**9+7
MOD = p
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

MA = 0
for i in range(N-K+1):
    MA = (MA + A[N-1-i]*nCr(N-1-i,K-1))%p

MI = 0
for i in range(N-K+1):
    MI = (MI + A[i]*nCr(N-1-i,K-1))%p

out = MA-MI
if out<0:
    out += p
print(out)

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

int main(){
    int a , b , c , x ;
    cin >> a >> b >> c >> x ;
    int ans = 0 ;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if ( i*500+j*100+k*50 == x ) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0 ;
}


Measured memory_bytes: 256
V, E = map(int, input().split())

dis = [[float("inf")] * V for _ in range(V)]
for i in range(E):
	s, t, d = map(int, input().split())
	dis[s][t] = d

dp = [[-1] * V for _ in range(1<<V)]

def rec(s, v):
	if dp[s][v] >= 0:
		return dp[s][v]

	if s == (1<<V) -1 and v == 0:
		dp[s][v] = 0
		return 0
	
	res = float("inf")
	for u in range(V):
		if not s >> u&1:
			res = min(res, rec(s|(1<<u), u)+dis[v][u])
	
	dp[s][v] = res
	return res

res = rec(0, 0)
if res == float("inf"):
	print(-1)
else:
	print(res)



Measured memory_bytes: 18784
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[100005],dp[100005];
int main()
{
  a[0]=1000000000;
  scanf("%d%d",&n,&a[1]);
  for(int i=2;i<=n;i++)
  {
    scanf("%d",&a[i]);
    dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
    dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
  }
  printf("%d\n",dp[n]);
  return 0;
}
    

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                bool[] memo = new bool[n];

                for (int i = 1; i < n; i++)
                {
                    int temp = (i * i) % n;
                    memo[temp] = true;
                }

                List<int> nums = new List<int>();

                for (int i = 0; i < n; i++)
                {
                    if (memo[i]) nums.Add(i);
                }

                int m = (n - 1) / 2;

                int[] counts = new int[m + 1];

                for (int i = 0; i < nums.Count; i++)
                {
                    for (int j = i + 1; j < nums.Count; j++)
                    {
                        int a = nums[i];
                        int b = nums[j];

                        int temp = a - b;

                        if (a - b < 0) temp += n;

                        if (temp > m) temp = n - temp;

                        counts[temp]++;
                    }
                }

                for (int i = 1; i <= m; i++)
                {
                    sb.AppendLine((counts[i] * 2).ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9896
#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 int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int dp[3001][3001];
int arr[3001];
int n;

int solve(int l , int r)
{
    if(r-l+1 == 1) return arr[l];
    if(r-l+1 == 2) return max(arr[l] , arr[r]);

    if(dp[l][r] != -1)return dp[l][r];

    int A = arr[l] + min(solve(l+1 , r-1) , solve(l+2 , r));
    int B = arr[r] + min(solve(l+1 , r-1) , solve(l , r-2));

    return dp[l][r] = max(A , B);
}
int32_t main()
{
    int n;
    cin>>n;
    memset(dp , -1 , sizeof(dp));
    for(int i=1; i<=n; i++)cin>>arr[i];
    int total = 0;
    for(int i=1; i <= n; i++)total += arr[i];
    int ans = solve(1 , n);
    // cout<<total<<endl;
    // cout<<ans<<endl;
    cout<<ans-(total-ans)<<endl;
    //cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include<stdio.h>
#define MAX 100
#define INFTY 200000
#define SHIRO 0
#define GRAY 1
#define KURO 2

int kazu,M[MAX][MAX],i,j;

void x(){
  int min,d[MAX],color[MAX],v;
  for(i=0;i<kazu;i++){
    d[i]=INFTY;
    color[i]=SHIRO;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    min=INFTY;
    int u=-1;
    for(i=0;i<kazu;i++){
      if(min>d[i] && color[i]!= KURO){
        u=i;
        min=d[i];
      }
    }
    if(u==-1)break;
    color[u]=KURO;
    for(v=0;v<kazu;v++){
      if(color[v]!=KURO && M[u][v]!=INFTY){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=GRAY;
        }
      }
    }
  }
  for(i=0;i<kazu;i++){
    if(d[i] == INFTY){
            printf("%d %d\n",i,-1);
        }
        else{
            printf("%d %d\n",i,d[i]);
        }
    }
}

int main(){
  scanf("%d",&kazu);
  for(i=0;i<kazu;i++){
    for(j=0;j<kazu;j++){
      M[i][j]=INFTY;
    }
  }
  int k,c,u,v;
  for(i=0;i<kazu;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  x();
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

P1 d[200002]={};

int main() {

	ll n;
	cin>>n;
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		d[i].first=b;
		d[i].second=a;
	}
	sort(d,d+n);

	ll t=0;
	rep(i,n){
		if(t+d[i].second>d[i].first){
			cout<<"No"<<endl;
			return 0;
		}
		t+=d[i].second;
	}
	cout<<"Yes"<<endl;
	return 0;

}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    vl x(3);
    rep(i, 3) {
        cin >> x[i];
    }
    sort(all(x));

    if(x[0] == 5 && x[1] == 5 && x[2] == 7) {
        out("YES");
    }
    else {
        out("NO");
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
vector<vector<lli> > dp;
vector<lli> prefix;
vector<lli> a;

lli min(lli x, lli y){
	return x<y?x:y;
}

lli go(int x,int y){
	if(dp[x][y]!=-1){
		return dp[x][y];
	}
	if(y-x==1){
		return dp[x][y]=a[x]+a[y];
	}
	lli s=1e18;
	for(int i=x;i<=y-1;i++){
		s=min(go(x,i)+go(i+1,y),s);
	}
	return dp[x][y]=s+prefix[y]-(x-1>=0?prefix[x-1]:0);
}

int main(){
	int n;
	cin>>n;
	prefix.assign(n,0);
	a.assign(n,0);
	cin>>a[0];
	prefix[0]=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		prefix[i]=prefix[i-1]+a[i];
	}

	dp.assign(n,vector<lli>(n,-1));	
	for(int i=0;i<n;i++){
		dp[i][i]=0;
	}
	cout<<go(0,n-1)<<endl;
}

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

using namespace std;

int n, k, an;
vector<int> g[111111];

int dfs(int u, int p){
	int cur = 0;
	for(int i = 0; i < g[u].size(); ++i){
		cur = max(cur, dfs(g[u][i], u) + 1);
	}
	if (cur == k - 1 && u != 1 && p != 1) ++an, cur = -1;
	return cur;
}

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&n,&k);
	for(int i = 1; i <= n; ++i){
		int x;
		scanf("%d",&x);
		if (i == 1){
			an = x != 1;
			continue;
		}
		g[x].push_back(i);
	}
	dfs(1, 0);
	printf("%d",an);
	return 0;
}

Measured memory_bytes: 12160
package main

import (
	"fmt"
)

func main() {
	var (
		num_500 = 0
		num_100 = 0
		num_50  = 0
		total   = 0
		sum     = 0
		count   = 0
	)
	fmt.Scan(&num_500, &num_100, &num_50, &total)
	for a := 0; a <= num_500; a++ {
		for b := 0; b <= num_100; b++ {
			for c := 0; c <= num_50; c++ {
				sum = 500*a + 100*b + 50*c
				if sum == total {
					count++
				}
			}
		}
	}
	fmt.Println(count)

}

Measured memory_bytes: 512
n = int(input())
h = list(map(int,input().split()))

answer = "Yes"
for i in range(n-2,0,-1):
    if h[i] > h[i+1] + 1:
        answer = "No"
        break
    elif h[i] == h[i+1] +1:
        h[i] -= 1

print(answer)

Measured memory_bytes: 14396
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local function array(n, default_val)
    local metatables = {}
    if default_val ~= nil then
        metatables[1] = {__index = function() return default_val end}
    end
    for i=2,n do
        metatables[i] = {__index = function(parent, k)
            local child = setmetatable({}, metatables[i-1])
            rawset(parent, k, child)
            return child
        end}
    end
    return setmetatable({}, metatables[n])
end
----
local N = read.n()
local h = read.N(N)
local function diff(i, j)
    if j > N then
        return 10^9
    end
    return math.abs(h[i] - h[j])
end
local tbl = array(1, 10^9)
tbl[1] = 0
for i=1,N-1 do
    tbl[i+1] = math.min(tbl[i+1], diff(i,i+1) + tbl[i])
    tbl[i+2] = math.min(tbl[i+2], diff(i,i+2) + tbl[i])
end
print(tbl[N])

Measured memory_bytes: 13176
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n&&n) {
		vector<vector<int > >v(n, vector<int>(n));
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)v[i][j] = -1;
		v[n / 2 + 1][n / 2] = 1;
		pair<int, int>pp;
		pp.first = n / 2 + 1;
		pp.second = n / 2;
		int cnt = 1;
		pair<int, int>pn;
		pn.first = pp.first + 1;
		pn.second = pp.second + 1;
		while (cnt < n*n) {
			if (pn.second == n) {
				pn.second = 0;
				//cout << "right" << endl;
			}
			if (pn.second == -1) {
				pn.second = n - 1;
				//cout << "left" << endl;
			}
			if (pn.first == n) {
				pn.first = 0;
				//cout << "under" << endl;
			}

			if (v[pn.first][pn.second] != -1) {
				pn.first++;
				pn.second--;
				//cout << "full" << endl;
			}
			else {
				cnt++;
				v[pn.first][pn.second] = cnt;
				pn.first++;
				pn.second++;
				//cout << "success" << endl;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				printf("%4d", v[i][j]);
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <cstdio>
#include <cmath>
#include <complex>
#include <algorithm>
using namespace std;
struct P{
	double x,y,z;
	P(double x,double y,double z) : x(x) , y(y) , z(z) {}
	P(){x=y=z=0;}
};

bool operator < (const P &a,const P &b){
	return a.x < b.x;
}

P p[100000];
P q[100];

double dist[100];
int n,Q;

void calc(int idx){
	dist[idx] = 1e15;
	/*for(int i = 0 ; i < n ; i++){
		double dx = (p[i].x-q[idx].x)*(p[i].x-q[idx].x);
		double dy = (p[i].y-q[idx].y)*(p[i].y-q[idx].y);
		double dz = (p[i].z-q[idx].z)*(p[i].z-q[idx].z);	
		dist[idx] = min( dist[idx] , sqrt(dx+dy+dz) );
	}*/
	int s = lower_bound(p,p+n,q[idx]) - p;
	for(int i = s ; i < n && abs(p[i].x-q[idx].x) < dist[idx] ; i++){
		double dx = (p[i].x-q[idx].x)*(p[i].x-q[idx].x);
		double dy = (p[i].y-q[idx].y)*(p[i].y-q[idx].y);
		double dz = (p[i].z-q[idx].z)*(p[i].z-q[idx].z);	
		dist[idx] = min( dist[idx] , sqrt(dx+dy+dz) );
	}
	for(int i = s-1 ; i >= 0 && abs(p[i].x-q[idx].x) < dist[idx] ; i--){
		double dx = (p[i].x-q[idx].x)*(p[i].x-q[idx].x);
		double dy = (p[i].y-q[idx].y)*(p[i].y-q[idx].y);
		double dz = (p[i].z-q[idx].z)*(p[i].z-q[idx].z);	
		dist[idx] = min( dist[idx] , sqrt(dx+dy+dz) );
	}
}

int main(){
	while(cin >> n >> Q&& n){
		for(int i = 0 ; i < n ; i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
		sort(p,p+n);
		while(Q--){
			int m;
			cin >> m;
			for(int i = 0 ; i < m ; i++){
				scanf("%lf%lf%lf",&q[i].x,&q[i].y,&q[i].z);
				calc(i);
			}
			double res = 0;
			for(int i = 1 ; i < m ; i++){
				double dx = (q[i].x-q[i-1].x)*(q[i].x-q[i-1].x);
				double dy = (q[i].y-q[i-1].y)*(q[i].y-q[i-1].y);
				double dz = (q[i].z-q[i-1].z)*(q[i].z-q[i-1].z);
				
				res += min( dist[i] + dist[i-1] , sqrt(dx+dy+dz) );
			}
			printf("%.10lf\n",res);
		}
	}
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    int a,b,t;
    while(1){
        cin>>a>>b;
        if(a==0){
            if(b==0){
                break;
            }
        }
        if(a>b){
            t=a;
            a=b;
            b=t;
        }
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int N;
    cin >> N;
    map<string,int> m;
    int maxi = 1;
    string t;
    for(int i = 0;i < N;i++)
    {
        cin >> t;
        if(m.count(t) == 0)
        {
            m.insert(make_pair(t,1));
            continue;
        }
        m[t]++;
        maxi = max(maxi,m[t]);
    }
    vector<string> ans;
    for(auto i : m)
    {
        if(i.second == maxi)
            ans.push_back(i.first);
    }
    sort(ans.begin(),ans.end());
    for(int i = 0;i < (int)ans.size();i++)
        cout << ans[i] << '\n';
}

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

int main(){
  int64_t S;
  cin >> S;
  string s_str = to_string(S);
  int length = s_str.size();
  int64_t sum = 0;
  for (int tmp = 0; tmp < (1 << length - 1); tmp++) {
    bitset<9> s(tmp);
    // (ビット列sに対する処理)
    //下から足していく
    //たしたら消去
    int64_t S_tmp = S;
    int flag = 0;
    for(int i = 0; i < length - 1; i++){
      //int flag = 0;
      if(s.test(i)){
        int64_t b = pow(10, i + 1 - flag);
        sum = sum + S_tmp % b;
        S_tmp = S_tmp / b;
        flag = i + 1;
      }else{
        continue;
      }
    }
    sum = sum + S_tmp;
  }
  cout << sum <<endl;
}
        

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
    static class Reader {
		BufferedReader br;
		StringTokenizer st;
 
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
 
	}
    static class Ele implements Comparable<Ele> 
    {  
        public int x,y;  
        Ele(int x,int y) 
        {  
            this.x=x;this.y=y; 
        }  
        public int compareTo(Ele ob) {  
        if(ob.x!=x)return x-ob.x;
        return this.y-ob.y;  
        }   
    }
    int a[][];int b[][];
    
    long gcd(long a,long b)
    {
        long min=Math.min(a,b);
        long max=Math.max(a,b);
        while (max%min!=0)
        {
            a=max%min;
            max=min;min=a;
        }
        return min;
    }
	public static void main(String[] args) throws IOException 
	{
		Reader sc=new Reader();//Solution G=new Solution();
		PrintWriter o = new PrintWriter(System.out);
		int t=1;
		//int t=sc.nextInt();
		
		int n,m,y0,x0,y1,x1,x2,y2,s0,s2;int a[],b[],in[],in1[];
		long k,l;boolean b1[],b2;String s1[],ss,s;
		//long l;long a[]; 
		ArrayList<ArrayList<Integer>> ll=new ArrayList<>();
		ArrayList<Integer> a1=new ArrayList<>();
		ArrayList<Integer> a2=new ArrayList<>();
		ArrayList<Integer> a3=new ArrayList<>();
		ArrayDeque<Integer> deq=new ArrayDeque<>();
		TreeSet<Integer> h0=new TreeSet<>();
		TreeSet<Integer> h1=new TreeSet<>();
		HashMap<Integer,Integer> h=new HashMap<>();
		try{
		while (t-->0)
		{
		    ss=sc.next();s=sc.next();n=s.length();
		    for (int i=0;i<ss.length()-s.length()+1;i++)
		    {
		        x0=0;
		        for (int j=0;j<s.length();j++)
		        {
		            if (s.charAt(j)!=ss.charAt(i+j))
		            x0++;
		        }
		        n=Math.min(n,x0);
		    }
		    o.println(n);
		    //o.println(s);
		    //o.println();
		    //o.println();
		    //o.println(h);
		    //o.println(x2);
		    //o.println();
		    h0.clear();ll.clear();a1.clear();a2.clear();h1.clear();
		}
		}
		catch (Throwable e)
		{
		    e.printStackTrace();
		}
		//o.println("HI");
		
        o.flush();
        o.close();
	}
} 

Measured memory_bytes: 34400
#include <iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

vector<int> obj[200010];
int main() {
	int h, w, n; cin >> w >> h >> n;
	for(int i = 0; i < n; ++i) {
		int x, y; cin >> x >> y;
		--x, --y;
		if(y > x) continue;
		obj[y].push_back(x);
	}
	for(int i = 0; i < h; ++i) {
		obj[i].push_back(w);
		sort(obj[i].begin(), obj[i].end());
	}
	for(int i = 0; i < w; ++i) {
		obj[h].push_back(i);
	}
	int y = 0, x = 0;
	int ans = 1e9, now = 0;
	while(true) {
		int r = *lower_bound(obj[y].begin(), obj[y].end(), x + 1) - x;
		ans = min(ans, now + r);
		if(r == 1) break;
		++x, ++now;
		int d = *lower_bound(obj[y + 1].begin(), obj[y + 1].end(), x);
		if(x != d) {
			++y;
		}
	}
	cout << ans << '\n';
	return 0;
}

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


void solve(){
  
}

int main() {
	// your code goes here
    
    int n;
    cin >> n;
    
    set<string> s;
    for(int i=0;i<n;i++){
        string x;
        cin >> x;
        
        s.insert(x);
    }
    
    cout << s.size();
}


Measured memory_bytes: 19184
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli N, A, B;
	cin >> N >> A >> B;

	if (abs(A - B) % 2 == 0) {
		COUT(abs(A - B) / 2);
	}
	else {
		// a b
		// |a <= b
		// a => <= b
		if (A > N - B + 1) {
			COUT((N - B + 1) + (abs(A - B) - 1) / 2);
		}
		else {
			COUT(A + (abs(A - B) - 1) / 2);
		}
	}



	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b[] = new int[n + 1];
		long ans = 0;
		b[0] = 1000000;
		b[n] = b[0];
		for (int i = 1; i < n; ++i)
			b[i] = sc.nextInt();
		sc.close();
		for (int i = 1; i <= n; ++i)
		ans += Math.min(b[i - 1], b[i]);
		System.out.println(ans);
	}
}

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

int main() {
 int N,a,b,sum=0,bsum=0;
  cin>>N>>a>>b;
  string s;
  cin>>s;
  for(int i=0;i<N;i++){
    if(s[i]=='a'&&sum<a+b){
      cout<<"Yes"<<endl;
      sum++;
    }
    else if(s[i]=='b'&&bsum<b&&sum<a+b){
      cout<<"Yes"<<endl;
      sum++;bsum++;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}
            
            

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl;
#define all(v) v.begin(), v.end()

const ll mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
  Combination(int sz) : _fact(sz+1), _rfact(sz+1), _inv(sz+1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i=1; i<=sz; i++) _fact[i] = _fact[i-1]*i;
    _rfact[sz] /= _fact[sz];
    for(int i=sz-1; i>=0; i--) _rfact[i] = _rfact[i+1]*(i+1);
    for(int i=1; i<=sz; i++) _inv[i] = _rfact[i]*_fact[i-1];
  }
  inline T fact(int k) const { return _fact[k]; }
  inline T rfact(int k) const { return _rfact[k]; }
  inline T inv(int k) const { return _inv[k]; }
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n-r);
  }
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p-q);
  }
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n+r-1, r);
  }
};
Combination<mint> c(100005);

int main() {
  int n;
  cin >> n;
  int A[n+1], cnt[n], l = -1, r = 0;
  fill(cnt, cnt+n, 0);
  rep(i,n+1) {
    cin >> A[i];
    A[i]--;
    cnt[A[i]]++;
  }
  rep(i,n+1) {
    if (cnt[A[i]] == 2) {
      if (l == -1)
        l = i;
      else
        r = i;
    }
  }
  rep1(i,n+1) {
    mint ans = 0;
    ans += c.C(n+1, i);
    ans -= c.C(n+l-r, i-1);
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 6284
n=int(input())
a = [int(input()) for _ in range(n)]
b=sorted(a)
c=[0]*n

for i in range(n):
	if a[i]==b[-1]:
		c[i]=b[-2]
	else:
		c[i]=b[-1]
for i in range(n):
	print(c[i])

Measured memory_bytes: 15660
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define pq priority_queue
#define st first
#define nd second
#define np next_permutation

using namespace std;
typedef long long ll;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ll p(ll x){
    return x * x;
}

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

    ll cnt[k];
    memset(cnt, 0, sizeof(cnt));
    fr(i, 1, n + 1){
        cnt[i % k] ++;
    }
    ll ans = 0;
    fr(i, 1, n + 1){
        if((((k - (i % k)) % k) * 2) % k != 0) continue;

        ans += p(cnt[(k - (i % k)) % k]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

R, G, B, N = rl()
UP = 3000
A = np.zeros(UP+1, dtype=np.int32)

for r in range(UP+1):
    if r * R > UP:
        break
    A[r*R::G] += 1

answer = A[N::-B].sum()
print(answer)
#08


Measured memory_bytes: 12496
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  ll n;
  cin >> n;
  cout << n*(n-1)/2 << endl;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M;
  cin >> N >> M;
  vector<vll> A(N);
  vll R(M, 0);
  REP(i, 0, N) {
    ll k;
    cin >> k;
    vll _A(M);
    REP(j, 0, k) {
      ll a;
      cin >> a;
      _A[a-1] = 1;
    }
    A[i] = _A;
  }

  vll result(M);
  REP(i, 0, M) {
    result[i] = A[0][i];
  }

  REP(i, 1, N) {
    REP(j, 0, M) {
      result[j] &= A[i][j];
    }
  }
  cout << count(result.begin(), result.end(), 1) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(input())
b = []
for i in range(m):
    b.append(input())

for i in range(n-m+1):
    for j in range(n-m+1):
        find = True
        for k in range(m):
            if not a[i+k][j:j+m] == b[k]:
                find = False
                break
        if find:
            print("Yes");sys.exit()
print("No")


Measured memory_bytes: 3064
n, m, q = gets.split(' ').map(&:to_i)
area = (0..n).map{(0..n).map{0}}

# 列車ごとの始発・終点
m.times {
    l, r = gets.split(' ').map(&:to_i)
    area[l][r] += 1
}

# 終点を過ぎた列車の本数
fns = (0..n).map{ |i|
    row = [0]
    (1..n).each{ |j|
        row << (row[-1] + area[i][j])
    }
    row
}

# 指定の区画に含まれている本数
# (区画内で終点を過ぎた列車の本数を取る)
out = (0..n).map{(0..n).map{nil}}   # メモ
q.times {|i|
    pl,qr = gets.split.map(&:to_i)
  
    if !out[pl][qr]
	   out[pl][qr] = (pl..qr).map{ |i| fns[i][qr] }.inject(:+)
    end
    puts out[pl][qr]
}


Measured memory_bytes: 11772