akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ctime>
#include <cstdlib>
#define rep(i, N) for (long i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N;
    cin >> N;
    if (N < 10)
    {
        cout << N << endl;
    }
    else if (10 <= N && N < 100)
    {
        cout << 9 << endl;
    }
    else if (100 <= N && N < 1000)
    {
        cout << N - 90 << endl;
    }
    else if (1000 <= N && N < 9999)
    {

        cout << N - 90 - (N -1000)-1 << endl;
    }
    else if (N >= 9999 && N < 100000)
    {
        cout << N - 90 - 9000 << endl;
    }
    else if (N == 100000)
    {
        cout << N - 9091 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed  main()
{
  long long a,b,c,d[15]={};
  cin>>a>>b>>c;
  d[0]==b;
  for(int i=1;i<=10;i++){
    c=a*c-b;
    cout<<c<<"\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
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; }

const ll INF = 1LL << 60;

int N;
ll h[100010];
ll dp[100010];

int main() {
    cin >> N;
    rep(i, N) {
        cin >> h[i];
    }

    rep(i, 100010) {
        dp[i] = INF;
    }

    dp[0] = 0;

    rep(i, N) {
        chmin(dp[i], dp[i-1] + abs(h[i]- h[i-1]));
        if(i > 1) {
            chmin(dp[i], dp[i-2] + abs(h[i]- h[i-2]));
        }
    }

    cout << dp[N-1];
    
    cout << endl;
    return 0;
}

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

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

	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for (int i = 0; i + 2 < s.length(); ++i) {
			if (s.charAt(i) == s.charAt(i + 1) && s.charAt(i + 1) == s.charAt(i + 2)) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
typedef pair <int, int> P;

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

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

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

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

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

    UnionFind uf_road(n);
    UnionFind uf_rail(n);

    for (int i = 0; i < k; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        uf_road.unite(p, q);
    }

    for (int i = 0; i < l; i++) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        uf_rail.unite(r, s);
    }

    vector <P> ps;
    for (int i = 0; i < n; i++) {
        ps.push_back(make_pair(uf_road.find(i), uf_rail.find(i)));
    }

    map<P, int> count;
    for (int i = 0; i < n; i++) {
        count[ps[i]]++;
    }
    for (int i = 0; i < n; i++) {
        cout << count[ps[i]] << " ";
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long M, long long K) {
    if (K == 0) {
        for (int i = 0; i < (2 << M); i++) {
            cout << (i == 0 ? "" : " ") << i / 2;
        }
        cout << endl;
        return;
    }
    if (K >= (1 << M)) {
        cout << -1 << endl;
        return;
    }

    if( M == 1 ){
        cout << -1 << endl;
        return;
    }

    cout << 0 << " " << K << " " << 0;

    deque<int> D;
    D.push_back(K);
    int t = 0;
    for(int i = 1 ; i < (1<<M) ; i++){
        if( i == K ) continue;
        D.push_back(i);
        D.push_front(i);
        t ^= i;
    }
    for( auto i : D){
        cout << " " << i;
    }
    cout << endl;
}

int main() {
    long long M;
    scanf("%lld", &M);
    long long K;
    scanf("%lld", &K);
    solve(M, K);
    return 0;
}


Measured memory_bytes: 2944
if __name__=='__main__':
    n = int(input())
    x = ['' for i in range(n)]
    y = ['' for i in range(n)]
    length = 0.0
    for i in range(n):
        x[i],y[i]=map(int,input().split())
    for i in range(n-1):
        for j in range(i+1,n):
            length += pow( (x[i]-x[j])**2+(y[i]-y[j])**2, 0.5)
    print(length*2.0/n)

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int H, W;	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i) {
		cin >> a[i];
	}
	vector<vector<bool>> isA(H, vector<bool>(W, 0));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			isA[i][j] = true;
		}
	}
	bool b = false;
	for (int j = 0; j < W; ++j) {
		b = false;
		for (int i = 0; i < H; ++i) {
			if (a[i][j] == '#') {
				b = true;
				break;
			}
		}
		if (!b) {
			for (int i = 0; i < H; ++i) {
				isA[i][j] = false;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		b = false;
		for (int j = 0; j < W; ++j) {
			if (a[i][j] == '#') {
				b = true;
				break;
			}
		}
		if (!b) {
			for (int j = 0; j < W; ++j) {
				isA[i][j] = false;
			}
		}
	}

	bool isOutput = false;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (isA[i][j]) {
				isOutput = true;
				cout << a[i][j];
			}
		}
		if (isOutput) {
			cout << endl;
		}
		isOutput = false;
	}
	cin >> H;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    s = input()
    if s.isupper():
        print('A')
    else: print('a')
    
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27168
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long power(long long a,long long now) {
	long long ans = 1;
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MAX_MOD;
		}
		now /= 2;
		a *= a;
		a %= MAX_MOD;
	}
	return ans;
}
long long inv(long long a) {
	return power(a, MAX_MOD - 2);
}
long long permutation(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
	}
	return ans;
}
long long combination(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
		ans *= inv(i + 1);
		ans %= MAX_MOD;
	}
	return ans;
}
int main() {
	long long n, k;
	cin >> n >> k;
	if (n <= k) cout << 1 << endl;
	else cout << 0 << endl;
	long long ans = 0;
	return 0;
}



Measured memory_bytes: 3084
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
a = list(map(int,input().split()))
a.sort()
alice = 0
bob = 0
for i in range(n):
    if i%2 == 0:
        bob += a[i]
    else:
        alice += a[i]
print(abs(alice - bob))

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

int main() {
    int n, k; cin >> n >> k;
    vector<pair<long long, int> > v(n);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    unordered_map<int, int> m;
    for (int i = 0; i < n; i++) {
        cin >> v[i].second >> v[i].first;
    }
    sort(v.rbegin(), v.rend());
    long long ans = 0;
    long long tmp = 0; long long kind = 0;
    int index = 0;
    while (index < k) {
        long long p = v[index].first; int q = v[index].second;
        tmp += p;
        if (m[q] == 0) {
            kind++;
        }
        m[q]++;
        pq.push(v[index]); index++;
    }
    ans = max(ans, kind * kind + tmp);
    for (int i = index; i < n; i++) {
        if (kind == k) break;
        long long p = v[i].first; int q = v[i].second;
        if (m[q] > 0) continue;
        else {
            while (!pq.empty()) {
                long long pt = pq.top().first;
                int qt = pq.top().second;
                pq.pop();
                if (m[qt] > 1) {
                    m[qt]--;
                    tmp -= pt;
                    break;
                }
            }
            pq.push(v[i]);
            m[q]++;
            tmp += p;
            kind++;
            ans = max(ans, kind * kind + tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6640
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
a,c,b = list(map(int, input().split()))

a = abs(a)
b = abs(b)
c = abs(c)

if b*c <= a:
  print(a - (b*c))
else:
  c -= a//b
  a = a%b
  #print(a,b,c)
  if c%2==0:
    print(a)
  else:
    print(abs(a-b))

Measured memory_bytes: 61536
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

s = [int(i) for i in STR()]
flag = False
ans = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = int(not s[i - 1])
        if flag:
            flag = False
            ans += 1
        else:
            flag = False
            ans += 1
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 66136
# coding: utf-8

a, b = map(int,input().split())
l = [i for i in range(2,14)]
l.append(1)

ia = l.index(a)
ib = l.index(b)
def p(s):
    print(s)
if ia > ib:
    p("Alice")
elif ia < ib:
    p("Bob")
else:
    p("Draw")

Measured memory_bytes: 9164
#include <cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define LL long long
#define INF 1e18
#define MAXN 100002
int n,m,s,t,u,v;
LL a,b,f=1e15,ans[MAXN];
struct Graph
{
	int cnt,head[MAXN],vis[MAXN];
	LL dis[MAXN];
	struct Edge{int next,to;LL dis;}edge[MAXN*2];
	queue<int> q;
	void add(int from,int to,LL dis)
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	void spfa(int s)
	{
		for(int i=1;i<=n;i++)
			dis[i]=INF;
		memset(vis,0,sizeof(vis));
		q.push(s);
		vis[s]=1;
		dis[s]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			vis[x]=0;
			for(int i=head[x];i!=0;i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>(dis[x]+edge[i].dis))
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to])
						q.push(to),vis[to]=1;
				}
			}
		}
	}
}g1,g2;
int main()
{
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld%lld",&u,&v,&a,&b);
		g1.add(u,v,a);g1.add(v,u,a);
		g2.add(v,u,b);g2.add(u,v,b);
	}
	g1.spfa(s);
	g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
		ans[i]=min(ans[i+1],g1.dis[i]+g2.dis[i]);
	for(int i=1;i<=n;i++)
		printf("%lld\n",f-ans[i]);
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<ll> A(N*3);
  for (auto& a : A) { cin >> a; }
  boost::sort(A, std::greater<ll>());
  ll sum{};
  for (int i = 1; i < N*2; i += 2) {
    sum += A[i];
  }
  cout << sum << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 2560
// https://atcoder.jp/contests/abc087/tasks/abc087_b

#include <iostream>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  int a, b, c, x, t, cnt = 0;
  cin >> a >> b >> c >> x;

  for (int i = 0; i <= a; i++) {
    if (x >= i * 500) {
      for (int j = 0; j <= b; j++) {
        t = (x - (i * 500 + j * 100)) / 50;
        if (t >= 00 && t <= c)
          cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	int a,b;
	
	
	scanf("%d %d",&a,&b);
	
	if(a < b){
	
		printf("a < b\n");
	}
	if(a > b){
		
		printf("a > b\n");
	}
	if(a == b){
		printf("a == b\n");
	}
	
}

Measured memory_bytes: 1012
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
flag = False
for i in range(1,10):
    if n%i==0:
        if 1 <= n//i <= 9:
            flag=True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

void solve(long long N, std::vector<long long> u, std::vector<long long> v) {
    long long ans = 0;

    rep(i, N) { 
        ans += (i+1) * (N-i);
    }

    rep(i, N-1) { 
        if (u[i] > v[i]) swap(u[i], v[i]);
        ans -= u[i] * (N - v[i] + 1);
    }

    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> u(N - 1);
    std::vector<long long> v(N - 1);
    for (int i = 0; i < N - 1; i++) {
        scanf("%lld", &u[i]);
        scanf("%lld", &v[i]);
    }
    solve(N, std::move(u), std::move(v));
    return 0;
}


Measured memory_bytes: 6440
import math
from heapq import heappop
import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))

l = 0
r = max(A)+1

while(l+1 < r):
    m = (l+r)//2
    tmp = 0
    for a in A:
        tmp += math.ceil(a / m)-1
    if tmp <= K:
        r = m
    else:
        l = m

print(r)


Measured memory_bytes: 31112
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int k,s,x,y,z,ans=0;
    cin>>k>>s;
    int l;
    for (x=0;x<=k;x++)
    {
        l=s-x;
        if (l>2*k || l<0)
            continue;
        if (l>k)
        {
            z=k;
            y=l-k;
            ans+=(z-y+1);
        }
        else
            ans+=(l+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,x,sum=0,ans=1,l;
    cin >> n >> x;
    rep(i,n){
        cin >> l;
        sum+=l;
        if(sum<=x) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int ans=0;
  string s, t;
  cin >> s >> t;
  for (size_t i = 0; i < s.size()-t.size()+1; i++) {
    int count=0;
    for (size_t j = 0; j < t.size(); j++) {
      if (s[i+j]==t[j]) count++;
      if (ans<count) ans=count;
    }
  }
  cout << t.size()-ans << endl;
  return 0;
}


Measured memory_bytes: 3600
start = Time.now
D = gets.to_i
@c = gets.split.map(&:to_i)
@s = Array.new D
D.times do |i|
  @s[i] = gets.split.map(&:to_i)
end

t = Array.new D
score = 0
last = Array.new 26, 0
D.times do |i|
  best = -99999999999
  res = nil
  base_c = 0
  26.times do |t|
    base_c += (i - last[t] + 1) * @c[t]
  end
  
  26.times do |t|
    diff = @s[i][t]
    diff -= base_c
    diff += @c[t] * (i - last[t] + 1)

    if diff > best
      best = diff
      res = t
    end
  end
  score +=  best
  last[res] = i + 1
  t[i] = res
end

@q = Array.new
def calc_pena t
  kei = Array.new(26, (1+D)*D/2)
  last = Array.new(26, 0)
  t.each_with_index do |_t, i|
    kei[_t] -= (i+1 - last[_t]) * (D - i)
    last[_t] = i + 1
  end
  res = 0
  26.times do |i|
    res += kei[i] * @c[i]
  end
  res
end
pena = calc_pena(t)
base_score = score + pena

while(Time.now - start < 1.9) do
  100.times do
    new_t = t.dup
    new_base_score = base_score
    (rand(3)+1).times do
      d = rand(D)
      old = new_t[d]
      rep = rand(26)
      new_t[d] = rep
      new_base_score = new_base_score - @s[d][old] + @s[d][rep]
    end

    new_pena = calc_pena(new_t)
    if new_base_score - new_pena > base_score - pena
      t = new_t
      base_score = new_base_score
      pena = new_pena
    end
  end
end
t.each do |_t|
  puts _t + 1
end

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

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

// hi以下の素数を小さい順に返す
// O(hi^1.5)
vector<int> primes_under(int hi) {
    vector<int> primes;
    primes.push_back(2);
    for (int i = 3; i <= hi; i += 2) {
        bool ok = true;
        for (auto p : primes) {
            if (p*p > hi) { break; }
            if (i % p == 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            primes.push_back(i);
        }
    }
    return primes;
}

// nを素因数分解する
// 事前条件: primes は sqrt(n) 以下の素数をすべて含んでいなければならない
// O(sqrt(n))
vector<pair<int64_t, int>> prime_factorization(const vector<int>& primes, int64_t n) {
    vector<pair<int64_t, int>> factors;
    for (int64_t p : primes) {
        if (p*p > n) { break; }
        int cnt = 0;
        while (n % p == 0) {
            n /= p;
            ++cnt;
        }
        if (cnt > 0) {
            factors.push_back({p, cnt});
        }
    }
    if (n > 1) {
        factors.push_back({n, 1});
    }
    return factors;
}

template <class Func>
void foreach_divisor(const vector<pair<int64_t, int>>& factors, Func f, int i = 0, int64_t d = 1) {
    if (i == (int)factors.size()) {
        if (d != 1) {
            f(d);
        }
    } else {
        auto [factor, power] = factors[i];
        for (int k = 0; k <= power; ++k) {
            if (k != 0) { d *= factor; }
            foreach_divisor(factors, f, i+1, d);
        }
    }
}

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

    const auto primes = primes_under((int64_t)sqrt(N) + 1);

    int64_t ans = 0;

    // NがKの倍数でないときの場合の数を求める
    {
        int64_t n = 1;
        for (auto [factor, power] : prime_factorization(primes, N-1)) {
            n *= power + 1;
        }
        ans += n - 1;
    }

    // NがKの倍数であるときの場合の数を求める
    {
        foreach_divisor(prime_factorization(primes, N), [N, &ans](int64_t d) {
            int64_t N_ = N;
            while (N_ % d == 0) { N_ /= d; }
            if ((N_ - 1) % d == 0) { ans++; }
        });
    }

    cout << ans << '\n';
}


Measured memory_bytes: 3836
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    int A, B;
    cin >> A >> B;
    
    cout << max(max(A+B, A-B), A*B);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                for(int i = 0 ; i < n ; i++){
                        int out = 0;
                        int runner = 0;
                        int point = 0;
                        while(out < 3){ 
                                String s = sc.next();
                                if(s.equals("HIT")){
                                        if(runner == 3){ 
                                                point++;
                                        }else{
                                                runner++;
                                        }   
                                }   
                                if(s.equals("HOMERUN")){
                                        point += runner+1;
                                        runner = 0;
                                }   
                                if(s.equals("OUT")){
                                        out++;
                                }   
                        }   
                        System.out.println(point);
                }   
                sc.close();
        }   
}

Measured memory_bytes: 12000
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

bool dfs(string &s, int now){
  if(now == s.size()){
    return true;
  }

  if(now>s.size()){
    return false;
  }
  
  if(s.substr(now, 5)=="dream"){
    if(dfs(s, now+5)){
      return true;
    }
  }

  if(s.substr(now, 7)=="dreamer"){
    if(dfs(s, now+7)){
      return true;
    }
  }
  
  if(s.substr(now, 5)=="erase"){
    if(dfs(s, now+5)){
      return true;
    }
  }
  
  if(s.substr(now, 6)=="eraser"){
    if(dfs(s, now+6)){
      return true;
    }
  }
  
  return false;
}

int main() {
  string s; cin >> s;

  if(dfs(s, 0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


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

int main() {
  int N;
  
  cin >> N;
  
  if(N % 1110 <= 9 || N % 1000 % 111 == 0) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

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

vector<int> arr;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int p;
		cin>>p;
		arr.push_back(p);
	}
	int ans=0;
	for(int j=1;j<n-1;j++){
		vector<int> a={arr[j-1], arr[j], arr[j+1]};
		sort(a.begin(), a.end());
		if(arr[j]==a[1])ans++;
	}
	cout<<ans;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  int N,K;
  cin >> N >> K;
  if(K==100){
    K = 101;
  }
  string ans = to_string(K);
  for(int i = 0; i < N; i++){
    ans += "00";
  }
  cout << ans << endl;
}



Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  string S;
  cin >> S;
  string ans = "";
  REP(i,S.length()){
    ans += 'x';
  }

  cout << ans << "\n";
  return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,c;
ll G[505][505];
ll cost[35][35];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>c;
  rep(i,c) rep(j,c) cin>>cost[i][j];
  rep(i,n) rep(j,n) cin>>G[i][j], G[i][j]--;
  
  vvll sum(3, vll(c));
  rep(ki,3){
    ll min=INF;
    rep(kj,c){
      ll tmp=0;
      rep(i,n){
        rep(j,n){
          if((i+j)%3==ki) tmp+=cost[G[i][j]][kj];
        }
      }
      // cout<<tmp<<endl;
      sum[ki][kj]=tmp;
    }
  }
  ll ans=INF;
  rep(i,c){
    rep(j,c){
      rep(k,c){
        if(i==j || j==k || k==i) continue;
        chmin(ans,sum[0][i]+sum[1][j]+sum[2][k]);
      }
    }
  }
  cout<<ans<<endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

bool ok[100100];

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		li a;
		cin >> a;
		ok[i] = (a - 1 != i);
	}

	li res = 0;
	for (li i = 1; i < n; ++i) {
		if (!ok[i - 1]) {
			++res;
			ok[i - 1] = true;
			ok[i] = true;
		}
	}
	if (!ok[n - 1]) {
		res++;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

    priority_queue<int> pq;
    ll expo, expoP;
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    rep(i, x) {
        for(int p = 2; p < x; p++) {
            expo = pow(i, p);
            if (expo > x) {
                break;
            }
            pq.push(expo);
        }
    }

    cout << pq.top() << endl;
    return 0;
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

# もっとも早い日に貪欲に働いたパターン
# もっとも遅い日に貪欲に働いたパターン
# 上記でX回目の仕事が同じ日であればその日は必ず働く必要がある

N,K,C = map(int,readline().split())
S = readline().rstrip()

fast = [0] * K
ind = 0
cnt = 0
while cnt < K: # K回働くまで
  if S[ind] == "o":
    fast[cnt] = ind
    cnt += 1
    ind += (C + 1)
  else:
    ind += 1

late = [0] * K
ind = len(S) - 1
cnt = 0
while cnt < K:
  if S[ind] == "o":
    late[cnt] = ind
    cnt += 1
    ind -= (C + 1)
  else:
    ind -= 1
    
late = late[::-1]

ans = []
for i in range(K):
  if fast[i] == late[i]:
    ans += [fast[i] + 1]
    
for a in ans:
  print(a)

Measured memory_bytes: 33540
R,G,B,N = map(int,input().split(" "))

count = 0
for r in range(N+1):
    left = N - R*r
    if left < 0:
        break
    for g in range(N+1):
        left2 = left - g*G
        if left2 < 0:
            break
        if left2%B == 0:
            count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
signed main(){
	int n,p,sum=0,ma=0;
	cin>>n;
	rep(i,n){
		cin>>p;
		sum+=p;
		ma=max(ma,p);
	}
	cout<<sum-ma/2<<endl;
	return 0;
}

Measured memory_bytes: 256
n = [int(x) for x in input()]
for i in range(2 ** 3):
    a = list([str(n[0]), '-', str(n[1]), '-', str(n[2]), '-', str(n[3])])
    total = n[0]
    for j in range(3):
        if ((i >> j) & 1):
            a[int(2*j)+1] = '+'
            total = total + n[j+1]
        else:
            total = total - n[j+1]
    if total == 7:
        a.append('=7')
        print(''.join(a))
        exit()

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

int main(){
	int n,m,S[13],H[13],C[13],D[13];
	char pattern;
	for(int i=0;i<13;i++){
		S[i]=H[i]=C[i]=D[i]=0;
	}
	cin >>n;
	if(n-52==0) return 0;

	for(int j=0;j<n;j++){
		cin>>pattern>>m;
		switch(pattern){
			case 'S':S[m-1]=1; break;
			case 'H':H[m-1]=1; break;
			case 'C':C[m-1]=1; break;
			case 'D':D[m-1]=1; break;
		}
	}
	for(int i=0;i<13;i++){
		if(S[i]==0) cout<<"S "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(H[i]==0) cout<<"H "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(C[i]==0) cout<<"C "<<i+1<<endl;
	}
	for(int i=0;i<13;i++){
		if(D[i]==0) cout<<"D "<<i+1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3016
#include<stdio.h>
int main()
{	
  char a,b,c,d,e,f;
  scanf("%c%c%c%c%c%c" ,&a,&b,&c,&d,&e,&f);
  if (c==d & e==f){
  printf("Yes");
  }
  else{
    printf("No");
  }
      return 0;
}

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

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

  vector<int> array1;
  vector<int> array2;
  for (int i = 1; i <= N; i++) {
    array1.push_back(i);
    array2.push_back(i);
  }

  vector<int> P(N, 0);
  vector<int> Q(N, 0);
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];

  int count = 0;
  int a = 0;
  do {
    if (P == array1) {
      a = count;
    } else {
      count++;
    }
  } while (next_permutation(array1.begin(), array1.end()));

  count = 0;
  int b = 0;
  do {
    if (Q == array2) {
      b = count;
    } else {
      count++;
    }
  } while (next_permutation(array2.begin(), array2.end()));

  cout << abs(a-b) << endl;
}

Measured memory_bytes: 3576
H,W = map(int,input().split())
board =list()
ans =list()
count = 0
for y in range(H):
  board.append (input())
  ans.append(["#"]*W)
for y in range(H):
  for x in range(W):
    if board[y][x] ==".":
      count = 0
      for y2 in range(y-1,y+2):
        for x2 in range(x-1,x+2):
          if y2<0 or y2>= H:
            continue
          elif x2<0 or x2>= W:
            continue
          else:
            if board[y2][x2] == "#":
              count += 1
      ans[y][x] = count
for y in range(H):
  for x in range(W):
    print(ans[y][x],end="")
  print()
            

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	unsigned long long a[n];
	unsigned long long sum = 1;
	unsigned long long ju = powl(10,18);
	int count = 0;
	// keisan
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i] == 0) count++;
	}
	if(count > 0){
		cout << "0" << endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		ju = ju/a[i];
		if(ju == 0){
			cout << "-1";
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		sum *= a[i];
	}
	cout << sum << endl;
	// syutsuryoku
}

Measured memory_bytes: 4376
import java.util.*;
import java.util.function.ToDoubleFunction;


public class Main {
    private static final String ex = "3\n" +
            "4\n" +
            "2";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        int a = Integer.parseInt(scanner.nextLine());
        int b = Integer.parseInt(scanner.nextLine());
        int h = Integer.parseInt(scanner.nextLine());

        System.out.println((a + b) * h / 2);
    }
}


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

int main(void) {
    int N, K;
    cin >> N >> K;

    int a[N] = {0};
    for (int i = 0; i < K; i++) {
        int num;
        cin >> num;
        for (int j = 0; j < num; j++) {
            int data;
            cin >> data;
            a[data-1]++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (0 == a[i]) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3640
from collections import deque


def get_pow():
    cache = {}

    def func(x):
        if x not in cache:
            cache[x] = pow(2, x, mod)
        return cache[x]

    return func


mod = 1000000007
n = int(input())
parents = list(map(int, input().split()))
children = [set() for _ in range(n + 1)]
for c, p in enumerate(parents):
    children[p].add(c + 1)

levels = [{0}]
while True:
    level = set()
    for p in levels[-1]:
        level.update(children[p])
    if not level:
        break
    levels.append(level)
levels.reverse()

level_node_count = []
balls = [None] * (n + 1)

for i, level in enumerate(levels):
    level_node_count.append(len(level))
    for node in level:
        cn = children[node]
        if cn:
            if len(cn) == 1:
                bs = balls[cn.pop()]
                bs.appendleft([1, 1, 0])
                balls[node] = bs
                continue
            balls_from_children = [balls[c] for c in children[node]]
            balls_from_children.sort(key=len)
            bs1 = balls_from_children[0]
            for bs2 in balls_from_children[1:]:
                for (b10, b11, b12), b2 in zip(bs1, bs2):
                    b2[2] = ((b11 + b12) * b2[1] + b12 * b2[0]) % mod
                    b2[1] = (b10 * b2[1] + b11 * b2[0]) % mod
                    b2[0] = b2[0] * b10 % mod
                bs1 = bs2
            lim = len(balls_from_children[-2])
            for i, b in enumerate(bs1):
                if i >= lim:
                    break
                b[0] = (b[0] + b[2]) % mod
                b[2] = 0
            bs1.appendleft([1, 1, 0])
            balls[node] = bs1
        else:
            balls[node] = deque([[1, 1, 0]])

level_node_count.reverse()

pow2 = get_pow()
print(sum(b[1] * pow2(n - l + 1) % mod for l, b in zip(level_node_count, balls[0])) % mod)


Measured memory_bytes: 234176
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int N;
    cin >> N;
    int i;
    ll B[N-1];
    for(i=0;i<N;i++){
      cin >>B[i];
    }
    ll ans =B[0]+B[N-2];
    for(i=0;i<N-2;i++){
      ans+=min(B[i],B[i+1]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
function abmp(a,b,p);if b==0;1;elseif b%2==0;k=abmp(a,div(b,2),p);(k*k)%p;else;(a*abmp(a,b-1,p))%p;end;end;;
function binarr(n,p);z=1;for i in 1:n;z=z*i%p;end;fac=Array{Int}(n+1);inv=Array{Int}(n+1);inv[n+1]=abmp(z,p-2,p)
for i in 0:n-1;inv[n-i]=(inv[n+1-i]*(n-i))%p;end;for i in 0:n;fac[i+1]=(((z*inv[i+1])%p)*inv[n+1-i])%p;end;fac;end;

function main()
	mod = 1000000007
	n,m,k = readline() |> split |> parseMap
	x = 0
	b = binarr(n*m-2,mod)
	for i in 1:n-1
		x = (x+i*(b[k-1]*(n-i)%mod*m%mod*m%mod))%mod
	end
	for i in 1:m-1
		x = (x+i*(b[k-1]*(m-i)%mod*n%mod*n%mod))%mod
	end
	println(x)
end
main()


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

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

    cout<<fixed<<setprecision(10)<<2*R*M_PI<<"\n";

	
	return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#define BASE 1000000007
using namespace std;
long long n,m,i,j,s[1001][1001],a[1001][1001];
char x;
int main()
{
    cin >>n>>m;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=m; j++)
        {
            cin >>x;
            if (x=='.')
                a[i][j]=1;
            else
                a[i][j]=0;
        }
    }
    s[1][1]=1;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=m; j++)
        {
                if (a[i][j])
                {
                    s[i][j]=(s[i][j]+s[i-1][j]+s[i][j-1])%BASE;
                }
        }
    }
    cout <<s[n][m];
    return 0;
}


Measured memory_bytes: 15872
import math
D,G = map(int, input().split())
pclist = [list(map(int, input().split())) for _ in range(D)] + [[0,0]]
bits=[format(i, '0'+str(D)+'b') for i in range(2**D)]
ans = 10**5
for bit in bits:
    resn = 0
    res = 0
    maxi = bit.rfind('0')+1
    for i, b in enumerate(bit):
        if b == '1':
            resn += pclist[i][0]
            res += pclist[i][0]*100*(i+1)+pclist[i][1]
    if res >= G:
        if resn < ans:
            ans = resn
    elif maxi > 0 and res+(pclist[maxi-1][0]-1)*100*maxi >= G:
        if G-res > 0:
            resn += math.ceil((G-res)/(100*maxi))
        if resn < ans:
            ans = resn
print(ans)

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

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

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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 (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


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

    map<char,int> mp;
    mp['m'] = 1000;
    mp['c'] = 100;
    mp['x'] = 10;
    mp['i'] = 1;

    int n; cin >> n;
    auto str2int = [&](string s) {
        int co = 1, ret = 0;
        for (char c : s) {
            if (mp.count(c)) {
                ret += co * mp[c];
                co = 1;
            } else {
                co = c - '0';
            }
        }
        return ret;
    };
    auto int2str = [&](int x) {
        string ret;
        for (char c : {'m', 'c', 'x', 'i'}) {
            if (x / mp[c] > 1) ret += to_string(x / mp[c]);
            if (x / mp[c] > 0) ret += c;
            x %= mp[c];
        }
        return ret;
    };

    while (n--) {
        string s, t; cin >> s >> t;
        cout << int2str(str2int(s) + str2int(t)) << endl;
    }

    return 0;
}



Measured memory_bytes: 3260