akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back
 
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()
 
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=0;
int main(){
    int n ; cin >> n ; 
    int res = 0;
    REP(i, n){
        int v ; cin >> v ; 
        if((i+1)%2 == 0)continue;
        if((v)&1)
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    ll A, B, N; cin >> A >> B >> N;
    ll m;
    if (B-1 <= N) {
        m = B-1;
    } else {
        m = N % B;
    }
    ll ans = A * m / B;
    out(ans);

    return 0;
}





Measured memory_bytes: 3564
N=int(input())
mod=10**9+7
dp=[{}for i in range(N)]
list=['AGC','ACG','GAC']
def dfs(x,y):
  if x in list:
    return 0
  if y==N:
    return 1
  if x in dp[y]:
    return dp[y][x]
  ans=0
  for i in 'ACGT':
    if x[0]=='A' and i=='C' and (x[1]=='G' or x[2]=='G'):
      continue
    ans+=dfs(x[1:]+i,y+1)
  dp[y][x]=ans%mod
  return ans%mod
print(dfs('TTT',0))

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

int main() {
    string s;
    cin >> s;
    int c = atoi(s.substr(0,2).c_str());
    int t = atoi(s.substr(2,2).c_str());
    bool a = 0 < c && c <= 12;
    bool b = 0 < t && t <= 12;
    if (a && b) cout << "AMBIGUOUS" << endl;
    else if (!a && !b) cout << "NA" << endl;
    else if (!a && b) cout << "YYMM" << endl;
    else if (a && !b) cout << "MMYY" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    lli a, b;
    cin >> a >> b;
    lli cnt = 0;
    while (a <= b) {
        a *= 2;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"bytes"
)

var MAX int = 250
var N int
var outBuffer bytes.Buffer

func parent(i int) int {
	return i/2
}

func left(i int) int {
	return i*2
}

func right(i int) int {
	return i*2+1
}

func print(A []int) {
	for i:=1; i<=N; i++ {
		outBuffer.WriteString(fmt.Sprintf("node %d: key = %d, ", i, A[i]))
		p := parent(i)
		l := left(i)
		r := right(i)
		if p > 0 {
			outBuffer.WriteString(fmt.Sprintf("parent key = %d, ", A[p]))
		}
		if l <= N {
			outBuffer.WriteString(fmt.Sprintf("left key = %d, ", A[l]))
		}
		if r <= N {
			outBuffer.WriteString(fmt.Sprintf("right key = %d, ", A[r]))
		}
		fmt.Printf("%s\n", outBuffer.String())
		outBuffer.Reset()
	}
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	N = nextInt(scanner)
	A := make([]int, N+1)
	for i:=1; i<=N; i++ {
		A[i] = nextInt(scanner)
	}
	print(A)
}


Measured memory_bytes: 1136
#include<cstdio>

using namespace std;

int main(){
    char s[51], t[51];
    scanf("%s", s);
    scanf("%s", t);
    int i = 0;
    int index = -1;
    while(s[i] != 0){
        int j = 0;
        bool flag = true;
        while(t[j] != 0){
            if (s[i+j] != t[j] && s[i+j] != '?'){
                flag = false;
                break;
            }
            j++;
        }
        if (flag) index = i;
        i++;
    }
    i = 0;
    if (index == -1){
        puts("UNRESTORABLE");
        return 0;
    }
    i = 0;
    while(s[i] != 0){
        if (s[i] == '?' && i != index) s[i] = 'a';
        else if (i == index){
            int j = 0;
            while(t[j] != 0){
                s[i+j] = t[j];
                j++;
            }
            i += j - 1;

        }
        i++;
    }
    printf("%s\n", s);

}

Measured memory_bytes: 256
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let mut s = scan_split::<i32>();
    s.sort();
    if s[0] + s[1] == s[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

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

    int a, p;
    cin >> a >> p;

    p += 3 * a;
    cout << p / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		String op = scan.next();
		int b = scan.nextInt();
		

		if(op.equals("-"))
			System.out.println(a-b);
		else
			System.out.println(a+b);
	}
}

Measured memory_bytes: 21588
import java.util.Scanner;


public class Main {
	static Scanner sc = new Scanner(System.in);
	Squ in;
	Squ out = new Squ(150, 150);

	public static void main(String[] args) {
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if( (h|w) == 0 ) break;
			new Main(new Squ(h, w)).find().print();
		}
	}

	Main(Squ in) {
		this.in=in;
	}

	Main find() {
		for(int y=1; y<150; y++) {
			for(int x=y+1; x<150; x++) {
				Squ exam = new Squ(y, x);
				if( exam.compareTo(in) <= 0 ) continue;
				if( exam.compareTo(out) < 0 ) out = exam;
			}
		}

		return this;
	}

	void print() {
		System.out.println(out);
	}
}


class Squ implements Comparable<Squ> {
	int h, w, tk;

	Squ(int h, int w) {
		this.h = h; this.w = w;
		tk = h*h + w*w;
	}

	@Override
	public int compareTo(Squ op) {
		int ret = tk - op.tk;
		if(ret == 0) ret = h - op.h;
		return ret;
	}

	@Override
	public String toString() {
		return h+" "+w;
	}
}

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

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

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

    bool flag = false;

    for(int i = 0; i < n; i++){
        if(color.at(i) == 'Y'){
            flag = true;
        }
    }

    if(flag){
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
s=list(map(int, input().split()))
s=sorted(set(s))
q=int(input())
t=list(map(int, input().split()))

def binarySearch(A,key):
    left=0
    right=len(A)
    #二部探索
    while left<right:
        mid=(left+right)//2
        if A[mid]==key:
            return True
        elif key < A[mid]:
            right=mid
        else:
            left=mid+1
    return False

count=0
for i in t:
    if binarySearch(s,i):
        count+=1
        #print("a",i)

print(count)


Measured memory_bytes: 16712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int main()
{
  int n;
  cin >> n;
  int ans = n / 2;
  if (n & 1)
    ans++;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	vector<vi> v(n, vi(3)); cin >> v;
	ll ans = 0;
	REP(bit, 1 << 3)
	{
		vi a;
		for (auto w : v)
		{
			ll tmp = 0;
			REP(i, 3)
			{
				if ((bit >> i) & 1) tmp += w[i];
				else tmp -= w[i];
			}
			a.push_back(tmp);
		}
		sort(a.rbegin(), a.rend());
		ll tmp = 0;
		REP(i, m) tmp += a[i];
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

typedef vector<int> Col;
typedef vector< Col > Matrix;

Matrix mul(const Matrix& A, const Matrix& B, int M){
  const int R = A.size(), C = B[0].size(), sz = B.size();
  Matrix AB(R, Col(C));

  for(int i=0;i<R;++i)
    for(int j=0;j<C;++j)
      for(int k=0;k<sz;++k){
		AB[i][j] += A[i][k] * B[k][j];
		AB[i][j] %= M;
	  }

  return AB;
}

Matrix powA(const Matrix& A, int n, int MOD){
  const int N = A.size();
  Matrix p(N, Col(N, 0)), w = A;
  for(int i=0;i<N;++i) p[i][i] = 1;

  while(n>0){
	if(n&1)
	  p = mul(p, w, MOD);
	w = mul(w, w, MOD);
	n >>= 1;
  }

  return p;
}


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

  int N,M,A,B,C,T;
  while(cin>>N>>M>>A>>B>>C>>T,N){
	Matrix init(N, Col(1,0));
	REP(i,N) cin >> init[i][0];
	
	Matrix m(N, Col(N, 0));
	REP(i,N) m[i][i] = B;
	REP(i,N-1) m[i+1][i] = A;
	REP(i,N-1) m[i][i+1] = C;
	
	Matrix state = mul(powA(m, T, M), init, M);
	
	cout << state[0][0];
	FOR(i,1,N)
	  cout << " " << state[i][0];
	cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1288
#include<stdio.h>
int main(void){
    int a, b, c, i, n=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            n++;
        }
    }
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline

MOD = 10**9 + 7

N = int(input())
ball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())

# x座標を1,2,...,N
# y座標をN+1,N+2,...,N+N

graph = [set() for _ in range(N+N+1)]
for x,y in ball:
    graph[x].add(y+N)
    graph[y+N].add(x)

visited = [False] * (N+N+1)
components = []
for x in range(1,N+N+1):
    if visited[x]:
        continue
    V = set([x])
    E = []
    q = [x]
    visited[x] = True
    while q:
        y = q.pop()
        for z in graph[y]:
            if y < z:
                E.append((y,z))
            if visited[z]:
                continue
            V.add(z)
            visited[z] = True
            q.append(z)
    components.append((V,E))

def make_get_pattern(V):
    deg1 = [x for x in V if len(graph[x]) == 1]
    get = {}
    while deg1:
        x = deg1.pop()
        if not graph[x]:
            continue
        y = graph[x].pop()
        se = graph[y]; se.remove(x)
        if len(se) == 1: deg1.append(y)
        if x < y:
            get[(x,y)] = 0
        else:
            get[(y,x)] = 1
    for x in V:
        if graph[x]:
            y = graph[x].pop()
            break
    # 残りはサイクル
    graph[y].remove(x)
    if x > y: x,y = y,x
    get[(x,y)] = 2
    while graph[x]:
        y = graph[x].pop()
        graph[y].remove(x)
        if x < y:
            get[(x,y)] = 3
        else:
            get[(y,x)] = 2
        x = y
    return get

def F(V,E):
    # V is connected
    if len(E) != len(V):
        return 0
    ret = 0
    E.sort()
    get = make_get_pattern(V)
    den1,den2 = 1,1
    dp1 = {x:0 for x in V}
    dp2 = {x:0 for x in V}
    for x,y in E:
        if get[(x,y)] == 0:
            k1 = dp1[x] + 1; k2 = dp2[x] + 1
        elif get[(x,y)] == 1:
            k1 = dp1[y] + 1; k2 = dp2[y] + 1
        elif get[(x,y)] == 2:
            k1 = dp1[x] + 1; k2 = dp2[y] + 1
        else:
            k1 = dp1[y] + 1; k2 = dp2[x] + 1
        dp1[x] += k1; dp1[y] += k1
        dp2[x] += k2; dp2[y] += k2
        den1 *= k1; den2 *= k2
        den1 %= MOD; den2 %= MOD
    return sum(pow(x,MOD-2,MOD) for x in (den1,den2))

prob = 1
for c in components:
    prob *= F(*c)
    prob %= MOD

answer = prob
for n in range(1,N+N+1):
    answer *= n
    answer %= MOD
print(answer)

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

#define N 200123
#define mod 1000000007

int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
 float r, phi;
 phi = 3.1415f;
 cin >> r;
 cout << 2*phi*r << endl;  
 return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( array[ 0 ] ))

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	ll a, b;
	cin >> a >> b;
	cout << (ll)(a * b) / __gcd( a, b ) << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if (a<=b) {
		cout << a << endl;
	}
	else {
		cout << a - 1 << endl;
	}
}


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

struct Node
{
  int key;
  Node *next, *prev;
};

Node *nil;

Node *listSearch(int key)
{
  Node *cur = nil->next;
  while (cur != nil && cur->key != key)
  {
    cur = cur->next;
  }
  return cur;
}

void init()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  Node *cur = nil->next;
  int isf = 0;
  while (1)
  {
    if (cur == nil)
      break;
    if (isf++ > 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t)
{
  if (t == nil)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst()
{
  deleteNode(nil->next);
}

void deleteLast()
{
  deleteNode(nil->prev);
}

void deleteKey(int key)
{
  deleteNode(listSearch(key));
}

void insert(int key)
{
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main()
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++)
  {
    scanf("%s%d", com, &key);
    if (com[0] == 'i')
    {
      insert(key);
      np++;
      size++;
    }
    else if (com[0] == 'd')
    {
      if (strlen(com) > 6)
      {
        if (com[6] == 'F')
          deleteFirst();
        else if (com[6] == 'L')
          deleteLast();
      }
      else
      {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 33800
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println((a*3+b)/2);
		
	}
}


Measured memory_bytes: 21204
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	if(!k) {
		cout << n * n;
		return 0;
	}
	for(int i = k + 1; i <= n; ++i)
		ans += (n / i) * (i - k) + max(n % i - k + 1, 0ll);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const ull INF3 = 18446744073709551600LL;
bool flag = true;
bool fl = false;
bool f = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };

int main() {
	int n;
	std::string s, t;
	std::cin >> n >> s >> t;
	int ans = n;
		for (;ans < 2 * n;ans++) {
			std::string S, T;
			int k = 2 * n - ans;
			for (int i = n - k;i < n;i++) {
				S += s[i];
			}
			for (int i = 0;i < k;i++) {
				T += t[i];
			}
			if (S == T) {
				std::cout << ans << std::endl;
				flag = false;
				break;
			}
		}
		if (flag)std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int MAX = 500000;
const int inf = 2000000000;

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int left, int mid, int right){
    int n1 = mid - left; // 左の配列の要素数
    int n2 = right - mid; // 右の配列の要素数
    for(int i=0; i<n1; i++) L[i] = A[left+i];
    for(int i=0; i<n2; i++) R[i] = A[mid+i];
    L[n1] = R[n2] = inf;
    int i=0, j=0;
    for(int k=left; k<right; k++){
        cnt++;
        if(L[i] <= R[j]) A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(int A[], int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A,left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for(int i=0; i<n; i++) scanf("%d", &A[i]);

    mergeSort(A, 0, n);

    for(int i=0; i<n; i++){
        if(i) cout << " ";
        printf("%d", A[i]);
    }
    cout << endl;

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


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=0;
	while(1){
		x++;
		if(x%2==1){
			c-=b;
		}
		else{
			a-=d;
		}
		if(a<=0){
			cout<<"No";
			return 0;
		}
		if(c<=0){
			cout<<"Yes";
			return 0;
		}
	}	
	return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int sum=0;
	vector<int> a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	for (int i=1; i<n; i++) {
		sum+=a[i];
	}
	sum+=(a[0]/2);
	cout << sum;
	return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      // スペース区切りの整数の入力
      string[] input = Console.ReadLine().Split(' ');
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);

      if(a * b % 2 == 0)
        Console.WriteLine("Even");
      else
        Console.WriteLine("Odd");
    }

  }
}

Measured memory_bytes: 27368
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    string s, t, u;
    cin >> s >> t >> u;
    vector<map<int, int>> v(n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        v[i][s[i]]++, v[i][t[i]]++, v[i][u[i]]++;
        int p = 0;
        for (auto &&j : v[i]) {
            p = max(p, j.second);
        }
        ans += 3-p;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
fn main() {
 let v:Vec<u32>={
  let mut b=String::new();
  let s=std::io::stdin();
  s.read_line(&mut b).unwrap();
  b.split_whitespace().flat_map(str::parse).collect()
 };
 println!("{}",(v[0]..v[1]+1).filter(|i|v[2]%i==0).count());
}


Measured memory_bytes: 5024
package main

import (
  "fmt"
)

func main() {
  var w string 
  fmt.Scan(&w)
  res := make(map[rune]int)
  for _, c := range w {
    res[c] ^= 1
  }
  ans := "Yes"
  for _, v := range res {
    if v == 1 {
      ans = "No"
      break
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
n = int(raw_input())

mat = []
for i in range(n):
    mat.append(map(int,raw_input().split()))
    
dp = [0,0,0]

for day in range(n):
    ndp = [0,0,0]
    data = mat[day]
    
    for i in range(3):
        for j in range(3):
            if i != j:
                ndp[j] = max(ndp[j], dp[i]+data[j])
    dp = ndp
print max(dp)
   

Measured memory_bytes: 23940
<?php

while(($in = trim(fgets(STDIN))) !== '-1 -1 -1'){
sscanf($in,'%d %d %d', $h, $m, $s);
for($i=0;$i<2;$i++){	
$time = $h*3600+$m*60+$s;
$time=120*60-$time;
if($i>0){
	$time*=3;
}
if($time/3600<10){
	print("0".floor($time/3600));
	print(":");
	$time%=3600;
}
else{
	print(floor($time/3600));
	print(":");
	$time%=3600;
}
if($time/60<10){
	print("0".floor($time/60));
	print(":");
	$time%=60;
}
else{
	print(floor($time/60));
	print(":");
	$time%=60;
}
if($time<10){
	print("0".$time);
}
else{
	print($time);
	}	
	print("\n");
}
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll H, W, K, ORIG[30][31], A[30][31];

  void init() {
    scanf("%lld %lld %lld", &H, &W, &K);
    rep(i, H) {
      string s;
      cin >> s;
      rep(j, W) ORIG[i][j] = s[j] - '0';
    }
  }

  ll calc(ll si, ll sj) {
    memcpy(A, ORIG, sizeof ORIG);
    A[si][sj] = 0;
    for(ll i = si; 0<i; i--) swap(A[i][sj], A[i-1][sj]);
    ll score = 0, base = 1;
    // rep(i, H) {
    //   // debug
    //   rep(j, W) cerr << A[i][j] << " ";
    //   cerr << endl;
    // }
    while(1) {
      bool disappeared = false;
      rep(i, H) {
        ll prev_num = 0, same_cnt = 0;
        rep(j, W+1) {
          if(prev_num && (prev_num == A[i][j])) {
            same_cnt++;
          } else {
            if(same_cnt >= K) {
              rep(k, same_cnt) {
                score += base * A[i][j-k-1];
                A[i][j-k-1] = 0;
              }
              disappeared = true;
            }
            prev_num = A[i][j];
            same_cnt = 1;
          }
        }
      }
      if(!disappeared) break;
      rep(c, H-1) for(ll i = H-1; c<i; i--) rep(j, W) {
        if(A[i][j] == 0) swap(A[i][j], A[i-1][j]);
      }
      base *= 2;
    }
    return score;
  }

  void solve() {
    ll ans = 0;
    rep(i, H) rep(j, W) ans = max(ans, calc(i, j));
    cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

const int H = 20;
const int W = 100;
int A, B;
vector<string> BackB, BackW;

void init_data(void) {
	string black = string(W, '#');
	BackB.resize(H, black);
	string white = string(W, '.');
	BackW.resize(H, white);
}

void make_data(char c, vector<string> &V) {
	int cnt = (c == '.') ? A - 1 : B - 1;
	for (int j = 0; j < H / 2; ++j) {
		for (int i = 0; i < W / 2; ++i) {
			if (cnt == 0)
				return;
			V[j * 2][i * 2] = c;
			--cnt;
		}
	}
}

void print_data(void) {
	cout << 2 * H << ' ' << W << '\n';
	for (int j = 0; j < H; ++j)
		cout << BackB[j] << '\n';
	for (int j = H - 1; j >= 0; --j)
		cout << BackW[j] << '\n';
}

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

	cin >> A >> B;
	init_data();
	make_data('.', BackB);
	make_data('#', BackW);
	print_data();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

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

void dfs(vector<vector<edge> >& G, vector<bool>& vis, vector<ll>& D, int tmp, int par, ll cost) {
  if(!vis[tmp]) {
    if(par != -1) {
      D[tmp] = D[par] + cost;
    }
    vis[tmp] = true;
    for(auto ne: G[tmp])
      dfs(G, vis, D, ne.to, tmp, ne.cost);
  }
}

int main() {
  int N;
  cin >> N;
  vector<vector<edge> > G(N);
  rep(i, N-1) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back(edge(b, c));
    G[b].push_back(edge(a, c));
  }
  int Q, K;
  cin >> Q >> K;
  K--;
  vector<bool> vis(N);
  vector<ll> D(N);
  dfs(G, vis, D, K, -1, 0);
  rep(i, Q) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << D[x] + D[y] << endl;
  }
  return 0;
}



Measured memory_bytes: 15872
cij =[]
for i in range(3):
    cij.append(list(map(int, input().split(" "))))

bi_list = []
for b1 in range(-50000, 50000):
    b2 = b1 - (cij[0][0] - cij[0][1])
    b3 = b1 - (cij[0][0] - cij[0][2])

    a1 = cij[0][0]+cij[0][1]+cij[0][2] -b1-b2-b3
    a2 = cij[1][0]+cij[1][1]+cij[1][2] -b1-b2-b3
    a3 = cij[2][0]+cij[2][1]+cij[2][2] -b1-b2-b3
    if a1/3+b1 ==cij[0][0] and a1/3+b2 ==cij[0][1] and a1/3+b3 ==cij[0][2] and a2/3+b1 ==cij[1][0] and a2/3+b2 ==cij[1][1] and a2/3+b3 ==cij[1][2] and a3/3+b1 ==cij[2][0] and a3/3+b2 ==cij[2][1] and a3/3+b3 ==cij[2][2]:
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 3064
import bisect

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
for _ in range(Q):
    x = int(input())
    sr = min(bisect.bisect_left(S, x), A - 1)
    sl = max(sr - 1, 0)
    tr = min(bisect.bisect_left(T, x), B - 1)
    tl = max(tr - 1, 0)
    print(min(abs(x - S[sl]) + abs(S[sl] - T[tl]),
              abs(x - S[sl]) + abs(S[sl] - T[tr]),
              abs(x - S[sr]) + abs(S[sr] - T[tl]),
              abs(x - S[sr]) + abs(S[sr] - T[tr]),
              abs(x - T[tl]) + abs(T[tl] - S[sl]),
              abs(x - T[tl]) + abs(T[tl] - S[sr]),
              abs(x - T[tr]) + abs(T[tr] - S[sl]),
              abs(x - T[tr]) + abs(T[tr] - S[sr])))


Measured memory_bytes: 12092
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    H = readInts()
    G = [[] for _ in range(n)]
    for i in range(m):
        a,b = map(lambda x:int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)
    #print(G)
    # 各数字について調べる
    cnt = 0
    for i in range(n):
        if len(G[i]) == 0:
            cnt += 1
            continue
        ok = True
        for k in G[i]:
            if H[i] <= H[k]:
                ok = False
                break
        if ok:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
  main()


Measured memory_bytes: 31232
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int x[6];

int main(){
  scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]);
  
  for(int i=0;i<5;i++){
    if(x[i]==0){
      printf("%d\n",i+1);}}
  
  return 0;
}


Measured memory_bytes: 1644
#include <stdio.h>
#include <stdlib.h>

#define MAXN 100000

int A[MAXN+1];
int DP[MAXN+1];

int flog (int n)
{
	int i,tmp1,tmp2;

	DP[1] = 0;
	DP[2] = abs(A[1]-A[2]);

	for ( i = 3; i <= n; i++ ) {
		tmp1 = DP[i-1]+abs(A[i]-A[i-1]);
		tmp2 = DP[i-2]+abs(A[i]-A[i-2]);
		DP[i] = tmp1<tmp2 ? tmp1:tmp2;
	}

	return DP[n];

}

int main(void)
{
	int i,n;

	scanf("%d", &n);
	for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);

	printf("%d", flog(n));

	return 0;
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String work[] = new String[4];
        int table[][][] = new int[4][3][10];
 
        for(int a = 0; a < 4; a++){
            for(int b = 0; b < 3; b++){
                for(int c = 0; c < 10; c++)table[a][b][c] = 0;
            }
        }
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            for(int loop = 0; loop < N; loop++){
                work = br.readLine().split("\\s+");
                table[Integer.parseInt(work[0])-1][Integer.parseInt(work[1])-1][Integer.parseInt(work[2])-1] += Integer.parseInt(work[3]);
            }
 
 
            print(table[0]);
            for(int i = 1; i <= 3; i++){
                System.out.printf("####################\n");
                print(table[i]);
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private static void print(int house[][]){
 
        for(int row = 0; row < 3; row++){
            for(int col = 0; col < 10; col++){
                System.out.printf(" %d", house[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 25916
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B==C+D)
    cout<<"Balanced"<<endl;
  else if(A+B<C+D)
    cout<<"Right"<<endl;
  else
    cout<<"Left"<<endl;
    return 0;
}

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

int A(int N){
    return 2*N;
}

int B(int N,int K){
    return N + K;
}
int main(void){
    
  int N,K,ans=1;
  cin >> N >> K;
  for(int i=0;i<N;i++){
      int a = A(ans);
      int b = B(ans,K);
      
      if(a < b) ans = a;
      else ans = b;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int a, b, c;
  cin >> a >> b >> c;

  cout << (a ^ b ^ c) << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/* ======IO====== */
var (
	InputString func() string
)

func init() {
	InputString = newInputString(os.Stdin)
}

func newInputString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("error scan")
		}
		return r.Text()
	}
}

func InputInt() int {
	return int(readInt64())
}
func InputInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func InputInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func InputInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(InputString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func InputIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = InputInt()
	}
	return b
}

func InputFloat64() float64 {
	return float64(inputFloat64())
}

func inputFloat64() float64 {
	f, err := strconv.ParseFloat(InputString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func InputFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = InputFloat64()
	}
	return b
}

func InputRuneSlice() []rune {
	return []rune(InputString())
}

/* ======Math====== */
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func Round(f float64) float64 {
	return math.Floor(f + .5)
}

/* ======Heap====== */

type IntHeap []int

func (h IntHeap) Len() int { return len(h) }

// default minimum heap
func (h IntHeap) Less(i, j int) bool  { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

/* ======Util====== */

func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic("strtoi error")
	} else {
		return i
	}
}

//
//type sortable [][]int
//
//func (s sortable) Len() int { return len(s) }
//
//func (s sortable) Less(i, j int) bool { return s[i][0] < s[j][0] }
//
//func (s sortable) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func main() {
	N := InputInt()
	Bs := InputIntSlice(N - 1)
	ans := Bs[0]
	for i := 1; i < N-1; i++ {
		ans += Min(Bs[i-1], Bs[i])
	}
	ans += Bs[N-2]
	fmt.Print(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s,t,v="",w="";
	cin>>s>>t;
	int s_size=s.size(),t_size=t.size();
	vector<char> a(s_size);
	vector<char> b(t_size);
	for(int i=0;i<s_size;i++){
		a[i]=s[i];
	}
	for(int i=0;i<t_size;i++){
		b[i]=t[i];
	}

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=0;i<s_size;i++){
		char c=a[i]-'a';
		v = v+c;
	}

	for(int i=t_size-1;i>=0;i--){
		char d=b[i]-'a';
		w = w+d;
	}

	if(v<w){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N, K;
    cin >> N >> K;
    int A[200005];
    A[0] = N;
    REP(i, 1, N+1) cin >> A[i];

    int num[200005] = {0};
    num[0] = 0;
    REP(i, 1, N+1) {
        num[A[i]]++;
        num[0] = max(num[0], A[i]);
    }

    sort(num+1, num+num[0]+1);

    ll ans = 0;
    REP(i, 1, num[0]+1-K) {
        ans += num[i];
    }

    // rep(i, num[0]+1) {
    //     cout << num[i] << " ";
    // } cout << endl;

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


Measured memory_bytes: 1792
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

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

void debug_print(vector< vector <int> > &S, int row, int column_max){
    REP(i,row){
        REP(j,column_max){
            cout << S[i][j];
        }
        cout << endl;
    }
}

void plus_row(vector< vector <int> > &S, int row, int column_max){
    REP(i, column_max){
        S[row][i] = 2;
    }
}

void plus_col(vector< vector <int> > &S, int col, int row_max){
    REP(i, row_max){
        S[i][col] = 2;
    }
}

int count_black(vector< vector <int> > &S, int H, int W, int K){
    int count;
    count = 0;
    REP(i, H){
        REP(j, W){
            if(S[i][j] == 1){count += 1;}
        }
    }
    return count;
}

void rep_set(vector<int> &A, int count){
    int i;
    int j;
    REP(i, 6){
        j = i + 1;
        if(count % (int)pow(2, j) >= (int)pow(2, j-1)){
            A[i] = 1;
        }
        else{
            A[i] = 0;
        }
    }

}


void renew(vector< vector <int> > &S, int H, int W, vector<int> &rep_H, vector<int> &rep_W){
    REP(i, H){
        if(rep_H[i] == 1){
            plus_row(S, i, W);
        }
    }
    REP(i, W){
        if(rep_W[i] == 1){
            plus_col(S, i, H);
        }
    }
}
void reset(vector< vector <int> > &S,vector< vector <int> > &init_S, int H, int W){
    REP(i, H){
        REP(j, W){
            S[i][j] = init_S[i][j];
        }
    }
}

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    int H_max, W_max;
    H_max = pow(2, H);
    W_max = pow(2, W);
    vector<int> rep_H(W, 0);
    vector<int> rep_W(H, 0);

    vector< vector <int> > S(H, vector <int>(W, 0));
    vector< vector <int> > init_S(H, vector <int>(W, 0));

    int output = 0;
    int count = 0;

    REP(i,H){
        string si;
        cin >> si;
        REP(j,W){
            if(si[j] == '#'){
                S[i][j] = 1;
                init_S[i][j] = 1;
            }
        }
    }

    
    REP(i, H_max){
        rep_set(rep_H, i);
        REP(j, W_max){
            rep_set(rep_W, j);
            renew(S, H, W, rep_H, rep_W);
            //debug_print(S, H, W);
            count = count_black(S, H, W, K);
            if(count == K){output += 1;}
            reset(S, init_S, H, W);
        }
    }

    cout << output << endl;


    return 0;
}


Measured memory_bytes: 3976
n,m,x = map(int,input().split())
c=[]
a=[]
INF = float("inf")
stock = INF
for _  in range(n):
    c_temp,*a_temp = list(map(int,input().split()))
    c.append(c_temp)
    a.append(a_temp)

for bit in range(1 << n):
    cost_total = 0
    smart_total = [0]*m

    for i in range(n):
        if (bit >> i) & 1:
            # i冊目を買うときの処理
            smart = []
            cost_total += c[i]
            smart = a[i]
            for j , sm in enumerate(smart):
                smart_total[j] += sm
        #else:
            # i冊目を買わないときの処理（今回は何もしないので省略）
    judege = True
    for i in range(m):
        if smart_total[i] < x:
            judege = False
    if judege:
        stock = min(cost_total,stock)
if stock == INF:
    print("-1")
else:
    print(stock)

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

int main()
{
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >>r;
    if(x<0 || y<0 || W<x+r || H<y+r){        
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;            
    }
    return 0;
}


Measured memory_bytes: 3096
from itertools import takewhile, count

def is_prime(x):
    if x == 1:
        return False
    for z in takewhile(lambda y: (y * y) <= x, count(2)):
        if (x % z) == 0:
            return False
    return True

def solve(x):
    while not is_prime(x):
        x += 1
    return x

print(solve(int(input())))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
////////////////////////////////////////////////////////////////////////////////
int n;
vector<int> g[100005];


void dfs(int cur,int d,int par,auto& dist,auto& vis){
	vis[cur] = true; 
	dist[cur] = d;
	
	for(auto i: g[cur]){
	  if( i != par){
	     dfs(i,d+1,cur,dist,vis);
       }
    }
}


vector<int> distf(int u){
	
	vector<int> dist(n+1);
	vector<bool> vis(100005,false);
	
	dfs(u,0,-1,dist,vis);
	
	return dist;
}


int main(){
    
   
    cin >> n; 
    
    int t,a;
    cin >> t >> a;
    
    for(int i=0;i<n-1;i++) {
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);		
	}   
   
    vector<int> dt = distf(t);
    vector<int> da = distf(a);
         
    int ans = 0;
    
    for(int i =1;i<=n;i++){
	     if( dt[i] < da[i]) ans = max(ans,da[i]);	
	}
    cout << ans - 1 << endl;
     
}


Measured memory_bytes: 12928