akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;

#define pb push_back
#define eb emplace_back

const int MAX_N = 1e5+10;
int N;
vector<pair<ll,ll>> v, u;

struct E
{
	int f, t, cost;
	bool operator<(const E& o) const
	{
	    return cost<o.cost;
	}
};

vector<E> edges;

int par[MAX_N];

void init()
{
	for(int i=0;i<N;++i) par[i]=i;
}

int look(int x)
{
	if(par[x]==x) return x;
	return par[x] = look(par[x]);
}

void comb(int x, int y)
{
	int a=look(x), b=look(y);
	if(a!=b){
		par[a]=b;
	}
}

void solve()
{
	for(int i=0;i<N;++i) u.eb(v[i].first,i);
	sort(u.begin(),u.end());
	for(int i=1;i<N;++i) edges.pb(E{u[i].second,u[i-1].second,u[i].first-u[i-1].first});
	u.clear();
	for(int i=0;i<N;++i) u.eb(v[i].second,i);
	sort(u.begin(),u.end());
	for(int i=1;i<N;++i) edges.pb(E{u[i].second,u[i-1].second,u[i].first-u[i-1].first});
	
	init();
	ll res = 0;
	sort(edges.begin(),edges.end());
	for(const auto& e : edges){
		int from = e.f, to = e.t, cost = e.cost;
		if(look(from)!=look(to)){
			res+=cost;
			comb(from, to);
		}
	}
	cout<<res;
}

int main()
{
	cin >> N;
	ll a, b;
	for(int i=0;i<N;++i){
		cin >> a >> b;
		v.eb(a, b);
	}
	solve();
	return 0;
}

Measured memory_bytes: 11104
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=1e5+5;
const int MOD=1e9+7;
const int INF=INT_MAX;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define read(x) cin>>x;

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

int lcm(int a, int b){
    return ((a*b)/__gcd(a,b));
}

int nelements(int l, int r){return (abs(r-l)+1);}

int pow2(int a){
    return a*a;
}

int pow3(int a){
    return a*a*a;
}

#define l_shift(x,y) (x<<y)
#define r_shift(x,y) (x>>y)

vector<int> movy={0,0,1,-1};
vector<int> movx={1,-1,0,0};

bool fit(pii a, pii b){
    if(a.first<b.first && a.second<b.second)return true;
    return false;
}

void solve(){
    int n;
    cin>>n;
    vector<int> h(n), dp(n);
    for(int &it:h)cin>>it;
    dp[0]=0;
    for(int i=1;i<n;i++){
        if(i-2>=0 && i-1>=0){
            int delta1=abs(h[i]-h[i-1]);
            int delta2=abs(h[i]-h[i-2]);
            dp[i]=min(dp[i-1]+delta1,dp[i-2]+delta2);
        }
        else if(i-1>=0){
            int delta=abs(h[i]-h[i-1]);
            dp[i]=dp[i-1]+delta;
        }
    }
    cout<<dp[n-1]<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    //freopen("OUT.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3980
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] dp = new int[n+100];
		int[] h = new int[n+100];
		
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		for(int i = 0; i < n; i++) h[i] = sc.nextInt();
		
		dp[0] = 0;
		
		for(int i = 0; i < n; i++) {
			for(int j = 1; j <=k; j++) {
				dp[i+j] = Math.min(dp[i+j], dp[i]+Math.abs(h[i]-h[i+j]));
			}
		}
		
		System.out.println(dp[n-1]);
	}
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 10000000

int main()
{
  int n,m;cin>>n>>m;
  vector<int> c(m);
  int i,j;
  rep(i,m)cin>>c[i];
  vector<vector<int>> dp(m+1,vector<int>(n+1,INF));
  dp[0][0]=0;
  for(i=1;i<=m;i++)
  {
    for(j=0;j<=n;j++)
    {
      dp[i][j]=dp[i-1][j];
      if(j-c[i-1]>=0)
      {
        dp[i][j]=min(dp[i][j-c[i-1]]+1,dp[i][j]);
      }
    }
  }
  cout<<dp[m][n]<<endl;
}


Measured memory_bytes: 7056
#include<bits/stdc++.h>
using namespace std;
struct node{
int to,nxt,id,color;
}e[200001];
inline bool cmp(node x,node y){
if(x. id!=y. id)return x. id<y.id;
return x.color>y.color;}
int n,cnt ,head[100001],ans,x,y;
inline void Add(int xx,int yy,int iidd){
e[++cnt]. to=yy;
e[cnt].nxt=head[xx];
e[cnt]. id=iidd;
head[xx]=cnt;}
void Df5(int xx,int fa,int lst){
int cc=0; 
for(register int i=head[xx];i;i=e[i].nxt){
if(e[i].to!=fa){
++cc;
if(cc==lst)++cc;
e[i].color=cc;
if(cc>ans)ans=cc;
Df5(e[i].to,xx,cc);
}
}
}
int main(){
scanf("%d",&n);
for(register int i=1;i<n;i++){
scanf( "%d%d" ,&x,&y);
Add(x,y,i);
Add(y,x,i);}
Df5(1,0,0);
printf("%d\n" ,ans);
sort(e+1,e+(n-1)*2+1,cmp);
for(register int i=1;i<=(n-1)*2;i++)if(e[i]. id!=e[i-1]. id)printf("%d\n" ,e[i]. color);
}


Measured memory_bytes: 5120
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


A = read_col(5, 1)[0]

k = read_a_int()

if A[-1] - A[0] > k:
    print(':(')
else:
    print('Yay!')


Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,l,n) for(int i=l;i<n;++i)
int ans = 0;
int oddans = 0;
int pol[200];
int oddpol[100];
int oddpolcount = 0;
int memo[1000000];
int oddmemo[1000000];
int memorep(int n);
int oddmemorep(int n);
using namespace std;
int main() {
  pol[0] = 1;
  oddpol[oddpolcount++] = 1;
  int def = 3;
  int defdef = 3;
  REP(i,1,180){
    pol[i] = pol[i-1] + def;
    if(pol[i]%2==1) oddpol[oddpolcount++] = pol[i];
    def += defdef++;
  }
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    ans = memorep(n);
    oddans = oddmemorep(n);
    int i = 0;
    cout << ans << " " << oddans << endl;
  }
  return 0;
}

int memorep(int n){
  assert(n < 1000000);
  if(memo[n]!=0) return memo[n];
  int result;
  int min = 1000000;
  for(int i = 179;i>=0;i--){
    result = n-pol[i];
    if(result == 0){
      return memo[n] = 1;
    }
    if(result > 0){
      result = memorep(result) + 1;
      if(min > result) min = result;
    }
  }
  return memo[n] = min;
}

int oddmemorep(int n){
  if(oddmemo[n]!=0) return oddmemo[n];
  int result;
  int min = 1000000;
  for(int i = oddpolcount-1;i>=0;i--){
    result = n-oddpol[i];
    if(result == 0){
      return oddmemo[n] = 1;
    }
    if(result > 0){
      result = oddmemorep(result) + 1;
      if(min > result){
        min = result;
      }
    }
  }
  return oddmemo[n] = min;
}

Measured memory_bytes: 8848
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int n, k, num;
vector<double> field;
vector<double> kitai;

double max_num = -1;

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

    field.assign(n, -1);
    kitai.assign(n+1, -1);
    for (int i = 0; i < n;++i){
        cin >> num;
        field[i] = (1 + num);
    }
    for (int i = 0; i < n; ++i)
    {
        if (i == 0){
            kitai[0] = 0.0;
        }
            kitai[i+1] = field[i] + kitai[i];
    }
    for (int i = 0; i < n-k+1; ++i)
    {
        double ans = kitai[i + k] - kitai[i];
        if (max_num < ans/2)
        {
            max_num = ans/2;
        }
    }
    printf("%.10f\n", max_num);
    return 0;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader( new InputStreamReader(System.in));
		
		String s=br.readLine();
		System.out.println(s.substring(0, s.length()-8));

	}

}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

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

  long long ans = 1;
  vector<int> num(3,0);
  for(int i = 0;i < N;i++) {
    int n = 0;
    for(int j = 0;j < 3;j++) {
      if(A.at(i) == num.at(j)) n++;
      if(n == 1 && A.at(i) == num.at(j)) num.at(j)++;
    }
    ans *= n;
    ans %= MOD;
  }

  cout << ans << endl;

}



Measured memory_bytes: 640
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim();
    var data = inputs.split(' ').map(Number);
    var a = data[0];
    var b = data[1];
    var c = data[2];
    var count = 0;
    for (var i = a; i < b + 1; i++){
    	if (c % i === 0){
    		count ++;
    	}
}
    console.log(count);
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

string s;

int main() {
  cin >> s;
  int res = 0;
  for (int i = 0; i < 3; ++i)
    if (s[i] == 'R') {
      int cnt = 0;
      while (i < 3 && s[i] == 'R') ++cnt, ++i;
      res = max(res, cnt);
    }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3668
from sys import stdin

def main():
  N = int(input())
  P = stdin.readline().rstrip().split()
  if '0' in P:
    print(0)
    return
  # print(P)
  ans = 1
  for a in P:
    ans *= int(a)
    if ans > 1000000000000000000:
      print(-1)
      return
  print(ans)

main()


Measured memory_bytes: 19524
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, t;
  cin >> n >> t;
  vector<long long> h(n);
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }
  vector<long long> b(n), c(n);
  b[0] = h[0];
  c[0] = h[0] * 2;
  for (int i = 1; i < n; i++){
    b[i] = b[i - 1] + h[i];
    c[i] = max(c[i - 1], b[i]) + h[i];
  }
  for (int i = 0; i < n; i++){
    if (t < b[i]){
      cout << 1 << endl;
    } else {
      cout << (t - b[i]) / (c[i] - b[i]) + 2 << endl;
    }
  }
}


Measured memory_bytes: 5212
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	char str[1200], ans[1200];
	int i, len;
	gets(str);
	len = strlen(str);
	for (i = 0; i < len; i++) {
		if (str[i] >= 'a' && str[i] <= 'z')
			ans[i] = str[i] - 'a' + 'A';
		else if (str[i] >= 'A' && str[i] <= 'Z')
			ans[i] = str[i] - 'A' + 'a';
		else
			ans[i] = str[i];
	}
	ans[i] = '\0';
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		string X = GetString();
		int numS = 0;
		int numDelete = 0;
		for(int i = 0; i < X.Length; i++)
		{
			if(X[i] == 'S')
				numS++;
			else
			{
				if(numS > 0)
				{
					numS--;
					numDelete += 2;
				}
			}
		}
		Console.WriteLine(X.Length - numDelete);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 12512
#include<iostream>
using namespace std;
int main(){
  int n,m,s;
  cin>>n;
  m=n*(n-1)/2-n/2;
  s=n+1-n%2;//和がこの値になるペアは除外
  cout<<m<<endl;
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      if(i+j!=s) cout<<i<<" "<<j<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define si set<int>
#define msi map<string, int>
#define rsz(a) resize(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;
int digits(int n) {
  n = abs(n);
  if(n < 10) return 1;
  elif(n < 100) return 2;
  elif(n < 1000) return 3;
  elif(n < 10000) return 4;
  elif(n < 100000) return 5;
  elif(n < 1000000) return 6;
  elif(n < 10000000) return 7;
  elif(n < 100000000) return 8;
  elif(n < 1000000000) return 9;
  else return 10;
}


int main() {
  io();
  
  vi arr;
  fori(i, 3) {
  	int a;
    cin >> a;
    arr.pb(a);
  }
  qsort(arr);
  if(arr[0] == arr[1] && arr[1] != arr[2]) cout << "Yes";
  elif(arr[1] == arr[2] && arr[0] != arr[1]) cout << "Yes";
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7;

signed main() {
  std::vector<double> x(3),y(3);
  for(int i=0;i<3;i++)cin>>x[i]>>y[i];
  double a,b,c;
  a=sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]));
  b=sqrt((x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1]));
  c=sqrt((x[0]-x[2])*(x[0]-x[2])+(y[0]-y[2])*(y[0]-y[2]));
  double M=max({a,b,c});
  double r=abs((x[0]-x[2])*(y[1]-y[2])-(x[1]-x[2])*(y[0]-y[2]))/(a+b+c);
  double ans=M*r/(2*r+M);
  cout<<fixed<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

ll DP[100010][3];

ll X[100010][3];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(DP, 0, sizeof(DP));
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> X[i][0] >> X[i][1] >> X[i][2];
    for (int i = 0;i < N;i++) {
        for (int j = 0;j < 3;j++) {
            for (int k = 0;k < 3;k++) {
                if (j == k) continue;
                DP[i + 1][k] = max(DP[i + 1][k], DP[i][j] + X[i][k]);
            }
        }
    }
    ll sol = 0;
    for (int i = 0;i < 3;i++) sol = max(sol, DP[N][i]);
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
    using namespace std;
     
    int main(){
    int A,B,C,X;
     
    cin>>A>>B>>C>>X;
    int res=0;
    for(int a=0; a <= A; ++a){
    for(int b=0; b <= B; ++b){
    for(int c=0; c <= C; ++c){ 
    int total = 500*a +100*b +50*c;
    if (total==X) ++res;
    } 
    }
    }
    cout << res <<endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    string s;
    cin >> s;
    
    string ans="";
    if(s.substr(0, 4)>"2020")
        ans="TBD";
    else if(s.substr(0, 4)=="2019") {
        if(s.substr(5, 2)>"04") ans="TBD";
        else if(s.substr(5, 2)=="04" && s.substr(8, 2)>"30") ans="TBD";
        else ans="Heisei";
    }else
        ans="Heisei";

    pt(ans);
}




Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

pii in[100050];
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		in[i] = pii(t1, t2 - 1);
	}
	sort(in + 1, in + M + 1, [](pii a, pii b) {
		return a.second < b.second;
	});

	int ans = 0, mx = -1;
	for (i = 1; i <= M; i++) {
		if (mx >= in[i].first) continue;
		ans++;
		mx = max(mx, in[i].second);
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func solve() {
	var N int
	fmt.Scan(&N)

	d := make([]int, N)
	for i, _ := range d {
		fmt.Scan(&d[i])
	}

	sort.Ints(d)
	ans := 1
	for i := 1; i < len(d); i++ {
		if d[i-1] < d[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	solve()
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var h=new int[s[0]];
		var a=new int[s[0]];
		for(int i = 0;i<s[2];i++) {
			var e=sc.I-1;
			h[e]++;
		}
		for(int i = 0;i<s[0];i++) {
			Console.WriteLine("{0}",(s[1]-(s[2]-h[i]))>0?"Yes":"No");
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 18268
import java.util.*;
class Main{
	static int search(int[] data, int key){
		int[] a = new int[data.length+1];
        System.arraycopy(data, 0, a, 0, data.length);
        a[a.length-1]=key;
		for(int i=1;i <= a.length-1;i++){
			if(a[i-1]==key && i<=a.length-2){
				return 1;
			    
		    } if(a[a.length-1-i]!=a[a.length-1] && i==a.length-1){
			    return 0;
			}
	    }return 1;
	}
	public static void main(String[] args){
		int count = 0;
		Scanner x=new Scanner(System.in);
	    int s1 = x.nextInt();
		int[] r1=new int[s1+1];
		for(int i=0;i<s1;i++){
		    r1[i]=x.nextInt();
		}
		
	    int s2 = x.nextInt();
		int[] r2=new int[s2];
		for(int j=0;j<s2;j++){
		    r2[j]=x.nextInt();
		}
		x.close();
		if(s1<s2){
		for(int i=0;i<s1;i++){
			if(search(r1,r2[i])==1){
				count++;
			}
		}
		}else if(s1>s2){
			for(int j=0;j<s2;j++){
			    if(search(r1,r2[j])==1){
				    count++;	
		       }
			}
		}
		System.out.println(count);
	}
}


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

// void ans(int n){
    
// }

int main(){
    int n;
    cin>>n;
    if(n>=400 && n<=599){
        cout<<8;
        return 0;
    }
    if(n>=600 && n<=799){
        cout<<7;
        return 0;
    }
    if(n>=800 && n<=999){
        cout<<6;
        return 0;
    }
    if(n>=1000 && n<=1199){
        cout<<5;
        return 0;
    }
    if(n>=1200 && n<=1399){
        cout<<4;
        return 0;
    }
    if(n>=1400 && n<=1599){
        cout<<3;
        return 0;
    }
    if(n>=1600 && n<=1799){
        cout<<2;
        return 0;
    }
    if(n>=1800 && n<=1999){
        cout<<1;
        return 0;
    }
}


Measured memory_bytes: 3632
from collections import deque

UNVISITED=0
ENTERED=1
VISITED=2

def nextNL(u, nList, state):
    l=nList[u]
    for i in l:
        if(state[i]==UNVISITED):
            return i
    return -1

def dfs(s,t,nList,state, color,icol):

    S=[]

    S.append(s)
    state[s]=ENTERED
    color[s]=icol
    while(len(S)>0):
        current=S[-1]
        next=nextNL(current, nList, state)
        if next!=-1:
            S.append(next)
            state[next]=ENTERED
            color[next]=icol
        else:
            state[S.pop()]=VISITED

    return color[s]==color[t]

def main():

    n,m=list(map(int,input().split()))
    nList=[]
    for _ in range(n):
        nList.append([])

    for _ in range(m):
        s,t=list(map(int,input().split()))
        nList[s].append(t)
        nList[t].append(s)
    
    state=[UNVISITED]*n

    q=int(input())

    icol=-1
    color=[icol]*n
    for _ in range(q):
        s,t=list(map(int,input().split()))
        if(color[s] == -1) and (color[t] == -1):
            icol+=1
            res=dfs(s,t,nList,state,color,icol)
            if(res==True):
                print('yes')
            else:
                print('no')
        elif (color[s]==-1) or (color[t]==-1):
            print('no')
        elif (color[s] == color[t]):
            print('yes')
        else:
            print('no')
    
if __name__=='__main__':
    main()


    




Measured memory_bytes: 24768
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int a,b,c;

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

    cout<<a*c/2<<endl;
}

Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

len = s.length

i = 0
hash = {}
s.chars { |ch|
    if hash.key?(ch)
        hash[ch].push(i)
    else
        hash[ch] = [i]
    end
    i += 1
}

i = -1
t.chars { |ch|
    # print ch," ",i,"\n"
    if hash.key?(ch)
        list = hash[ch]
        pos = i%len

        if list.last <= pos
            i += len+list[0] - pos
        else
            head = 0
            tail = list.size-1
            mid = (head+tail)/2
            while head < tail
                if list[mid] <= pos
                    head = mid + 1
                else
                    tail = mid
                end
                mid = (head+tail)/2
            end
            i += list[mid] - pos
        end
    else
        i = -2
        break
    end
}

p i+1

Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using ull = unsigned long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

const int MX = 2010;

int main(){
    vector<string> s(3);
    rep(i, 3) cin >> s[i];
    sort(s.begin(), s.end());
//    vector<vector<vector<bool>>> d(3, vector<vector<bool>>(3, vector<bool>(MX, true)));
    bool d[3][3][MX];
    int ans = MX * 3;
    do{
        rep(i, 3) for(int j = i + 1; j < 3; j++) rep(k, s[i].size()){
            string pre = s[i], post = s[j];
            bool ok = true;
            for (int ni = k; ni < pre.size(); ni++){
                int nj = ni - k;
                if (nj >= post.size()) break;
                if (pre[ni] == '?' or post[nj] == '?') continue;
                if (pre[ni] != post[nj]) ok = false;
            }
            d[i][j][k] = ok;
        }
        auto f = [&](int i, int j, int k) {
            if (k >= s[i].size()) return true;
            return d[i][j][k];
        };
//        rep(x, s[0].size() + 1)rep(y, max(s[1].size() + 1, s[0].size() - x + 1)){
        rep(x, MX)rep(y, MX){
            if (!f(0, 1, x)) continue;
            if (!f(1, 2, y)) continue;
            if (!f(0, 2, x + y)) continue;
            int now = 0;
            now = max<int>(now, s[0].size());
            now = max<int>(now, x + s[1].size());
            now = max<int>(now, x + y + s[2].size());
            ans = min(ans, now);
        }
    }while(next_permutation(s.begin(), s.end()));
    cout << ans << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u128; n]
    };

    let mut a: Vec<u128> = a;
    a.sort();

    let mut result = a[0];

    for i in 1..n {
        result = gdg(result, a[i]);
    }

    println!("{}", result)
}

fn gdg(a: u128, b: u128) -> u128 {
    let mut a = a;
    let mut b = b;

    if a > b {
        let tmp = a;
        a = b;
        b = tmp;
    }

    let mut r = a % b;

    while r != 0 {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}


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

int main() {
string r;
char a,b,c;
cin>>r;
a=r[0];
b=r[1];
c=r[2];

int q=0;
if(a=='R')
{q++;
}
if(b=='R')
{q++;}
if(c=='R')
{q++;}
if(b=='S'&&q==2)
{
  cout << 1 << endl;
}
else{cout << q<< endl;}
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<>());
    int n=min(s.size(),t.size());
    int flag=-1;
    rep(i,n) {
        if (s[i]<t[i]) {
            flag=1;
            break;
        } else if (s[i]>t[i]) {
            flag=0;
            break;
        }
    }
    if (flag==-1) {
        if (s.size()<t.size()) flag=1;
        else flag=0;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
   
    return 0;  
}

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

int main() {
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(x-r>=0 && y-r>=0 && x+r<=w && y+r<=h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<bool, lli> P;
typedef tuple<lli, lli, lli> tup;

class CompareDist
{
public:
    bool operator()(P n1, P n2) {
        return n1.second<n2.second;
    }
};

int main() {
    lli n, k;
    cin2(n, k);
    string s;
    cin1(s);

    lli rl = 0;
    lli lr = 0;
    lli ans = 0;
    REP(i, 0, n-1) {
        if (s[i] == s[i+1])
            ans++;
        else if (s[i] == 'R' && s[i+1] == 'L')
            rl++;
        else
            lr++;
    }

    if (s[0] == 'L') {
        if (k > rl) {
           if ( s[n-1] == 'R')
               cout << ans + rl * 2 + 1 << endl;
           else
               cout << ans + rl * 2 << endl;
        }
        else
            cout << ans + k * 2 << endl;
    }
    else {
        if (k > lr) {
            if (s[n-1] == 'L') {
                cout << ans + lr * 2 + 1 << endl;
            }
            else
                cout << ans + lr * 2 << endl;
        }
        else
            cout << ans + k * 2 << endl;

    }

}


Measured memory_bytes: 512
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] <= now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)


Measured memory_bytes: 13708
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int edgenum[100000];
vector<pair<int, int>> edge;
int main() {
	string s;
	int ans = 0, memo = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') memo++;
		else {
			ans = max(ans, memo);
			memo = 0;
		}
	}
	cout << max(ans, memo) << endl;
}

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

int main(){
 string A, B;
 cin >> A >> B;
 int count = 0;
 int n = A.size();
 for (int i = 0; i<n; i++){
     if(A[i]!=B[i])
         count++;
 }
 cout << count << endl;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  set<char> S;
  for(char c:s){
    S.insert(c);
  }
  int si=s.size();
  int si2=S.size();
  if(si==si2){
    cout<<"yes"<<'\n';
  }
  else{
    cout<<"no"<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, M, K;
  
  std::cin >> N >> M >> K;

  for (int i = 0; i <= N; i ++)
    for (int j = 0; j <= M; j ++)
      if (M * i + N * j - i * j * 2 == K) {
        std::cout << "Yes" << std::endl;

        return 0;
      }

  std::cout << "No" << std::endl;

  return 0;
}


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

int main(void){
  int k,n,st,pre,ans;
  vector<int> v;
  
  cin >> k >> n;
  cin >> st;
  pre = st;
  for (int i=1; i<n; i++){
    int t; cin >> t;
    v.push_back(t-pre);
    pre = t;
  }
  v.push_back(k-pre+st);
  sort(v.begin(), v.end());
  ans = 0;
  for (int i=0; i<n-1; i++){
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
n = gets.to_i
a = gets.split.map(&:to_i)

pair = Struct.new("Pair", :c, :s)
dp = Array.new(n+1).map{Array.new(3)}

dp[0][0] = pair.new(1000, 0) # none
dp[0][1] = pair.new(1000, 0) # buy 
dp[0][2] = pair.new(1000, 0) # sale

for i in 1..n
    v = a[i-1]

    vv = Array.new(3)
    vmax = -1
    vmaxj = 0
    cmax = -1
    cmaxj = 0
    for j in 0...3
        dp[i][j] = 
        vv[j] = dp[i-1][j].s * v + dp[i-1][j].c
        if vv[j] > vmax || (vv[j] == vmax && dp[i-1][j].s > dp[i-1][vmaxj].s)
            vmaxj = j
            vmax = vv[j]
        end
        if dp[i-1][j].c > cmax
            cmaxj = j
            cmax = dp[i-1][j].c
        end
    end

    dp[i][0] = pair.new(dp[i-1][vmaxj].c, dp[i-1][vmaxj].s)

    dp[i][1] = pair.new(vv[vmaxj], 0)

    m = cmax / v
    dp[i][2] = pair.new(dp[i-1][cmaxj].c - m * v, dp[i-1][cmaxj].s + m)
end

ans = -1
for j in 0...3
    vv = dp[n][j].s * v + dp[n][j].c
    if vv > ans
        ans = vv
    end
end

puts ans


Measured memory_bytes: 14348
N, T = map(int, input().split())
time = list(map(int, input().split()))
syawaend = 0
ans = 0
for i in range(N):
  if syawaend <= time[i]:
    syawaend = time[i]+T
    ans += T
  else:
    syawaend = time[i]+T
    ans += time[i]-time[i-1]
print(ans)


Measured memory_bytes: 85456
powlist=[1,1]
for i in range(2,2001):
    powlist.append(powlist[-1]*i%(10**9+7))

a=powlist[-1]

nums=format(10**9+5,"b")

lists=[a,a**2]
add=a**2
for i in range(28):
    add=add**2%(10**9+7)
    lists.append(add)

odds=1
for i in range(30):
    if nums[i]=="1":
        odds=odds*lists[29-i]%(10**9+7)
    else:
        continue

invlists=[odds]
for i in range(2000,1,-1):
    what=invlists[0]*i%(10**9+7)
    invlists.insert(0,what)
invlists.insert(0,1)
####下処理の終了#####
n,k=map(int,input().split())
for i in range(1,k+1):
    if i>min(n-k+1,k):
        print(0)
    elif i<=min(n-k+1,k):
        ans=((powlist[n-k+1]*powlist[k-1]%(10**9+7))*(invlists[i]*invlists[n-k+1-i]%(10**9+7))*(invlists[i-1]*invlists[k-i]%(10**9+7)))%(10**9+7)
        print(ans)
    

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    vector<int> b(N-1);
    for (int i = 0; i < N-1; i++){
        cin >> b[i];
    }
    int ans = 0;
    if (N == 2){
        cout << b[0]*2 << endl;
        return 0;
    }
    ans += b[0];
    for (int i = 0; i < N-2; i++){
        ans += min(b[i],b[i+1]);
    }

    ans += b[N-2];
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  int x = 0, ans = 0;

  for (int i = 0; i < N; i++) {
      char M;
      cin >> M;
      if(M=='I') x++;
      else if(M=='D') x--;
      ans = max(ans, x);
  }
  cout << ans << endl;
}

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

int dic[2236920];

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

  for (int i = 0; i < n; i++) {
    string command, str;
    cin >> command >> str;

    int key = 0, key2;
    for (int i = 0; i < str.size(); i++) {
      switch (str[i]) {
      case 'A':
        key2 = 1;
        break;
      case 'C':
        key2 = 2;
        break;
      case 'G':
        key2 = 3;
        break;
      case 'T':
        key2 = 4;
        break;
      }

      key += key2 * pow(4, str.size() - i - 1);
    }

    if (command[0] == 'i') {
      dic[key - 1] = 1;
    } else if (dic[key - 1]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 8768
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		int m=1<<n;
		var a=new int[m];
		for(int i = 0;i<m;i++) {a[i]=sc.I;}
		for(int i = 1;i<m;i<<=1) {
			for(int j = 0;j<m;j+=i<<1) {
				if(a[j]!=a[j+i]){a[j]=Abs(a[j]-a[j+i]);}
			}
		}
		Console.WriteLine("{0}",a[0]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main()
{
    string s;
    cin >> s;
    bool flag = true;
    for (int i = 0; i < s.size() - 1; i++)
    {
        if (s[i] == s[i + 1])
            flag = false;
    }
    puts(flag ? "Good" : "Bad");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;
const int INFI = (1 << 29);
const ll INFL = (1LL << 62);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) int(x.size())
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define forn(tourBina, n) for(ll tourBina = 0; tourBina < n; tourBina++)
#define fore(tourBina, l, r) for(ll tourBina = l; tourBina <= r; tourBina++)
#define DBG(x) cerr << #x << " = " << x << endl
#define pb(x) push_back(x)

using namespace std;

void solve()
{
    ll n;
    
    cin >> n;
    
    cout << ceil(n/2.) << "\n";
}

int main()
{
	FIO;
	
	#ifdef tourBina
        //freopen("input.in", "r", stdin);
	#endif
    
    solve();
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int n;
  vector<int> h(100010);
  vector<long long> dp(100010);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < n; i++) dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
  }

  cout << dp[n-1] << endl;
}

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

int main() {
  int n, k; cin >> n >> k;
  vector<int> p(n); rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  ll sum = 0;
  rep (i, k) sum += p[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3624