akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, k; cin >> n >> k;
  vll a(n); rep(i, n) cin >> a[i];
  ll ans = 1;
  for(ll i = k;i < n;i++)
  {
    if(a[i - k] < a[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(4); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 4672
#include <bits/stdc++.h>
using namespace std;
int i,j,k,x,y,z,l,m,n,count1=0,count2=0;
int gcd(int,int);
void A(void);
void B(void);
void C(void);
void D(void);
void E(void);
void F(void);

int main(void){
    C();
}

void C(){
    int minv=-1,sum=0;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m,0));
    for(i=0;i<n;i++){
        cin>>c[i];
        for(j=0;j<m;j++){
            cin>>a[i][j];
        }   
    }
    for(i=0;i<(1<<n);i++){
        vector<int> suma(m,0);
        bitset<12> bit(i);
        for(j=0;j<n;j++){
            if(bit.test(j)){
                sum+=c[j];
                for(k=0;k<m;k++){
                    suma[k]+=a[j][k];
                }
            }
        }
        for(k=0;k<m;k++){
            if(suma[k]>=x)count1++;
        }
        if(count1==m){
            if(minv==-1)minv=sum;
            else minv=min(minv,sum);
        }
        sum=0;
        count1=0;
    }
    cout<<minv<<endl;
}

Measured memory_bytes: 3636
// AtCoder My Practice
// author: Leonardoen @ NEETSDKASU

// 解説読後

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let s = get().as_bytes();
    
    let mut mp = std::collections::BTreeMap::new();
    
    let c = 1 << n;
    
    for x in 0..c {
    	let mut s1 = String::new();
        let mut s2 = String::new();
    	for i in 0..n {
        	if x & (1 << i) == 0 {
            	s1.push(s[i] as char);
            } else {
            	s2.push(s[i] as char);
            }
        }
        s1.push('_');
        s1.push_str(&s2);
        *mp.entry(s1).or_insert(0) += 1;
    }
	
    let mut ans = 0i64;
    
    for x in 0..c {
    	let mut s1 = String::new();
        let mut s2 = String::new();
    	for i in 0..n {
        	if x & (1 << i) == 0 {
            	let i = s.len() - 1 - i;
            	s1.push(s[i] as char);
            } else {
            	let i = s.len() - 1 - i;
            	s2.push(s[i] as char);
            }
        }
        s1.push('_');
        s1.push_str(&s2);
        ans += *mp.get(&s1).unwrap_or(&0);
    }

	println!("{}", ans);
}


Measured memory_bytes: 26876
N = int(input())
songs = []
for i in range(N):
    s, t = map(str, input().split())
    songs.append((s, int(t)))
X = input().strip()
ans = 0
sleep = False
for s, t in songs:
    if sleep:
        ans += t
    if s == X:
        sleep = True
print(ans)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main () {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut cnt = 0;
    for i in 0..n {
        let mut x = a[i];
        while x > 0 && x % 2 == 0 {
            x /= 2;
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);

ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
 /*struct cmp{ bool operator() ( const, const )const{}};
  use as set<ll> ,cmp> a*/
int main()
{
  Summon_Tourist;
  //freopen("input.txt" , "r" , stdin );
  ll x;
  cin>>x;
  ll p = 0 ; ll q = 0;
  for( ll i = -200 ; i<=200 ; i++ )
  {
      for( ll j = -200 ; j<=200 ; j++ )
      {
          if((pow(i,5) - pow(j,5)) == x)
            {
                p = i ;
                q = j;
            }
      }
  }
  cout<<p<<" "<<q;
  return 0;

}



Measured memory_bytes: 4060
S = input()
ans = 'No'
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
  ans = 'Yes'
if S[0] == S[2] and S[1] == S[3] and S[0] != S[1]:
  ans = 'Yes'
if S[0] == S[3] and S[1] == S[2] and S[0] != S[1]:
  ans = 'Yes'
print(ans)

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<int> v;
  vector<double> x(n), y(n);
  rep(i, n) {
    cin >> x[i];
    cin >> y[i];
    v.push_back(i); 
  }

  int m = 0;
  double ans = 0.0;
  do {
    rep(i, n-1) { 
      int cur = v[i];
      int next = v[i+1];
      double xd = x[cur] - x[next]; 
      double yd = y[cur] - y[next]; 
      ans += sqrt(xd * xd + yd * yd);
    }
    m++;
  } while (next_permutation(v.begin(), v.end()));
  cout << ans/m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define REP(i,l,r) for(ll i=l; i<(ll)(r); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
ll gcd(ll a,ll b){if(b==0)return abs(a);return gcd(b,a%b);}
ll lcm(ll a,ll b){if(a==b&&a==0) return 0;else return a/gcd(a,b)*b;}
int upcmpll(const void *a,const void *b){
    return (*(ll*)a == *(ll*)b?0:(*(ll*)a > *(ll*)b?1:-1));
}
void sort_u(ll *a,int n){qsort(a,n,sizeof(ll),upcmpll);}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    char s[101010], t[101010];
    scanf("%s%s", s, t);
    int ok = 1;
    ll ans_l = lcm(m, n);
    rep(i, n){
        ll tmpi = i*(ans_l/n);
        if(tmpi%(ans_l/m) == 0){
            int j = tmpi/(ans_l/m);
            if(j >= 0 && j < m){
                if(s[i] != t[j]){
                    ok = 0;
                    break;
                }
            }
        } 
    }
    ll num = (ok ? ans_l : -1LL);
    printf("%lld", num);
}


Measured memory_bytes: 1868
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

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

	string s;
	cin >> s;
	bool ok = true;
	if (s.size() % 2 == 0) {
		for (int i = 0; i < s.size() / 2; i += 2) {
			if (s[i] != 'h' || s[i + 1] != 'i')
				ok = false;
		}
	}
	else {
		ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}
ll a[2010];
ll c[2010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);

    ll N, x;
    cin >> N >> x;

    ll ans = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
        c[i] = a[i];
        ans += a[i];
    }

    for (int i = 0; i < N; ++i)
    {
        ll cost = i * x;
        for (int j = 0; j < N; ++j)
        {
            c[j] = min(c[j], a[(j + N - i) % N]);
        }

        for (int j = 0; j < N; ++j)
            cost += c[j];
        ans = min(ans, cost);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
map<char, char> mp;
map<char, char> mp2;

int main(){
    string s,t;
    cin>>s>>t;
    ll n=s.length();
    bool f=true;
    for(char c='a';c<='z';c++){
        mp[c]='A';
        mp2[c]='A';
    }
    for(int i=0;i<n;i++){
        if(mp[s[i]]=='A'){
            mp[s[i]]=t[i];
        }else{
            if(mp[s[i]]!=t[i]){
                f=false;
                break;
            }
        }
        if(mp2[t[i]]=='A'){
            mp2[t[i]]=s[i];
        }else{
            if(mp2[t[i]]!=s[i]){
                f=false;
                break;
            }
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
const int Nmax=200010;

int main() {
	ll Z,W,a[2010];
	int N;
	cin >> N >> Z >> W;
  	for(int i=0;i < N;i++) cin >> a[i];
  	cout << max(abs(W-a[N-1]), abs(a[N-2]-a[N-1])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n % 2 == 1) {
        printf("%.7lf\n", (n / 2 + 1) * 1.0 / n * 1.0);
    } else {
        printf("%.7lf\n", (n / 2) * 1.0 / n * 1.0);
    }
    return 0;
}

Measured memory_bytes: 256
(* O(n) *)
Scanf.scanf " %d" @@ fun n ->
  let g = Array.make n [] in
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d %d" @@ fun u v w ->
      let u, v = u - 1, v - 1 in
      g.(u) <- (v, w mod 2 = 0) :: g.(u);
      g.(v) <- (u, w mod 2 = 0) :: g.(v);
  done;
  let cs = Array.make n 0 in
  let rec dfs v p c =
      cs.(v) <- c;
      let f (v2, w) = if v2 <> p then dfs v2 v @@ if w then c else -c in
      List.iter f g.(v) in
  dfs 0 (-1) 1;
  Array.iter (fun c -> max 0 c |> Printf.printf "%d\n") cs

Measured memory_bytes: 20224
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

class MyScanner{
    InputStream stream;
    public MyScanner(){
        stream = System.in;
    }
    
    public int nextInt(){
        int ret = 0;
        try{
            while(true){
                char readed = (char)stream.read();
                if(readed < '0' || readed > '9'){
                    break;
                }
                ret = ret * 10 + (readed - '0');
            }
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            return ret;
        }
    }
}

class Main {
    public static void main(String args[]) {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            MyScanner sc = new MyScanner();
            int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
            a += b;
            int passed = 0, ab = 0;
            char[] s = br.readLine().toCharArray();
            for(int i = 0; i < n; ++i){
                if(s[i] == 'b'){
                    ab++;
                }
                if(s[i] == 'a' && passed < a){
                    ++passed;
                    System.out.println("Yes");
                }else if(s[i] == 'b' && passed < a && ab <= b){
                    ++passed;
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}


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

int main() {
	int a;
	vector<int> A;
	while (cin >> a) {
		if (a == 0) {
			cout << A.back() << endl;
			A.pop_back();
		}
		else A.push_back(a);
	}
	return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int factorial(int n){
    int fac=1;
    for(int i=1;i<=n;i++)
     fac=fac*i;
    return fac;
}
int main(){
    FAST
    int n;
    cin>>n;
    vector<double>v(n);
    vector<pair<double,double>>d;
    int x,y;
    for(int i=1;i<=n;i++){
        cin>>x>>y;
        d.push_back({x,y});
    }
    iota(v.begin(),v.end(),0);
    double ans=0;
    double dis=0;
    double res=0;
    do{
        for(int i=0;i<n-1;i++){
            dis+=((d[v[i]].first-d[v[i+1]].first)*(d[v[i]].first-d[v[i+1]].first) + (d[v[i]].second-d[v[i+1]].second)*(d[v[i]].second-d[v[i+1]].second));
            dis=sqrt(dis);
            res+=dis;
            dis=0;
        }
        ans+=res;
        res=0;
        dis=0;
    } while(next_permutation(v.begin(),v.end()));
    cout<<fixed<<setprecision(10);
    cout<<ans/factorial(n);
    return 0;
}

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

// 参考：https://ei1333.github.io/algorithm/union-find.html
struct UnionFind{
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)
            return(false);
        if(data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0)
            return(k);
        return(data[k] = find(data[k]));
    }
    
    int size(int k){
        return(-data[find(k)]);
    }
};
 
int main(){
    int N, M, K;
    cin >> N >> M >> K;

    UnionFind uf(N);

    int A[M], B[M];
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        uf.unite(A[i], B[i]);
    }
    int C[K], D[K];
    for(int i=0;i<K;i++){
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }

    int ans[N];
    // 連結成分のサイズ
    for(int i=0;i<N;i++)
        ans[i] = uf.size(i);
    // 友達関係
    for(int i=0;i<M;i++){
        if(uf.find(A[i]) == uf.find(B[i])){
            ans[A[i]]--;
            ans[B[i]]--;
        }
    }
    // ブロック関係
    for(int i=0;i<K;i++){
        if(uf.find(C[i]) == uf.find(D[i])){
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }

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

}

Measured memory_bytes: 3200
h,w=map(int,input().split())

ans=h*w

if h%3==0:
    ans=0
else:
    ans=w
if w%3==0:
    ans=0
else:
    ans=min(ans,h)


for i in range(1,h):
    if w%2==0:
        l=[i*w,(h-i)*(w//2),(h-i)*(w//2)]
        ans=min(ans,max(l)-min(l))
    else:
        l=[i*w,(h-i)*(w//2+1),(h-i)*(w//2)]
        ans=min(ans,max(l)-min(l))

for i in range(1,w):
    if h%2==0:
        l=[i*h,(w-i)*(h//2),(w-i)*(h//2)]
        ans=min(ans,max(l)-min(l))
    else:
        l=[i*h,(w-i)*(h//2+1),(w-i)*(h//2)]
        ans=min(ans,max(l)-min(l))

print(ans)


Measured memory_bytes: 41308
// Created by sz
#include <bits/stdc++.h>
using namespace std;

int nxt[100005];
int pre[100005];
int temp[100005];

typedef  long long ll;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string input;
    cin>>input;
    int len = input.length();
    int ans = 0;
    for(int i =0; i< len; i++){
        ans += input[i] == '2' ?1:0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
totalPattern = S.count("R")*S.count("G")*S.count("B")
for i in range(N-1):
    for j in range(i+1,N):
        k=j+(j-i)
        if k>N-1:
            continue
        if not S[i] == S[j] and not S[i] == S[k] and not S[j] == S[k]:
            totalPattern-=1
print(totalPattern)

Measured memory_bytes: 9192
n,k=map(int,input().split())

mod=10**9+7
for i in range(1,k+1):
    numerator=(n-k+1)%mod
    denominator=i
    for j in range(1,i):
        numerator=(((numerator*(j+n-k+1-i))%mod)*(j+k-i))%mod
        denominator=(denominator*j*j)%mod
    print((numerator*(pow(denominator,mod-2,mod)))%mod)

Measured memory_bytes: 73764
def solve():
  ans = -float('inf')
  N, K = map(int, input().split())
  P = list(map(lambda x:int(x)-1, input().split()))
  C = list(map(int, input().split()))
  for i in range(N):
    score = 0
    now = i
    visited = [-1]*N
    scores = [0]*N
    visited[now] = 0
    for j in range(1,K+1):
      now = P[now]
      score += C[now]
      ans = max(ans, score)
      if visited[now]>=0:
        cyc = j - visited[now]
        up = score - scores[now]
        break
      scores[now] = score
      visited[now] = j
    else:
      continue
    if up<=0:
      continue
    cnt = j+1
    if K-cyc>=j:
      score += (K-cyc-j)//cyc * up
      ans = max(ans, score)
      cnt += (K-cyc-j)//cyc*cyc
    for j in range(cnt,K+1):
      now = P[now]
      score += C[now]
      ans = max(ans, score)
  return ans
print(solve())

Measured memory_bytes: 91196
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

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


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
const int MAX_N = 131072;

int main() {
  string S;
  cin>>S;
  int ans = S.size()-1;
  int N = S.size();
  for(int i = 0; i < N-1; i++){
    if(S[i]!=S[i+1]){
      chmin(ans,max(i,N-2-i));
    }
  }
  cout<<ans+1<<endl;
}

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

#define ll                   long long
#define MOD                  1000000007
#define fast()               ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define fd(i,a,b)          for(ll i=(ll)a;i<(ll)b;i++)
#define bk(i,a,b)          for(ll i=(ll)a;i>=(ll)b;i--)
#define pb                   push_back
#define vi                   vector<ll>
#define test()               ll t; cin>>t; while(t--)
#define endl                 "\n"
#define param                greater<ll>()
#define ff                   first
#define ss                   second
#define all(v)               v.begin(),v.end()
#define mk                   make_pair
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define MAX 1000000000000000000

using namespace std;

const ll N = 1e5+10;


double dp[3010][3010];

int main()
{

    fast()

    ll t;
    // cin>>t;
    t=1;

    while(t--)
    {
       ll i,j,a,b,d=0,n;

        cin>>n;
        
        double p[n+1];
        
        for(i=1;i<=n;i++)
        {
          cin>>p[i];
        }
        
       dp[0][0]=1.0;
        
        for(i=1;i<=n;i++)
        {
            for(j=0;j<=i;j++)
            {
                if(j==0)
                dp[i][j]=dp[i-1][j]*(1.0-p[i]);
                else
                dp[i][j]=dp[i-1][j]*(1.0-p[i]) + dp[i-1][j-1]*p[i];
                
                
            }
        }
        
        double res=0.0;
        
        for(i=(n+1)/2;i<=n;i++)
        {
          res+=dp[n][i];
        }
        
    std::cout << std::setprecision(10) << std::fixed;
    cout<<res;
        
       
       
       
       



        // vector < ll > vec(n+1),sum(n+1,0),vec2(n+1);


        

    //   ll ans=0;

        
    //     for(i=1;i<=n;i++)
    //     {
    //         ans=max(ans,dp[i]);
            
    //         // cout<<dp[i]<<" ";
          
    //     }
        
        
        // for(i=1;i<=n;i++)
        // {
        //     for(j=1;j<=m;j++)
        //     {
        //         cout<<dp[i][j];
                
        //     }
        //     cout<<endl;
        // }
        



    }

}



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

int main()
{
    char c;
    std::cin >> c;

    char ans;
    switch (c)
    {
    case 'A':
        ans = 'T';
        break;
    case 'T':
        ans = 'A';
        break;
    case 'C':
        ans = 'G';
        break;
    case 'G':
        ans = 'C';
        break;
    }

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

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

int main(){ //ABC 175
    /* A */
    string s;
    cin >> s;
    int ans=0,cnt=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='R'){
            cnt++;
            if(ans<cnt)ans=cnt;
        }else{cnt=0;}
    }
    cout << ans << endl;

    /* B
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        ans += s.at(i) - '0';
    }
    cout << ((ans%9==0)? "Yes":"No") << endl;*/

    /* C 
    int n;
    cin >> n;
    vector<int64_t> a(n);
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    int64_t ans=0;
    for(int i=1;i<n;i++){
        if(a[i-1]>a[i]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;*/


    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
// #define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

signed main()
{
	ll a,v,b,w,t;
	fin>>a>>v>>b>>w>>t;
	if(a>b) a=-a,b=-b;
	puts((a+v*t>=b+w*t)?"YES":"NO");
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll gcd(ll a,ll b) {
    if(b == 0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
    return (a/gcd(a,b))*b;
}
int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll cnt_b = b - b/c - b/d + (b/lcm(c,d));
    ll cnt_a = (a-1) - (a-1)/c - (a-1)/d + ((a-1)/lcm(c,d));
    ll ans = cnt_b-cnt_a;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

struct edge{
	ll to;
	ll cost;
	edge(ll to, ll cost) :to(to), cost(cost){};
};

vector<edge> G[100];
ll n, m;
ll a, b, c, d;
char k;
ll sum[100];
ll iki, kaeri;

void djikstra(int start){
	REP(i, 100){
		sum[i] = INF;
	}
	sum[start] = 0;

	priority_queue<P> que;//fi:cost,se:vertex
	que.push(P(0, start));

	while (que.size()){
		P p = que.top(); que.pop();
		int v = p.second;

		if (sum[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if (sum[e.to] > sum[v] + e.cost){
				sum[e.to] = sum[v] + e.cost;
				que.push(P(sum[e.to], e.to));
			}
		}
	}
}

int main(){
	cin >> n >> m;
	REP(i, m){
		cin >> a >> k >> b >> k >> c >> k >> d;
		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, d));
	}
	cin >> a >> k >> b >> k >> c >> k >> d;
	djikstra(a);
	iki = sum[b];
	djikstra(b);
	kaeri = sum[a];
	cout << c - d - iki - kaeri << endl;
}

Measured memory_bytes: 1200
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in [0]*m]
AB.sort(key=lambda x:x[1])
l=-1
ans=0
for i in range(m):
    if AB[i][0]>l:
        ans+=1
        l=AB[i][1]-1

print(ans)

Measured memory_bytes: 65240
/*
 * atcoder/abc104/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const ll INF = 100000000000000000;
const int MAX_N = 1100;
const int MAX_G = 110;
const int MAX = 11;
int D, G;
vector<ll> S, P, C;

/*
 * 全探索
 * 難易度nを全部解く or 一切解かない or 残っている最高得点のものを部分的に解く
 */
ll rec(int n = 0, ll acc = 0, bool partial = true) {
  if (n==D) return acc >= G ? 0 : INF;

  ll min_ = INF;
  // 全部解く
  chmin(min_, P[n] + rec(n + 1, acc + S[n] * P[n] + C[n], partial));
  // 一切解かない
  chmin(min_, rec(n + 1, acc, partial));

  // 部分的に解くことが可能、かつ意味があるなら
  if (partial and acc + (S[n] * (P[n] - 1)) >= G) {
    ll count = 0;
    while (S[n] * count + acc < G) count++;
    chmin(min_, count + rec(n + 1, acc + count * S[n], false));
  }

  return min_;
}

void solve() {
  cin >> D >> G;
  ll p, c;
  loop(d,0,D) {
    cin >> p >> c;
    P.push_back(p); C.push_back(c);
    S.push_back((d+1)*100);
  }

  reverse(P.begin(), P.end());
  reverse(S.begin(), S.end());
  reverse(C.begin(), C.end());

  cout << rec() << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
  
using namespace std;
int main() 
{
  int n,m;
  cin>>n>>m;
  int a=1,b=n;
  for(int i=0;i<m;i++)
  {
    cout<<a<<' '<<b<<'\n';
    a++;
    b--;
    int d1=b-a,d2=n-d1;
    if(d1==d2||d1+2==d2) b--;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
 	int n;
  	cin>>n;
  
  	int p[n];
  	rep(i,n)p[i]=0;
  	int x,y,z;
  	
  	int m=sqrt(n)+1;
  
 	for(int x=1;x<m;x++){
     	for (int y=1;y<m;y++){
        	for (int z=1;z<m;z++){
              int f=x*x+y*y+z*z+x*y+y*z+z*x;
              if(f<=n)p[f]++;                   
            }        
        }
    }
   
	rep(j,n)cout<<p[j]<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >>a >> b >> c;
    if(a+b>=c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N,X=map(int,input().split())
H=[1]
P=[1]

for i in range(N):
    H.append(H[i]*2+3)
    P.append(P[i]*2+1)

def f(n,x):
    if n==0:
        return  1
    else:
        if x==1:
            return 0
        elif x<2+H[n-1]:
            return f(n-1,x-1)
        elif x==2+H[n-1]:
            return P[n-1]+1
        elif x<H[n]:
            return P[n-1]+f(n-1,x-H[n-1]-2)+1
        elif x==H[n]:
            return P[n]
print(f(N,X))

Measured memory_bytes: 3064
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll a = inp1, b = inp1, c = inp1;
    ll amax = max({a, b, c});
    ll ans = 0;
    while (a+2 <= amax) { a += 2; ans++; }
    while (b+2 <= amax) { b += 2; ans++; }
    while (c+2 <= amax) { c += 2; ans++; }
    a -= amax;
    b -= amax;
    c -= amax;
    a *= -1;
    b *= -1;
    c *= -1;
    switch(a+b+c) {
        case 1: ans += 2; break;
        case 2: ans += 1; break;
    }

    say(ans);
    
}

Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1, m+1), n):
    now = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            now += d[i]
    ans = max(ans, now)
print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;
typedef pair<string, ll> psl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll X, ini, i;
    cin >> X;
    ini = 100;
    for(i = 1; i <= 10000000000; i++) {
        ini += ini * 0.01;
        if(ini >= X) {
            break;
        }
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 3636
lines = $stdin.read
array = lines.split("\n")

n = array[0].to_i
a = array[1].split(" ").map(&:to_i)
b = []

for i in 0...(a.length)

  if n % 2 == 0
    if i % 2 == 0
      b.push a[i]
    else
      b.unshift a[i]
    end
  else
    if i % 2 == 1
      b.push a[i]
    else
      b.unshift a[i]
    end
  end

  #b.push(a[i])
  #b.reverse!
end

puts b.join(" ")


Measured memory_bytes: 27612
//Yash Kodesia, IIITM.
#include<bits/stdc++.h>
using namespace std;
#define   debug3(x,y,z)   cout<<x<<" "<<y<<" "<z<<"\n";
#define   present(c,x)    ((c).find(x) != (c).end())
#define   debug2(x,y)     cout<<x<<" "<<y<<"\n";
#define   rep2(i,k,n)     for(int i=k;i<=n;i++)
#define   repd(i,k,n)     for(int i=n;i>=k;i--)
#define   rep1(i,k,n)     for(int i=k;i<n;i++)
#define   linp2(x,y)      ll x,y; cin>>x>>y;
#define   linp1(n)        ll  n; cin>>n;
#define   debug(x)        cout<<x<<"\n";

#define   all(x)          x.begin(),x.end()
#define   vpll            vector<pll >
#define   sz(a)           a.size()
#define   vll             vector<ll>
#define   MOD             1000000007
#define   pll             pair<ll,ll>
#define   ppb             pop_back
#define   INF             1e18+7

#define   ff              first
#define   ss              second
#define   pf              pop_front
#define   pb              push_back
#define   ld              long double
#define   eb              emplace_back
#define   vb              vector<bool>
#define   ll              long long int
#define   vs              vector<string > 

const ll MAX2 = 105;
const ll MAX3 = 1005;
const ll MAX4 = 10005;
const ll MAX5 = 100005;
const ll MAX6 = 1000005;
const ll MAX7 = 10000005;


// Start
 
 
void solve(){
  linp2(x,y);
  cout<<x+y/2;
}
int main(){
  int t;
  t=1;
  //freopen ("input.txt","r",stdin);
  //freopen ("output.txt","w",stdout);
  cin.sync_with_stdio(0), cin.tie(0);
  //cin>>t;
  while(t--){
          solve();
          cout<<"\n";
     }
return 0;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

/*小数点以下の長さを指定
cout << fixed << setprecision(15) << y << endl;
*/

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


int main() {
	int n;
	cin >> n;
	vector<pair<double, string>>kane;
	rep(i, n){
		double x;
		string u;
		cin >> x >> u;
		kane.emplace_back(x, u);
	}

	double ans = 0;
	rep(i, kane.size()){
		if (kane[i].second == "JPY"){
			ans += kane[i].first;
		}
		else{
			ans += kane[i].first * 380000;
		}
	}

	cout << fixed << setprecision(10) << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int h, w;
    cin >> h >> w;
    vector< vector<string> > s(h);
    repi(i, s){
        *i = vector<string>(w);
        repi(j, *i){
            cin >> *j;
        }
    }
    
    rep(i, h){
        rep(j, w){
            if(s[i][j] == "snuke"){
                cout << (char)(j + 'A') << i + 1 << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
a = input()
b = input()
c = input()
Sa = [a[i] for i in range(len(a))]
Sb = [b[i] for i in range(len(b))]
Sc = [c[i] for i in range(len(c))]
turn = "a"
while True:
  if turn == "a":
    if len(Sa) == 0:
      print("A")
      break
    else:
      turn = Sa.pop(0)
  elif turn == "b":
    if len(Sb) == 0:
      print("B")
      break
    else:
      turn = Sb.pop(0)
  else:
    if len(Sc) == 0:
      print("C")
      break
    else:
      turn = Sc.pop(0)

Measured memory_bytes: 3064
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m,sum = 0;
    cin >> n >> m; 
    
    for(int i =1; i < n; i++){
        sum += n - i; 
    }
    
    for(int i =1; i < m; i++){
        sum += m - i; 
    }
    
    cout << sum; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int INF=1e9;
const int N=100010;
inline int ceil(int x,int y){
	return x/y+(x%y!=0);
}

void printa(int num){
	while(num--)printf("A");
}

void printb(int num){
	while(num--)printf("B");
}

struct data{
	int a,b,w;
	data(){}
	data(int a,int b,int w):a(a),b(b),w(w){}
	int len(){return (a+b)*w;}
	void print(int l,int r){
		int k1,k2,k3,k4;int i;
		k1=l%(a+b);if(!k1)k1=a+b;
		k2=r%(a+b);if(!k2)k2=a+b;
		k3=ceil(l,a+b);
		k4=ceil(r,a+b);
		if(k3==k4){
			if(k2<=a)printa(k2-k1+1);
			else if(k1>a)printb(k2-k1+1);
			else printa(a-k1+1),printb(k2-a);
		}else{
			if(k1<=a)
				printa(a-k1+1),printb(b);
			else printb(a+b-k1+1);
			rep(i,1,k4-k3-1)
				printa(a),printb(b);
			if(k2>a)printa(a),printb(k2-a);
			else printa(k2);
		}
	}
};data s[N];int cnt;
int ans;

int calc(int a,int b){
	if(!a&&!b)return 0;
	if(!a)return INF;
	if(b<a)return ceil(a,b+1);
	return ceil(b,a);
}

int work1(int a,int b,int nowa,int nowb){
	int l=1,r=min(a/nowa,b/nowb)+1,mid,ret=0;
	while(l<r){
		mid=l+r>>1;
		if(calc(a-nowa*mid,b-nowb*mid)<=ans)
			ret=mid,l=mid+1;
		else r=mid;
	}
	return ret;
}

int work2(int a,int b){
	int l,r,mid,ret=0;
	r=min(ans,a)+1;
	l=min(ans,a);
	l=min(l,max(a-b,0));
	while(l<r){
		mid=l+r>>1;
		if(calc(b,a-mid)<=ans)
			ret=mid,l=mid+1;
		else r=mid;
	}
	return ret;
}

int work3(int a,int b){
	int l,r,ret=0,mid;
	if(b<=a)return 1;
	l=1;r=min(ans,b-a)+1;
	while(l<r){
		mid=l+r>>1;
		if(calc(a,b-mid)<=ans)ret=mid,r=mid;
		else l=mid+1;
	}
	return ret;
}

void find(int l,int r){
	int now=0;int i;
	rep(i,1,cnt) if(s[i].len()){
		if(now+s[i].len()<l)now+=s[i].len();
		else break;
	}
	if(now+s[i].len()>=r){
		s[i].print(l-now,r-now);return;
	}
	s[i].print(l-now,s[i].len());
	now+=s[i++].len();
	for(;i<=cnt;i++)if(s[i].len()){
		if(now+s[i].len()<r){
			now+=s[i].len();
			s[i].print(1,s[i].len());
		}
		else break;
	}
	s[i].print(1,r-now);
}

int main(){
	int T,a,b,l,r,nowa,nowb,x,i;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&a,&b,&l,&r);cnt=0;
		ans=min(calc(a,b),calc(b,a));
		if(calc(a,b)>ans){
			x=work3(a,b);nowb=x;
			s[++cnt]=data(0,x,1);
			b-=x;
		}
		while(a&&b){
			x=work2(a,b);nowa=x;
			s[++cnt]=data(x,0,1);
			a-=x;
			x=work3(a,b);nowb=x;
			s[++cnt]=data(0,x,1);
			b-=x;
			if(nowa&&nowb){		
				x=work1(a,b,nowa,nowb);
				s[++cnt]=data(nowa,nowb,x);
				a-=nowa*x;b-=nowb*x;
			}
		}
		if(a)s[++cnt]=data(a,0,1);
		if(b)s[++cnt]=data(0,b,1);
		find(l,r);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define BUF_SIZE 8192

double calc_tmp(int base, int height, double cmp) {
   return fabs(base - height * 0.006  - cmp);
}
int main(void) {
  char line[BUF_SIZE];
  FILE *fp;
  fp = stdin;
  int n, base, a;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d", &n);
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d %d", &base, &a);

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  double min = 100000;
  int argmin = -1;
  int i;
  for(i = 0; i < n; i++) {
    char *buf = strtok(tmpbuf, " ");
    int height = strtol(buf, NULL, 10);
    double tmp = calc_tmp(base, height, a);
    if(tmp < min) {
      min = tmp;
      argmin = i+1;
    }
    tmpbuf = NULL;
  }
  printf("%d\n", argmin);
  return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000],s3[10000];

	int ara[n_size],ara2[n_size];

	cin>>s>>s3;


	f(i,0,max(strlen(s)-1,strlen(s3)-1))
   {
        if(i<=strlen(s)-1)cout<<s[i];
        if(i<=strlen(s3)-1) cout<<s3[i];

   }
	cout<<endl;


}




Measured memory_bytes: 256