akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, h: u64
    }
    println!("{}", (a+b)*h/2);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
int main()
{
	int n, a[1024], h = 0, m = 0;
	cin >> n;
	for (int i = 0; i < n; cin >> a[i], i++);
	for (int i = 0; i < n; i++) {
		if (a[i] >= h) {
			h = a[i];
			++m;
		}
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 256
W,H,c = input().split()
W = int(W)
H = int(H)

for i in range(H):
    for j in range(W):
        if (i == 0 or i == H-1) and (j == 0 or j == W-1):
            print("+", end="")
        elif i == 0 or i == H-1:
            print("-", end="")
        elif j == 0 or j == W-1:
            print("|", end="")
        elif 2*i == H-1 and 2*j == W-1:
            print(c, end="")
        else:
            print(".", end="")
    print("")



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

class Main{
    public static void main(String[] args){
    	InputStreamReader isr = new InputStreamReader(System.in);
    	BufferedReader br = new BufferedReader(isr);
    	try {
			String buf = br.readLine();
			int num = Integer.parseInt(buf);
			System.out.println(num * num * num);
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
}

Measured memory_bytes: 16864
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


struct V{
    V(){
        g = -1;
    }

    int g;
    vector<int> e_e;
    vector<int> o_e;
};


int main(){
    long long N;
    cin >> N;

    vector<V> nodes(N);
    int u, v, w;

    for(int i = 0; i < N - 1; ++i){
        cin >> u >> v >> w;
        if(w % 2 == 0){
            nodes[u-1].e_e.push_back(v-1);
            nodes[v-1].e_e.push_back(u-1);
        }
        else{
            nodes[u-1].o_e.push_back(v-1);
            nodes[v-1].o_e.push_back(u-1);
        }
    }

    queue<int> q;
    q.push(0);
    nodes[0].g = 0;

    while(q.size()){
        auto& node = nodes[q.front()];
        q.pop();

        for(int& v : node.e_e){
            if(nodes[v].g == -1){
                q.push(v);
                nodes[v].g = node.g;
            }
        }
        for(int& v : node.o_e){
            if(nodes[v].g == -1){
                q.push(v);
                nodes[v].g = 1 - node.g;
            }
        }
    }

    for(int i = 0; i < N; ++i){
        cout << nodes[i].g << endl;
    }
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i,H) cin >> A[i];

  bool flag = false;
  queue<pair<int,int>> que;
  que.push(make_pair(0, 0));
  while(!que.empty()) {
    pair<int,int> p = que.front();
    que.pop();
    
    if(p.first == H - 1 && p.second == W - 1) flag = true;
    int dx[] = {0, 1};
    int dy[] = {1, 0};
    REP(k,2) {
      int yk = p.first + dy[k];
      int xk = p.second + dx[k];
      if(xk >= W || yk >= H) continue;
      if(A[yk][xk] == '#') que.push(make_pair(yk, xk));
    }
  }

  int cnt = 0;
  REP(i,H)REP(j,W) if(A[i][j] == '#') ++cnt;
  if(cnt != H + W - 1) flag = false;

  if(flag) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    A,B=pin()
    print(A*B//(gcd(A,B)))
#%%submit!
resolve()

Measured memory_bytes: 5428
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

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

    int max = 0;
    int j = 1;
    while (n > 0) {
        max++;
        n -= j++;
    }

    int excluded = abs(n);

    for (int i = 1; i <= max; i++) {
        if (i != excluded) {
            std::cout << i << std::endl;
        }
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int ans;
	if(n<10) ans=n;
	else if(n<100) ans=9;
	else if(n<1000) ans=9+(n-99);
	else if(n<10000) ans=9+900;
	else if(n<100000) ans=9+900+(n-9999);
	else ans=9+900+90000;
	cout << ans << endl;
	return 0;
}

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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define pii pair < int, int >

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);

    string x;
    cin >> x;

    if(x.size() == 3) reverse(x.begin(),x.end());

    cout << x << endl;


}




Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        k: usize,
    }
    let mut ans = 0;
    for i in 1..=k {
        for j in 1..=k {
            for k in 1..=k {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}


Measured memory_bytes: 2172
import java.util.Arrays;
import java.util.Scanner;

// Java8
public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	void run() throws Exception {
		int n = sc.nextInt();
		int m = sc.nextInt();

		Hoge[] ds = new Hoge[m];
		
		for(int i=0; i<m; i++) {
			int p = sc.nextInt();
			int y = sc.nextInt();
			Hoge d = new Hoge(p, y);
			ds[i] = d;
		}
		Hoge[] cl = ds.clone();
		Arrays.sort(cl);

		int id = 1;
		for(int i=0; i<m; i++) {
			if(i==0 || cl[i].getPref() != cl[i-1].getPref()) id = 1;
			cl[i].setId(id++);
		}
		
		for(int i=0; i<m; i++) System.out.println(ds[i]);
	}
}
class Hoge implements Comparable<Hoge>{
	int pref;
	int year;
	int id;

	Hoge(int p, int y) {
		pref = p;
		year = y;
	}
	
	@Override
	public int compareTo(Hoge o)
	{
		return pref<o.pref ? 1 : pref>o.pref ? -1 : Integer.compare(year, o.year);
	}

	public void setId(int id)
	{
		this.id = id;
	}
	
	public int getPref()
	{
		return pref;
	}

	public int getYear()
	{
		return year;
	}

	@Override
	public String toString()
	{
		return String.format("%06d%06d", pref, id);
	}
}

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

using namespace std;
typedef long long ll;
    
int main()
{
    string N;
    cin >> N;

    if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

using namespace std;

int main() {

	string a, b, c;

	cin >> a >> b;

	c.append(a);
	c.append(a);

	if(c.find(b) != string::npos) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

bool ACGT(char c) {
	return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}

int main() {
	string str;
	cin >> str;
	int ans = 0;
	for (int i = 0; i < str.length(); i++) {
		int tmp = 0;
		for (;ACGT(str[i+tmp]);tmp++);
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;


//----------------------------------------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e5+1;//                                                             |
//----------------------------------------------------------------------------------

vl grp(N,0);
vl vis(N,0);
vl ans,ans2;
void dfs(ll x)
{   
    if(vis[x]==1) ans.eb(x);
    else if(vis[x]==2) ans2.eb(x);
    if(vis[grp[x]]<3){
        vis[grp[x]]++;
        dfs(grp[x]);
    }
}


//main func
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
    ll a,b;cin>>a>>b;
    vl v(a);
    for(int i=0;i<a;i++) {ll k;cin>>k;grp[i+1]=k;}
    vis[1]=1;
    vis[0]=1;
    dfs(1ll);
    int f=0;
    if(ans.size()-ans2.size()<=0) f=1;
    if(!f) ans.resize(ans.size()-ans2.size());
    
    if(b<ans.size() && !f) cout<<ans[b]<<"\n";
    else{
        if(!f)
            b-=(ans.size());
           
        cout<<ans2[b%ans2.size()]<<"\n";
    }
	return 0;
}

Measured memory_bytes: 28020
#include<cstdio>
using namespace std;
char A[55][55],B[55][55];
int n,m;
bool cmp(int a,int b)
{
	for(int x=a;x<a+m;x++)
		for(int y=b;y<b+m;y++)
			if(A[x][y]!=B[x-a][y-b])
				return 0;
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf(" %c",&A[i][j]);
	for(int i=0;i<m;i++)
		for(int j=0;j<m;j++)
			scanf(" %c",&B[i][j]);
	for (int i = 0; i <n-m+1; i++)
		for (int j = 0; j <n-m+1; j++)
			if(cmp(i,j))
			{
				printf("Yes\n");
				return 0;
			}	
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  vector<vector<int>> dp(3010,vector<int>(3010,0));
  for(int i=0;i<s.size();i++){
    for(int j=0;j<t.size();j++){
      if(s[i]==t[j]) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  string c="";
  int i=s.size(),j=t.size();
  while(i>0&&j>0){
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else{
      c=s[i-1]+c;
      i--,j--;
    }
  }
  cout<<c;
}

Measured memory_bytes: 37760
#include <bits/stdc++.h>
using namespace std;
bool solve()
{
    int n;
    string str;
    cin >> n >> str;
    if (n & 1)
        return 0;
    for (int i = 0, j = n / 2; j < n; i++, j++)
    {
        if (str[i] != str[j])
            return 0;
    }
    return 1;
}
int main()
{
    puts(solve() ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
#include <bit>
#include <bitset>
#include <cstdint>
#include <initializer_list>
typedef long long int ll;
using namespace std;
const int MOD = 1000000007;


int main() {
	int N, X, T; cin >> N >> X >> T;
	int num = N / X,ans=0;
	if (N % X == 0) {
		ans = T * num;
	}
	else {
		ans = T * (num + 1);
	}
	cout << ans << endl;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int dp[50][50][101]; // l, r, k
bool flg[50][50][101];
vector<int> v;

int calc(int l, int r, int k){
    if(flg[l][r][k]) return dp[l][r][k];
    if(k == 0) return 0;
    int ret = max({0, calc(l, r, k-1), calc(l+1, r, k-1) + v[l], calc(l, r-1, k-1) + v[r]});
    if(k >= 2) ret = max({ret, calc(l+1, r, k-2), calc(l, r-1, k-2)});
    dp[l][r][k] = ret;
    flg[l][r][k] = true;
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int l = 0; l <= k; ++l){
                dp[i][j][l] = 0;
                if(l == 0) flg[i][j][l] = true;
            }
        }
    }
    v = vector<int>(n);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
        dp[i][i][0] = 0;
        for(int j = 1; j <= k; ++j){
            dp[i][i][j] = max(v[i], 0);
            flg[i][i][j] = true;
        }
    }
    cout << calc(0, n-1, k) << "\n";
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>

int main() {

	int n, a, b;
	std::cin >> n >> a >> b;

	int A, B;

	A = a*n;
	B = b;

	if (A<B) {
		std::cout << A << std::endl;
	}
	else {
		std::cout << B << std::endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;


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

  int k ,n;
  cin >> k >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  vec b(n);
  REP(i,n - 1){
    b[i] = a[i + 1] - a[i];
  }
  b[n - 1] = k - a[n - 1] + a[0];

  sort(b.begin(), b.end());

  int ans = 0;
  REP(i,n-1){
    ans += b[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  ll a,b;
  cin >> a >> b;

  auto f = [](ll x){
    ll res = 0;
    rep(i,(x+1)%4) res ^= x-i;
    return res;
  };
  cout << (f(a-1)^f(b)) << endl;
}

Measured memory_bytes: 256
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multi int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T a){while(n--)cin >> *a, ++a;}
template<typename T1, typename T2> void read(int n, T1 a, T2 b){while(n--)cin >> *a >> *b, ++a, ++b;}
template<typename T> void write(int n, T a){while(n--)cout << *a << " \n"[n==0], ++a;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
int n, m, res[maxn];
vector<int> q[maxn], g[maxn];	
struct bit{
	int v[maxn]{};
	void modify(int p, int nv){
		for(;p <= m;p += p & -p)v[p] += nv;
	}
	int query(int p){
		p = min(p, m);
		int res = 0;
		for(;p;p ^= p & -p)res += v[p];
		return res;
	}
}t;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	rep0(i, n){
		int l, r;
		cin >> l >> r;
		g[l].emplace_back(r);
	}
	rep1(i, m)q[0].emplace_back(i);
	priority_queue<int, greater<int>> pq;
	rep0(i, m+1){
		dout(i) <<'\n';
		while(pq.size() and pq.top() < i){
			t.modify(pq.top(), -1);
			pq.pop();
		}
		for(int j : g[i]){
			t.modify(j, 1);
			pq.push(j);
		}
		for(int j : q[i]){
			// dout(j), cout << "Q " << i+j-1 << ' ' << t.query(j+i-1) << '\n';
			res[j] += t.query(j+i-1);
			q[j+i].emplace_back(j);
		}
	}
	rep1(i, m)cout << res[i] << '\n';
}

Measured memory_bytes: 41336
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

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

    const int INF = 1000000000;

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    vector<int> d(n + 1);
    vector<int> p(n + 1);
    deque<int> nx = {n};
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '1') {
            d[i] = INF;
        } else {
            while (!nx.empty() && nx.back() > i + m) {
                nx.pop_back();
            }
            if (nx.empty()) {
                d[i] = INF;
            } else {
                p[i] = nx.back();
                d[i] = d[p[i]] + 1;
                while (!nx.empty() && d[nx.front()] >= d[i]) {
                    nx.pop_front();
                }
                nx.push_front(i);
            }
        }
    }
    if (d[0] >= INF) {
        cout << -1;
    } else {
        int x = 0;
        while (x < n) {
            // x -> p[x]
            cout << p[x] - x << "\n";
            x = p[x];
        }
    }

//    9 3
//    0001000100
//    ..  . .  .
    return 0;
}

Measured memory_bytes: 1488
import java.io.IOException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int y = 501;
		int z = y * y;
		while (true) {
			int n = scanner.nextInt();
			int h = scanner.nextInt();
			if ((n | h) == 0)
				break;

			Set<Integer> set = new HashSet<Integer>();
			while (h-- > 0) {
				String s = scanner.next();
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				if (s.equals("xy")) {
					for (int i = 0; i < n; i++)
						set.add(a + y * b + i * z);
				} else if (s.equals("xz")) {
					for (int i = 0; i < n; i++)
						set.add(a + i * y + b * z);
				} else {
					for (int i = 0; i < n; i++)
						set.add(i + a * y + b * z);
				}
			}
			System.out.println(n * n * n - set.size());
		}
	}
}

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

using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a == b)
    cout << "Draw" << endl;
  else if (a == 1)
    cout << "Alice" << endl;
  else if (b == 1)
    cout << "Bob" << endl;
  else
    cout << (a > b ? "Alice" : "Bob") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    ll N;
    cin>>N;
    int flag=0;
    for(int i=0;i<50000;i++){
        if((int)((double)i*1.08)==N){
            cout<<i;
            flag=1;
            break;
        }
    }
    if(flag==0){
        cout<<":(";
    }
}

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


public class Main {
	public static void main(String[] aegs){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int a = 0;
		String t = "";
		while (true){
			try {
				t = br.readLine();
				if(t == null){
					break;
				}
				a = Integer.parseInt(t);
			} catch (NumberFormatException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
		

		int b = 0;
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					for(int l=0;l<10;l++){
						if((i+j+k+l) == a){
							b++;
							
						}
					}
				}
			}
		
		}
		
		System.out.println(b);
		}
		
	}

}

Measured memory_bytes: 18620
import std.stdio;
import std.string;
import std.conv;
 
int main()
{
    while (true) {
        string[] s1 = readln.chomp.split;
        int n = s1[0].to!int;
        int m = s1[1].to!int;
        int a = s1[2].to!int;
        if (n == 0 && m == 0 && a == 0) break;
        int max = -1;
 
        int[1001][1001] N;
        for (int i = 0; i < 1001; i++)
            for (int j = 0; j < 1001; j++)
                N[i][j] = i;
        bool flag = true;
        for (int i = 0; i < m; i++) {
            string[] s2 = readln.chomp.split;
            int h = s2[0].to!int;
            int p = s2[1].to!int;
            int q = s2[2].to!int;
 
            N[p][h] = q;
            N[q][h] = p;
        }
 
        max = 1000;
        while (max) {
            a = N[a][max];
            --max;
        }
        writeln(a);
    }
 
    return 0;
}

Measured memory_bytes: 5912
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b-1)/b*c;
	re 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;

signed main(){
	string s; cin >> s;
	bool ok = true;
	int N = s.size();
	for(int i = 0; i < N; i++){
		if(s[i] != s[N - 1 - i]) ok = false;
	}
	int x = (N - 1)/2, y = (N + 1)/2;
	for(int i = 0; i < x; i++){
		if(s[i] != s[x - i - 1]) ok = false;
	}
	for(int i = y - 1; i < N; i++){
			if(s[i] != s[N - 1- i]) ok = false;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100005
const long long inf=0x3f3f3f3f3f3f3f3f;

namespace segtree{
    struct msg{
        long long mn;
        long long settag;
        msg operator +(const msg &b){
            return (msg){min(mn,b.mn),-inf};
        }
        void pushdown(msg &son){//不修改父亲
            if(settag!=-inf){
                son.mn=son.settag=settag;
            }
        }
    };
    const int L=0,R=1;
    msg ini[N];
    struct xds{
        int son[2];
        msg x;
    }a[N*4];int cnt;
    void build(int &k,int l,int r){
        k=++cnt;
        if(l==r){
            a[k].x=ini[l];
        }else{
            int mid=(l+r)>>1;
            build(a[k].son[L],l,mid);
            build(a[k].son[R],mid+1,r);
            a[k].x=a[a[k].son[L]].x+a[a[k].son[R]].x;
        }
    }
    msg modify(int k,int l,int r,int ql,int qr,msg val){
        if(ql==l&&r==qr) return val.pushdown(a[k].x),a[k].x;
        else{
            a[k].x.pushdown(a[a[k].son[L]].x);
            a[k].x.pushdown(a[a[k].son[R]].x);
            int mid=(l+r)>>1;
            msg ret;
            if(qr<=mid) ret=modify(a[k].son[L],l,mid,ql,qr,val);
            else if(ql>mid) ret=modify(a[k].son[R],mid+1,r,ql,qr,val);
            else ret=modify(a[k].son[L],l,mid,ql,mid,val)+modify(a[k].son[R],mid+1,r,mid+1,qr,val);
            a[k].x=a[a[k].son[L]].x+a[a[k].son[R]].x;
            return ret;
        }
    }
}
int root,n,len;
void setval(int l,int r,long long val){
    if(r<l) return;
    segtree::modify(root,1,len,l+1,r+1,(segtree::msg){0LL,val});
}
long long getmn(int l,int r){
    return segtree::modify(root,1,len,l+1,r+1,(segtree::msg){0LL,-inf}).mn;
}

int l[N],r[N];
long long A[N],f[N];int B[N],k;
vector<int> val;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld%d",&A[i],&B[i]);
        if(B[i]==1&&2*A[i]>k) return puts("-1"),0;
        A[i]+=A[i-1];
    }
    for(int i=1;i<=n;i++){
        if(B[i]==2) l[i]=0,r[i]=k-1;
        else l[i]=(-2*A[i-1]%k + k)%k , r[i]=(-2*A[i]%k +k)%k;
        val.push_back(l[i]);val.push_back(r[i]);
    }
    sort(val.begin(),val.end());
    val.erase(unique(val.begin(),val.end()),val.end());
    for(int i=1;i<=n;i++){
        l[i]= lower_bound(val.begin(),val.end(),l[i])-val.begin();
        r[i]= lower_bound(val.begin(),val.end(),r[i])-val.begin();
    }
    len=val.size();
    segtree::build(root,1,len);
    for(int i=n;i>=1;i--){//贪心
        int t=getmn(l[i],l[i]);
        if(t==0) f[i]=0;
        else f[i]=f[t]+(val[l[t]]-val[l[i]]+k)%k;
        if(l[i]<=r[i]){
            setval(0,l[i]-1,i);
            setval(r[i]+1,len-1,i);
        }else{
            setval(r[i]+1,l[i]-1,i);
        } 
    }
    long long ans=f[1],tot;
    for(int i=0;i<len;i++){
        int t=getmn(i,i);
        if(t==0) tot=0;
        else tot=f[t]+(val[l[t]]-val[i]+k)%k;
        ans=min(ans,tot);
    }
    cout<<ans+2*A[n]<<endl;
    return 0;
}

Measured memory_bytes: 9332
N = gets.to_i
arr =  [*1..100].repeated_combination(3).to_a
ns = Array.new(10000, 0)
tmp = 0
(arr.length).times do |i|
	tmp = arr[i][0]**2 + arr[i][1]**2 + arr[i][2]**2 + arr[i][0]*arr[i][1] + arr[i][0]*arr[i][2] + arr[i][1]*arr[i][2]
	if tmp <= 10000
		if arr[i][0] != arr[i][1] && arr[i][0] != arr[i][2] && arr[i][1] != arr[i][2]
			ns[tmp-1] += 6
		elsif arr[i][0] == arr[i][1] && arr[i][0] == arr[i][2] && arr[i][1] == arr[i][2]
			ns[tmp-1] += 1
		else
			ns[tmp-1] += 3
		end
	end
end

N.times do |i|
	p ns[i]
end

Measured memory_bytes: 25944
# coding: utf-8
#78
import math

n = int(input())
B=0

for i in range(n):
    N = int(input())
    A=0
    s = int(math.sqrt(N)+1)
    if N==2:
        B += 1
    else:
        for j in range(2,s):
            if N%j==0:
                A += 1
                break
        if (A==0):
            B += 1
print(B)


Measured memory_bytes: 5672
#include <iostream>
#include <queue>
using namespace std;
int n,G[101][101];
int d[101];
int dis;
void bfs(){
    queue<int>q;
    int u=1;
    q.push(u);
    d[u]=dis;
    while(!q.empty()){
        u=q.front();
        dis=d[u]+1;
        for(int i=1;i<=n;i++)
        {
            if(G[u][i]==1 && d[i]==-1)
            {
                q.push(i);
                d[i]=dis;
            }
        }
        q.pop();
    }
}
int main()
{
    int u,k,v;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        d[i]=-1;
        for(int j=1;j<=n;j++)
            G[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            G[u][v]=1;
        }
    }
    dis=0;
    bfs();
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<d[i]<<endl;
    return 0;
}


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

using namespace std;

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

    string s;
    cin >> s;
    int n = s.length();
    if (s[0] != '1' || s[n - 1] != '0') {
        cout << -1 << '\n';
        return 0;
    }

    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[n - 2 - i]) {
            cout << -1 << '\n';
            return 0;
        }
    }

    int r = 1;
    for (int i = n - 2; i >= 0; i--) {
        int t = n - i;
        cout << r << " " << t << '\n';
        if (s[i] == '1')
            r = t;
    }
    return 0;
}


Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	vector<char> c(6);
	rep(i, 6) {
		cin >> c[i];
	}
	if (c[0] == c[5] && c[1] == c[4] && c[2] == c[3]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	} 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
int count = 0;
int max =0;
for(int i=0;i<n;i++){
	if(s[i]=='I'){
		count++;
	}
	else if(s[i]=='D')
	count--;

	if(max<count)
	max = count;
}


cout<< max <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

// 方向ベクトル
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};

int main() {
    ll h, w;
    cin >> h >> w;

    vvl board(h, vl(w));
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            if(s[j] == '#') {
                board[i][j] = 1;
            }
        }
    }

    queue<pair<ll, ll>> next;
    vvl visited(h, vl(w));

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if(visited[i][j]) {
                continue;
            }
            next.push(make_pair(i, j));  
            visited[i][j] = 1;
            ll cntBlack = 0, cntWhite = 0;
            while(!next.empty()) {
                ll x = next.front().first;
                ll y = next.front().second;
                if(board[x][y]) {
                    cntBlack++;
                }
                else {
                    cntWhite++;
                }
                rep(k, 4) {
                    ll nx = x + dx[k];
                    ll ny = y + dy[k];
                    if(nx < 0 || h <= nx || ny < 0 || w <= ny) {   
                        continue;
                    }
                    if(visited[nx][ny] || board[x][y] == board[nx][ny]) {
                        continue;
                    }
                    next.push(make_pair(nx, ny));
                    visited[nx][ny] = 1;
                }
                next.pop();
            }
            ans += cntBlack*cntWhite;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 2816
fun main(args:Array<String>) {
    val(n,m) = readLine()!!.split(" ").map { it.toInt() }
    val img = (1..n).map { readLine()!! }
    val template = (1..m).map { readLine()!! }
    for(i in (0 .. (n-m))) {
        val subImg = img.subList(i, i + m)
        for(j in (0..(n-m))) {
            if(template.indices.all { k->subImg[k].substring(j).startsWith(template[k]) })            {
                println("Yes")
                return
            }
        }
    }
    println("No")
}


Measured memory_bytes: 37896
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcopy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;


int f(int a, int k){
	while(a>k&&a%k){
		int t=a/k+1;
		int q=a/k*k;
		int j=(a-q+t-1)/t;
		a-=t*j;
	}
	a/=k;
	return a;
}


int main(){
	int n,r=0;
	scanf("%d",&n);
	while(n--){
		int a,k;
		scanf("%d%d",&a,&k);
		r^=f(a,k);
	}
	puts(r?"Takahashi":"Aoki");
	return 0;
}

Measured memory_bytes: 256
/*
  ->->->->->-> Vora Mahammadasim <-<-<-<-<-<-
*/
#include<bits/stdc++.h>
#define int  long long
#define Mod 10000007
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'R' && i%2!=0)
        {
            cout<<"No";
            return 0;
        }
        else if(s[i] == 'L' && i%2 == 0){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        long full = H * W;
        long min = full;
        for (int i = 0; i <= H / 2; i++) {
            long[] areas = new long[3];
            areas[0] = i * W;
            areas[1] = ((H - i) / 2) * W;
            areas[2] = full - areas[0] - areas[1];
            Arrays.sort(areas);
            min = Math.min(min, areas[2] - areas[0]);

            areas[0] = i * W;
            areas[1] = (H - i) * (W / 2);
            areas[2] = full - areas[0] - areas[1];
            Arrays.sort(areas);
            min = Math.min(min, areas[2] - areas[0]);
        }
        long tmp = H;
        H = W;
        W = tmp;
        for (int i = 0; i <= H / 2; i++) {
            long[] areas = new long[3];
            areas[0] = i * W;
            areas[1] = ((H - i) / 2) * W;
            areas[2] = full - areas[0] - areas[1];
            Arrays.sort(areas);
            min = Math.min(min, areas[2] - areas[0]);

            areas[0] = i * W;
            areas[1] = (H - i) * (W / 2);
            areas[2] = full - areas[0] - areas[1];
            Arrays.sort(areas);
            min = Math.min(min, areas[2] - areas[0]);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N,T;
    cin>>N>>T;
    vi t(N);
    cin>>t;
    int cur=0;
    int ans=0;
    REPF(i,1,N) {
        if(cur+T>t[i]) {
            ans+=(t[i]-cur);
            cur=t[i];
        } else {
            ans+=T;
            cur=t[i];
        }
    }
    cout<<ans+T<<endl;
    return 0;
}


Measured memory_bytes: 1792
S = input()
A = []
t = 0
n, m = 1, 0
now = "R"
for i in range(1, len(S)):
    s = S[i]
    if now == "R":
        if s == "R":
            t = i
            n += 1
        else:
            m += 1
            now = "L"
    else:
        if s == "L":
            m += 1
        else:
            A.append((t, n, m))
            t = i
            n = 1
            m = 0
            now = "R"
else:
    A.append((t, n, m))
B = []
for t, n, m in A:
    for _ in range(n - 1):
        B.append("0")
    if abs(n - m) % 2 == 0:
        b = (n + m) // 2
        B.append(str(b))
        B.append(str(b))
    elif n > m:
        b = (n + m) // 2
        if n % 2 == 0:
            B.append(str(b))
            B.append(str(b + 1))
        else:
            B.append(str(b + 1))
            B.append(str(b))
    else:
        b = (n + m) // 2
        if m % 2 == 0:
            B.append(str(b + 1))
            B.append(str(b))
        else:
            B.append(str(b))
            B.append(str(b + 1))
    for _ in range(m - 1):
        B.append("0")
print(" ".join(B))


Measured memory_bytes: 15640
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int N, ans;
int B[101];
int main() {
	cin >> N;
	for (int i=1; i<N; i++) cin >> B[i];
	B[0] = B[N] = 1<<30;

	for (int i=1; i<=N; i++) {
		ans += min(B[i], B[i-1]);
	}

	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

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

    if ((a < b) && (b < c)) {
        std::cout << "Yes";
    } else {
        std::cout << "No";
    }
    std::cout << std::endl;
       
    return 0;
}


Measured memory_bytes: 3092
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

use std::cmp::{max, min};

fn main() {
  let a: usize = read();
  let b: usize = read();
  let q: usize = read();
  let mut a_vec: Vec<i64> = read_n(a);
  let mut b_vec: Vec<i64> = read_n(b);
  let mut q_vec: Vec<i64> = read_n(q);

  a_vec.sort();
  b_vec.sort();


  for i in q_vec {
    let mut answers = vec![];
    // aを先に回る
    let points = close_points(&a_vec, i);
    for j in points {
      let points2 = close_points(&b_vec, j);
      for k in points2 {
        answers.push((i - j).abs() + (j - k).abs())
      }
    }

    // bを先に回る
    let points = close_points(&b_vec, i);
    for j in points {
      let points2 = close_points(&a_vec, j);
      for k in points2 {
        answers.push((i - j).abs() + (j - k).abs())
      }
    }
    println!("{}", answers.iter().min().unwrap());
  }
}

fn close_points(a_vec: &Vec<i64>, i: i64) -> Vec<i64> {
  let mut return_value = vec![];
  let mut a_idx = a_vec.lower_bound(&i);
  if a_idx == a_vec.len() {
    a_idx -= 1;
    return_value.push(a_vec[a_idx]);
  } else {
    return_value.push(a_vec[a_idx]);
    if a_idx != 0 {
      return_value.push(a_vec[a_idx - 1]);
    }
  }
  return return_value;
}

use std::cmp::Ordering;

pub trait BinarySearch<T> {
  fn lower_bound(&self, x: &T) -> usize;
  fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
  fn lower_bound(&self, x: &T) -> usize {
    let mut low = 0;
    let mut high = self.len();

    while low != high {
      let mid = (low + high) / 2;
      match self[mid].cmp(x) {
        Ordering::Less => {
          low = mid + 1;
        }
        Ordering::Equal | Ordering::Greater => {
          high = mid;
        }
      }
    }
    low
  }
  fn upper_bound(&self, x: &T) -> usize {
    let mut low = 0;
    let mut high = self.len();

    while low != high {
      let mid = (low + high) / 2;
      match self[mid].cmp(x) {
        Ordering::Less | Ordering::Equal => {
          low = mid + 1;
        }
        Ordering::Greater => {
          high = mid;
        }
      }
    }
    low
  }
}

Measured memory_bytes: 36092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
 
vector<int> primes;
int counter[101];
 
int main(void){
	int n;
	cin>>n;
	primes.push_back(2);
	rep(i,101){
		counter[i] = 0;
	}
	counter[2] = 1;
	rep(i,n+1){
		int nokori = i;
		if(i == 0 || i == 1 || i==2){
			continue;
		}
		rep(j,primes.size()){
			if(nokori%primes[j]==0){
				nokori /= primes[j];
				counter[primes[j]]++;
				if(nokori == 1){
					break;
				}
				j--;
			}
		}
		if(nokori > 1){
			primes.push_back(nokori);
			counter[nokori] = 1;
			//cout<<nokori<<" ";
		}
	}

	ll a3 = 0, a5=0,a35=0,a55=0,a355=0;
	rep(i,n+1){
		//cout<<counter[i]<<" ";
		ll na3 = a3, na5=a5,na35=a35,na55=a55,na355=a355;
		if(counter[i] >= 2){
			na3 += 1;
			na35 += a5;
			na355 += a55;
		}
		if(counter[i] >= 4){
			na5 += 1;
			na35 += a3;
			na355 += a35;
			na55 += a5;
		}
		if(counter[i] >= 14){
			na35 += 1;
			na355 += a5;
		}
		if(counter[i] >= 24){
			na55 += 1;
			na355 += a3;
		}
		if(counter[i] >= 74){
			na355 += 1;
		}
		a3=na3,a5=na5,a35=na35,a55=na55,a355=na355;
	}
	cout<<a355<<endl;
}

Measured memory_bytes: 256