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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	int K = -1;
	for (int k = 1; k < 1000; k++) {
		if (k*(k-1)/2== N) {
			K = k;
			break;
		}
	}
	if (K == -1) {
		cout << "No" << endl;
		return;
	}
	vvint dats(K);
	cout << "Yes" << endl;

	int i = 0, j = 1;
	for (int u = 1; u <= N; u++) {
		dats[i].push_back(u);
		dats[j].push_back(u);
		j++;
		if (j == K) {
			i++;
			j = i+1;
		}
	}

	cout << K << endl;
	for (int i = 0; i < K; i++) {
		cout << dats[i].size();
		for (auto &u : dats[i]) {
			cout << " " << u;
		}
		cout << el;
	}

}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 4252
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s; cin >> s;
    map<char,int> m;
    int si = SIZE(s);
    rep(i,si){
        m[s[i]]++;
    }
    rep(i,26){
        if(m['a'+i] % 2 == 1){
            no();
            return 0;
        }
    }
    yes();
    return 0;
}


Measured memory_bytes: 256
/*input

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

int fun(int a,int b,int c,int k)
{
	if(c>b && b>a) return 1;
	if(k==0) return 0;

	int ans = 0;
	ans|=fun(a*2,b,c,k-1);
	ans|=fun(a,b*2,c,k-1);
	ans|=fun(a,b,c*2,k-1);
	return ans;
}

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


	if(fun(a,b,c,k)) cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int n,k;
	cin>>n>>k;
	int a[n+1],dp[n+1];
	loop(i,1,n+1) 
	{
		cin>>a[i];
		dp[i] = INF;
	}

	dp[1] = 0;
	loop(i,2,n+1)
	{
		for(int j=1;j<=k;j++)
		{
			if(i-j<=0) break;
			dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
		}
	}
	cout<<dp[n]<<endl;
	return 0;		
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  char op;
  cin >> a >> op >> b;
  if(op == '+') cout << a+b << endl;
  else cout << a-b << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        final int a = Integer.parseInt(line[0]);
        final int b = Integer.parseInt(line[1]);
        final long pow = Math.round(Math.pow(100, a));
        if (b <= 99) {
            System.out.println(b * pow);
        } else {
            System.out.println(101 * pow);
        }
    }
}


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

int main() {
  string a, b;
  cin >> a >> b;
  if (a == "H") {
    cout << b << endl;
  }
  else if (a == "D" && b == "H") {
    cout << "D" << endl;
  }
  else {
    cout << "H" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int n = scanner.nextInt();
        int sum = 0;
        int tmp = 0;
        int[] intArray = new int[n];

        for(int i = 0; i < n; i++) {
        	tmp = scanner.nextInt();
        	intArray[i] = tmp;
        	sum += tmp;
        }

        tmp = 100*n; // 初期値で最大の重さをセット
        int tmp2 = 0;

        for(int j = 0; j < n-1; j++) {
        	tmp2 += intArray[j];
        	if(Math.abs(sum-tmp2-tmp2) < tmp) {
        		tmp = Math.abs(sum-tmp2-tmp2);
        	}
        }

        System.out.println(tmp);


    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21332
#include<stdio.h>
int main()
{
    unsigned long long int A,B,count=0,temp;
    while(scanf("%lld %lld",&A,&B)!=EOF)
    {
        temp=A;
        while(temp<=B)
        {
            count++;
            temp+=temp;
        }
        printf("%lld\n",count);
        count=0;
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--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 ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
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 debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(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;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  int n = in();
  map<int,int> m;
  rep(i,n)++m[in()];
  foreach(i,m){
    if(i.second>=3){
      i.second -= (i.second-1) / 2 * 2;
    }
  }
  int cnt = 0;
  foreach(i,m)if(i.second==2)++cnt;
  if(cnt&1){
    cout << m.size()-1 << endl;
  }else{
    cout << m.size() << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
s = input()

print(s.replace('a','x').replace('b','x').replace('c','x').replace('d','x').replace('e','x').replace('f','x').replace('g','x').replace('h','x').replace('i','x').replace('j','x').replace('k','x').replace('l','x').replace('m','x').replace('n','x').replace('o','x').replace('p','x').replace('q','x').replace('r','x').replace('s','x').replace('t','x').replace('u','x').replace('v','x').replace('w','x').replace('y','x').replace('z','x'))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(B - A <= 0) {
			System.out.println("delicious");
		} else if(B - A <= X) {
			System.out.println("safe");
		} else {
			System.out.println("dangerous");
		}
	}
}


Measured memory_bytes: 23636
// AOJ 1134: Name the Crossing
// 2017.11.13 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ 503
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table

int insert(char *s, int w, int id)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

int lookup(char *s, int w)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	return -1;
}

#define INT 0x20202020
char name[202][36]; int sz;
int rel[202][202];

int main()
{
	int n, m, w, i, j, k;
	char buf[36], *p, *q;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		memset(hash, 0, sizeof(hash));
		memset(rel, INT, sizeof(rel));

		n = atoi(buf), sz = 0;
		while (n--) {
			fgets(name[sz], 35, stdin);
			p = q = name[sz]; while (*p != '-') p++; w = p - q, *p++ = 0;
			if ((i = insert(q, w, sz)) < 0) i = sz++;
			q = p; while (*p > ' ') p++; w = p - q, *p = 0;
			if ((j = insert(q, w, sz)) < 0) j = sz++;
			rel[i][j] = 1;
		}
		printf("%d\n", sz);

		for (i = 0; i < sz; i++) for (j = 0; j < sz; j++) if (j != i) {
			int f = 0;
			for (k = 0; k < sz; k++) {
				if (rel[i][k] & 1 && rel[k][j] & 1 ||
					rel[j][k] & 1 && rel[k][i] & 1) { f = 0; break; }
				if (!f) {
					if (rel[i][k] & 1 && rel[j][k] & 1 ||
						rel[k][i] & 1 && rel[k][j] & 1) f = 1;
				}
			}
			if (f) rel[i][j] = rel[j][i] = 0;
		}

		for (k = 0; k < sz; k++) for (i = 0; i < sz; i++) for (j = 0; j < sz; j++)
			if (rel[i][j] > rel[i][k] + rel[k][j]) rel[i][j] = rel[i][k] + rel[k][j];

		fgets(buf, 10, stdin); m = atoi(buf);
		while (m--) {
			fgets(buf, 35, stdin);
			p = q = buf; while (*p != '-') p++;	w = p - q, *p++ = 0;
			if ((i = lookup(q, w)) < 0) goto no;
			q = p; while (*p > ' ') p++; w = p - q, *p = 0;
			if ((j = lookup(q, w)) < 0) goto no;
			if (rel[i][j] & 1) puts("YES");
			else {
no:				puts("NO");
			}
		}
	}
	return 0;

}

Measured memory_bytes: 1868
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>9||b>9)
        puts("-1");
    else
        cout<<a*b<<endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Function
import Data.Char
import Data.List
import Text.Read
import Text.ParserCombinators.ReadPrec

import qualified Data.ByteString.Char8 as B

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine
  print $ solve as

solve :: [Int] -> Int
solve xs = go 0 xs
 where
  go acc [] = acc
  go acc [x] = if odd x then acc + 1 else acc
  go acc (x:_:xs) = if odd x then go (acc + 1) xs else go acc xs


Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const int MAX_N = 1000000;

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;

    for (T i = 2; i * i <= n; i++) {
        // 素数だったら
        if (spf[i] == i) {
            for (T j = i * i; j <= n; j += i) {
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

template<typename T>
set<T> factolization(T x, vector<T> &spf) {
    set<T> ret;
    while (x != 1) {
        ret.insert(spf[x]);
        x /= spf[x];
    }
    return ret;
}

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    auto spf = smallest_prime_factors(MAX_N);

    bool flag_p = true;
    set<ll> st;
    rep(i, N) {
        auto result = factolization(A[i], spf);
        for (auto itr : result) {
            // cout << A[i] << " " << itr << endl;
            if (st.count(itr) > 0) {
                flag_p = false;
            }
            st.insert(itr);
        }
        if (!flag_p) break;
    }

    ll G = A[0];
    repd(i, 1, N) {
        G = gcd(G, A[i]);
    }

    if (flag_p) cout << "pairwise coprime" << endl;
    else if (G == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 11176
#include <stdio.h>

int main(void)
{
    unsigned long int N;
    scanf("%lu", &N);
    
    unsigned long int cnt=0;
    unsigned long int mid;

    if((N%2)==0) {
        mid = N/2;
    } else {
        mid = N/2 + 1;
    }

    cnt=(N-1) - mid + 1;

    for(int i=1; i<=(mid-1); i++) {
        if((N%i)==0) {
            cnt+=((N/i)-1);
        } else {
            cnt+=(N/i);
        }
    }

    printf("%lu", cnt);
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int A, B; std::cin >> A >> B;
  int ans = 0;
  for(int i=A; i<=B; i++) {
    std::string a = std::to_string(i);
    std::string b = a;
    std::reverse(b.begin(), b.end());
    if ( a == b ) ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int N=1e5+5;
char str[N];
int fa[N];
int main()
{
	scanf("%s",str+1);
	int len=strlen(str+1);if(str[1]=='0'||str[len]=='1')return puts("-1"),0;
	for(int i=1;i<=len/2;++i)if(str[i]!=str[len-i])return puts("-1"),0;
	for(int i=2,x=1;i<=len;++i)
	{
		fa[i]=x;if(str[i-1]&1)x=i;
	}
	for(int i=2;i<=len;++i)printf("%d %d\n",i,fa[i]);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 2e5+7;
const int maxV = 90010;
 
const int MOD = 1e9+7;
 
int T;
const int maxN = 2e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int t[maxN];
int lowbit(int x)
{
	return x & (-x);
}
void add(int x,int p)
{
	for(;x<=n;x += lowbit(x))
	{
		t[x] = max(t[x],p);
	}
}
int get(int x)
{
	int p = 0;
	for(; x; x-=lowbit(x))
	{
		p = max(p,t[x]);
	}
	return p;
}
int main() {
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		int p = lower_bound(v.begin(),v.end(),a[i]) - v.begin() + 1;
		a[i] = p; 
	}
	reverse(a+1,a+n+1); 
	int ans = 1;
	for(int i=1;i<=n;i++)
	{
		int x = a[i];
		int v = get(x);
		add(x,v+1);
		ans = max(ans,v+1); 
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[1001];
int n;
int dx[]={1,0,-1},dy[]={1,1,1};
int ful(int y,int x){
    int sum=0;
    while(1){
        x++;
        if(s[y].size()<=x){
            x--;
            break;
        }
        if(s[y][x]==' '){
            x--;
             break;
        }
    }
    s[y][x]='#';sum++;
        if(y+1<n){
          if(x+1<s[y+1].size()&&x-1>=0){
           if(s[y+1][x+1]=='*'&&s[y+1][x-1]=='*'){
              sum+=ful(y+1,x+1);
            }
            else goto L;
         }
          else{L:;int ppp=0;
          r(i,3){
          int yy=y+dy[i];
          int xx=x+dx[i];
           if(yy>=0&&yy<n&&xx>=0)
             if(xx<s[yy].size())
                 if(s[yy][xx]=='*')
                    if(!ppp)
                     sum+=ful(yy,xx),ppp++;}}
           }

    //cout<<y<<x<<endl;r(k,n)cout<<s[k]<<endl;
    return sum;
}
int con(int y,int x){
    int sum=0,p=x,pp=x;
    for(;x<s[y].size();){
        if(s[y][x]=='#'){
            break;
        }
        if(p==pp)s[y][x]='#';
        if(x-1>=0)if(s[y][x-1]=='#'&&s[y][x]=='*')s[y][x]='#';
        sum++;
        x++;p++;
    }
    r(i,3){
        int yy=y+dy[i];
        int xx=pp+dx[i];
        if(yy>=0&&yy<n&&xx>=0)
            if(xx<s[yy].size())
                if(s[yy][xx]=='*')
                    sum+=con(yy,xx);
    }
    return sum;
}
void del(){
    r(i,n)r(j,s[i].size())
      if(s[i][j]=='#')s[i][j]=' ';
}
int main(){

    int ppp=0;

    while(cin>>n,n){

        if(ppp)cout<<"----------"<<endl;

        ppp++;

        string t;

        getline(cin,t);

        r(i,n){

            getline(cin,t);

            s[i]=t;

            //cout<<t<<endl;
        }

        map<int,int>m;

        for(int i=0;i<n;i++){

            for(int j=0;j<s[i].size();j++){

                int sum=0;

                if(s[i][j]=='*'){

                    sum+=ful(i,j);//r(k,n)cout<<s[k]<<endl;

                    sum+=con(i,j);

                    del();

                    m[sum]++;//cout<<sum<<endl;
                }
                
            }

        }

        for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
            cout<<(*it).first<<' '<<(*it).second<<endl;
        
    }
}

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

int main() {
  int n,a, b, cnt = 0;
  cin >> n >> a >> b;
  for (int i=1; i <= n; i++) {
    int sum = 0, tmp = i;
    for (int j=0; j < 5; j++) {
      sum += tmp % 10;
      tmp /= 10;
    }
    cnt += (a <= sum && b >= sum ? i : 0);
  }
  cout << cnt << endl;
}

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

int main() {
    ll X; cin >> X;
    int A, B;
    for (int i = -1000; i <= 1000; i++) {
        for (int j = -1000; j <= 1000; j++) {
            if (pow(i, 5) == pow(j, 5) + X) A = i, B = j;
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int N;
	cin >> N;
	if(N<=111) cout << 111 << endl;
	else if(N<=222) cout << 222 << endl;
	else if(N<=333) cout << 333 << endl;
	else if(N<=444) cout << 444 << endl;
	else if(N<=555) cout << 555 << endl;
	else if(N<=666) cout << 666 << endl;
	else if(N<=777) cout << 777 << endl;
	else if(N<=888) cout << 888 << endl;
	else cout << 999 << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    long long a, b, result;
    a = A;
    b = B;
    bool abc = true;
    long long j, k = 1;


    for (long long i = 0; abc; i++) {
        if (a > b) {
            j++;
            b = B * j;
        }
        else {
            k++;
            a = A * k;
        }

        if (a == b) {
            cout << a << endl;
            abc = false;
            break;
        }
    }
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	double a = 0;
	rep(i, n){
		double c; cin >> c;
		a += 1/c;
	}
	cout << fixed << setprecision(10) << 1/a;
} 

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

using namespace std;

int main(){
	long long n, ans = 0;
	cin >> n;
	vector<long long> a(n + 1);
	for(int i = 1; i <= n; i++){
		long long in;
		cin >> in;
		a[i] = a[i - 1] + in;
	}
	sort(a.begin(), a.end());
	long long cnt = 1;
	for(int i = 1; i <= n; i++){
		if(a[i - 1] == a[i]){
			cnt++;
		}else{
			if(cnt >= 2) ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
		if(i == n){
			if(cnt >= 2) ans += cnt * (cnt - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int n[11], i, j;
	for(i = 0 ; i < 10 ; i++)
	{
		scanf("%d", &n[i]);
	}
	for(i = 0 ; i < 9 ; i++)
	{
		for(j = 1 ; j <= 9-i ; j++)
		{
			if(n[i] < n[i+j])
			{
				int p = n[i];
				n[i] = n[i+j];
				n[i+j] = p;
			}
		}
	}
	for(i = 0 ; i < 3 ; i++)
	{
		printf("%d\n", n[i]);
	}
	return 0;
}


Measured memory_bytes: 2092
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
  else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int k = sc.nextInt();
		
		long[] a = new long[x];
		long[] b = new long[y];
		long[] c = new long[z];
		
		for (int i = 0; i < x; i++) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < y; i++) {
			b[i] = sc.nextLong();
		}
		for (int i = 0; i < z; i++) {
			c[i] = sc.nextLong();
		}
		Cakes cakes = new Cakes(a, b, c, k);
		ArrayList<Long> points = cakes.calcPoints();
		for (int i = 0; i < k; i++) {
			System.out.println(points.get(i));
		}
	}
	
}

class Cakes {
	int k;
	ArrayList<Long> a = new ArrayList<>();
	ArrayList<Long> b = new ArrayList<>();
	ArrayList<Long> c = new ArrayList<>();
	
	Cakes(long[] a, long[] b, long[] c, int k) {
		this.k = k;
		setDecOreder(a, this.a);
		setDecOreder(b, this.b);
		setDecOreder(c, this.c);
	}
	void setDecOreder(long[] longs, ArrayList<Long> list) {
		Arrays.sort(longs);
		int length = longs.length;
		int arySize = Math.min(k, length);
		for (int i = 0; i < arySize; i++) {
			list.add(longs[length - 1 - i]);
		}
	}
	ArrayList<Long> calcPoints() {
		ArrayList<Long> points = new ArrayList<>();
		for (int ia = 0; ia < a.size(); ia++) {
			for (int ib = 0; ib < b.size(); ib++) {
				if ((ia + 1) * (ib + 1) > k) {
					break;
				}
				for (int ic = 0; ic < c.size(); ic++) {
					if ((ia + 1) * (ib + 1) * (ic + 1) > k) {
						break;
					}
					long point = a.get(ia) + b.get(ib) + c.get(ic);
					points.add(point);
				}
			}
		}
		Collections.sort(points, Comparator.reverseOrder());
		return points;
	}
}


Measured memory_bytes: 33176
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

const int N = 303;
const int MOD = 998244353;
int memo[N][N][N];

vector<int> v;
int count(int ind, int ones, int k) {
  if (k < 0) return 0;
  if (ones < 0) return 0;
  if (ind == 0) return 1;
  int& res = memo[ind][ones][k];
  if (res != -1) return res;
  res = 0;
  for (int i = 0; i <= v[ind] + ones; ++i) {
    res =
        (res + count(ind - 1, v[ind] + ones - i, k - max(0, v[ind] - i))) % MOD;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  string s;
  int k;
  cin >> s >> k;

  memset(memo, -1, sizeof memo);
  v.emplace_back(0);
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '1') {
      ++v.back();
    } else {
      v.emplace_back(0);
    }
  }

  cout << count(sz(v) - 1, 0, min(N - 1, k)) << endl;

  return 0;
}

Measured memory_bytes: 112240
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n, sum = 0;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> que;
    REP(i,0,n){
        int a;
        cin >> a;
        sum += a;
        if (a % 10 != 0) que.push(a);
    }

    if (sum % 10 != 0) cout << sum << endl;
    else if (que.size() == 0) cout << 0 << endl;
    else cout << sum - que.top() << endl;
    
    return 0;
}

Measured memory_bytes: 256
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=float("inf")
m1=float("inf")
if n==0:
    print(x)
else:
    for i in range(x,x-100,-1):
        if i not in p:
            m=i
            break
    for i in range(x+1,x+100):
        if i not in p:
            m1=i
            break
    diff=abs(x-m)
    diff1=abs(x-m1)
    if diff<diff1:
        print(m)
    elif(diff>diff1):
        print(m1)
    else:
        print(min(m,m1))


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int ft[100005];
void update(int i, int v){
    for(;i<=100000;i+=(i&-i)) ft[i] += v;
}
int query(int i){
    int ans = 0;
    for(;i>0;i-=(i&-i)) ans+=ft[i];
    return ans;
}

int l[300005], r[300005];
vector<int> del[100005];
int main(){
    int n, m, sum = 0;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &l[i], &r[i]);
        del[r[i]-l[i]+1].emplace_back(i);
        sum++;
    }

    for(int d=1;d<=m;d++){
        int ans = sum;
        for(int i=d;i<=m;i+=d){
            ans += query(i);
        }

        for(int j=0;j<sz(del[d]);j++){
            int idx = del[d][j];
            update(l[idx], 1);
            update(r[idx]+1, -1);
            sum--;
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 12084
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 1000010;

char in[MAXN];
int n, d[MAXN], sum_dig;

void add(int x) {
  for (int i = 0; x > 0; ++i) {
    x += d[i];
    
    sum_dig -= d[i];
    d[i] = x % 10;
    sum_dig += d[i];

    x /= 10;    
  }
}

void mul(int x) {
  int carry = 0;
  for (int i = 0; i < n; ++i) {
    carry += x * d[i];
    d[i] = carry % 10;
    carry /= 10;
  }
  if (carry) {
    d[n] = carry;
    ++n;
  }
}

int main(void) {
  scanf("%s",in);
  n = (int)strlen(in);
  REP(i, n) {
    d[i] = in[n-1-i] - '0';
  }
  mul(9);
  REP(i, n) sum_dig += d[i];
    
  int k = 0;
  while (sum_dig > 9 * k)  {
    add(9);
    ++k;
  }

  printf("%d\n",k);
  
  return 0;
}


Measured memory_bytes: 4608
import numpy as np
N,C=map(int,input().split())
ans=10**9
a=np.array([0]*C)
b=np.array([0]*C)
c=np.array([0]*C)
s=[]
t=[]
for i in range(C):
    s.append(list(map(int,input().split())))
for i in range(N):
    t.append(list(map(int,input().split())))
for j in range(N):
    for i in range(N):
        if (i+j)%3==0:
            a+=np.array(s[t[i][j]-1])
        elif (i+j)%3==1:
            b+=np.array(s[t[i][j]-1])
        else:
            c+=np.array(s[t[i][j]-1])
from itertools import permutations
for i,j,k in permutations(range(C),3):
    p=a[i]+b[j]+c[k]
    ans=min(p,ans)
print(ans)    
            
    

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

using namespace std;

#define REPEAT(i, N) for (int i = 0; i < (N); i++)

int main() {
  int N;
  vector<int> d;
  
  cin >> N;
  
  if (N % 2 == 1) {
    cout << 0 << endl;
    
    return 0;
  }
  
  REPEAT(i, N) {
    int d_i;
    
    cin >> d_i;
    
    d.push_back(d_i);
  }
  
  sort(d.begin(), d.end());
  
  int mid = N / 2;
  
  cout << d[mid] - d[mid - 1] << endl;
  
  return 0;
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll H,M,h,m,K;
    cin >> H >> M >> h >> m >> K;
    ll sum = (h-H)*60 + m-M;
    ll out = sum-K;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char c = s.charAt(0);
		boolean ans = false;
		for(int i = 0; i < s.length(); i++) {
			ans = ans || (c != s.charAt(i));
		}
		System.out.println(ans ? "Yes" : "No");

	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll H, W, i, j, k, c[10][10], A[201][201], ans=0;

    cin >> H >> W;

    for(i=0; i<=9; i++){
        for(j=0; j<=9; j++){
            cin >> c[i][j];
        }
    }

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            cin >> A[i][j];
        }
    }

    for(k=0; k<=9; k++){
        for(i=0; i<=9; i++){
            for(j=0; j<=9; j++){
                chmin(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            if(A[i][j]!=-1){
                ans += c[A[i][j]][1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<stack>
#include<string>

using namespace std;

int main(){
    int n;
    cin >> n;
    char temp, top;
    stack<char> s;
    string t;
    cin >> t;
    temp = t[0];
    s.push(temp);
    for (int i = 1; i < n; i++)
    {
        top = s.top();
        temp = t[i];
        if (top != temp)
        {
            s.push(temp);
        } 
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    vector<Int> L(N+1);
    L[0] = 2; L[1] = 1;
    
    rep(i, 2, N+1) {
      L[i] = L[i-2] + L[i-1];
    }
  
    cout << L[N] << endl;
}


Measured memory_bytes: 256
from collections import deque
s = input().split()
sd = deque()
for i in s:
    sd.append(i)
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            sd.appendleft(res[2])
        else:
            sd.append(res[2])
    else:
        if order == 1:
            sd.append(res[2])
        else:
            sd.appendleft(res[2])

sd_str="".join(list(sd))
if order == -1:
    print(sd_str[::-1])
else:
    print(sd_str)

Measured memory_bytes: 6900
N = int(input())
S = []

ac = 0
wa = 0
tle = 0
re = 0

for i in range(N):
    s = input()
    S.append(s)

for si in S:
    if si == 'AC':
        ac += 1
    elif si == 'WA':
        wa += 1
    elif si == 'TLE':
        tle += 1
    else:
        re += 1

print('AC', 'x', ac)
print('WA', 'x', wa)
print('TLE', 'x', tle)
print('RE', 'x', re)


Measured memory_bytes: 16236
#include<iostream>
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x%7==0){
    cout << "thu" << endl;
  }else if(x%7==1){
    cout << "fri" <<endl;
  }else if(x%7==2){
    cout << "sat" <<endl;
  }else if(x%7==3){
    cout << "sun" <<endl;
  }else if(x%7==4){
    cout << "mon" <<endl;
  }else if(x%7==5){
    cout << "tue" <<endl;
  }else if(x%7==6){
    cout << "wed" <<endl;
  }
  return 0;
}



Measured memory_bytes: 3132
import java.util.Scanner;

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

        int[] sum = new int[N+1];
        sum[0]=0;
        for(int i=0;i<N;i++){
            if(S.charAt(i)=='#'){
                sum[i+1]=sum[i]+1;
            }else{
                sum[i+1]=sum[i];
            }
        }
        int ans=N;
        for(int i=0;i<=N;i++){
            int cnt = sum[i] + ( (N-i) - (sum[N]-sum[i]) );
            // System.out.println(cnt);
            if(ans>cnt)ans=cnt;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 29368
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
    int n;
    cin >> n;
    vec<int> b(n - 1);
    rep(i,n-1){

	    cin>>b[i];
    }
    ull ans=0;
    for(int i=1;i!=n-1;++i){
ans+=min(b[i-1],b[i]);
    }
    ans+=b[0]+b[b.size()-1];
cout<<ans<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    i64 S[3333];
    void solve() {
        int n, s;
        cin >> n >> s;
        i64 ans = 0;
        for (int i = 0; i < n; ++i) {
            int t;
            cin >> t;
            if (s - t >= 0) {
                (ans += 1ll * (n - i) * S[s - t] % MOD) %= MOD;
                if (t == s)
                    (ans += 1ll * (n - i) * (i + 1) % MOD) % MOD;
                for (int j = s; j - t >= 0; --j) {
                    S[j] = (S[j] + S[j - t]) % MOD;
                }
                S[t] = (S[t] + i + 1) % MOD;
            }
        }
        cout << ans << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

struct PAIR {
  int no1, no2;
} typedef pair2;

using namespace std;

double func ( int w, int s ) { return (double)s/(w+s); }

int main()
{
  int a,b,c,d,e,f;
  vector<pair2> W,S;// W = { ano, bno }, S = { cno, dno }
  int wsum, ssum;
  double per = 0;
  double p;

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

  p = func(100,e);

  for ( int i = 0 ; i*a*100 <= f; ++i ) {
    for ( int j = 0; i*a*100 + j*b*100 <= f; ++j ) W.push_back({i,j});
  }

  for ( int i = 0; i*c <= f; ++i ) {
    for ( int j = 0; i*c + j*d <= f; ++j ) S.push_back({i,j});
  }

  wsum = ssum = 0;
  for ( int i = 0; i < W.size(); ++i ) {
    for ( int j = 0; j < S.size(); ++j ) {
      int tmps, tmpw;
      tmpw = ( a*W[i].no1+b*W[i].no2 ) * 100;
      tmps = c*S[j].no1+d*S[j].no2;
      if ( tmpw+tmps <= f && func(tmpw,tmps) <= p ) {
        if ( func(tmpw,tmps) > per ) {
        per = func(tmpw,tmps);
        wsum = tmpw;
        ssum = tmps;
      }
      }
    }
  }

  if ( ssum == 0 ) wsum = 100*a;
  cout << wsum+ssum << " " << ssum << "\n";
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define ld double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-22
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, c;
    cin >> a >> b >> c;
    if (b-a == c-b) cout << "YES";
    else cout << "NO";
    return 0;
}


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

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

    double W, H, x, y;
    cin>>W>>H>>x>>y;
    cout<<W*H/2<<" ";
    if(2*x==W && 2*y==H)
        cout<<1;
    else
        cout<<0;
    return 0;
}

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

using namespace std;

int main(void) {

	int n;
	cin >> n;

	vector<int> p(n);

	for (int i = 0; i < n; i++) cin >> p[i];

	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		
		// 3つのうち最大値と最小値を引いてp[i]と一致したら2番目
		int sum = p[i - 1] + p[i] + p[i + 1];

		// すべて等しい場合2番目に小さくない
		if (p[i - 1] == p[i] && p[i] == p[i + 1]) continue;

		sum -= max({ p[i - 1], p[i], p[i + 1] });
		sum -= min({ p[i - 1], p[i], p[i + 1] });

		if (sum == p[i]) ans++;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>

using namespace std;

char orin[100005];

int main(void)
{
	int cnt = 0;
	scanf("%s", orin);
	for (int i = 1; orin[i]; ++i)
	{
		if (orin[i] != orin[i - 1])
			++cnt;
	}
	printf("%d", cnt);
}

Measured memory_bytes: 256
#入力
H, A = map(int, input().split())

#出力
s = 1
counter = 1
while counter>0:
    if H - A >0:
        H = H - A
        s = s + 1
        counter = counter
    else:
        H = H - A
        s = s
        counter = counter - 1
        print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V<int> a;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    bool is_yes = true;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            if (!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
                is_yes = false;
                break;
            }
        } 
    }

    if (!is_yes) cout << "DENIED\n";
    else cout << "APPROVED\n";
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
 
t = 1
tl = [1]
ts = {1}
for i in range(len(a)):
 
    t = a[t-1]
    if t in ts:
        break
    else:
        tl.append(t)
        ts.add(t)
 
tl2 = tl[tl.index(t):len(tl)]
 
 
if k < len(tl):
    ans = tl[k]
else:
    k = k - (len(tl) - len(tl2))
    j = k % len(tl2)
    ans = tl2[j]
 
print(ans)

Measured memory_bytes: 32340