akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def check(n):
    if n == 1:
        return False
    i = 2
    while i*i <= n:
        if n%i == 0:
            return False
        i += 1
    return True
f = [0 for i in range(100001)]
for i in range(1,100001):
    f[i] += f[i-1]
    if check(i):
        if check((i+1)//2):
            f[i] += 1
q = I()
for i in range(q):
    l,r = LI()
    print(f[r]-f[l-1])

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve


Measured memory_bytes: 52912
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  int a[n+10];
  map<int,int>mp;
  rep(i,0,n){
    cin>>a[i];
    mp[a[i]]++;
  }

  int ans=0;
  for(map<int,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    int d=itr->second-itr->first;
    if(d>0)ans+=d;
    else if(d<0)ans+=itr->second;
  }

  out(ans);



  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int n,x;
    cin >> n >> x;
    vector<int> a(n);

    int amin = INT_MAX;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        amin = min(amin, a[i]);
    }

    x -= accumulate(a.begin(), a.end(), 0);
    cout << n + x / amin << endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  int max = 1, min = N;
  for(int i = 0; i < M; i++){
    int L, R;
    cin >> L >> R;
    if(max < L){
      max = L;
    }
    if(R < min){
      min = R;
    }
  }
  
  if(min < max){
    max = min + 1;
  }
  
  cout << min - max + 1 << endl;
}


Measured memory_bytes: 256
// AOJ 2021: Princess in Danger
// 2017.12.11 bal4u@uu

#include <stdio.h>
#include <string.h>

#define INF 0x07070707

int n;
char f[101];
int dist[101][101];

void warshallFloyd()
{
	int i, j, k, t;

    for (k = 0; k < n; k++)	for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
		t = dist[i][k] + dist[k][j];
		if (t < dist[i][j]) dist[i][j] = t;
	}
}

char buf[400], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int m, l, k, a, h, i, j, x, y, t, ans;

	while (fgets(p=buf, 60, stdin) && *p != '0') {
		n = getint(), m = getint(), l = getint();
		k = getint(), a = getint(), h = getint();

		memset(f, 0, sizeof(f));
		f[a] = f[h] = 1;
		if (l > 0) {
			fgets(p=buf, sizeof(buf), stdin);
			while (l--) f[getint()] = 1;
		}

		memset(dist, 0x07, sizeof(dist));
		for (i = 0; i < n; i++) dist[i][i] = 0;
		while (k--) {
			fgets(p=buf, 20, stdin);
			x = getint(), y = getint(), t = getint();
			dist[x][y] = dist[y][x] = t;
		}

		warshallFloyd();
		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			if (!f[i] || !f[j] || dist[i][j] > m)
				dist[i][j] = dist[j][i] = INF;
		}
		warshallFloyd();

		ans = dist[a][h];
		if (ans == INF) puts("Help!");
		else {
			if (ans > m) ans = (ans << 1) - m;
			printf("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 1764
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

var sc = bufio.NewScanner(os.Stdin)


func main() {
  sc.Split(bufio.ScanWords)
  N := ri()
  
  ws := make(Ws, N)
  for i := 0; i < N; i++ {
    ws[i] = Work{ri(), ri()}
  }
  sort.Sort(ws)
  s := 0
  for _,w := range ws {
    s += w.A
    if s > w.B {
      fmt.Println("No")
      return
    }
  }
  fmt.Println("Yes")
}

type Work struct { A, B int }

type Ws []Work
func (a Ws) Len() int { return len(a) }
func (a Ws) Less(i, j int) bool { return a[i].B < a[j].B }
func (a Ws) Swap(i, j int) { a[i], a[j] = a[j], a[i] }



Measured memory_bytes: 4352
#include <iostream>

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

    int val, count = 0;
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        if(val != i + 1){
            ++count;
        }
    }

    std::string ans = "NO";
    if(0 == count || 2 == count){
        ans = "YES";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1046527
#define L 14

char H[M][L];

int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1;

    for (int i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }

    return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
    long long key, h;
    key = getKey(str);

    for (int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }

    return 0;
}

int insert(char str[]) {
    long long key, h;
    key = getKey(str);
    for (int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }

    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %s", com, str);

        if (com[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}



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

typedef long long ll;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = INT_MAX;

vi reach[MAXN];

void solve() {
	ll n;
	cin >> n;

	ll a[n];
	F0R(i, n) {
		cin >> a[i];
		ll prev = (i + 1) - a[i];
		ll next = (i + 1) + a[i];
		if(prev > 0) reach[prev].pb(-(i + 1));
		if(next <= n) reach[next].pb(i + 1);
	}
	ll ans = 0;
	
	FOR(i, 1, n + 1) {
		ll p = 0,n = 0;
		for(auto x: reach[i]) {
			if(x < 0) n++;
			else p++;
		}
		ans += (p * n);
	}

	cout << ans << "\n";

	
}

int32_t main() {_
	//tc(t)
		solve();
}




Measured memory_bytes: 34172
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	
    int o[100010] = {0};
    int e[100010] = {0};
    // vector<int> o(100010, 0), e(100010, 0);
    // vector<int> o(1e5 + 1, 0), e(1e5 + 1, 0);

	// when changing input process -> result doesn't change
    int a, b;
    for(int i=0;i<n/2;i++){
        cin>>a>>b;o[a]++;e[b]++;
    }
    /*
    rep(i, 1, n)
	{
		int x; cin >> x;
		if (i % 2 == 1) ++o[x];
		else ++e[x];
	}
    */
	int mxO, mxOId, secO, mxE, mxEId, secE;
	mxO = secO = mxE = secE = 0;
    // mxO = secO = mxE = secE = mxOId = mxEId = 0;
	
    for(int i=0;i<=100000;i++){
        if(o[i]>mxO){
            secO=mxO;mxO=o[i];mxOId=i;
        }
        else if(o[i]>secO)
        secO=o[i];
        if(e[i]>mxE){
            secE=mxE;mxE=e[i];mxEId=i;
        }
        else if(e[i]>secE)
        secE=e[i];
    }
    // rep(i, 0, 100005)
    // // rep(i, 0, 100000)
	// {
	// 	if (mxO < o[i])
    //     // if (mxO <= o[i])
	// 	{
	// 		secO = mxO;
	// 		mxO = o[i];
	// 		mxOId = i;
	// 	}
	// 	else if (secO < o[i]);
	// 	{
	// 		secO = o[i];
	// 	}
    //     if (mxE < e[i])
    //     // if (mxE <= e[i])
	// 	{
	// 		secE = mxE;
	// 		mxE = e[i];
	// 		mxEId = i;
	// 	}
	// 	else if (secE < e[i])
	// 	{
	// 		secE = e[i];
	// 	}
	// }

    // output process changed -> result doesn't change
    int ans;
    if(mxEId==mxOId)
    ans=max(secE,secO)+mxE;
    else
    ans=mxE+mxO;
    cout<<n-ans<<endl;
    return 0;
    /*
    if (mxOId != mxEId) cout << n - mxO - mxE << endl;
	else
	{
		int res = max(mxO + secE, secO + mxE);
		cout << n - res << endl;
	}
    */
}


Measured memory_bytes: 1024
from bisect import *
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
INF=10**12
C=[0]
D=[0]
for i in range(N):
  C.append(C[i]+A[i])
for i in range(M):
  D.append(D[i]+B[i])
P=0
for i in range(N+1):
  if K<C[i]:
    break
  P=max(P,i+bisect_right(D,K-C[i])-1)
print(P)


Measured memory_bytes: 132600
n = int(input())
def dfs(s):
    if int(s) > n:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


struct UnionFind {
    vector<ll> par;
        
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
    
    ll find(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(ll x, ll y) {
        return find(x) == find(y);
    }
    
    bool unite(ll x, ll 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;
    }
    
    ll size(ll x) {
        return -par[find(x)];
    }

    void print(ll x){
        rep(i,x){
            cout<<par[i]<<endl;
        }
        return ;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll d,g,ans=INF;
    cin>>d>>g;
    ll p[20],c[20];
    rep(i,d){
        cin>>p[i]>>c[i];
    }
    rep(bit,(1<<d)){
        ll s=0,cnt=0,rmax=-1;
        rep(i,d){
            if(bit & (1<<i)){
                s+=100*(i+1)*p[i]+c[i];
                cnt+=p[i];
            }
            else{
                rmax=i;
            }
        }
        if(s<g){
            ll s1=100*(rmax+1);
            ll need=(g-s+s1-1)/s1;
            if(need>=p[rmax]){
                continue;
            }
            cnt+=need;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int a,b,c,x,y,ans;
    cin >> a >> b >> c >> x >> y;
    if (x > y)
    {
        ans = min(a+b, 2*c) * min(x, y) + min(a, 2*c) * (x-y);
    } else {
        ans = min(a+b, 2*c) * min(x, y) + min(b, 2*c) * (y-x);
    }

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

Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::string S) {
  int result = 0;
  int c = 0;
  rep(i, S.size()) {
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      c++;
    } else {
      c = 0;
    }
    if (c > result) {
      result = c;
    }
  }

  cout << result << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main()
{
    int n;
    map<int, int> a;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
    {
        int num;
        scanf("%d", &num);
        a[num]++;
    }
    map<int, int>::iterator it;
    int sum = 0, ou = 0;
    for(it = a.begin(); it != a.end(); ++it)
    {
        sum++;
        if((it->second) % 2 == 0) ou++;
    }
    if(ou % 2 == 1) sum--;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4992
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
n,m=map(int,input().split())
uf=UnionFind(n)
p=list(map(int,input().split()))
for i in range(m):
  x,y=map(int,input().split())
  uf.union(x-1,y-1)
  
ans=0
for i in range(n):
  if uf.same(p[i]-1,i):
    ans+=1
print(ans)

Measured memory_bytes: 83900
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n-k; i++){
        if(a[i] < a[i+k]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 4400
n = int(input())
w = []
for i in range(n):
    w.append(input())
for i in range(n):
    for j in range(i+1,n):
        if w[i] == w[j]:
            print("No")
            exit()
for i in range(n - 1):
    if w[i][-1] != w[i + 1][0]:
        print("No")
        exit()
print("Yes")

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

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

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    
    for(int i=0 ; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    rep(i,N)   cin >> B[i];
    rep(i,N-1) cin >> C[i];

    int ans = 0;
    int pre_eat=-5;
    int eat = -1;

    for(int i=0;i < N; i++){
        int eat = A[i];
        ans += B[eat];
        if(eat == pre_eat+1){
            ans += C[pre_eat];
        }
        pre_eat = eat;
    }

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

Measured memory_bytes: 256
//#include<iostream>
//#include<vector>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<(int)(n); i++)

int main (void){
    int N,temp;
    string S;

    cin >> N >> S;

    vector<int> s(N+1,0);

    int cnt_E=0;

    rep(i,N){
        if(S[i] == 'E'){
            cnt_E++;
        }
        s[i] = cnt_E;
    }

    int m = N;

    rep(i,N){
        temp = i-s[i-1]+ (cnt_E-s[i]);
        m = min(temp,m);

    }

    cout << m;

}



Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

ll solve(ll N) {
    // 素因数分解 O(x^(1/2))
    auto PrimeFactor = [](ll x) {
        map<ll, ll> pr;
        for ( ll k = 2; k * k <= x; k++ ) {
            while ( x % k == 0 ) {
                pr[k]++;
                x /= k;
            }
        }
        if ( x > 1 ) pr[x]++;
        return pr;
    };
    map<ll,ll> pr = PrimeFactor(2*N);
    vector<ll> ps,as;
    for ( auto pp : pr ) {
        ps.push_back(pp.first);
        as.push_back(pp.second);
    }
    ll ans = 1LL<<60;
    int bm = ps.size();
    for ( int b = 0; b < 1<<bm; b++ ) {
        ll p1 = 1, p2 = 1;
        for ( int ii = 0; ii < bm; ii++ ) {
            if ( (b >> ii) & 1 ) {
                for ( int i = 0; i < as[ii]; i++ ) p1 *= ps[ii];
            } else {
                for ( int i = 0; i < as[ii]; i++ ) p2 *= ps[ii];
            }
        }
        ll x, y;
        extGCD(p1,p2,x,y);
        if ( y >= 0 ) {
            x += p2;
            y -= p1;
        }
        ans = min(ans,-p2*y);
    }

    return ans;
}

ll solve_small_1(ll N) {
    for ( ll k = 1; k <= 2*N; k++ ) {
        ll x = k*(k+1)/2;
        if ( x % N == 0 ) return k;
    }
    return -1;
}
struct Data {
    int id;
    ll N;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_n(1, 10000);

    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,3});
    ts.push_back({++id,11});
    for ( int i = 0; i < 100; i++ ) {
        int n = rnd_n(mt64);
        ts.push_back({++id,n});
    }
    
    for ( Data& t : ts ) {
        auto ans0 = solve(t.N);
        auto ans1 = solve_small_1(t.N);
        if ( ans0 != ans1 ) {
            cout << t.id << " " << ans0 << " " << ans1 << "\n";
        }
    }
    cout << "end" << "\n";
}

int main() {
    //test();
    ll N;
    cin >> N;
    ll ans = solve(N);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std; 
long long n,k,s,y,a[400500],i;
int main()
{
 cin>>n;
 for(i=0; i<n; i++)
 {
 	cin>>a[i];
 	a[i]-=i+1;;
 }
 sort(a,a+n);
 s=0;
 for(i=0;i<n;i++)
  s+=abs(a[i]-a[n/2]); 
  cout<<s;
  s+=s;
} 

Measured memory_bytes: 1792
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

FILE *in, *ans;
int tno;

int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outd(double d) {
	char s[128];
	sprintf(s, "%.10lf\n", d);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int getmin(int val1, int val2) {
	if (val1 < val2) {
		return val1;
	}
	else {
		return val2;
	}
}

int getmax(int val1, int val2) {
	if (val1 > val2) {
		return val1;
	}
	else {
		return val2;
	}
}

typedef struct data {
	int x, y;
} data;


int sortfnc(const void *v1, const void *v2) {
	data *d1 = (data *)v1;
	data *d2 = (data *)v2;

	if (d1->x > d2->x) {
		return 1;
	}
	else if (d1->x < d2->x) {
		return -1;
	}

	if (d1->y > d2->y) {
		return 1;
	}
	else if (d1->y < d2->y) {
		return -1;
	}

	return 0;
}

int n;
data datas[50];
data ptn[2500];
int pcnt;

int fnc2() {
	int i, j;

	n = geti();
	if (n <= 2) {
		return 1;
	}

	for (i = 0; i < n; i++) {
		datas[i].x = geti();
		datas[i].y = geti();
	}
	qsort(datas, n, sizeof(data), sortfnc);

	pcnt = 0;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			ptn[pcnt].x = datas[j].x - datas[i].x;
			ptn[pcnt].y = datas[j].y - datas[i].y;
			pcnt++;
		}
	}
	qsort(ptn, pcnt, sizeof(data), sortfnc);

	int x = ptn[0].x;
	int y = ptn[0].y;
	int len = 1;
	int max = len;
	for (i = 1; i < pcnt; i++) {
		if (x == ptn[i].x && y == ptn[i].y) {
			len++;
			max = getmax(max, len);
		}
		else {
			x = ptn[i].x;
			y = ptn[i].y;
			len = 1;
		}
	}

	return n - max;
}

int fnc1() {
	int ret = fnc2();
	outi(ret);
	return 0;
}

int main() {

#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc1();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc1();
#endif

	return 0;
}


Measured memory_bytes: 252
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add_self(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int add(int a,int b){
	int c=a+b;
	if(c>=mod){
		c-=mod;
	}
	return c;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

bool pos(ll mask,vi &a,vi &b,int n){
	for(int i=0;i<n;i++){
		vector<bool>vis(51);
		vis[a[i]]=true;
		for(int j=50;j>=1;j--){
			if(mask&(1ll<<j)){
				for(int k=0;k<=50;k++){
					if(vis[k]){
						vis[k%j]=true;
					}
				}
			}
		}
		if(!vis[b[i]]){
			return false;
		}
	}
	return true;
}

void solve(){
	int n;
	cin>>n;
	vi a(n),b(n);
	cin>>a>>b;
	ll tot=1ll<<51;
	tot--;
	ll ans=0;
	debug(pos(2,a,b,n));
	for(int i=50;i>=0;i--){
		if(pos(tot^(1ll<<i),a,b,n)){
			tot^=1ll<<i;
		}
		else{
			ans|=1ll<<(i);
		}
		debug(i,ans);
	}
	if(pos((1ll<<50)-1,a,b,n)){
		cout<<ans;
	}
	else{
		cout<<-1;
	}
	
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

vector<int> pt(100001, 0);
signed solve()
{
	int n, k, q;
	cin >> n >> k >> q;
	REP(i, q)
	{
		int a;
		cin >> a;
		a--;
		pt[a]++;
	}

	REP(i, n)
	{
		if (k - (q - pt[i]) > 0)
			print("Yes");
		else
			print("No");
	}

	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define INF (1<<24)

int M,N;
string field[150];
typedef vector<int> Group;
map<Group, int> memo;

int dfs(Group g, int used)
{
	if(g.size() == 0) return -1;
	if(g.size() == 1) return 0;

	if(memo.count(g)) return memo[g];
	
	int res = INF;
	for(int j=0; j<M; j++) {
		Group ngA, ngB;
		if((used >> j) & 1) continue;
		for(int l=0; l<g.size(); l++) {
			if(field[g[l]][j]=='0') ngA.push_back(g[l]);
			if(field[g[l]][j]=='1') ngB.push_back(g[l]);
		}

		sort(ngA.begin(), ngA.end());
		sort(ngB.begin(), ngB.end());

		int costA = dfs(ngA, used|(1<<j));
		int costB = dfs(ngB, used|(1<<j));

		res = min(res, max(costA, costB) + 1);
	}

	memo[g] = res;

	return memo[g];
}

int main()
{
	while(cin >> M >> N, (M||N)) {
		for(int i=0; i<N; i++) 
			cin >> field[i];

		memo.clear();

		Group init(N);
		for(int i=0; i<N; i++)
			init[i] = i;

		cout << dfs(init, 0) << endl;
	}
}

Measured memory_bytes: 2272
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N;
  int ans = 0;
  string s;

  cin >> s;

  N = s.size();
  for(int i = 1; i <= N; i++){
    if(i%2 == 1){
      if(s[i-1] == 'L'){
        ans++;
        continue;
      }
    }else{
      if(s[i-1] == 'R'){
        ans++;
        continue;
      }
    }
  }
  if(ans > 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
int A, B;
  string S;
  cin >> A >> B >> S;
  //入力終了
  
  for(int i=0; i<A+B+1; i++){
	if(i == A){
      if(S[i] != '-'){
        cout << "No" << endl;
       return 0; 
      }
    }
    else
      if(S[i]<'0' || '9'<S[i]){ 
		cout << "No" << endl;
       return 0; 
      }
  }
  
  cout << "Yes" << endl;

return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#define INFTY 1000000000

int nml[110];

int MM[110][110];

int min(int a, int b) {
	if (a >= b)return b;
	else return a;
}

int main() {
	int N;
	int j;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &nml[i], &nml[i + 1]);
	}

	for (int i = 1; i <= N; i++) {
		MM[i][i] = 0;
	}

	for (int l = 2; l <= N; l++) {
		for (int i = 1; i <= N - l + 1; i++) {
			j = i + l - 1;
			MM[i][j] = INFTY;
			for (int k = i; k <= j - 1; k++) {
				MM[i][j] = min(MM[i][j], MM[i][k] + MM[k + 1][j] + nml[i - 1] * nml[k] * nml[j]);
			}
		}
	}

	printf("%d\n", MM[1][N]);


	return 0;
}


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

int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = N%K;
    ans = min(ans, abs(ans-K));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# D - Banned K

from collections import Counter

N = int(input())
A = [int(a) for a in input().split()]

counter = Counter(A)
total = 0
for v in counter.values():
    total += v * (v - 1) // 2

for i in range(N):
    print(total - (counter[A[i]] - 1))


Measured memory_bytes: 26780
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ll d;
	cin >> d;
	ll n = 26;
	vector<ll> c(n);
	for (ll i = 0; i < n; ++i) cin >> c[i];
	vector<vector<ll>> s(d, vector<ll>(n));
	for (ll i = 0; i < d; ++i) {
		for (ll j = 0; j < n; ++j) {
			cin >> s[i][j];
		}
	}
	for (ll i = 0; i < d; ++i) {
		cout << distance(s[i].begin(), max_element(s[i].begin(), s[i].end())) + 1 << endl;
	}
}


Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>

using namespace std;


int main()
{
	int n = 0;

	cin >> n;

	vector<int> a = vector<int>(n);

	for (int i = 1; i < n; ++i)
	{
		int t = 0;
		cin >> t;
		a[t - 1]++;
	}

	for (int i = 0; i < n; ++i)
	{
		cout << a[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <list>
#include <cmath>
#define ll long long
using namespace std;

int main() {
    ll a, b;
    char c;
    cin >> a >> b;
    list< list < char > > bigger;
    list<char> smaller;
    for(ll i = 0; i < a; i++) {
        for(ll j = 0; j < b; j++){
            cin >> c;
            smaller.push_back(c);
        }
        smaller.push_back('#');
        smaller.push_front('#');
        bigger.push_back(smaller);
        smaller.clear();
    }
    for(ll j = 0; j < b; j++){
        smaller.push_back('#');
    }
    smaller.push_back('#');
    smaller.push_front('#');
    bigger.push_front(smaller);
    bigger.push_back(smaller);
    for(auto i: bigger) {
        for(auto j:i) cout << j;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 640
// ref: https://atcoder.jp/contests/abc116/submissions/4553155

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<int> h(N);
    for (int i=0; i<h.size(); i++) { cin >> h[i]; }

    int cnt = 0;
    while(*max_element(h.begin(), h.end()) > 0) {
        int i = 0;
        for (i=0; i<h.size(); i++) {
            if (h[i] != 0) { break; }
        }

        ++cnt;
        for (int j=i; j<h.size(); j++) {
            if (h[j] == 0) { break; }
            --h[j];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    vector<int> r(n);
    for(int i=0;i<n;i++){
        cin>>l[i]>>r[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=r[i]-l[i]+1;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

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

int main() {
  int k;
  cin >> k;
  string s;
  rep(i,k){
    s=s+"ACL";
  }
  cout << s << endl;
    

  return 0;

}

Measured memory_bytes: 3628
test_solver::Int->Int->Int
test_solver x y = if x == y then (x-1)*2
                            else let a = max x y in
                                 let b = min x y in
                                 let n' = floor (sqrt (fromIntegral (a*b))) in
                                 let n  = if n'*n'>= a*b then (n'-1) else n' in
                                 if n*(n+1) < a*b then (((n-b)*2)+1) + ((b-1)*2)
                                                  else ((n-b)*2) + ((b-1)*2)

n_do::Int->IO()
n_do 0 = return ()
n_do n = do
  abc<-getLine
  let a:b:[]=map read (words abc)
  print (test_solver a b)
  n_do (n-1)


main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  n_do n


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


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

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    else return gcd(y, x%y);
}

int main(int argc, char const *argv[]) {
    long long a, b;
    cin >> a >> b;

    long long ans = a * b / gcd(a, b);
    cout << ans << endl;
    return 0;
}


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

int main(){
  int K; cin >> K;
  string S; cin >> S;
  if (S.size() > K) {
    S = S.substr(0, K);
    S += "...";
  }
  cout << S<< endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 200200;
int n, a[N], tmp[N], ans; 
bool check(int x) {
	for(int i = 1; i <= 2 * n - 1; i++) tmp[i] = ( a[i] >= x );
	int l, r; l = r = n;
	for( ; l >= 1; l--, r++) {
		if(tmp[l] == tmp[l + 1]) return tmp[l];
		if(tmp[r] == tmp[r - 1]) return tmp[r];
	}
	return tmp[n] ^ (n & 1) ^ 1;
}
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= 2 * n - 1; i++) 
        scanf("%d", &a[i]);
    int l = 1, r = 2 * n;
    while(l <= r) {
    	int mid = (l + r) / 2;
    	if(check(mid)) l = mid + 1, ans = mid;
    	else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1792
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int d;
    cin >> d;
    assert(d == 365);
    vector<int> c(26);
    for(int i = 0; i < 26; i++){
        cin >> c[i];
    }
    vector<vector<int> > s(d, vector<int> (26));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++){
            cin >> s[i][j];
        }
    }
    int tries = 5000;
    int ans = 0;
    vector<int> fin;
    for(int tt = 0; tt < tries; tt++){
        vector<int> t(d), satisfaction(d);
        for(int i = 0; i < d; i++){
            t[i] = rng() % 26;
            t[i]++;
        }
        int sat = 0;
        vector<int> last(26);
        for(int i = 0; i < d; i++){
            last[t[i] - 1] = i + 1;
            sat += s[i][t[i] - 1];
            for(int j = 0; j < 26; j++){
                sat -= (i + 1 - last[j]) * c[j];
            }
            satisfaction[i] = sat;
        }
        // for(int i = 0; i < d; i++){
        //     cout << satisfaction[i] << "\n";
        // }
        // for(int i = 0; i < d; i++){
        //     cout << t[i] << "\n";
        // }
        int res = max(1000000 + satisfaction[d - 1], 0);
        if(res > ans || tt == 0){
            ans = res;
            fin = t;
        }
    }
    for(int i = 0; i < d; i++){
        cout << fin[i] << "\n";
    }
    // cout << ans << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define ll long long

using namespace std;


int main(){
  	int n,m,k;
  	ll temp;
  	cin >> n >> m >> k;
  	ll psA[n+1], psB[m+1];
  	memset(psA, 0, sizeof psA);
  	memset(psB, 0, sizeof psB);
	
  	for (int i = 1; i <= n; i++) {cin >> temp; psA[i] = temp + psA[i-1];}
  	for (int i = 1; i <= m; i++) {cin >> temp; psB[i] = temp + psB[i-1];}
  	
  	int maxx = 0;
  	int j = m;
  
  	for(int i = 0; i <= n; i++){
      if (psA[i] > k) break;
      while(psB[j] > k-psA[i]) j--;
      maxx = max(maxx, i+j);
    }
    cout << maxx << endl;
  	return 0;
}

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int t=0;
  for(int i=0;i<=(int)(N/100);i++){
    if((N-100*i)<=5*i)t=1;
  }
  if(t){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int H,N,A,sum=0;
  cin>>H>>N;
  for(int i=0;i<N;i++){
    cin>>A;
  sum=sum+A;
  }
  
  if(sum>=H){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
def solve():
     n = int(input())
     dic = set()
     for i in range(n):
          a = input().split()
          if a[0] == "insert":
               dic.add(a[1])
          if a[0] == "find":
               if a[1] in dic:
                    print("yes")
               else:
                    print("no")
solve()


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

vector<int> input(int N){
    int i;
    vector<int> out(N);

    for(i=0;i<N;i++)cin>>out[i];

    return out;
}

int main(){
    int N,i;
    int result=0;
    vector<int> B;
    cin>>N;
    B=input(N-1);

    result+=B[0]+B[N-2];

    for(i=1;i<=N-2;i++)result+=min(B[i],B[i-1]);
    cout<<result<<endl;
    return 0;
}

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

int main(int argc, char *argv[])
{
  int C1,C2,C3;
  while( scanf("%d %d %d",&C1,&C2,&C3) !=EOF){;
  int d = 0;
    for(int i = 1;i <=10;i++){
      if(i != C1&& i != C2&& i!=C3){
	if(C1 + C2 + i <=20){
	  d++;
	}
      }
    }
    if((double)d/7 >=0.5){//残り七枚でその当たり牌を引く確率
      cout <<"YES"<<endl;
    }else{
      cout <<"NO"<<endl;
    }
  }
  return 0;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> c(9,vector<int>(9));
    for (int i=1;i<=N;i++){
        int r = i%10;
        int t = i;
        while (t>=10){
            t/=10;
        }
        if (t>0&&t<=9&&r>0&&r<=9){
            t--;r--;
            c[t][r]++;
        }
    }
    ll sum = 0;
    for (int i=0;i<9;i++){
        for (int j=0;j<9;j++){
            sum += (ll)c[i][j]*c[j][i];
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b, c; cin >> a >> b;
	//string s; cin >> s;
	if (a + b >= 10)cout << "error";
	else cout << a + b;


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

typedef unsigned long long u64; 
typedef unsigned int uint;

using namespace std;

#define MIN(a, b) a < b ? a : b

#define MOD 1000000007

int main()
{
	int n;
	vector<int> a;
	vector<int> answer[2];
	vector<int> l;

	unsigned long long _4 = 0, _2 = 0, _1 = 0;

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		unsigned long long b;
		cin >> b;
		if( b % 4 == 0)
		{
			_4++;
		}
		else if(b % 2 == 0)
		{
			_2++;
		}
		else
		{
			_1++;
		}
	}

	if(_4*2+1 >= n)
	{
		cout << "Yes" << endl;
	}
	else if(_4*2 >= n - _2)
	{
		cout << "Yes" << endl;
	}
	else if(_2 >= 2 && _2 == n)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back({b,a});

    }

    sort(v.begin(),v.end());
    ll f=0;
    for(int i=0;i<n;i++){
        ll bb=v[i].first;
        ll aa=v[i].second;
        f+=aa;
        if(f>bb){
            cout<<"No"<<endl;
            return 0;
        }


    }
    cout<<"Yes"<<endl;



    return 0;
}


Measured memory_bytes: 6512
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

import heapq

N = I()
A = III()
B = III()

x = []
for i,b in enumerate(B):
    heapq.heappush(x,(-b,i))

counter = 0

while x:
    temp = heapq.heappop(x)
    i = temp[1]
    b = -temp[0]
    a = B[(i-1)%N]
    c = B[(i+1)%N]
    if b == A[i]:
        continue
    elif b<A[i]:
        print(-1)
        exit()
    else:
        d,m = divmod(b-A[i],a+c)
        if d==0:
            print(-1)
            exit()
        elif m == 0:
            B[i] = A[i]
            counter += d
        else:
            B[i] = A[i]+m
            heapq.heappush(x,(-B[i],i))
            counter += d

print(counter)

Measured memory_bytes: 123120
#include <stdio.h>

bool mp[105][105];

int main()
{
	int a,b;
	
	scanf("%d%d",&a,&b);
	
	a--;
	b--;
	
	for (int i = 0;i < 50;i++)
	{
		for (int j = 0;j < 100;j++)
		{
			mp[i][j] = 1;
		}
	}
	
	int x = 0,y = 0;
	
	while (a)
	{
		mp[x][y] = 0;
		
		a--;
		
		y += 2;
		
		if (y >= 100)
		{
			x += 2;
			y = 0;
		}
	}
	
	x = 99,y = 0;
	
	while (b)
	{
		mp[x][y] = 1;
		
		y += 2;
		
		b--;
		
		if (y >= 100)
		{
			x -= 2;
			y = 0;
		}
	}
	
	printf("100 100\n");
	
	for (int i = 0;i < 100;i++)
	{
		for (int j = 0;j < 100;j++)
		{
			if (mp[i][j]) printf("#");
			else printf(".");
		}
		
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 128