akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define prime 31
#define mp make_pair
#define INF 1000000000
#define mod 1000000007
#define fi first
#define se second
int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	ll ans=0;
	ll dp[n+1]={0};
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		dp[i+1]=dp[i]+arr[i];
	}
	for(ll i=1;i<n;i++)
	{
		ll x=(((dp[n]-dp[i]+mod)%mod)*(arr[i-1]%mod))%mod;
		ans=(ans+x)%mod;
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  int idx = 0;
  while(idx < n) {
    int cnt = 0;
    while(idx < n && a[idx++] == 1) ++cnt;
    chmax(ans, cnt+1);
  }
  cout << ans << endl;

  return 0;
}



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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int linearSearch( vector<ll> A, int n, int key ){
    int i = 0;
    A.at(n) = key;
    while ( A.at(i) != key ) i++;
    return i != n;
}

int main (void) {
    ll N, M, ans;
    ans = 0LL;
    scanf("%lld", &N);
    vector<ll> S(N+1);
    REP(int, i, 0, N) scanf("%lld", &S.at(i));
    scanf("%lld", &M);
    vector<ll> T(M);
    REP(int, i, 0, M) scanf("%lld", &T.at(i));

    REP(int, i, 0, M){
        ans += linearSearch( S, N, T.at(i) );
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3364
#include <iostream>

using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;
    if (a == 'H') {
        cout << b << endl;        
    } else if (b == 'H') {
        cout << 'D' << endl;
    } else {
        cout << 'H' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    tmp = 0
    for j in range(m):
        tmp += a[i][j] * b[j]
    tmp += c
    if tmp > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){

	int A,B,C;
	
	scanf("%d%d%d",&A,&B,&C);
	
	if(A<=B && B<=C){
		printf("%d",(B-A)+(C-B));
	
	}else if(B<=A && A<=C){
		printf("%d",(A-B)+(C-B));
		
	}else if(A<=C && C<=B){
		printf("%d",(C-A)+(B-C));
		
	}else if(B<=C && C<=A){
		printf("%d",(C-B)+(A-C));
		
	}else if(C<=B && B<=A){
		printf("%d",(B-C)+(A-B));
	
	}else if(C<=A && A<=B){
		printf("%d",(A-C)+(B-A));
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

int main(){
	ll t,d,p;
	while(scanf("%lld%lld%lld",&t,&d,&p),t){
		ll pre=1e9,ans=0;
		while(t--){
			ll x;
			scanf("%lld",&x);
			if(x>=p)pre=0;
			if(t&&pre<d)ans++;
			pre++;
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2104
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
// constexpr ll inf = 1ll<<61;
// constexpr ll mod = 1e9+7;

signed main(){
  int n,k; cin >> n >> k;
  vi h(n); rep(i,n) cin >> h[i];

  sort(all(h));
  int minv = 1ll<<60;
  rep(i,n-k+1)
    minv = min(minv, h[i+k-1]-h[i]);
  cout << minv << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

using namespace std;

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;

    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;

    i = 0; j = 0;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;

    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;

    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;

    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;

    if (p < r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main()
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++) {
        // マージソートとクイックソートの結果を比べる
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 4948
l, r = map(int, input().split())
ans = 2018

if r - l >= 2018:
    print(0)
else:
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            ans = min(ans, (i * j) % 2019)
    print(ans)


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

int main(){
    
    string w;
    cin >> w;
    int length = w.size();
    map<char,int>alphabet;
    map<char,int>::iterator it;

    for(int i = 0 ; i < length ; i++){
        alphabet[w[i]]++;
    }

    for (it=alphabet.begin(); it!=alphabet.end(); ++it){
         if(it->second % 2 != 0){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define MP make_pair
#define F first
#define S second

struct Node {
    int parentIndex;
    int diffFromParent;
};

int main() {
    int n, q;
    cin >> n >> q;
    auto nodes = vector<Node>(n, Node{-1, 0});

    // Union-Find で根ノートを見つけながら指し直す。返値は (根のインデックス，根からの距離)
    function<pair<int, int>(int)> root = [&](int index) {
        auto &node = nodes[index];
        if (node.parentIndex == -1) { // これが根ノードの場合
            return MP(index, 0);
        } else { // 親ノードがある場合
            auto p = root(node.parentIndex);
            auto rootIndex = p.F; // 親ノードの根のインデックス
            auto diffFromRoot = p.S; // 根からの距離
            node.parentIndex = rootIndex; // このノードの親ノードを根ノードに差し替え
            node.diffFromParent = diffFromRoot + node.diffFromParent; // 根からの距離をセット
            return MP(rootIndex, node.diffFromParent);
        }
    };

    rep(i, q) {
        int q;
        cin >> q;
        if (q == 0) { // 新たな関係が与えられたとき
            int x, y, z;
            cin >> x >> y >> z;
            auto rx = root(x); // xの属する木の根のインデックス，根からの距離
            auto ry = root(y); // yの属する木の根のインデックス，根からの距離
            if (rx.F != ry.F) { // xとyが異なる木に属するとき
                nodes[ry.F].parentIndex = rx.F; // yの属する木の根を，xの属する木の根の直属の子とする
                nodes[ry.F].diffFromParent = nodes[x].diffFromParent + z - nodes[y].diffFromParent; // 新しく張った辺の重みを回り込んで計算
            }
        } else {
            int x, y;
            cin >> x >> y;
            auto rx = root(x);
            auto ry = root(y);
            if (rx.F == ry.F) { // xとyが同じ木に属するとき
                PUTS(nodes[y].diffFromParent - nodes[x].diffFromParent); // 根からの距離の差を報告
            } else {
                puts("?");
            }
        }
    }
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans[101]={};
  for(int i=a;i<b;i++)ans[i]++;
  for(int i=c;i<d;i++)ans[i]++;
  int sum=0;
  rep(i,101){
    if(ans[i]==2)sum++;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string d;
    int in=0;
    cin>>d;
    s=d[0];
    for(int j=1;j<d.size();){
      if(d[j]=='-'&&in+1==s.size()){s+=d[j+2];in++;}
      else if(d[j]=='-')s[++in]=d[j+2];
      else if(in<=0)s=d[j+2]+s;
      else s[--in]=d[j+2];
      j+=3;
      //cout<<s<<endl;
    }
    cout<<s<<endl;
  }

}

Measured memory_bytes: 1212
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	vector<string> word(4);
	word[0] = "dream";
	word[1] = "dreamer";
	word[2] = "erase";
	word[3] = "eraser";
	
	string str;
	cin >> str;
	int pos = str.size()-1;
	while( pos>=0 ){
		bool flag = false;
		for(int i=0;i<4;++i){
			int size = word[i].size();
			string temp = "";
			if( pos-size+1 >= 0 ){
				temp = str.substr(pos-size+1,size);
			}
			if( word[i] == temp ){
				pos = pos-size;
				flag = true;
				break;
			}
		}
		if( flag == false ){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 512
/*
link: 
tags: 
*/
#include<bits/stdc++.h>
#define to_l(a) ((a)<<1)
#define to_r(a) ((a)<<1|1)
#define lowbit(a) ((a)&(-a))
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int int_inf=0x3f3f3f3f;
const ll ll_inf=0x3f3f3f3f3f3f3f3f;
const int max_n=1e5+5;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,j;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll max1=(b*d);
	max1=max(max1,c*b);
	max1=max(max1,c*a);
	max1=max(max1,a*d);
	cout<<max1<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<algorithm>
using namespace std;
const int P=1000000007;
int main() {
  int n;
  cin>>n;
  
  int arr[n];
  for(int i=0;i<n;i++){
  	cin>>arr[i];
  }
  sort(arr,arr+n);
  if(n%2==0){
  	int x=1;
  	for(int i=0;i<n;i+=2){
  	  if(arr[i]==i+1 and arr[i+1]==i+1){
  	  	x*=2;
  	  	x%=P;
  	  }else{
  	  	x=0;
  	  	break;
  	  }
  	}
  	cout<<x<<endl;
  }else{
  	int x=1;
  	if(arr[0]!=0){
  	  cout<<0<<endl;
  	}else{
	  	for(int i=1;i<n;i+=2){
	  	  if(arr[i]==i+1 and arr[i+1]==i+1){
	  	  	x*=2;
	  	  	x%=P;
	  	  }else{
	  	  	x=0;
	  	  	break;
	  	  }
	  	}
	  	cout<<x<<endl;  		
  	}
  	
  }
}



Measured memory_bytes: 640
N, M = map(int, input().split())
pS = [tuple(map(str, input().split())) for _ in range(M)]

AC = [False] * (N+1)
WA = [0] * (N+1)

pena = 0
for p, s in pS:
    p = int(p)
    if AC[p]:
        continue
    if s == 'WA':
        WA[p] += 1
    else:
        AC[p] = True
        pena += WA[p]
ac = sum(AC)
print(ac, pena)

Measured memory_bytes: 71256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n,m;
    cin >> n >> m;
//    cout << n << " " << m << endl;
  	vector<int> s(m);
  	vector<int> c(m);
    for (int i = 0; i < m; i++) {
        cin >> s[i];
        cin >> c[i];
    }
/*
    for (int i = 0; i < m; i++) {
        cout << s[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < m; i++) {
        cout << c[i] << " ";
    }
    cout << endl;
*/
    int f[n];
    int ans_ary[n];
    bool flgx[n];
  if(n == 0){
    n = 1;
  }
  for(int i = 0; i<3; i++){
        f[i] = n - i;
//        cout << f[i];
        ans_ary[i] = 0;
//        cout << ans_ary[i];
    	flgx[i] = false;
  }
//    cout << endl;
 
  
    for (int i = 0; i < m; i++) {
//        cout << "s[i] :" << s[i]  << endl;
//        cout << "ans_ary[s[i]] :" << ans_ary[s[i]]  << endl;
//        cout << "c[i] :" << c[i]  << endl;
        if(ans_ary[s[i]-1] == 0 || ans_ary[s[i]-1] == c[i]){
            ans_ary[s[i]-1] = c[i];
            flgx[s[i]-1] = true;
        }else{
            cout << "-1" << endl;
            return 0;            
        }
//        cout << ans_ary[i];
    }
//  cout << ans_ary[0] << " " << ans_ary[1] << " " << ans_ary[2] << endl;
//    cout <<  endl;
/*
  	if(ans_ary[0] == 0){
        cout << "-1" << endl;
        return 0;
      }else{
        ans_ary[f[n]] = 1;
      }
*/ 
 
//  	cout << flgx[0] << " " << flgx[1] << " " << flgx[2] << endl;
    if( (flgx[0] == false && flgx[1] == false && flgx[2] == false && n-1 != 0)
       	||((ans_ary[0] == 0 || ans_ary[1] == 0 || ans_ary[2] == 0) && (flgx[0] != true && n-1 != 0) )
      	){  
        for(int i = 0; 0<n; i++){
    //		cout << i << flgx[i] << endl;
            if(flgx[i] == false){
                ans_ary[i] = 1;
    //            cout << i << ans_ary[i] << endl;
                break;
            }      
    //        cout << i << ans_ary[i] << endl;
        }
    }
 
//  cout << ans_ary[0] << " " << ans_ary[1] << " " << ans_ary[2] << endl;
//  cout << n << n-1 << endl;
  	bool flg = false;
    for(int i = 0; i<n; i++){
        if( (i == n-1 && ans_ary[n-1] == 0 && flgx[3-n] != true)
            ||ans_ary[i] != 0 || flg == true){
            cout << ans_ary[i];
          	flg = true;
        }
    }
  	if(flg == false){
      cout << "-1" << endl;
      return 0;
    }      
    cout << endl;
 
}

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

typedef long long ll;
typedef pair<ll,ll> P;
template<typename T>

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


vector<T> compress(vector<T> &C1, vector<T> &C2){
    vector<T> vals;
    int N = (int)C1.size();
    REP(i,N){
        vals.push_back(C1[i]);
        vals.push_back(C1[i]+1);

        vals.push_back(C2[i]);
        vals.push_back(C2[i]+1);
    }

    sort(ALL(vals));
    vals.erase(unique(ALL(vals)), vals.end());

    REP(i,N){
        C1[i] = lower_bound(ALL(vals), C1[i]) - vals.begin();
        C2[i] = lower_bound(ALL(vals), C2[i]) - vals.begin();
    }

    return vals;
}



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

    vector<ll> X1(N);
    vector<ll> Y1(N);
    vector<ll> X2(N);
    vector<ll> Y2(N);
    REP(i,N){
        cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    }

    vector<ll> X = compress(X1, X2);
    vector<ll> Y = compress(Y1, Y2);

    int w = X.size();
    int h = Y.size();

    vector<vector<int>> G(h, vector<int>(w, 0));

    REP(i,N){
        G[Y1[i]][X1[i]] ++;
        G[Y1[i]][X2[i]] --;
        G[Y2[i]][X1[i]] --;
        G[Y2[i]][X2[i]] ++;
    }

    REP(i,h){
        REP(j,w-1){
            G[i][j+1] += G[i][j];
        }
    }
    REP(i,h-1){
        REP(j,w){
            G[i+1][j] += G[i][j];
        }
    }

    ll ans = 0;
    REP(i,h-1){
        REP(j,w-1){
            if(G[i][j]>0){
                ans += (Y[i+1] - Y[i]) * (X[j+1] - X[j]);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 253380
s=input()
character=["q","w","e","r","t","y","u","i","o","p","l","k","j","h","g","f","d","s","a","z","x","c","v","b","n","m"]
flag=0
for i in range(len(s)):
    if i==0:
        if s[i]!="A":
            print("WA")
            exit()
    elif 2<=i<=len(s)-2:
        if flag==1 and s[i]=="C":
            print("WA")
            exit()
        elif flag==0 and s[i]=="C":
            flag=1
        elif flag==0 and not s[i] in character:
            print("WA")
            exit()
        elif flag==1 and not s[i] in character:
            print("WA")
            exit()
    else:
        if not s[i] in character:
            print("WA")
            exit()
if flag==0:
    print("WA")
    exit()
print("AC")


Measured memory_bytes: 3064
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	number, _ := strconv.Atoi(scanner.Text())
	if number == 1 {
		fmt.Println("Hello World")
	} else if number == 2 {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		fmt.Println(a + b)
	}
}

Measured memory_bytes: 640
# Problem D - Line++

# input
N, X, Y = map(int, input().split())

# initialization
graph = [[0]*(N+1) for i in range(N+1)]
kyori_list = [0]*N

# dp count
for i in range(1, N+1):
    for j in range(i, N+1):
        if i==j:
            continue
        graph[i][j] = min(j-i, abs(X-i)+1+abs(Y-j))
for i in range(1, N+1):
    for j in range(1, N+1):
        if i==j:
            continue
        kyori_list[graph[i][j]] += 1

# output
for i in range(1, N):
    print(kyori_list[i])


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

int x, y;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> x >> y;
	if (x < y) {
		if (1LL * x * y >= 0)
			cout << y - x;
		else
			cout << abs(abs(x) - abs(y)) + 1;
	}
	else if (x < 0)
		cout << 1 + abs(y) - abs(x) + 1;
	else if (x == 0)
		cout << abs(y) + 1;
	else if (y >= 0)
		cout << 1 + (x - y) + (y > 0);
	else if (y <= -x)
		cout << (-y) - x + 1;
	else
		cout << 1 + x - (-y);
}


Measured memory_bytes: 256
using System;

public class AtCoderA
{
    static void Main()
    {
        string s = Console.ReadLine();

        string front = s.Substring(0, 2);
        string end = s.Substring(2, 2);

        int f = int.Parse(front);
        int e = int.Parse(end);

        bool fValid = 0 < f && f <= 12;
        bool eValid = 0 < e && e <= 12;


        if (fValid && eValid)
        {
            Console.WriteLine("AMBIGUOUS");
        }
        else if (fValid)
        {
            Console.WriteLine("MMYY");
        }
        else if (eValid)
        {
            Console.WriteLine("YYMM");
        }
        else
        {
            Console.WriteLine("NA");
        }
    }
}

Measured memory_bytes: 11092
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
  dp = np.zeros((5,C+1), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((5,C+1), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[0] = dp[-1]
    #上からアイテムを取って移動
    new_dp[1][1:] = np.maximum(new_dp[1][1:],dp[-1][1:]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[:,j] = np.maximum(new_dp[:,j],new_dp[:,j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[k,j] = max(new_dp[k,j],new_dp[k-1,j-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[-1] = np.maximum(new_dp[-1],new_dp[k])
    dp = new_dp
  ans = dp[-1,-1]
  return ans

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; 
   cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < n + 1; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    a[i+1] += a[i]; b[i+1] += b[i];
  }
  int res = 0;
  for (int i = 1; i < n + 1; i++) {
    res = max(res, a[i] + b[n] - b[i-1]);
  }
  cout << res << '\n';
  return 0;
  
}


Measured memory_bytes: 256
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	int res = 0;
      	res = a > b ? a-- : b--;
        res += Math.max(a, b);
      	System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include <iostream>

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

    if (a > b)
    {
        c += a;
        a--;
    }
    else
    {
        c += b;
        b--;
    }
    if (a > b)
    {
        c += a;
        a--;
    }
    else
    {
        c += b;
        b--;
    }
    std::cout << c << std::endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}L M(L i){return i?B[i]+M(i^i&-i):0;}L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}L K(L f){p=X[f];n=X[b];return p-n?M(O[E[p]<E[n]?p=n,a=b,b=f,a:f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!b|a;S(a=H[a],O[a]=b++))X[a]=p;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33388
n, k = map(int, input().split())
a = list(map(int, input().split()))

if k == 1:
    print(0)
    exit()

MOD = 10 ** 9 + 7

a.sort()

class ModCmb:
    def __init__(self, size):
        self.inv = [1] * (size + 1)
        self.fact = [1] * (size + 1)
        temp_inv = [1] * (size + 1)
        for i in range(2, size + 1):
            temp_inv[i] = ( -(MOD // i) * temp_inv[MOD%i] ) % MOD
        for i in range(2, size + 1):
            self.fact[i] = self.fact[i-1] * i % MOD
            self.inv[i] = self.inv[i-1] * temp_inv[i] % MOD

    def cmb(self, n, r):
        if n <= 1 or n == r:
            return 1
        elif r == 1:
            return n
        else:
            return  (self.fact[n] * self.inv[r] % MOD ) * self.inv[n-r] % MOD

mc = ModCmb(n)

mx = 0
mi = 0
temp = k
H = k - 1
L = n - k
while H < n:
    #print(temp, L, H)
    cmb = mc.cmb(temp - 1, k - 1)
    mi = (mi + a[L] * cmb) % MOD
    mx = (mx + a[H] * cmb) % MOD
    temp += 1
    L -= 1
    H += 1

print((mx + MOD - mi) % MOD)

Measured memory_bytes: 63344
<?php
/*
    Problem URL : http://abc054.contest.atcoder.jp/tasks/abc054_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d", $N, $M);

for ($i = 0; $i < $N; $i++) {
    $mapN[$i] = str_split(trim(fgets(STDIN)));
}
for ($i = 0; $i < $M; $i++) {
    $mapM[$i] = str_split(trim(fgets(STDIN)));
}

for ($x = 0; $x <= $N - $M; $x++) {
    for ($y = 0; $y <= $N - $M; $y++) {
        // echo ("\$x = $x : \$y = $y\n");
        $bool = true;
        for ($i = 0; $i < $M; $i++) {
            for ($j = 0; $j < $M; $j++) {
                if ($mapM[$i][$j] != $mapN[$x+$i][$y+$j]) {
                    $bool = false;
                }
            }
        }
        if ($bool == true) {
            echo "Yes\n";
            exit;
        }
    }
}

echo "No\n";


Measured memory_bytes: 3192
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]

    if all(i%2==0 for i in A):
        print('second')
    else:
        print('first')




resolve()

Measured memory_bytes: 44252
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
struct node{
	ll a,b;
}bra[1000006];
bool cmp1(node a1,node a2)
{
	return a1.b>a2.b;
}
bool cmp2(node a1,node a2)
{
	return a1.a-a1.b>a2.a-a2.b;
}
bool cmp3(node a1,node a2)
{
	return a1.a>a2.a;
}
int main(void)
{
	ll l=0,r=0;
	ll n;
	string s;
	cin>>n;
	for(ll j=0;j<n;j++)
	{
		bra[j].b=10000000;
		cin>>s;
		ll cnt=0,hav=0;
		for(ll i=0;i<s.size();i++)
		{
			if(s[i]=='(') cnt++;
			else
			{
				hav=1;
				cnt--;
				bra[j].b=min(bra[j].b,cnt);
			}
		}
		if(hav==0) bra[j].b=cnt;
		bra[j].a=cnt;
	}
	sort(bra,bra+n,cmp3);
	ll askd=0;
	while(askd<n)
	{
		if(bra[askd].a<0) break;
		askd++;
	}
	sort(bra,bra+askd,cmp1);
	sort(bra+askd,bra+n,cmp2);
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
//		printf("%lld %lld\n",bra[i].a,bra[i].b);
	}
	for(ll i=0;i<n;i++)
	{
		if(sum+bra[i].b<0) printf("No"),exit(0);
		sum+=bra[i].a;
	}
	if(sum!=0) printf("No");
	else printf("Yes");
}

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

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

    bool cood[109][109];
    for (int i = 0; i < 109; i++) {
        for (int j = 0; j < 109; j++) {
            cood[i][j] = false;
        }
    }

    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        
        if (a == 1) {
            for (int j = 0; j < h; j++) {
                for (int k = 0; k < x; k++) {
                    cood[j][k] = true;
                }
            }
        } else if (a == 2) {
            for (int j = 0; j < h; j++) {
                for (int k = x; k < w; k++) {
                    cood[j][k] = true;
                }
            }
        } else if (a == 3) {
            for (int j = 0; j < y; j++) {
                for (int k = 0; k < w; k++) {
                    cood[j][k] = true;
                }
            }
        } else if (a == 4) {
            for (int j = y; j < h; j++) {
                for (int k = 0; k < w; k++) {
                    cood[j][k] = true;
                }
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!cood[i][j]) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;



int main(){

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    int cnt = 0;
    rep(i, n-1) if(s[i] != s[i+1]) ++cnt;
    ppp(n-max(cnt-2*k+1, 1));
    return 0;
}


Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import floor
def main():
    x = int(readline())
    a = 100
    i = 0
    while a < x:
        a =  floor(a*(1.01))
        i+=1
    print(i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		const int INF = 1 << 29;
		int h = -1, n = -1;
		cin >> h >> n;
		if (h < 0) return 0;
		vector<int> a(n), b(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i] >> b[i];
		}
		vector<int> dp(20002, INF);
		dp[0] = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j <= 20000 - a[i]; ++j) {
				dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
			}
		}
		int ans = INF;
		for (int i = h; i <= 20000; ++i) {
			ans = min(ans, dp[i]);
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

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

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX (1e+9)+7
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
const int INF = 1e9 + 1;
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/


int main(void) {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            cin >> A[i][j];
    for(int i = 0; i < H; ++i)
        for(int j = 0; j < W; ++j)
            cin >> B[i][j];
 
    static bool dp[82][82][12800];
    dp[0][1][0] = dp[1][0][0] = true;
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            for(int k = 0; k < 12800; ++k) {
                int tmp = abs(A[i - 1][j - 1] - B[i - 1][j - 1]);
                if(dp[i - 1][j][k]) {
                    dp[i][j][k + tmp] = true;
                    dp[i][j][abs(k - tmp)] = true;
                }
                if(dp[i][j - 1][k]) {
                    dp[i][j][k + tmp] = true;
                    dp[i][j][abs(k - tmp)] = true;
                }
            }
        }
    }
 
    int ans = INF;
    for(int k = 0; k < 12800; ++k)
        if(dp[H][W][k]) ans = min(ans, k);
 
    cout << ans << endl;
    return 0;
}

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

    char chess(int h,int w){
        if((h+w)%2==0){
            return '#';
        }
        return '.';
    }
    int main()
    {
        int H,W;
        while(true){
            cin>>H>>W;
            if(H==0&&W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    cout<<chess(i,j);
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }



Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cassert>

#define ll long long

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

int main()
{
    int N, M;
    std::cin >> N >> M;
    dsu d(N);
    for(int i=0; i < M; i++) {
        int x, y;
        std::cin >> x >> y;
        --x; --y;
        d.merge(x, y);
    }
    int cnt = 0;
    for(int i=0; i < N; i++) {
        if(d.leader(i) == i)
            cnt++;
    }
    std::cout << cnt-1 << std::endl;
    return 0;
}

Measured memory_bytes: 3732
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println(a/b);
        System.out.println(a%b);
        double c =a;
        System.out.printf("%.5f %n", c/b);
    }
}


Measured memory_bytes: 26384
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long l, r;
	cin >> l >> r;

	if (l <= 2019 && 2019 <= r) {
		cout << 0 << endl;
		return 0;
	}

	long i, j;
	long left, right;
	long  ans = 2018;
	long imax = min(r, l + 2019);
	for (i = l; i < imax; i++) {
		for (j = l + 1; j <= imax; j++) {
			left = i % 2019;
			right = j % 2019;
			ans = min(ans, (left*right)%2019);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map &:to_i

r=0;csum=[0] + a.map{|x|r+=x}
sumA=csum[-1]
#p a,csum
#0.upto(n){|i|
#  (i+1).upto(n){|j|
#    p [i,j,csum[j]-csum[i]]
#  }
#}
#p a
#p [*0..n].combination(2).count{|i,j|
#  csum[j]==csum[i]
#}
r= csum.group_by(&:itself).map{|k, v|[k,v.size]}
p Hash[r].values.inject(0){|s,x|s+x*~-x/2}

Measured memory_bytes: 68712
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vll A(N+1);
  ll count = 0;
  for(int i = 0; i < N+1; i++){
    cin >> A.at(i);
    count += A.at(i);
  }
  count--;
  
  if(N == 0){
    if(A.at(0) == 1) cout << 1 << endl;
    else cout << -1 << endl;
    return 0;
  }

  vll num1(N+1, 0), num2(N+1, 0);
  num1.at(0) = 1; num2.at(0) = 0;
  ll counter = count;
  for(int i = 0; i < N; i++){
    if(num1.at(i) < A.at(i)){
        cout << -1 << endl;
        return 0;
      }
      else{
        num1.at(i) -= A.at(i);
        num2.at(i) += A.at(i);
      }

      ll bunki = min(count, num1.at(i));
      count -= bunki;
      num1.at(i+1) = bunki + num1.at(i);
  }
  if(count != 0){
    cout << -1 << endl;
    return 0;
  }
  if(num1.at(N) + num2.at(N) != A.at(N)){
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0LL;
  for(int i = 0; i <= N; i++){
    ans += num1.at(i);
    ans += num2.at(i);
  }
  cout << ans << endl;
}

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

int main() {
  ll k, a, b;
  cin >> k >> a >> b;

  ll ans = 1;

  if (b - a <= 2) {
    cout << 1 + k << endl;
    return 0;
  }
  if (k <= a - 1) {
    cout << 1 + k << endl;
    return 0;
  }

  ans = a;
  ll num = k - (a - 1);
  if (num % 2 == 0) {
    ans += num / 2 * (b - a);
  } else {
    ans += num / 2 * (b - a) + 1;
  }

  cout << ans << endl;
}


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

int sum(int n) {
  int sum=0;
  while (n>0) {
    sum += n%10;
    n/=10;
  }
  return sum;
}

int main() {
  int N, A, B, x=0; cin >> N >> A >> B;
  for (int i=1; i<=N; i++) {
    if ( sum(i) >= A && sum(i) <= B ) x+=i;
  }
  cout << x << endl;
}
    

Measured memory_bytes: 256
class Node
  attr_accessor :key, :left, :right, :parent
  def initialize key
    @key = key
  end
  
  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end
  
  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end
  
def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x
    x = z.key < x.key ? x.left : x.right
  end
  
  unless y
    $root = z
  else
    z.key < y.key ? y.left = z : y.right = z
    z.parent = y
  end
end

def find(x)
  y = $root
  while y
    return y if y.key == x
    z = y
    y = x < y.key ? y.left : y.right
  end
  return nil
end

def delete(x)
  y = find(x)
  z = position(y)
  if y.right.nil? || y.left.nil? then delete2(y,z)
  else
    p = y.right
    while p
      break if p.left == nil
      p = p.left
    end
    y.key = p.key
    z = position(p)
    delete2(p,z)
  end
end

def position(n)
  n.parent.right && n.parent.right.key == n.key
end

def delete2(y,z)
  if y.left.nil? && y.right.nil?
    z ? y.parent.right = nil : y.parent.left = nil
  elsif y.left.nil?
    if z 
      y.parent.right = y.right
      y.parent.right.parent = y.parent
    else 
      y.parent.left = y.right
      y.parent.left.parent = y.parent
    end
  elsif y.right.nil?
    if z
      y.parent.right = y.left
      y.parent.right.parent = y.parent
    else
      y.parent.left = y.left
      y.parent.left.parent = y.parent
    end
  end
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  elsif command == "find"
    if find($key.to_i) then puts "yes"
    else puts "no"
    end
  elsif command == "delete"
    delete($key.to_i)
  else
    $root.inorder
    puts
    $root.preorder
    puts
  end
end

Measured memory_bytes: 56968
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	int w,a,b; cin >> w >> a >> b;
	if (a+w < b){
		cout << b - (a+w) << endl;
	}else if(b+w < a){
		cout << a - (b+w) << endl;
	}else{
		cout << 0 << endl;
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */

int main() {
    int N; cin >> N;
    int A[N], B[N];
    int ans;
    rep(i, N) {
        cin >> A[i] >> B[i];
    }
    sort(A, A + N);
    sort(B, B + N);
    if(N % 2) {
        int l = A[N/2], r = B[N/2];
        ans = r - l + 1;
    }else {
        int l = (A[N/2] + A[N/2 - 1]);
        int r = (B[N/2] + B[N/2 - 1]);
        ans = r - l + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5204
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

int f(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

void Main(){
    int N;
    cin >> N;
    vec<ll> B(N-1);
    REP(i, N-1){
        cin >> B[i];
    }
    ll sum = B[0] + B[N-2];
    FOR(i, N-1, 1){
        sum += min(B[i], B[i-1]);
    }
    cout << sum << el;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define PER(i, a, b) for(int i = a; i >= b; i--)
#define LL long long
inline int read() {
    int x = 0, flag = 1;char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') flag = - 1;
        ch = getchar();
    }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * flag;
}

int n;
vector<int> G[10];
bool bo = false;
bool b[5];

inline void dfs(int x, int step) {
    //cout << x << " " << step << endl;
    if(step == 3 || bo) {
        bo = true;
        return;
    }
    b[x] = true;
    REP(i, 0, G[x].size() - 1) {
        if(!b[G[x][i]]) dfs(G[x][i], step + 1);
    }
    b[x] = false;
}

int main() {   
    REP(i, 1, 3) {
        int x = read(), y = read();
        G[x].push_back(y); G[y].push_back(x);
    }
    REP(i, 1, 4) dfs(i, 0);
    if(bo) cout << "YES" << endl;
    else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256