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

int main() {
  int A,B,a,b,c,d,sum=0;
  cin >> A>>B;
  int i=A;

  for(i;i<=B;i++){
    a=i/10000;
    b=i/1000%10;
    c=i/10%10;
    d=i%10;
    if(a==d&&b==c)
      sum++;
  }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];

    int sum = 0;
    rep(i,n)
    {
        sum += b[a[i]-1];
        if(i>0 && a[i] == a[i-1]+1)
            sum += c[a[i-1]-1];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, k = gets.split.map(&:to_i)
arr = []
if k >= b - a
  (a..b).each do |n|
    puts n
  end
else
  (a...a+k).each do |n|
    arr << n
  end
  (b-k+1..b).each do |n|
    arr << n
  end
end
arr.uniq.each do |n|
  puts n
end

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

using namespace std;

int main()
{
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;

	int mx = max(c, d);
	for (int i = a; i < mx; i++) {
		if (s[i - 1] == '#' && s[i - 1] == s[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	if (c < d) {
		cout << "Yes" << endl;
	} else {
		for (int i = b - 2; i < d - 1; i++) {
			if (s[i] == '.' && s[i] == s[i + 1] && s[i] == s[i + 2]) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

//below here

int main(){
	int n,t;
	cin >> n >> t;
	int ans = 0;
	vvector<int> dp(2,vector<int>(t,0));
	rep(i,n){
		int a,b;
		cin >> a >> b;
		per(j,t){
			if(j+a<t){
				chmax(dp[0][j+a],dp[0][j]+b);
				chmax(dp[1][j+a],dp[1][j]+b);
				chmax(ans,dp[1][j]+b);
			}
			chmax(dp[1][j],dp[0][j]+b);
		}
	}
	foreach(i,dp){
		foreach(j,i){
			chmax(ans,j);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N, A[100010];
map<ll, ll> m;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>A[i];
        m[A[i]]++;
    }

    vector<ll> v;

    for (auto itr = m.begin(); itr != m.end(); itr++){
        int t = (*itr).second;

        while(t >= 2){
            v.push_back((*itr).first);
            t -= 2;
        }
    }

    sort(v.begin(), v.end(), greater<ll>());

    ll ans = 0;

    REP(i,0,v.size()){
//        REP(j,i+1,v.size()){
//            if(i == j) continue;
//            ans = max(ans, v[i] * v[j]);
//        }
        if(i + 1 <= N - 1) ans = max(ans, v[i] * v[i+1]);
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

int N,U,V,M;
int u[512][512], n[512][512];
map<int, int>mu,mn;
int dy[]={-1,1,-1,1,-1,1,0,0}, dx[]={-1,1,0,0,1,-1,1,-1};

int countLine(int y, int x, int a[512][512]){
  int res = 0, f;
  f = 1;
  rep(i,N) f &= (a[y][i]==0);
  res += f;
  f = 1;
  rep(i,N) f &= (a[i][x]==0);
  res += f;
  if(y==x){
    f = 1;
    rep(i,N) f &= (a[i][i]==0);
    res += f;
  }
  if(y==N-x-1){
    f = 1;
    rep(i,N) f &= (a[i][N-i-1]==0);
    res += f;
  }
  if(res>0 && N==1)  res = 1;
  return res;
}

int main(){
  int x[100005];
  scanf("%d%d%d%d",&N,&U,&V,&M);
  rep(i,N) rep(j,N){
    scanf("%d", &u[i][j]);
    mu[u[i][j]] = i*N+j;
  }
  rep(i,N) rep(j,N){
    scanf("%d", &n[i][j]);
    mn[n[i][j]] = i*N+j;
  }
  rep(i,M) scanf("%d", x+i);
  int ru = 0, rn = 0;
  rep(i,M){
    if(mu.find(x[i]) != mu.end()){
      int pos = mu[x[i]];
      u[pos/N][pos%N] = 0;
      ru += countLine(pos/N, pos%N, u);
    }

    if(mn.find(x[i]) != mn.end()){
      int pos = mn[x[i]];
      n[pos/N][pos%N] = 0;
      rn += countLine(pos/N, pos%N, n);
    }
    if(ru >= U && rn >= V){ puts("DRAW"); return 0;}
    else if(ru >= U){ puts("USAGI"); return 0; }
    else if(rn >= V){ puts("NEKO"); return 0; }
  }
  puts("DRAW");
  return 0;
}

Measured memory_bytes: 16156
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    ll L, R, sub;
    cin >> L >> R;
    int ans = 2019;
    for(ll i=L; i<R; i++){
        for(ll j=i+1; j<=R; j++){
            sub = (i*j)%2019;
            if(ans > sub) ans=sub;
            if(ans == 0) break;
        }
        if(ans == 0) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    int cou = 0;
    for (int i = 0; i < 3; i++)
    {
        if (a[i] == b[i])
        {
            cou++;
        }
    }
    cout << cou << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i=2; i*i<=n; i++) {
        if(n % i != 0) continue;
        ll num = 0;
        while(n % i == 0)  {num++; n /= i;}
        res.push_back(make_pair(i, num));
    }
    if(n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n; cin >> n;
    ll ans = 0;
    for(auto x : prime_factorize(n)) {
        ll a = 0, b = 1;
        while(x.second - b >= 0) {x.second -= b; b++; a++;}
        ans += a;
    }
    cout << ans << endl;
}


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

const int N = 5005;
const int mod = 1e9 + 7;

void add(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}

int mul(int x,int y) {
	return 1LL * x * y % mod;
}

int n;
vector<int> g[N];
int fac[N], C[N][N];
int F[N][N];
int nchild[N];
vector<int> roots;
int a[N], tot = 0;

void dfs(int u,int p) {
	nchild[u] = 1;
	bool flag = true;
	for (int v : g[u]) if (v != p) {
		dfs(v, u);
		nchild[u] += nchild[v];
		if (nchild[v] > (n / 2)) flag = false;
	}
	if (n - nchild[u] > n / 2) flag = false;
	if (flag) roots.push_back(u);
}

int main() {
	scanf("%d", &n);
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
	for (int i = 0; i <= n; ++i) C[i][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= i; ++j) {
			C[i][j] = C[i - 1][j];
			add(C[i][j], C[i - 1][j - 1]);
		}
	} 
	for (int i = 2; i <= n; ++i) {
		int u, v; scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, -1);
	if (roots.size() == 2) return cout << mul(fac[n / 2], fac[n / 2]) << '\n',0;
	else {
		int root = roots[0];
		dfs(root, -1);
		for (int v : g[root]) a[++tot] = nchild[v];
	}
	F[0][0] = 1;
	for (int i = 1; i <= tot; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int k = 0; k <= a[i]; ++k) {
				if (j >= k) add(F[i][j], mul(mul(F[i - 1][j - k], fac[k]), mul(C[a[i]][k], C[a[i]][k])));
			}
		} 
	}
	int res = 0;
	for (int i = 0; i <= n; ++i) {
		int cur = mul(F[tot][i], fac[n - i]);
		if (i & 1) add(res, mod - cur);
		else add(res, cur);
	}
	cout << res << '\n';
}

Measured memory_bytes: 196224
using System;
using System.Collections.Generic;
using System.Linq;

namespace CsharpProgramTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // 枚数
            var s = Console.ReadLine().Split(' ');
            var count = int.Parse(s[0]);
            // 金額
            var value = int.Parse(s[1]);

            for(var x = 0; x <= count; x++) {
                for(var y = 0; y <= count - x; y++) {
                    var z = count - x - y;
                    var sum = x * 10000 + y * 5000 + z * 1000;
                    if(value == sum) {
                        Console.WriteLine(x + " " + y + " " + z);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 11092
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n;

int main() {
	cin >> n;
	cout << (n%2?2LL * n:n) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int h, w;

        while(true) {
            h = sc.nextInt();
            w = sc.nextInt();
            
            if (h == 0 && w == 0) {
                break;
            }

            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            for (int i = 0; i < w; i++) {
                if ((i % 2) == 0) {
                    sb1.append("#");
                    sb2.append(".");
                } else {
                    sb1.append(".");
                    sb2.append("#");
                }
            }
            

            for (int j = 0; j < h; j++) {
                if ((j % 2) == 0) {
                    System.out.println(sb1);
                } else {
                    System.out.println(sb2);
                }

            }

            System.out.println();

        }
    }
}

Measured memory_bytes: 27672
#include <stdio.h>

int main(void){
	char s[4];
	int num = 0;
	scanf("%s", s);
    
     for(int i=0; i<4; i++){
		 if(s[i] == '+'){
			 num++;
		 }else if(s[i] == '-'){
			 num--;
		 }
	 }	 
	 printf("%d\n",num);
	 
	 return 0;
}

Measured memory_bytes: 128
import math
a,b_sub = list(input().split())

b_sub = list(b_sub)
b = int(b_sub[0])*(10**2) + int(b_sub[2])*10 + int(b_sub[3])
a = int(a)

ans = a*b
ans = list(str(ans))
n = len(ans)

ans_1 = 0
if n >= 3:
  for i in range(1,n-1):
    ans_1 += int(ans[-2-i])*(10**(i-1))
else:
  ans_1 = 0

print(ans_1)

Measured memory_bytes: 9208
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
typedef pair<P,int> P2;


int n;
vector<P> edge[200000];
priority_queue< P,vector<P>,greater<P> > que;
int d[200000];

signed main(){
  cin >> n;
  REP(i,n-1){
    int u1,v1,w1;
    cin >> u1 >> v1 >> w1;
    edge[u1].pb(P(v1,w1));
    edge[v1].pb(P(u1,w1));
  }
  for(int i=1;i<=n;i++) d[i] = INF;
  d[1] = 0;
  que.push(P(0,1));
  while(que.size()>0){
    P now = que.top();//距離、点
    que.pop();
    if (d[now.second] < now.first) continue;
    REP(i,edge[now.second].size()){
      P now2 = edge[now.second][i];//点、距離
      if(d[now2.first] > now.first + now2.second){
        d[now2.first] = now.first + now2.second;
        que.push(P(d[now2.first],now2.first));
      }
    }
  }
  FOR(i,n){
    if((d[i]-d[1])%2==0) cout << 0 << endl;
    else cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<string, int> blood;
    char ch;
    int tmp;
    string str;

    while (cin >> tmp >> ch >> str) {
        blood[str]++;
    }
    
    cout << blood["A"] << '\n' << blood["B"] << '\n'
         << blood["AB"] << '\n' << blood["O"] << endl;

    return 0;
}

Measured memory_bytes: 1212
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int n,b;
  cin>>n;

  vi a(n);
  cin>>a;

  int ans=0;

  REP(i,n-1) if((b=a[i]-a[i+1])>0) ans += b;

  cout<<ans+a[n-1]<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#define mod 1000000007
#define INF LLONG_MAX
#define loop(i,x,n) for(int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define ll long long 
#define vpl vector< pair<ll,ll> >
#define vpi vector< pair<int,int> >
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define se second
#define fi first
using namespace std;

int solve(int n,int arr[]){
	int dp[n+1];
	
	dp[0] = 0;
	
	for(int i=1;i<n;i++){
		int l1 = INT_MAX;
		int l2 = INT_MAX;
		if(i-1 >= 0){
			l1 = abs(arr[i]-arr[i-1]) + dp[i-1];
		}
		if(i-2 >= 0){
			l2 = abs(arr[i]-arr[i-2]) + dp[i-2];
		}
		
		dp[i] = min(l1,l2);
	}
	
	return dp[n-1];
}


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

	
	int n;
	cin >> n;
	
	int arr[n];
	
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	
	cout << solve(n,arr) << "\n";
	
	
	
	return 0;
}



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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string a, b;

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int count = 0;
    a = s.substr(0, i);
    b = s.substr(i, s.size() - 1);
    for (char c = 'a'; c <= 'z'; c++) {
      if (a.find(c) != string::npos && b.find(c) != string::npos) count++;
    }
    ans = max(ans, count);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 384
s=input()
n=len(s)
if s!=s[::-1]:
    print("No")
elif s[:(n-1)//2]!=s[(n-1)//2-1::-1] or s[(n+3)//2-1:]!=s[n-1:(n+3)//2-2:-1]:
    print("No")
else:
    print("Yes")

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << 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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n,m;cin>>n>>m;
  ll a[n][m];rep(i,0,n)rep(j,0,m)cin>>a[i][j];
  ll b[m];rep(i,0,m)cin>>b[i];

  rep(i,0,n){
    ll sum=0;
    rep(j,0,m){
      sum+=a[i][j]*b[j];
    }
    out(sum);
  }

  return 0;
}



Measured memory_bytes: 3096
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <stack>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
//#include <unordered_set>
#define INF 2147483647
#define MAXN  1000100
#define PII pair<int, int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 35;
ll a[MAXN];

int main()
{
	//ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef local_debug
	ifstream inputs("input.txt");
	cin.rdbuf(inputs.rdbuf());
	freopen("input.txt", "r", stdin);
#endif
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		sort(a, a + n);
		for (int i = 1; i < n; i++) a[i] += a[i - 1];
		int ans = 1;
		for (int i = 0; i < n-1; i++)
		{
			if (a[i]*2 >= (a[i + 1] - a[i]))
				ans++;
			else
				ans = 1;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
S = []
T = []
for i in range(n):
    s, t = input().split(' ')
    t = int(t)
    S.append(s)
    T.append(t)
x = input()

idx = S.index(x)
played = T[idx+1:]
time = sum(played)
print(time)

Measured memory_bytes: 3064
##knapsackProblem
n, w = map(int, input().split())
vw = [list(map(int, input().split())) for _ in range(n)]

dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]

for i in range(n + 1):
    for j in range(w + 1):
        if j == 0:
            dp[i][j] = 0
        elif i == 0:
            dp[i][j] = 0
        else:
            if j - vw[i - 1][1] >= 0:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - vw[i - 1][1]] + vw[i - 1][0])
            else:
                dp[i][j] = dp[i - 1][j]

ans = 0
for i in range(n + 1):
    ans = max(ans, max(dp[i]))

print(ans)



Measured memory_bytes: 25948
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

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

	int H=in(),W=in();
	vector<vector<int>> M(H,vector<int>(W));
	REP(i,H){
		REP(j,W){
			char c = in<char>();
			M[i][j] = c=='#' ? 1 : 0;
		}
	}
	bool NG = false;
	REP(i,H){
		REP(j,W){
			if(M[i][j]==1){
				int count = 0;
				if(i>0 && M[i-1][j]==1) count++;
				if(i<H-1 && M[i+1][j]==1) count++;
				if(j>0 && M[i][j-1]==1) count++;
				if(j<W-1 && M[i][j+1]==1) count++;
				if(!count){
					NG = true;
					break;
				}
			}
		}
		if(NG) break;
	}
	
	cout << (NG ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int A[n][m], b[m][1], C[n][1];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> A[i][j];
  for (int i = 0; i < m; i++)
    cin >> b[i][0];
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < m; j++)
      tmp += A[i][j] * b[j][0];
    C[i][0] = tmp;
  }
  for (int i = 0; i < n; i++)
    cout << C[i][0] << endl;
  return 0;
}

Measured memory_bytes: 1200
def rotate(s,deg):
    if deg==180:
        return s.translate(str.maketrans({'U': 'D', 'D': 'U', 'L':'R', 'R':'L'}))
    elif deg==90:
        return s.translate(str.maketrans({'U': 'L', 'D': 'R', 'L':'D', 'R':'U'}))
    elif deg==-90:
        return s.translate(str.maketrans({'U': 'R', 'D': 'L', 'L':'U', 'R':'D'}))
def mirror(s,direc):
    if direc=="x":
        return s.translate(str.maketrans({'L':'R', 'R':'L'})) 
    elif direc=="y":
        return s.translate(str.maketrans({'U': 'D', 'D': 'U'}))
def solver1(x,y):
    go="R"*x+"U"*y
    back=rotate(go,180)
    go2="DR"+go+"UL"
    back2="UL"+back+"DR"
    return go+back+go2+back2

a,b,c,d=map(int,input().split())
xf=c-a
yf=d-b
x=abs(c-a)
y=abs(d-b)
print(solver1(x,y))

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int x;
	cin >> x;

	// 何回100を引けるか？
	int num100 = 0;
	while(x - 100 >= 0 )
	{
		num100++;
		x -= 100;
	}

	// 5の区分
	int k5 = 0;
	while(k5 * 5 < x){
		k5++;
	}

	if(k5 <= num100) cout << 1;
	else cout << 0;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	seq := []int{a, b, c}
	sort.Ints(seq)

	t0 := seq[len(seq)-1]
	t := t0
	for range make([]struct{}, k) {
		t *= 2
	}

	ans := 0
	for _, v := range seq {
		ans += v
	}
	ans += t - t0

	fmt.Println(ans)
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	q := getNextInt(scanner)
	r := 0
	prev := make([]string, 0)
	next := make([]string, 0)
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		if t == 1 {
			r++
			continue
		}
		f := getNextInt(scanner)
		c := getNextString(scanner)
		if r%2 == 0 {
			if f == 1 {
				prev = append(prev, c)
				continue
			}
			next = append(next, c)
			continue
		}
		if f == 1 {
			next = append(next, c)
			continue
		}
		prev = append(prev, c)
	}
	if r%2 == 0 {
		for i := len(prev) - 1; i >= 0; i-- {
			fmt.Fprint(writer, prev[i])
		}
		for i := 0; i < len(s); i++ {
			fmt.Fprintf(writer, "%c", s[i])
		}
		for i := 0; i < len(next); i++ {
			fmt.Fprint(writer, next[i])
		}
		fmt.Fprintln(writer, "")
		return
	}
	for i := len(next) - 1; i >= 0; i-- {
		fmt.Fprint(writer, next[i])
	}
	for i := len(s) - 1; i >= 0; i-- {
		fmt.Fprintf(writer, "%c", s[i])
	}
	for i := 0; i < len(prev); i++ {
		fmt.Fprint(writer, prev[i])
	}
	fmt.Fprintln(writer, "")
}


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

using namespace std;

#define MAX_N 105
#define MAX_K 100005

int n, k, w[MAX_N], v[MAX_N];

long long dp[MAX_N][MAX_K];

long long f_imp(int, int);

long long f(int p, int wh)
{
	if (dp[p][wh] == 0)
		dp[p][wh] = f_imp(p, wh) + 1;
	return dp[p][wh] - 1;
}

long long f_imp(int p, int wh)
{
	if (p == n - 1)
	{
		if (w[p] <= wh)
			return v[p];
		return 0;
	}
	if (w[p] <= wh)
	{
		return max(f(p + 1, wh), f(p + 1, wh - w[p]) + v[p]);
	}
	return f(p + 1, wh);
}

int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", w + i, v + i);
	}
	printf("%lld\n", f(0, k));
}


Measured memory_bytes: 78080
ball_color = list(map(str, input().split()))
ball_num = list(map(int, input().split()))
trash_color = input()

if (trash_color == ball_color[0]):
    ball_num[0]=ball_num[0]-1
elif (trash_color == ball_color[1]):
    ball_num[1]=ball_num[1]-1

print(str(ball_num[0]) + " " + str(ball_num[1]))

Measured memory_bytes: 3060
// CPP program for finding number of divisor 
#include<iostream>
#include <bits/stdc++.h> 
using namespace std; 


// driver program 
int main() 
{ 
    int a, b;
    cin >> a >> b;
    // for(i=1;i<=n;i++)
    // {
    //     ans += (i*divCount(i));
    // }
    cout << a*b;
	return 0; 
} 


Measured memory_bytes: 3648
N, M = gets.chomp.split.map(&:to_i)

edges = []

M.times do
  a, b, c = gets.chomp.split.map(&:to_i)

  edges << [a, b, c]
end

def find_negative_loop(edges)
  ret = Array.new(N + 1, 0)

  N.times do |i|
    edges.each do |from, to, cost|
      if ret[to] > ret[from] - cost
        ret[to] = ret[from] - cost

        if i == N - 1
          return true
        end
      end
    end
  end

  false
end

def bellman_ford(s, edges)
  ret = Array.new(N + 1, Float::INFINITY)
  ret[s] = 0

  N.times do |i|
    update = false

    edges.each do |from, to, cost|
      if ret[to] > ret[from] - cost
        ret[to] = ret[from] - cost
        update = true

        ret[to] = -Float::INFINITY if i == N - 1
      end
    end

    break unless update
  end

  ret
end

ret = bellman_ford(1, edges)

if ret[N] == -Float::INFINITY
  puts 'inf'
else
  puts -ret[N]
end


Measured memory_bytes: 2172
/*
 * @Author: Kaizyn
 * @Date: 2020-06-07 19:52:31
 * @LastEditTime: 2020-06-07 20:19:59
 */ 
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 2e2+7;

template <typename T>
struct LinearBase {
  int sz = sizeof(T)*8, zero;
  T tot;
  vector<T> b, rb, p;
  LinearBase(){ init(); }
  void init() {
    tot = zero = 0;;
    vector<T>(sz, 0).swap(b);
    vector<T>().swap(rb);
    vector<T>().swap(p);
  }
  template <typename TT>
  void build(TT a[], const int &n) {
    init();
    for (int i = 1; i <= n; ++i) insert(a[i]);
  }
  void merge(const LinearBase xj) {
    for (int i : xj.b) if (i) insert(i);
  }
  void insert(T x) {
    for (int i = sz-1; i >= 0; --i) if ((x>>i)&1) {
      if (!b[i]) { b[i] = x; return; }
      x ^= b[i];
    }
    zero = 1;
  }
  bool find(T x) {
    for (int i = sz-1; i >= 0; --i) if ((x>>i)&1) {
      if (!b[i]) { return false; }
      x ^= b[i];
    }
    return true;
  }
  T max_xor() {
    T res = 0;
    for (int i = sz-1; i >= 0; --i)
      if (~(res>>i)&1) res ^= b[i];
      // res = max(res, res^b[i]);
    return res;
  }
  T min_xor() {
    if (zero) return 0;
    for (int i = 0; i < sz; ++i)
      if (b[i]) return b[i];
  }
  void rebuild() {
    rb = b;
    vector<T>().swap(p);
    for (int i = sz-1; i >= 0; --i)
      for (int j = i-1; j >= 0; --j)
        if ((rb[i]>>j)&1) rb[i] ^= rb[j];
    for (int i = 0; i < sz; ++i)
      if (rb[i]) p.emplace_back(rb[i]);
    tot = ((T)1<<p.size())+zero;
  }
  T kth_min(T k) {
    if (k >= tot || k < 1) return -1;
    if (zero && k == 1) return 0;
    if (zero) --k;
    T res = 0;
    for (int i = (int)p.size()-1; i >= 0; --i)
      if ((k>>i)&1) res ^= p[i];
    return res;
  }
  T kth_max(const T &k) {
    return kth_min(tot-k);
  }
};

int n;
long long a[N];
string s;
LinearBase<long long> lb;

inline void solve() {
  lb.init();
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> s;
  int res = 0;
  for (int i = n; i; --i) {
    if (s[i-1] == '1') {
      res |= !lb.find(a[i]);
    } else {
      lb.insert(a[i]);
    }
  }
  cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

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

int main () {
  long long N;
  cin >> N;
  long long sum = 0;
  int Max;
  
  for (long long i = 1; i <= N; i++) {
    sum += i;
    if (sum >= N){
      Max = i;
      break;
    }
  }
  
  cout << Max << endl;
  
  sum = N - Max;
  
  for (int i = Max-1; i > 0; i--) {
    if (sum >= i){
      cout << i << endl;
      sum -= i;
    }
    if (sum == 0){
      return 0;
    }
  }
}



Measured memory_bytes: 3592
n,m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
ans = "No"

for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if B[k] != A[k+i][j:j+m]:
                break
            if k == m-1 and B[k] == A[k+i][j:j+m]:
                ans = "Yes"
                
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	char chess[300];

	int i, j, k, temp1, temp2, FLAG=0;
	int H[100], W[100];

	//配列chessに格納
	for(i=0;i<300;i++){
		chess[i] = ('#');
	}

	//行列の大きさを配列HとWに格納,両方0なら終了
	for(i=0;i<100;i++){
		scanf("%d", &temp1);
		scanf("%d", &temp2);

		if(temp1==0 && temp2==0){
			break;
		}else{
			H[i] = temp1;
			W[i] = temp2;
			FLAG++;
		}
	}

	//行列の描画
	for(i=0;i<FLAG;i++){
		for(k=0;k<H[i];k++){
			for(j=0;j<W[i];j++){
				printf("%c", chess[j]);
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

int k;
vector<int> dp;
int find(vector<int>& arr, int i) {
	if (i < 0)
		return 1e6;

	if (i == 0)
		return 0;

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

	int ans = abs(arr[i] - arr[i - 1]) + find(arr, i - 1);
	for (int j = 2; j <= k; j++) {
		if (i - j >= 0)
			ans = min(ans, abs(arr[i] - arr[i - j]) + find(arr, i - j));
	}
	dp[i] = ans;
	return dp[i];
}


int main() {
	int n;
	cin >> n >> k;
	dp.resize(n, -1);
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	cout << find(arr, n - 1);
	// vector<vector<int>> dp(n, vector<int>(k, INT_MAX));
	// dp[0][0] = 0;
	// for (int i = 0; i < n; i++) {
	// 	int min_ele = INT_MAX;
	// 	for (int j = 0; j < k; j++) {
	// 		if (i - j >= 0) {
	// 			dp[i][j] = min(dp[i][j], dp[i][i - j] + abs(arr[i] - arr[i + j]));
	// 		}
	// 	}
	// }
	// cout << dp[n - 1][k - 1];
	return 0;
}

Measured memory_bytes: 11884
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(x) setprecision(x)<<fixed
#define ss second
#define fori(v) for(lli i=0; i<v; i++)
#define forj(v) for(lli j=0; j<v; j++)
#define fork(v) for(lli k=0; k<v; k++)
#define forl(v) for(lli l=0; l<v; l++)
#define fort(v) for(lli t=0; t<v; t++)
#define forz(v) for(lli z=0; z<v; z++)
#define lli long long int
#define MAX 100004
#define double long double
#define ch 51
#define max_bit 20
#define pb push_back
#define magic 3
lli inf = pow(10,16);
lli modulo = pow(10,9)+7;
double eps = 1e-11;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void deal(){
	// n ^ (m-2) * number of pairs * 2  * (m-1) / n^ m =  number of pairs * 2 * (m-1 ) / n^2
	double n,m,d;
	cin>>n>>m>>d;
	double num = n - d;
	double aver = num * (m-1) / (n*n);
	if(d!=0)
		aver*=2;
	cout<<setp(12)<<aver;
}
int main() {
//	cin.open("i.txt");
//	cout.open("o.txt");
//	while(1)
	
	deal();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert                                                                      //copy NUL check.cpp
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ 1ad.cpp -o 1ad.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{    ll sum=0;
	int n,i=0;
	cin>>n;
	long int a[n+1],b[n];
	
for(i=1;i<n;i++)
{
	cin>>b[i];
	
}
sum=b[n-1]+b[1];
a[1]=b[1];
a[n]=b[n-1];
a[n-1]=b[n-1];

for(i=n-2;i>0;i--)
{
	
	if(b[i]<a[i+1])
	{   
		
		a[i+1]=b[i];
		a[i]=b[i];
	}
	else
		a[i]=b[i];
	
	
	
}
for(i=2;i<n;i++)
{
	sum+=a[i];;
	
}
cout<<sum;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int main(){
    int T;
    cin >> T;
    while(T--){
        LL a,b,c,d;
        cin >> a >> b >> c >> d;
        if(b>a) puts("No");
        else if(b>d) puts("No");
        else if(c>=b) puts("Yes");
        else{
            LL g=__gcd(b,d);
            LL t;
            if(c-b-a%g<0){
                t=(c-b-a%g)/g;
                if(abs(c-b-a%g)%g==0) t++;
            }
            else{
                t=(c-b-a%g)/g+1; 
            }
            if(a%g+g*t>=0) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [int(_) for _ in input().split()]
Hlist = list(map(lambda x:x-H[0],H))
result = 1
compareValue = Hlist[0]
for i in range(N-1):
  if Hlist[i+1] >= compareValue:
    result += 1
    compareValue = Hlist[i+1]
print(result)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

	vector< int> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << v[k - 1] << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
x=["SS","SW","WS","WW"]

def check(i,j):
    if x[i][j]=="S":
        if s[j]=="o":
            if x[i][j-1]=="S":
                return x[i][j+1]=="S"
            else:
                return x[i][j+1]=="W"
        else:
            if x[i][j-1]=="S":
                return x[i][j+1]=="W"
            else:
                return x[i][j+1]=="S"
    else:
        if s[j]=="o":
            if x[i][j-1]=="S":
                return x[i][j+1]=="W"
            else:
                return x[i][j+1]=="S"
        else:
            if x[i][j-1]=="S":
                return x[i][j+1]=="S"
            else:
                return x[i][j+1]=="W"

a=["S","W"]
for i in range(4):
    for j in range(n-2):
        if x[i][j+1]=="S":
            if s[j+1]=="o":
                x[i]+=a[x[i][j]!="S"]
            else:
                x[i]+=a[x[i][j]=="S"]
        else:
            if s[j+1]=="o":
                x[i]+=a[x[i][j]=="S"]
            else:
                x[i]+=a[x[i][j]!="S"]
    if check(i,0) and check(i,-1):
        print(x[i])
        break
else:
    print(-1)


Measured memory_bytes: 3820
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int ans=0;
		ans = Math.max(Math.max(A+B, A-B),A*B);
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")

#include<iostream>

using namespace std;
typedef unsigned int ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007 //10^9+7:合同式の法

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}



ll s[2001],t[2001],n,m={0};
mint dp[2001][2001]={0};

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    REP(i,n){cin>>s[i];}
    REP(i,m){cin>>t[i];}
    REP(i,n+1){dp[i][0]=1;}
    REP(i,m+1){dp[0][i]=1;}
    REP(i,n){
        REP(j,m){
            if(s[i]==t[j]){
                dp[i+1][j+1]+=(dp[i+1][j]+dp[i][j+1]);
            }else{
                dp[i+1][j+1]+=(dp[i+1][j]+dp[i][j+1]-dp[i][j]);
            }
        }
    }
    cout<<dp[n][m]<<"\n";
}

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

long long n,a[200005],r,r1,rez=1000000000000000;

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

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        r+=a[i];
    }
    for(int i=0;i<n-1;i++)
    {
        r1+=a[i];
        if(abs(r1-(r-r1))<rez)
            rez=abs(r1-(r-r1));
    }

    cout<<rez<<endl;

    return 0;
}


Measured memory_bytes: 5044
fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut shains: Vec<usize> = vec![0; n];

    for a in v.iter() {
        shains[*a-1] += 1;
    }

    for i in shains.iter() {
        println!("{}", *i);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
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; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};

ll conb(ll n){
  return n*(n-1)/2;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N, 0);
  vector<int> ball(N, 0);

  for(int i = 0; i < N; ++i){
    cin >> A[i];
    --A[i];
    ++ball[A[i]];
  }

  ll ans;
  for(int i = 0; i < N; ++i){
    ans += conb(ball[i]);
  }

  for(int i = 0; i < N; ++i){
    cout << ans - ball[A[i]] + 1 << endl;
  }

  return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define sz(a) (int) a.size()
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define lwb lower_bound
#define upb upper_bound

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  ff(i, 0, n - 1) a[i] = s[i] - '1';
  bool has1 = false;
  ff(i, 0, n - 1) {
    if (a[i] == 1) has1 = true;
  }
  if (!has1) {
    ff(i, 0, n - 1) a[i] /= 2;
  }
  int ans = 0;
  ff(i, 0, n - 1) {
    int j = (n - 1) - i;
    if ((i ^ j) == (i + j)) {
      ans += a[i]; ans %= 2;
    }
  }
  if (!has1) ans *= 2;
  cout << ans << '\n';
}

Measured memory_bytes: 5276
#include <cstdio>
#define MAX 1000000000LL
#define MAX_STRING "1000000000 "
using namespace std;

int main(int argc, char** argv)
{
	int n, k, i = 0;
	long long s;
	scanf("%d%d%I64d", &n, &k, &s);
	for(; i<k; i++)
		printf("%I64d ", s);
	if(s == MAX)
	{
		for(; i<n; i++) putchar('1'), putchar(' ');
		putchar('\n');
		return 0;
	}
	for(; i<n; i++) printf(MAX_STRING);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 6528