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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n, l, r; cin >> n >> l >> r;
    if(n == 0) break;
    vi a(n);
    REP(i, n) cin >> a[i];
    int ans = 0;
    FOR(i, l, r+1) {
      REP(j, n) {
        if(i%a[j] == 0) {
          ans += (j % 2 == 0) ? 1 : 0;
          break;
        }
        if(j == n-1) {
          ans += (n % 2 == 0) ? 1 : 0;
        }
      }
    }
    cout << ans << endl;
  }
}



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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x+1) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;

	string s;
	cin >> s;
	
	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool f=true;
	queue<string>a,b,c;
	string sa,sb,sc,t="a";
	cin>>sa>>sb>>sc;
	for(int i=0;i<sa.length();i++){
		a.push(sa.substr(i,1));
	}
	for(int i=0;i<sb.length();i++){
		b.push(sb.substr(i,1));
	}
	for(int i=0;i<sc.length();i++){
		c.push(sc.substr(i,1));
	}
	while(f){
		if(t=="a"){
			if(!a.empty()){
				t=a.front();
				a.pop();
			}else{
				cout<<"A"<<endl;
				return 0;
			}
		}else if(t=="b"){
			if(!b.empty()){
				t=b.front();
				b.pop();
			}else{
				cout<<"B"<<endl;
				return 0;
			}
		}else if(t=="c"){
			if(!c.empty()){
				t=c.front();
				c.pop();
			}else{
				cout<<"C"<<endl;
				return 0;
			}
		}
	}
}


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

int v[10000], w[10000];
int dp[10001][10001];
int main(){
    int N, W, ans = 0; cin >> N >> W;
    for(int i=0; i<N; i++) cin >> v[i] >> w[i];
    for(int i=0; i<N; i++) {
        for(int j=0; j<=W; j++) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if(j-w[i] >= 0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            ans = max(ans, dp[i+1][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7024
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 100001;
int weigh[MAX];
int value[MAX];
long dp[101][MAX];

int main()
{
	int W, n;
	cin >> n >> W;
	for (int i = 1; i <= n; i++)
		cin >> weigh[i] >> value[i];
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (j < weigh[i])
				dp[i][j] = dp[i - 1][j];
			else
			{
				dp[i][j] = max(dp[i-1][j], dp[i - 1][j - weigh[i]] + value[i]);
			}
		}
	}
	cout <<dp[n][W];
	return 0;
}

Measured memory_bytes: 78336
# https://atcoder.jp/contests/abc128/submissions/8312583
# 写経

def solve():
    from heapq import heappush, heappop
    from collections import defaultdict
    from operator import itemgetter
    import sys

    input = sys.stdin.readline

    inf = 1 << 31

    n, q = map(int, input().split())

    S = [0] * n
    T = [0] * n
    X = [0] * n
    for i in range(n):
        S[i], T[i], X[i] = map(int, input().split())

    e = [(t - x, 0, x) for t, x in zip(T, X)]
    e.extend([(s - x, 1, x) for s, x in zip(S, X)])
    e.extend([(int(input()), 2, idx) for idx in range(q)])
    # e = [*((t - x, 0, x) for t, x in zip(T, X)),
    #      *((s - x, 1, x) for s, x in zip(S, X)),
    #      *((int(input()), 2, idx) for idx in range(q))
    #      ]
    e.sort(key=itemgetter(0))
    # 安定ソートなので、0,1,2順になる（はず

    cnt = defaultdict(int)
    cnt[inf] = 1
    h = [inf]
    ret = [-1] * q
    for time, type, x in e:
        if type == 0:
            cnt[x] -= 1
        elif type == 1:
            heappush(h, x)
            cnt[x] += 1
        else:
            while not (cnt[h[0]]):
                heappop(h)
            curr = h[0]
            if curr != inf:
                ret[x] = curr

    print(*ret, sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 148572
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

ll gcd(ll a , ll b){ return b ? gcd(b,a%b) : a;}

int main()
{
    ll N;
    cin >> N;
    ll BTC = 380000;
    double count = 0.0;
    rep(i, N)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") {
            count += x;
        } else {
            count += BTC * x;
        }
    }
    cout << count << endl;
    return 0;
}



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

int main() {
	string s;cin>>s;
	set<char>se;
	for(char c:s){
		se.insert(c);
	}
	puts(s.size()==se.size()?"yes":"no");
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
-- import Text.Regex.Posix ((=~))
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

main :: IO ()
main = do
  n <- getInt
  print $ n `div` 3


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

int main()
{
    int ans = 0;
    std::string s, t;
    std::cin >> s;
    std::cin >> t;

    for (int i = 0; i < s.length(); i++) {
        if(s[i] == t[i]) ans++;
    }
    std::cout << ans << std::endl;
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, M;
int h[2001], w[2001];
int sum_h[2001], sum_w[2001];
int avail_h[2000000], avail_w[2000000];

signed main()
{
  while( cin >> N >> M, N | M ) {
    sum_h[0] = 0;
    Rep(i, N) {
      cin >> h[i];
      if ( i == 0 ) sum_h[i+1] = h[i];
      else sum_h[i+1] = sum_h[i] + h[i];
    }
    sum_w[0] = 0;
    Rep(i, M) {
      cin >> w[i];
      if ( i == 0 ) sum_w[i+1] = w[i];
      else sum_w[i+1] = sum_w[i] + w[i];
    }

    Rep(i, 2000001) avail_h[i] = avail_w[i] = 0;

    for ( int i = 0; i < N; i++ ) {
      for ( int j = i+1; j < N+1; j++ ) {
	avail_h[sum_h[j] - sum_h[i]]++;
      }
    }

    for ( int i = 0; i < M; i++ ) {
      for ( int j = i+1; j < M+1; j++ ) {
	avail_w[sum_w[j] - sum_w[i]]++;
      }
    }

    int ans = 0;
    //Rep(i, 20) cout << avail_h[i] << " " << avail_w[i] << endl;
    Rep(i, 2000000) ans += avail_h[i] * avail_w[i];

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

Measured memory_bytes: 34412
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int A, B;
	cin >> A >> B;
	int cnt = 0;
	for (int i = A;i < B + 1;++i) {
		string s = to_string(i);
		string t = s;
		reverse(t.begin(), t.end());
		if (s == t)++cnt;
	}
	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> v(n);
    for(auto &i: v) scanf("%d", &i);

    int ans = 0;
    rep(k, K+1){
        priority_queue<int, vector<int>, greater<>> que;
        rep(L, k+1)rep(R, k+1)if(L+R <= min(k, n)){
            rep(i, L) que.push(v[i]);
            rFor(i, n, n-R) que.push(v[i]);

            int cnt = K-k, tmp = 0;
            while(!que.empty()){
                int t = que.top();
                tmp += t;
                que.pop();
                if(cnt > 0 && t < 0){
                    --cnt;
                    tmp -= t;
                }
            }
            chmax(ans, tmp);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

ans = 0

R = defaultdict(int) 
#R= defaultdict(lambda:0) 

for i ,Ai in enumerate(A,1):
  R[i+Ai]+=1

L = defaultdict(int) 
for j ,Aj in enumerate(A,1):
  L[j-Aj]+=1

for i in R:
  ans+=R.get(i,0)*L.get(i,0)

print(ans)

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

const int INF = 10000;

int num_of_gt_self_type(const int type, const int unit, const vector< vector<int> >& spc){
    int res = 0;
    int v = spc[unit][type];
    for(int i = 0; i < spc.size(); i++){
        if(v < spc[i][type]){
            res++;
        }
    }
    return res;
}

int num_of_gt_self(const vector<int>& pts){
    int res = 0;
    int v = pts[0];
    for(int i = 0; i < pts.size(); i++){
        if(v < pts[i]){
            res++;
        }
    }
    return res;
}

bool risable(const int N, const vector<int>& r, const vector< vector<int> >& spc){
    vector<int> pts(N, 0);

    for(int type = 0; type < 3; type++){
        for(int unit = 0; unit < N; unit++){
            int rank = num_of_gt_self_type(type, unit, spc);
            pts[unit] += r[rank];
        }
    }
    /*
    for(int i = 0; i < N; i++){
        cout << pts[i] << endl;
    }
    */

    return num_of_gt_self(pts) < 8;
}

int main(void){
    int N;
    vector<int> r;
    vector< vector<int> > spc;
    cin >> N;
    r = vector<int>(N);
    spc = vector< vector<int> >(N, vector<int>(3));
    for(int i = 0; i < N; i++){
        cin >> r[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            cin >> spc[i][j];
        }
    }

    int ans = INF;
    for(int type = 0; type < 3; type++){
        for(int newv = spc[0][type]; newv <= 100; newv++){
            vector< vector<int> > newspc(spc);
            newspc[0][type] = newv;
            if( risable(N, r, newspc) ){
                ans = min(ans, newv - spc[0][type]);
                break;
            }
        }
    }

    if(ans == INF){
        cout << "Saiko" << endl;
    }else{
        cout << ans << endl;
    }
}

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

using namespace std;

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

        if (a >= b + c){
                cout << "0" << endl;
        }
        else if (a < b + c){
                cout << c - (a - b) << endl;
        }
        return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    string S,s;
    ll K,N,cnt1 = 0;
    ll flag = 0,cnt2 = 0,flag2 = 0,ans;

    cin >>S >> K;
    N = S.size();
    /* if(N >= 2 && K >= 2){
        if(S[0] == S[N-1]){
            cnt2++;
            flag =1;
        }
    }*/
    
    rep(i,N-1){
        /* if(cnt2>=1 && flag == 0 && i == N-2){
            flag = 1;
        }*/
        if(S[i] == S[i+1]  && flag == 0){
            cnt1++;
            flag = 1;
        }else{
            flag = 0;
        }
    }
    s = S+S;

    rep(i,N*2-1){
        if(s[i] == s[i+1]  && flag2 == 0){
            cnt2++;
            flag2 = 1;
        }else{
            flag2 = 0;
        }
    }

    ans = cnt1+(cnt2-cnt1)*(K-1);
    ll cnt3 = 0;
    rep(i,N-1){
        if(S[i] == S[i+1]){
            cnt3++;
        }

    }
    if(cnt3 == N-1){
        ans = (K*N)/2;
    }
    cout << ans << endl;
    
    
    return 0;
    

}

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
template <typename T>
using Vector = vector<vector<T>>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

const lli mod = 1E9 + 7;

void solve() {
	int n, m;
	string s;
	cin >> n >> m >> s;

	/// take maximum steps from N to 0 ///
	vector<int> steps;
	for (int i = n, j = max(i-m, 0); i > 0; j = max(i-m, 0)) {
		for (; j < i; ++j) {
			// printf("check: %d\n", j);
			if (s[j] == '0') {
				steps.Push(i - j);
				break;
			}
		}
		if (j == i) {
			cout << -1 << "\n";
			return;
		}
		// printf("    towards: %d\n", j);
		i = j;
	}

	accumulate(RALL(steps), 0, [](auto a, auto b) {
		cout << b << " ";
		return 0;
	});
	cout << "\n";
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<int, int>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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

    int n, m;
    while (cin >> n >> m) {
        vector<pair<int, int>> lr(m);
        forn(i, m) {
            cin >> lr[i].first >> lr[i].second;
        }

        auto res = lr[0];
        forn(i, m) {
            uax(res.first, lr[i].first);
            uin(res.second, lr[i].second);
        }
        
        cout << max(0, res.second - res.first + 1) << endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	int ans[101] = {0}, i, n;
	int b = 0;
	while(cin >> n){
		ans[n] ++;
		if(ans[n] > b){
			b = ans[n];
		}
	}
	
	for(i = 1; i <= 100; i ++){
		if(b == ans[i]){
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  deque<char> s;
  string t;
  cin >> t;
  for (char c : t) {
    s.push_back(c);
  }
  int flipped = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      flipped ^= 1;
    } else {
      int f; char c;
      cin >> f >> c;
      --f;
      f ^= flipped;
      if (f) {
        s.push_back(c);
      } else {
        s.push_front(c);
      }
    }
  }
  if (flipped) {
    reverse(begin(s), end(s));
  }
  for (char c : s) {
    cout << c;
  }
  cout << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 976
//
//  main.cpp
//  DPL

#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
vector<ll>as(3005);
vector<vector<bool>>flag(3005,vector<bool>(3005,false));
vector<vector<ll>>dp(3005,vector<ll>(3005));
ll f(int i,int j){
   if(flag.at(i).at(j)) return dp.at(i).at(j);
    if(i==j){
        return dp.at(i).at(j)=as.at(i);
    }
    flag.at(i).at(j)=true;
    return dp.at(i).at(j)=max(as.at(i)-f(i+1,j),as.at(j)-f(i,j-1));
}
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    rep(i,n) {
        cin>>as.at(i);
    }
    rep(i,n){
        for(int j=i;j<n;j++){
            dp.at(i).at(j)=f(i,j);
        }
    }
    cout<<dp.at(0).at(n-1)<<endl;
    return 0;
}


Measured memory_bytes: 75092
#include<stdio.h>
#include<string.h>
int main()
{
    char str[200000];
    int i,j,len,ca,cb,count;
    while(gets(str))
    {
        count=0;
        len=strlen(str);
        for(i=0; i<len; i++)
        {
            if(str[i]=='A')
            {
                ca=i;
                break;
            }
        }
        for(j=len-1; i>=0; j--)
        {
            if(str[j]=='Z')
            {
                cb=j;
                break;
            }
        }
        count=cb-ca;
        printf("%d\n",count+1);
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,t=0,ans=1;
    cin >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++) {
        cin >> a.at(i);
    }
    t=a.at(0);
    for (int i=1;i<n;i++){
        if (a.at(i)>=t) {ans++;t=a.at(i);}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())

q=['WA' for i in range(n)]
w=[0 for i in range(n)]
ans=0
pen=0
for i in range(m):
    p,s=input().split()
    pi=int(p)-1
    if s=='AC' and q[pi]=='WA':
        ans+=1
        pen+=(w[pi])
        q[pi]='AC'
    else:
        w[pi]+=1
        

        
print(ans,pen)

Measured memory_bytes: 4656
#include<stdio.h>


int main(void){
	int h,w,i;
	char s[128];
	scanf("%d%d",&h,&w);
	for(i = 1;i <= h;i++){
		scanf("%s",s);
		printf("%s\n%s\n",s,s);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	string s,t;
	int ans=0;
	cin >> s >> t;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			ans++;
		}
	} 
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for(int i=0; i<n; i++)

int main() {
    int n; string s; cin >> n >> s;
    int ans = 0;
    rep(i, n){
        int tmp = 0;
        string s1 = s.substr(0, i), s2 = s.substr(i);
        for(char c='a'; c<='z'; c++){
            bool founds1 = false, founds2 = false;
            rep(j, s1.length()) if(s1[j] == c) founds1 = true;
            rep(j, s2.length()) if(s2[j] == c) founds2 = true;
            if(founds1 && founds2) tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main(){
  int i,j,n,A[N],flag = 1,temp,cunt = 0;
  scanf("%d",&n);
  for(i = 0; i < n;i++){
    scanf("%d",&A[i]);
  }
  
  while(flag){
    flag = 0;
    for(j = n-1;j > 0;j--){
      if (A[j] < A[j-1]){
	temp = A[j-1];
	A[j-1] = A[j];
	A[j] = temp;
	flag = 1;
	cunt++;
      }
    }
  }
for(i = 0;i < n;i++){
  if(i) printf(" ");
  printf("%d",A[i]);
      }
 printf("\n");
 printf("%d",cunt);
printf("\n");
return 0;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int a,b;
   cin >> a >> b;
   if(a>=1 && a<=9 && b>=1 && b<=9) cout << a*b << endl;
   else cout << "-1\n";
   
   return 0;
}

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

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

    int i = 0;
    while (true) {

        if (a <= 0 || c <= 0) break;

        if (i % 2 == 1) {
            a -= d;
        }
        else {
            c -= b;
        }

        i++;
    }

    string ans = "Yes";

    if (a <= 0) ans = "No";

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int A,B,C;  cin>>A>>B>>C;
  if((A==B)&&(B!=C)) cout<<"Yes"<<endl;
  else if((B==C)&&(C!=A)) cout<<"Yes"<<endl;
  else if((C==A)&&(A!=B)) cout<<"Yes"<<endl;
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        int count = 0;
        
        for(int i = 0; i < 3; i++){
            if(S.charAt(i) == 'o') count++;    
        }
        System.out.println(700 + count * 100);
    }
}
 

Measured memory_bytes: 23764
include Math
define_method :max, -> (a,b) { a > b ? a : b }
define_method :min, -> (a,b) { a < b ?  a : b }
define_method :swap, -> (a,b) { a, b = b, a }
define_method :rep, -> (num, &block) { num.times do |i| block.call(i) end }
define_method :repl, -> (st,en, &block) { st.upto en-1 do |i| block.call(i) end }
define_method :array, -> (size,init = nil) { Array.new(size){init} }
define_method :darray, -> (size1, size2, init = nil) { Array.new(size1){Array.new(size2){init}} }
define_method :gi, -> () { gets.split.map(&:to_i) }
define_method :gs, -> () { gets.chomp }
define_method :putall, -> (obj) { obj.each do |o| puts o end }


n = gi[0]
ans = 1
rep n do |i|
ans *= i+1
ans %= (10**9+7)
end

puts ans


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

int main() {
    int n, t, a, ans = -1;
    cin >> n >> t >> a;
    float best_temp_diff = 100000;
    for (int i = 0; i < n; i++) {
        int h;
        float temp_diff;
        cin >> h;
        temp_diff = abs(t - h * 0.006 - a);
        if (temp_diff < best_temp_diff) {
            best_temp_diff = temp_diff;
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools

def main():
    N, M, X = map(int, input().split())
    C = [0] * N
    A = []
    for n in range(0, N):
        l = input().split()
        C[n] = int(l[0])
        A.append([int(i) for i in l[1:]])

    min_cost = sum(C) + 1
    globalCanAchive = False
    for i in range(1,N+1):
        for comb in itertools.combinations(range(N), i):
            canAchive = True
            for m in range(M):
                r = sum([A[n][m] for n in comb])
                if (r < X):
                    canAchive = False
                    break
            if (canAchive):
                globalCanAchive = True
                cost = sum([C[n] for n in comb])
                min_cost = min(min_cost, cost)

    if (globalCanAchive):
        print(min_cost)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;


int main(){
	string str;
	cin>>str;
	map<char,int> mp;
	for(int i=0;i<str.size();i++){
		mp[str[i]]++;
	}
	for(auto a:mp){
		if(a.second%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <math.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
int main() {
  int w, s;
  scanf("%d %d", &s, &w);
  printf("%s", w >= s ? "unsafe" : "safe");
  return 0;
}

Measured memory_bytes: 2156
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

long long inputValuelong(){
    long long a;
    cin >> a;
    return a;
}

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int a,b,x;
    a = inputValue();
    b = inputValue();
    x = inputValue();
    int i;
  double asd;
    if(x<(a*a*b)/2){
      double s;
      s = double(x)/double(a*b)*2;
      asd = double(b)/double(s);
    }else{
	    double h;
    	h = double(x)/double(a*a);
    	//cout << h << endl;
    	double d = b-h;
    	//cout << d << endl;
    	asd = 2*d/double(a);
    	//cout << asd << endl;
    }

    double theta = atan(asd)*180/M_PI; 
    printf("%.10lf\n",theta);
    //cout << theta << endl;
    return 0;
}

Measured memory_bytes: 256
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-03-19 17:35:03
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 2000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

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

int dp[N + 1][N + 1];
int sum[N + 1];

int main()
{
    //freopen("circus.in", "r", stdin);
    //freopen("circus.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, k;
    cin >> n >> k;
    dp[0][0] = 1;
    rep(i, 0, n + 1) { // number of core items, number i+1 is not present
        rep(j, 0, n - i + 1) { // length of tail
            if (i == 0 && j == 0) {
                continue;
            }
            int alr = n - i - j;
            if (alr == k - 1) {
                // need to put 1
                if (i != 0) {
                    add(dp[i][j], dp[0][j + (i - 1)]);
                }
            } else {
                if (j > 0) {
                    add(dp[i][j], dp[i][j - 1]);
                    if (i == 0 && j > 1) {
                        add(dp[i][j], dp[i][j - 1]);
                    }
                }
                /*rep(t, 2, i + 1) {
                    add(dp[i][j], dp[t - 1][j + (i - t)]);
                }*/
                add(dp[i][j], sum[i + j - 1]);
            }
        }
        if (i > 0) {
            rep(j, 0, n - i + 1) {
                add(sum[i + j], dp[i][j]);
            }
        }
    }
    cout << dp[n][0] << "\n";
    return 0;
}


Measured memory_bytes: 15360
N = int(input())
xv=[]
for _ in range(N):
    xv.append(tuple(input().split()))
profit=0
for val in xv:
    if val[1]=='JPY':
        profit+=int(val[0])
    else:
        profit+=float(val[0])*380000.0

#print(N, xv)
print(profit)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int fa[100001];
int getfa(int x) {
	if (!fa[x]) return x;
	return fa[x] = getfa(fa[x]);
}
int main() {
	int n, m, ans;
	cin >> n >> m;
	ans = n - 1;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		u = getfa(u), v = getfa(v);
		if (u != v) fa[u] = v, --ans;
	}
	cout << ans << endl;
}

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

string shuffle(string word1,int h){
    string head = word1.substr(0,h);
    string tail = word1.substr(h,word1.size()-h);
    return tail + head;
}

int main(){
    int x,y;
    string word;
    while(1){
        cin >> word;
        if(word=="-") break;
        cin >> x;
        for(int i=0;i<x;i++){
            cin >> y;
            word = shuffle(word,y);
        }
        cout << word << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
H,W = map(int, input().split())

ans = 10**10
for i in range(1, H):
    if (H-i)%2 == 0:
        smax = max(W*i, (H-i)*W//2)
        smin = min(W*i, (H-i)*W//2)
    else:
        smax = max(W*i, (H-i+1)*W//2)
        smin = min(W*i, (H-i-1)*W//2)
    ans = min(ans, smax-smin)
    if W%2 == 1:
        smax = max(W*i, (H-i)*(W+1)//2)
        smin = min(W*i, (H-i)*(W-1)//2)
    else:
        smax = max(W*i, (H-i)*W//2)
        smin = min(W*i, (H-i)*W//2)
    ans = min(ans, smax-smin)

for i in range(1, W):
    if (W-i)%2 == 0:
        smax = max(H*i, (W-i)*H//2)
        smin = min(H*i, (W-i)*H//2)
    else:
        smax = max(H*i, (W-i+1)*H//2)
        smin = min(H*i, (W-i-1)*H//2)
    ans = min(ans, smax-smin)
    if H%2 == 1:
        smax = max(H*i, (W-i)*(H+1)//2)
        smin = min(H*i, (W-i)*(H-1)//2)
    else:
        smax = max(H*i, (W-i)*H//2)
        smin = min(H*i, (W-i)*H//2)
    ans = min(ans, smax-smin)
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main() {
	int addNumber[20];
	int ansNumber[200];
	int needAddN, needAnsN;
	int YorN;
	int i, j;

	scanf("%d", &needAddN);
	for (i = 0; i < needAddN; i++) {
		scanf("%d", &addNumber[i]);
	}
	scanf("%d", &needAnsN);
	for (i = 0; i < needAnsN; i++) {
		scanf("%d", &ansNumber[i]);
	}

	for (i = 0; i < needAnsN; i++) {
		int addBox;
		int down; //??°????????°????????????????????????
		down = 0;
		for (j = needAddN - 1; j >= 0; j--) {
			down++;
			addBox = addNumber[j];
			if (addBox == ansNumber[i]) {
				YorN = 1;
				break;
			}
			YorN = calc(ansNumber[i], addNumber, needAddN - down, addBox);
			if (YorN == 1) {
				break;
			}
		}
		if (YorN == 1) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}

	return 0;
}

int calc (int answer, int* addNumber, int count, int addBox) {
	int trueA;
	if (addBox > answer || count < 0) {
		return -1;
	}

	do {
		count--;
		if (count < 0) {
			return -1;
		}
		addBox += addNumber[count];
		if (addBox == answer) {
			trueA = 1;
		}
		else {
			trueA = calc(answer, addNumber, count, addBox);
			addBox -= addNumber[count];
		}
	} while (trueA == -1);

	return 1;
}

Measured memory_bytes: 580
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>

using namespace std;

int main()
{
    long long a, b, c, k;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
    long long ans = 0;
    if(k <= a){
        printf("%lld\n", k);
        return 0;
    }
    ans += a; k-= a;
    k = k>b ? k-b : 0;
    k<=0 ? 0 : ans-=k;
    printf("%lld\n", ans);
}


Measured memory_bytes: 1736
#include<stdio.h>
#include<complex>
#include<vector>
#include<algorithm>

int n, x[100], y[100];
long long h[100], H;

long long top(int, int);

int main()
{

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d%ld", x + i, y + i, h + i);
	}
	
	for (int cx = 0; cx <= 100; ++cx)
	{
		for (int cy = 0; cy <= 100; ++cy)
		{
			bool flag = 1;
			H = top(cx, cy);
			for (int i = 0; i < n; ++i)
				if (std::max((long long)0, H - std::abs(x[i] - cx) - std::abs(y[i] - cy)) != h[i])
				{
					flag = 0;
					break;
				}
			if (flag)
			{
				printf("%d %d %lld\n", cx, cy, H);
				return 0;
			}
		}
	}
	return -1;
}

long long top(int cx, int cy)
{
	for (int i = 0; i < n; ++i)
	{
		if (h[i] == 0) continue;
		return h[i] + std::abs(cx - x[i]) + std::abs(y[i] - cy);
	}
}

Measured memory_bytes: 128
//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
ll power(ll a, ll b)
{ a = a%mod;
    ll ans = 1;
    while(b>0)
    {
        if(b&1) {
            ans = ans*a;
            ans = ans%mod;
        }
        a = a*a;
        a = a%mod;
        b>>=1;
    }
    return ans%mod;
}
int main()
{
    //freopen("in.txt","r",stdin);
    start;
    ll i,j,k,n,m;
    cin>>n;
    ll sum=power(10,n);
    ll ami=power(9,n);
    ll tumi=power(8,n);
    ll ans=(sum+tumi)%mod;
    cout<<((ans-(2*ami))%mod+mod)%mod<<endl;
  rr;
}


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

int main(){
    char b;
    cin>>b;
    if(b=='A'){
        cout<<"T"<<endl;
    }
    else if(b=='T'){
        cout<<"A"<<endl;
    }
    else if(b=='C'){
        cout<<"G"<<endl;
    }
    else if(b=='G'){
        cout<<"C"<<endl;
    }
}

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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, sum = 0;
ll A[500000] = {}, B[500000] = {}, C[500000] = {}, dp[100][10] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = false, check2 = false;

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

int main() {

	//Code Line
	cin >> n;
	for (int i = 0; i < n - 1; i++)cin >> A[i];
	A[n - 1] = A[n - 2];
	sum += A[0];

		for (int i = 0; i < n - 1; i++) {
			sum += min(A[i], A[i + 1]);
		
		}

		cout << sum << endl;
	

	return 0;
}


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

int main()
{
  string S, T;
  cin >> S >> T;
  int N = S.size();
  vector<int> A(26, 0), B(26, 0), v1(N), v2(N);
  int n = 1, m = 1;
  for (int i = 0; i < N; i++)
  {
    int a = S.at(i) - 'a';
    int b = T.at(i) - 'a';
    if (A.at(a))
    {
      v1.at(i) = A.at(a);
    }
    else
    {
      v1.at(i) = A.at(a) = n;
      n++;
    }
    if (B.at(b))
    {
      v2.at(i) = B.at(b);
    }
    else
    {
      v2.at(i) = B.at(b) = m;
      m++;
    }
    if (v1.at(i) != v2.at(i))
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 


    fast;

    ll n;
    cin>>n;

    string s[n];
    for(ll i=0;i<n;i++)
      cin>>s[i];

    map<string,ll> m;

    for(ll i=0;i<n;i++)
      sort(s[i].begin(),s[i].end());

    for(ll i=0;i<n;i++)
      m[s[i]]++;

    ll ans=0;

    for(auto i:m)
      {
        ll x=(i.ss)*(i.ss-1);
        x/=2;
        ans+=x;
      }

    cout<<ans<<endl;
  
  }

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    ll X;
    cin >> X;
    for(ll ans = 1; ans <= 100000000; ans++) {
        if(ans * (ans + 1) >= 2 * X) {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0 for k in range(M)]
B = [0 for k in range(M)]

for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -= 1
good = [1 for k in range(N)]

for k in range(M):
    if H[A[k]] <= H[B[k]]:
        good[A[k]] = 0
    if H[A[k]] >= H[B[k]]:
        good[B[k]] = 0   
        '''
for k in range(N):
    if good[k] ==1:
        if k in A:
            for j in range(M):
                if k == A[j] and H[k]<=H[B[j]]:
                    good[k] = 0
                if k == A[j] and H[k]>=H[B[j]]:
                    good[B[j]] = 0
        if k in B:
            for j in range(M):
                if k == B[j] and H[k]<=H[A[j]]:
                    good[k] = 0
                if k == B[j] and H[k]>=H[A[j]]:
                    good[A[j]] = 0
'''
print(sum(good))
        

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


int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int c=k;
  while(k <= b){
    if((a <= k) && (k <= b)){
      cout << "OK" << endl;
      return 0;
    }
    k += c;
  }
    
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ff first
#define ss second
#define vi vector<int>
#define pb emplace_back
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<ll,ll>>
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i=0 ; i<n ; ++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;
 
using namespace std;

int main(){
	fast
	int a;
	cin >> a;
	int b,c;
	cin >> b >> c;
	int a1 = b/a;
	int a2 = c/a;
	
	cout << (((a1!=a2)||(b%a==0) || (c%a==0))?"OK":"NG");
}


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

#define ll long long
#define sz(x) (int)x.size();

using namespace std;

int r,d,x;

int main(){
	cin>>r>>d>>x;
	for(int i=0;i<10;i++){
		cout<<r*x-d<<'\n';
		x=r*x-d;
	}
}

Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main ()
{
    int N;
    cin>>N;
    int a,b,c,t,m,x;
    for(int i=1; i<=N; i++){

        cin>>a>>b>>c;
         t=a*a+b*b+c*c;
         m=max(a*a,max(b*b,c*c));
         x=t-m;
        if(m==x){
                cout<<"YES";
        }
        else {
            cout<<"NO";
        }
        
            cout<<endl;
    }
    return 0;
}



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

int main(){
	int H , W;
  	cin >> H >> W;
  	string S = string(W+2 , '#');
  	cout << S << endl;
	for (int i = 0 ; i < H ; i ++){
      cout << '#';
      string input;
      cin >> input;
      cout << input;
      cout << '#' << endl;
    }
  	cout << S << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x;
  cin>>x;
  if(x)
    cout<<0<<endl;
  else
    cout<<1<<endl;
}



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

int main()
{
	int k;
	string s;
	string temp;
	while(cin>>k>>s)
	{
		temp.assign(s.c_str());
		if(s.size()>k)
		{
			temp.assign(s.c_str(),k);
			temp.append("...");
		}
		cout<<temp<<endl;
		
	}
	
	
return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
///////////////////////////
int main() {
  long long int a,b,ans=2019;
  cin>>a>>b;
  if(b-a<=2019){
    for(long long int i=a;i<=b-1;i++){
      for(long long int j=i+1;j<=b;j++){
        ans=min(ans,(i%2019)*(j%2019)%2019);
      }
    }
    cout<<ans<<endl;
  }else{
    cout<<0<<endl;
  }
}
///////////////////////////


Measured memory_bytes: 256