akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,x,y;
    cin>>n;
    vector<pair<ll,ll> > v;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end(),sortbysec);
    ll time=0;
    for(i=0;i<n;i++)
    {
        time+=v[i].first;
        if(time>v[i].second)
            break;
    }
    if(i==n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vl a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(all(a));
    reverse(all(a));
    if(n%2) {
        ll ans = a[0];
        int cnt=1;
        for(int i=1;i<n;i++) {
            if(cnt==n-2) { 
                ans+=a[i];
                break;
            }
            ans+=2*a[i];
            cnt+=2;
        }
        cout<<ans;
    }
    else {
        ll ans = a[0];
        int cnt = 1;
        for (int i = 1; i < n; i++)
        {
            if (cnt == n - 1)
            {
                //ans += a[i];
                break;
            }
            ans += 2 * a[i];
            cnt += 2;
        }
        cout << ans;
    }
}

int main()
{
    fastio;
    int t;
    t = 1;
    //cin >> t;
    //int test=t;
    
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 4772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<string> s(H);
	vector<vector<int>> ans(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	int cnt = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] != '#') continue;
			cnt++;
			ans[i][j] = cnt;
			for (int k = 1; k < W; k++) {
				if (j + k >= W) break;
				if (s[i][j + k] != '.') break;
				ans[i][j + k] = cnt;
			}
			for (int k = 1; k < W; k++) {
				if (j - k < 0) break;
				if (s[i][j - k] != '.') break;
				ans[i][j - k] = cnt;
			}
		}
	}
	for (int i = 1; i < H; i++) {
		if (ans[i][0] != 0) continue;
		for (int j = 0; j < W; j++) {
			ans[i][j] = ans[i - 1][j];
		}
	}
	for (int i = H - 2; i >= 0; i--) {
		if (ans[i][0] != 0) continue;
		for (int j = 0; j < W; j++) {
			ans[i][j] = ans[i + 1][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << ans[i][j] << " \n"[j == W - 1];
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int w,h,n;
    cin >> w >>h >>n;
    int mx = 0, my = 0, nx = w, ny = h;
    REP(i,n) {
        int x,y,a;
        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
            mx = max(mx,x);
            break;
        case 2:
            nx = min(nx,x);
            break;
        case 3:
            my = max(my,y);
            break;
        case 4:
            ny = min(ny,y);
        default:
            break;
        }
    }
    int ans = 0;
    if (nx > mx && ny > my) ans = (nx - mx) * (ny - my);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
int n, m, l, r;
int main(){
    scanf("%d%d", &n, &m);
    l = 1; r = n;
    for(Rint i = 1;i <= m;i ++){
        int x, y;
        scanf("%d%d", &x, &y);
        l = max(x, l); r = min(y, r);
    }
    printf("%d\n", max(r - l + 1, 0));
}

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

int main(){
  long long int X;
  
  cin >> X;
  
  long long int out = 100;
  int year = 0;
  while (out < X){
    out += out / 100;
    // std::cout << out <<std::endl;
  
    year += 1;
  }
  std::cout << year <<std::endl;
  
}


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

  int main(){
    int a,b;cin>>a>>b;
    cout<<6-a-b;
  }

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        int ans = 1e9;
        int sum = accumulate(all(a), 0);
        int pre = 0;
        for (int i = 0; i + 1 < n; i++) {
                pre += a[i];
                int suf = sum - pre;
                ans = min(ans, abs(suf - pre));
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> S(N);
  for(int i=0 ; i<N ; i++) cin >> S.at(i);

  int ans = 100000;
  for(int i = 1; i<N ; i++){
      int S1=0, S2=0;
      for(int j = 0; j<i ; j++) S1 += S.at(j);
      for(int j = i; j<N ; j++) S2 += S.at(j);

      ans = min(ans, max(S1,S2) - min(S1,S2));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
num = gets.chomp.split(' ').map(&:to_i)
val = gets.chomp.split(' ').map(&:to_i)
val.sort!()
sub = []
0.upto(val.length-2) do |i|
  sub << val[i+1]-val[i]
end
sub.sort!()
sum = 0
0.upto(sub.length-num[0]) do |i|
  sum += sub[i]
end
puts sum

Measured memory_bytes: 12656
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b >> c;
	// max(a, max(b, c))
	if (c > b && b > a && c > a) {
		cout << a + b << "\n";
	}
	else if (c > b && b < a && c > a) {
		cout << a + b << "\n";
	}
	else if (c > b && a > b && a > c) {
		cout << b + c << "\n";
	}
	else if (a > b && a > c && b > c) {
		cout << b + c << "\n";
	}
	else if (b > a && a > c && b > c) {
		cout << a + c << "\n";
	}		
	else if (b > c && c > a && b > a) {
		cout << a + c << "\n";
	}
	else if (a == b && a > c) {
		cout << a + c << "\n";
	}
	else if (a == b && a < c) {
		cout << a + b << "\n";
	}
	else if (a == c && a < b) {
		cout << a + c << "\n";
	}
	else if (a == c && a > b) {
		cout << a + b << "\n";
	}
	else if (b == c && a < b) {	
		cout << a + c << "\n";
	}
	else if (b == c && a > b) {
		cout << c + b << "\n";
	}
	else if (a == b && b == c && a == c) {
		cout << a + b << "\n";
	}
	std::cin >> e;
}

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

public class Main{
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		
		for(int i = 0; i < n; i++){
			a.add(sc.nextInt());
		}
		sc.close();
		
		a.sort(Comparator.comparing(I -> I));
		if(isAbleArray(a)) System.out.println(count(n));
		else System.out.println(0);
		
	}
	
	static boolean isAbleArray(List<Integer> list){
		if(list.size() % 2 == 0){
			int k = 1;
			for(int i = 0; i < list.size(); i++){
				if(list.get(i) != k) return false;
				if(i % 2 == 1) k = k + 2;
			}
		}else{
			int k = 0;
			for(int i = 0; i < list.size(); i++){
				if(list.get(i) != k) return false;
				if(i % 2 == 0) k = k + 2;
			}
		}
		return true;
	}
	
	static long count(int n){
		long result = 1;
		if(n % 2 == 1){
			for(int i = 0; i < (n - 1)/2; i++){
				result = (result * 2) % 1_000_000_007L;
			}
		}else{
			for(int i = 0; i < n / 2; i++){
				result = (result * 2) % 1_000_000_007L;
			}
		}
		return result;
	}
}


Measured memory_bytes: 36556
K = int(input())

lis = [49] * 50

dif = K // 50
amari = K % 50

for i in range(50):

    lis[i] += dif

    if i < amari:
        lis[i] += 50 - amari + 1
    else:
        lis[i] -= amari

print (50)

print (" ".join(map(str,lis)))


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int v[N], w[N];
map<int, int> f[2];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ ) cin >> v[i] >> w[i];
	
	int t = 1;
	f[t][0] = 0;
	for (int i = 1; i <= n; i ++ )
	{
		t ^= 1;
		for (auto u : f[t ^ 1])
		{
			f[t][u.F] = max(f[t][u.F], u.S);
			if (u.F + v[i] <= m) f[t][u.F + v[i]] = max(f[t][u.F + v[i]], u.S + w[i]);
		}
	}
	
	int res = 0;
	for (auto u : f[t]) res = max(res, u.S);
	cout << res << endl;
    return 0;
}

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

using ll = long long;
using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll n;
    cin >> n;

    vector<ll> a(n);
    rep(i, n)cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 1;
    for(int i = 1; i < n; i++){
        ans++;
        if(a[i-1] == a[i]){
            ans-=2;;
            a[i] = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int  N;
    char S[3*100000 + 1];

    int ans = 0;
    int tmp = 0;
    char *seek;

    /* N読み取り */
    (void)scanf("%d%*c",&N);

    /* S読み取り */
    (void)scanf("%s%*c",&S);

    seek = &S[1];
    while (seek < &S[N])
    {
        if (*(seek-1) == 'W') tmp++;
        seek++;
    }

    ans = tmp;

    seek = &S[N-1];
    while (--seek >= &S[0])
    {
        if (*(seek) == 'W') tmp--;
        if (*(seek+1) == 'E') tmp++;
        if (tmp < ans) ans = tmp;

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

Measured memory_bytes: 512
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

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

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

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

    int N; cin >> N;
    vl t(N); REP(i, N) cin >> t[i];

    ll ans = t[0];
    FOR(i,1,N) {
        ans = lcm(ans, t[i]);
    }

    cout << ans << endl;

    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

struct BellmanFordMax {
	BellmanFordMax() {}
	BellmanFordMax(int n) { init(n); }
	vector<vector<pair<int, int> > > E; 
    int N;
	void init(int n) { N = n; E.resize(0); E.clear(); E.resize(n); }
	void add(int a, int b, int c) { E[a].push_back({ b, c }); }
	vector<ll> solve(int s) {
		vector<ll> res(N, -L_INF); //最終的な距離
		res[s] = 0;
 
        //最短経路を求める
		exrep(i, 0, N - 1) {
			exrep(cu, 0, N){
                if (-L_INF < res[cu]){
                    for(auto p:E[cu]) {
                        chmax(res[p.first], res[cu] + p.second);
                    }
                }
            }
		}

        //負のサイクルの見つける
		vector<bool> pos(N);
		exrep(i, 0, N) {
			exrep(cu, 0, N) {
                if (-L_INF < res[cu]) for(auto p:E[cu]) {
                    if (chmax(res[p.first], res[cu] + p.second)) {
                        pos[p.first] = true;
                    }
                    if (pos[cu]) pos[p.first] = true;
                }
			}
		}
 
		exrep(cu, 0, N) if (pos[cu]) res[cu] = L_INF;
 
		return res;
	}
};
//参考 はまやんさんのサイト
//https://www.hamayanhamayan.com/entry/2019/08/14/131217
//問題 ABC137 E https://atcoder.jp/contests/abc137/tasks/abc137_e
int N, M, P;
vector<pair<int, int>> E[2500];
signed main()
{   
    gearup;
    cin >> N >> M >> P;
 
	BellmanFordMax bf(N);
 
	exrep(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		bf.add(a, b, c - P);
	}
 
	ll ans = bf.solve(0)[N - 1];
 
	if (ans == L_INF) ans = -1;
	else if (ans < 0) ans = 0;
 
	cout << ans << endl;
}


Measured memory_bytes: 3868
#
# abc049 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """a"""
        output = """vowel"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """z"""
        output = """consonant"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """s"""
        output = """consonant"""
        self.assertIO(input, output)


def resolve():
    c = input()
    if c == "a" or c == "i" or c == "u" or c == "e" or c == "o":
        print("vowel")
    else:
        print("consonant")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16168
#include <stdio.h>

int main(void)
{
  	int	l;
  	int	r;
  	int d;
  	int	x;
  	int	cnt;
  
  	scanf("%d %d %d", &l, &r, &d);
  	
  	cnt = 0;
  	for(x=l; x<=r; x++)
    {
      	if(x % d == 0)
          	cnt++;
    }
  
  	printf("%d", cnt);
	return (0);
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> graph(N);
  vector<pair<int, int>> vp;
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
    vp.emplace_back(a, b);
  }

  // 各エッジの色
  map<pair<int, int>, int> edges_color;
  // 親を持つ場合、割り当てられた色
  vector<int> assigned_color(N, 0);

  vector<int> seen(N, 0);
  queue<int> que;

  seen.at(0) = 1;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int cur = 1;
    for (auto u : graph.at(v)) {
      // 探索済みの頂点はスルー
      if (seen.at(u)) continue;
      // 親となる頂点が使用した色は使用しない
      if (cur == assigned_color.at(v)) cur++;
      // 割り当てる色で無向グラフの辺の色を更新
      assigned_color.at(u) = cur;
      edges_color[make_pair(u, v)] = cur;
      edges_color[make_pair(v, u)] = cur;
      cur++;
      seen.at(u) = 1;
      que.push(u);
    }
  }

  int K = 0;
  for (int i = 0; i < N; i++) K = max(K, (int)graph.at(i).size());
  cout << K << endl;
  for (auto p : vp) cout << edges_color[p] << endl;
  return 0;
}


Measured memory_bytes: 20212
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    string S;
    int m, h, l;
    while(1) {
        cin >> S;
        l = S.length();
        if(S == "-")
            break;
        cin >> m;
        rep(i, m) {
            cin >> h;
            S += S;
            S = S.substr(h, l);
        }
        cout << S << endl;
    }
}


Measured memory_bytes: 3208
#include <stdio.h>

int main(){
	int n,k,i,j=0;

	scanf("%d %d",&n,&k);

	int h[n];
	for(i=0; i<n; i++){
		scanf("%d",&h[i]);
		if(h[i]>=k){
			j++;
		}
	}

	printf("%d",j);
	return 0;
}

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

import math
import itertools

dia = list(itertools.permutations([i+1 for i in range(n)]))

for i in range(len(dia)):
    if list(dia[i]) == p:
        sc_p = i
    if list(dia[i]) == q:
        sc_q = i

print(abs(sc_p - sc_q))


Measured memory_bytes: 46064
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
const int INF = 1<<30;

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

mint dp[100005][2];

int main(){
  string s; cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i,n){
    if(s[i] == '0'){
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
      dp[i+1][1] += dp[i][1] * 2;
    }else{
      dp[i+1][1] = dp[i][0] + dp[i][1];
      dp[i+1][0] += dp[i][0] * 2;
      dp[i+1][1] += dp[i][1] * 2;
    }
  }
  mint ans = dp[n][0]+dp[n][1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>


#define SIZE_OF_ARRAY(p) (sizeof(p)/sizeof(p[0]))

namespace{
    void printElems(const int* begin, const int* end){
        for (const int* p=begin; p != end; ++p){
            std::cout << *p << std::endl;
        }
        std::cout << std::endl;
    }
}
int main(){
    int n,k;
    std::cin >> n >> k;
    int p[n];
    for(int i=0; i<n; i++){
        std::cin >> p[i];
    }
    std::sort(p, p+SIZE_OF_ARRAY(p));
    int ans=0;
    for (int i=0; i<k; i++){
        ans = ans +  *(p+i);
    }
    std::cout << ans;
    return 0;
}

Measured memory_bytes: 3632
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    char s[4];
    cin>>s;
    if((s[1]==s[2]&&s[2]==s[3])||(s[0]==s[2]&&s[2]==s[1]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

#define ll long long

void solve() {
	int n;
	cin >> n;
	vector<int> v;
	int a;
	while(n--) {
		cin >> a;
		auto it = find(v.begin(), v.end(), a);
		if (it == v.end()) {
			v.push_back(a);
		} else {
			v.erase(it);
		}
	}
	cout << v.size() << "\n";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  string S, T;
  cin >> S;
  cin >> T;
  int ans = 0;
  REP(i,S.size()) {
    if (S[i] != T[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll ex(ll k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll A=0,B=0;
    REP(i,a){
        B = 10*B + b;
    }

    REP(i,b){
        A = 10*A + a;
    }
    if(A>B){
        cout << A << endl;
    }
    else{
        cout << B << endl;
    }
}


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

/* 

レーベンシュタイン距離(編集距離)
編集距離とは操作によって一つの文字列を別の文字列に
変形するのに必要な最小手順を表す

・挿入　文字列に別の文字を挿入
・削除　文字列から一つの文字を削除する
・置換　文字列の中の一文字を別の文字に置き換える

*/


int LevenshteinDistance(string s1,string s2) {
  int n = (int)s1.size(), m = (int)s2.size();
  vector<vector<int> > dp(n+1,vector<int>(m+1));
  for(int i=0;i<=n;++i) dp[i][0] = i;
  for(int i=0;i<=m;++i) dp[0][i] = i;
  for(int i=1;i<=n;++i) {
    for(int j=1;j<=m;++j) {
      dp[i][j] = min(dp[i-1][j]+1,
                     min(dp[i][j-1]+1,dp[i-1][j-1]+(s1[i-1]!=s2[j-1])));
    }
  }
  return dp[n][m];
}

int main(){
    string s1,s2; cin >> s1 >> s2;
    cout << LevenshteinDistance(s1,s2) << endl;
    return 0;
}



Measured memory_bytes: 6808
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                PrintWriter ou = new PrintWriter(System.out);
                int h = Integer.parseInt(sc.next());
                int w = Integer.parseInt(sc.next());
                int[][] a = new int[h][w];
                for(int i = 0 ; i < h ; i++){
                        for(int j = 0 ; j < w ; j++){
                                a[i][j] = Integer.parseInt(sc.next());
                        }
                }
                sc.close();
                int[][] q = new int[4][w * h];
                int yono = 0;
                for(int i = 0 ; i < w ; i++){
                        for(int j = 0 ; j < h - 1 ; j++){
                                if(a[j][i] % 2 != 0){
                                        q[0][yono] = j + 1;
                                        q[1][yono] = i + 1;
                                        q[2][yono] = j + 2;
                                        q[3][yono] = i + 1;
                                        yono++;
                                        a[j + 1][i]++;
                                }
                        }
                }
                for(int i = 0 ; i < w - 1 ; i++){
                        if(a[h - 1][i] % 2 != 0){
                                q[0][yono] = h;
                                q[1][yono] = i + 1;
                                q[2][yono] = h;
                                q[3][yono] = i + 2;
                                yono++;
                                a[h - 1][i + 1]++;
                        }
                }
                System.out.println(yono);
                for(int i = 0 ; i < yono ; i++){
                        ou.print(q[0][i] + " " + q[1][i] + " " + q[2][i] + " " + q[3][i] + "\n");
                }
                ou.flush();
        }
}

Measured memory_bytes: 67364
#include <iostream>
#include <cstdlib>

int main()
{
int a=0,b=0;
    std::cin>>a>>b;
    if(a>8||b>8){
    std::cout<<":("<<std::endl;
    }
    else{
    std::cout<<"Yay!"<<std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tuple>
using namespace std;
typedef vector<int> vi;
const int INF=1e9;
typedef long long ll;
int w,h;
ll d[105][105];
ll ans;
int g1,g2,n,m,s;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
  std::fill( (T*)array,(T*)(array+N),val );
}

void warshall_floyd()
{
  for(int k=1;k<=n;k++)
    {
      for(int i=1;i<=n;i++)
	{
	  for(int j=1;j<=n;j++)
	    {
	      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	    }
	}
    }
}


int main(void)
{
  
  while(cin >> n >> m >> s >> g1 >> g2 && n)
    {
      for(int i=1;i<=n;i++)
	{
	  for(int j=1;j<=n;j++)
	    {
	      d[i][j]=INF;
	      if(i==j) d[i][j]=0;
	    }
	}
      for (int i = 0;i<m;i++)
	{
	  int fro,to,cost;
	  cin >> fro >> to >> cost;
	  d[fro][to]=cost;
	  //d[to][fro]=cost;
	}
      warshall_floyd();
      ans=INF;
      for(int i=1;i<=n;i++)
	{
	  ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
	}
      cout << ans << endl;
    }
  return 0;
 
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;

  vector<int> vx(n);
  for (int i = 0; i < n; ++i) {
    cin >> vx.at(i);
  }

  vector<int> vy(m);
  for (int i = 0; i < m; ++i) {
    cin >> vy.at(i);
  }

  sort(vx.begin(), vx.end(), greater<int>());
  sort(vy.begin(), vy.end());

  bool res = false;
  for (int i = -100; i <= 100; ++i) {
    if (vx.at(0) < i && i <= vy.at(0)) {
      if (x < i && i <= y) {
        res = true;
      }
    }
  }

  if (res) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n-1)cin >> c[i];
    int ans = 0;
    int tmp = 0;
    rep(i,n){
        ans += b[a[i]-1];
        if(a[i]-tmp == 1)ans += c[tmp-1];
        tmp = a[i];
    }
    cout << ans << endl;

}


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

int main() {
  int A, B;
  string S;
  cin >> A >>  B;
  cin >> S;
  for (int i = 0; i < A; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) {
      cout << "No"; return 0;
    }
  }
  if (S[A] != '-') {
    cout << "No"; return 0;
  }
  for (int i = A+1; i < A+B+1; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) {
      cout << "No"; return 0;
    }
  }
  cout << "Yes"; return 0;
}



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

int main(){
  int n;
  cin >> n;
  ll val=7;
  ll ans=1;
  while(val%n!=0){
    val=val%n;
    val= val*10+7;
    if(ans==1000001) break;
    ans++;
  }
  if(ans==1000001) ans=-1;

  cout << ans << endl; 

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for (int i = m; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
const int INF = (int)(1e9);

template <typename T>
class SegmentTree
{
private:
  using Fn = function<T(T, T)>;
  int N; //要素数
  vector<T> dat;
  const T unit; //単位元 a * e = a
  Fn func;

public:
  SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    while (N < n_)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }

  void update(int k, T a)
  {             //k番目(0-indexed)をaに変更
    k += N - 1; //一番下
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2; //1つ上がる
      //更新
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]); //
    }
  }

  //[a, b)の値（最小値/和/etc.）を求める
  //kは節点の番号、l, rはその節点が[l,r)に対応づいていることを表す
  //外からはquery(a, b)と呼ぶ

  T query(int a, int b, int k = 0, int l = 0, int r = -1)
  {
    if (r < 0)
      r = N;
    if (r <= a || b <= l)
      return unit;
    //[a, b)が[l,r)を完全に含む
    if (a <= l && r <= b)
      return dat[k];
    else
    {
      int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return func(vl, vr); //
    }
  }
};

bool compare(bool b1, bool b2)
{
  return b1 && b2;
}

int my_max(int a, int b)
{
  return max(a, b);
}

int my_min(int a, int b)
{
  return min(a, b);
}

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

  int n, k;
  cin >> n >> k;
  int p[200010];
  rep(i, n) cin >> p[i];

  //[l,r] がsortされているか
  SegmentTree<bool> sg_sorted(n - 1, compare, true);
  SegmentTree<int> sg_max(n, my_max, -INF), sg_min(n, my_min, INF);
  rep(i, n - 1) sg_sorted.update(i, p[i] < p[i + 1]);
  rep(i, n)
  {
    sg_max.update(i, p[i]);
    sg_min.update(i, p[i]);
  }

  int no_changed = 0;
  int ans = 0;
  for (int l = 0, r = l + k; r <= n; l++, r++)
  {
    if (sg_sorted.query(l, r - 1))
    {
      no_changed = 1;
      continue;
    }
    if (l == 0)
    {
      ans++;
      continue;
    }
    if (p[l - 1] < sg_min.query(l, r - 1) && sg_max.query(l, r - 1) < p[r - 1])
    {
      continue;
    }

    ans++;
  }
  ans += no_changed;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), f(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	rep(i, n) cin >> f[i];
	ll ng = -1, ok = INF;
	while (ok - ng > 1) {
		ll mid = (ng + ok) / 2;
		vector<ll> c(n);
		rep(i, n) c[i] = mid / f[i];
		sort(all(c));
		ll cnt = 0;
		rep(i, n) cnt += max(a[i] - c[i], 0ll);
		if (cnt <= k) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

int main()
{
	long long n, x;
	cin >> n >> x;

	long long a[101];
	map<long long, int> sums;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];

		map<long long, int> cur_sums;
		for (auto& kv : sums)
			cur_sums[kv.first + a[i]] = max(cur_sums[kv.first + a[i]], kv.second + 1);

		cur_sums[a[i]] = max(cur_sums[a[i]], 1);

		sums = cur_sums;
	}

	int max_happy = 0;
	for (auto kv : sums)
	{
		if (kv.first < x)
			max_happy = max(max_happy, kv.second - 1);
		else if (kv.first == x)
			max_happy = max(max_happy, kv.second);
		else
			break;
	}

	sort(a, a + n);
	int cur_happy = 0;
	long long cur_sum = 0;
	for (int i = 0; i < n; i++)
	{
		cur_sum += a[i];
		if (cur_sum <= x)
			cur_happy++;
		else
			break;
	}

	if (cur_sum < x)
		cur_happy--;

	max_happy = max(max_happy, cur_happy);

	cout << max_happy;
}


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

char s[100005]; int n;
bool dp[100005];

int main() {
  scanf("%s", s + 1); n = strlen(s + 1);

  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    if (i>=5 && s[i-4]=='d' && s[i-3]=='r' && s[i-2]=='e' && s[i-1]=='a' && s[i]=='m')
      dp[i] |= dp[i-5];
    if (i>=7 && s[i-6]=='d' && s[i-5]=='r' && s[i-4]=='e' && s[i-3]=='a' && s[i-2]=='m' && s[i-1]=='e' && s[i]=='r')
      dp[i] |= dp[i-7];
    if (i>=5 && s[i-4]=='e' && s[i-3]=='r' && s[i-2]=='a' && s[i-1]=='s' && s[i]=='e')
      dp[i] |= dp[i-5];
    if (i>=6 && s[i-5]=='e' && s[i-4]=='r' && s[i-3]=='a' && s[i-2]=='s' && s[i-1]=='e' && s[i]=='r')
      dp[i] |= dp[i-6];
  }

  puts(dp[n] ? "YES" : "NO");

  return 0;
}

Measured memory_bytes: 384
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))


Measured memory_bytes: 20184
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    deque<ll> a(n-1);
    rep(i, n-1) cin >> a[i];
    a.push_front(1e9);
    a.push_back(1e9);
    ll ans = 0LL;
    rep(i, a.size()-1) {
        ans += min(a[i], a[i+1]);
        // cout << min(a[i], a[i+1]) << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;

ll ds(ll digit) {
	ll res = 0;
	while (digit != 0) {
		res += digit % 10;
		digit /= 10;
	}
	return res;
}
ll MOD = 1000000007;
int main() {
	ll N, K;
	cin >> N >> K;
	ll cnt[2000010];
		for (ll i = 0; i < N; ++i) {
			ll a;
			cin >> a;
			cnt[a - 1]++;
		}
	sort(cnt, cnt + N);
	ll ans = 0;
	for (ll i = 0; i < N - K; i++) {
		ans +=cnt[i];
	}
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
	string S;

	cin >> S;

	int acount = 0;
	int bcount = 0;
	int ccount = 0;

	for (int i = 0; i < S.length(); i++)
	{
		if (S[i] == 'a')
		{
			acount++;
		}
		else if (S[i] == 'b')
		{
			bcount++;
		}
		else
		{
			ccount++;
		}
	}

	if ((bcount == acount || bcount == acount + 1) && (ccount == acount || ccount == acount + 1))
	{
		cout << "YES" << endl;
	}
	else if ((bcount == acount || bcount == acount - 1) && (ccount == acount || ccount == acount - 1))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W, D; 
  cin >> H >> W >> D;

  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) REP(j, W){
    cin >> A[i][j];
    A[i][j]--;
  }

  vector<pair<int, int>> pos(H*W);
  REP(i, H) REP(j, W) pos[A[i][j]] = {i, j};

  vector<int> ans(H*W, 0);
  REP(i, H*W){
    if(i-D >= 0){
      ans[i] = ans[i-D]+abs(pos[i].first-pos[i-D].first)+abs(pos[i].second-pos[i-D].second);
    }
  }

  int Q;
  cin >> Q;

  REP(i, Q){
    int l, r;
    cin >> l >> r;
    cout << ans[r-1]-ans[l-1] << "\n";
  }

  return 0;
}

Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var W = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var sumAll = W.Sum();
        var sum1 = 0;
        var ans = int.MaxValue;

        for (int i = 0; i < N - 1; i++)
        {
            sum1 += W[i];
            var sum2 = sumAll - sum1;

            ans = Math.Min(ans, Math.Abs(sum1 - sum2));
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 28280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
int n;
cin >> n;
ll a[n],k,num=0,l,p;
cin >>k;
vector <pair<ll,ll>> v;
for(int i=0;i<n;i++){
  cin >> l>>p;
  v.push_back(make_pair(l,p));
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++) {
   num+=v[i].second;
   if(num>=k) {
     cout << v[i].first<<endl;
     break;
   }
}
}


Measured memory_bytes: 2420
import heapq
import sys
from collections import defaultdict

input = sys.stdin.readline
N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Measured memory_bytes: 72156
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 2e5+1;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    int q;
    cin>>q;

    int t;
    ll a,b;
    ll c = 0;
    ll median;
    priority_queue<ll>less;
    priority_queue<ll,vector<ll>,greater<ll>>more;
    ll n = 0;
    ll less_sum = 0, more_sum = 0;

    while(q--){
        cin>>t;

        if(t==1){
            cin>>a>>b;
            c+=b;

            if(n==0){
                median = a;
            }else{
                if(n%2){
                    if(a>median){
                        less_sum+=median;
                        more_sum+=a;
                        less.push(median);
                        more.push(a);
                    }else{
                        less_sum+=a;
                        more_sum+=median;
                        less.push(a);
                        more.push(median);
                    }
                    median = -1;

                    // cout<<"here\n";
                    
                }else{

                    if(a>=more.top()){
                        ll tp = more.top();
                        more.pop();
                        more.push(a);
                        more_sum+=a-tp;
                        median = tp;
                        a = tp;
                    }else
                    if(a<=less.top()){
                        ll tp = less.top();
                        less.pop();
                        less.push(a);
                        less_sum+=a-tp;
                        median = tp;
                        a = tp;
                    }else{
                        median = a;
                    }
                }
            }
            n++;

            // auto x = more;
            // while(x.size()){
            //     cout<<x.top()<<" ";
            //     x.pop();
            // }

            // cout<<"\n"<<median<<"\n";
            // auto y = less;
            // while(y.size()){
            //     cout<<y.top()<<" ";
            //     y.pop();
            // }
            // cout<<"\n\n";

        }else{
            if(n%2){
                cout<<median<<" ";
            }else{
                cout<<less.top()<<" ";
            }
            cout<< more_sum - less_sum + c <<"\n";
        }
    }


}


Measured memory_bytes: 3828