akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    int k, n;
    cin >> k >> n;
    lol a[n + 5];
    reps(i, n){
      cin >> a[i];
    }
    lol ans[n + 5] = {};
    reps(i, n){
      ans[i] += ans[i - 1] + a[i - 1];
    }
    a[0] = 0;
    a[n + 1] = 0;
    lol minv = a[n] - a[1];
    reps(i, n){
      minv = min({minv, a[i - 1] + (k - a[i]), (k - a[i + 1]) + a[i]});
    }
    cout << minv << '\n';
    return 0;
} 


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n, m;
    cin >> n >> m;
    cout << (n * (n - 1)/2) + (m * (m - 1)/2);
    return 0;
}


Measured memory_bytes: 256
def main():
    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data():
        return sys.stdin.readline().strip()

    def mdata():
        return map(int, data().split())

    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(10e9)

    s = data()
    t = data()
    dp = [[0] * (len(s) + 1) for i in range(len(t) + 1)]
    for i in range(1, len(t) + 1):
        for j in range(1, len(s) + 1):
            if s[j - 1] == t[i - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
    m = max(max(dp))
    ans = ''
    for i in range(len(t) - 1, -1, -1):
        for j in range(len(s) - 1, -1, -1):
            if dp[i + 1][j + 1] == m and s[j] == t[i]:
                ans = s[j] + ans
                m -= 1
                break
    out(ans+'\n')


if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
  int h;
  int n;
  cin >> h;
  cin >> n;
  int t=0;

  for(int i=0;i<n;i++){
    int tmp=0;
    cin >> tmp;
    t=t+tmp;
  }
  if(t>=h){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    ll ans = 0;
    vi l(n);
    REP(i, n){
        cin >> l[i];
    }

    sort(ALL(l));

    REP(i, n)
    {
        FOR(j, i+1, n)
        {
            auto itr = lower_bound(ALL(l), l[i] + l[j]);

            ans += (itr - l.begin()) - j - 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s;
    int n,m;
    while(1){
        cin >> s;
        n = 0;
        if(s[0] == '#')break;
         
        if(s[0] == 'y' || s[0] == 'h' || s[0] == 'n' || s[0] == 'u' || s[0] == 'j' || s[0] == 'm' || s[0] == 'i' || s[0] == 'k' || s[0] == 'o' || s[0] == 'l' || s[0] == 'p' ){
        m = 0;
        }
        else m = 1;
        for(int i = 1;i < s.size();i++){
            if(s[i] == 'y' || s[i] == 'h' || s[i] == 'n' || s[i] == 'u' || s[i] == 'j' || s[i] == 'm' || s[i] == 'i' || s[i] == 'k' || s[i] == 'o' || s[i] == 'l' || s[i] == 'p'){
                if(m == 1){
                    n++;
                    m = 0;
                }
            }
            else if(s[i] == 'b' || s[i] == 'g' || s[i] == 't' || s[i] == 'r' || s[i] == 'f' || s[i] == 'v' || s[i] == 'c' || s[i] == 'd' || s[i] == 'e' || s[i] == 'w' || s[i] == 's' || s[i] == 'x' || s[i] == 'z' || s[i] == 'a' || s[i] == 'q'){
                if(m == 0){
                    n++;
                    m = 1;
                }
            }
        }
        cout << n <<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=1e6+10,mod=1e9+7;


bool check(string s){
    int i=0,j=s.si-1;
    while(i<j){
        if(s[i]!=s[j])return 0;
        i++,j--;
    }
    return 1;
}

int main ()
{
    FASTIO
    long double x;
    cin >> x;
    x /= 3;
    long double siz = x*x*x;
    cout << fixed << setprecision(12) << siz << endl;
    return 0;
}
/**
*/


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

int arr[100005];
vector <string> ans;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z,x,c;
	cin>>z>>x>>c;
	int a;
	for(int q=1;q<=c;q++)
	{
		cin>>a;
		arr[a]++;
	}
	
	for(int q=1;q<=z;q++){
		if(x-c+arr[q]<=0)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
}

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

using namespace std;

int main()
{
   	string str1;
  	string str2;
    
    cin>>str1>>str2;
    
  	int len1 = str1.length();
  	int len2 = str2.length();
  
  	int dp[len1+1][len2+1];
  	
  	memset(dp,0,sizeof(dp));
  	
  	int maxi  = 0 ;
    
    int first;
    int second;
    
    first = second = 0 ;
    
  	for(int i=1;i<len1+1;i++)
    {
      	for(int j=1;j<len2+1;j++)
        {
          	if(str1[i-1]==str2[j-1])
            {
              	dp[i][j] = dp[i-1][j-1]+1;
            }
          
          	else
            {
              	dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
          
          	//maxi = max(maxi,dp[i][j]);
          if(maxi<dp[i][j])
          {
            	first = i ;
            	second = j;
          }
        }
    }
  	string s="";
 	 while(first && second)
     {
       	if(str1[first-1]==str2[second-1])
        {
          s = str1[first-1]+s;
          first--;
          second--;
        }
       	
       	else
        {
          	dp[first-1][second]>dp[first][second-1]?first--:second--;
        }
     }
  	cout<<s<<endl;
}

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

using namespace std;
typedef long long ll;


#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, 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 int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,k;cin>>n>>k;
  ll h[n+10];rep(i,0,n)cin>>h[i];
  if(n<=k){
    out(0);
    return 0;
  }
  sort(h,h+n,greater<ll>());
  ll ans=0;
  rep(i,0,n){
    if(i>k-1){
      ans+=h[i];
    }
  }

  out(ans);

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=100006;
int n,k,t1,t2,cnt=0,a[N],v[N],f[N],head[N];
struct edge{int nxt,to;}e[N<<1];
struct xd{
    int z,i;
    bool operator < (const xd &b) const {return z>b.z;}
}tmp,nw;
priority_queue<xd> q; 
inline void add(int u,int v){e[++cnt].nxt=head[u],e[cnt].to=v,head[u]=cnt;} 
inline int read(){
  int T=0,F=1; char ch=getchar();
  while(ch<'0'||ch>'9'){if(ch=='-') F=-1; ch=getchar();}
  while(ch>='0'&&ch<='9') T=(T<<3)+(T<<1)+(ch-48),ch=getchar();
  return F*T; 
} 
int main(){
	n=read();
	for(int i=1;i<n;++i) t1=read(),t2=read(),add(t1,t2),add(t2,t1);
	k=read();
	for(int i=1;i<=k;++i) tmp.i=read(),tmp.z=read(),a[tmp.i]=tmp.z,f[tmp.i]=1,q.push(tmp);
	while(!q.empty()){
	    tmp=q.top(),q.pop(),v[tmp.i]=1;
	    for(int i=head[tmp.i];i;i=e[i].nxt){
		    if(!v[e[i].to]){
			   if(f[e[i].to]&&a[e[i].to]!=tmp.z+1){printf("No\n"); return 0;}
			   v[e[i].to]=1,f[e[i].to]=1,nw.i=e[i].to,nw.z=tmp.z+1,a[nw.i]=nw.z,q.push(nw);
			}
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n;++i) printf("%d\n",a[i]);
	return 0;
}

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

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

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

    vector<int> L(N);
    REP(i, N) {
        cin >> L[i];
    }

    vector<int> L_cnt(3100, 0);
    REP(i, N) {
        L_cnt[L[i]]++;
    }

    vector<int> L_sum(3100, 0);
    REPS(i, 3100-1) {
        L_sum[i] = L_sum[i-1] + L_cnt[i];
    }

    int ans = 0;
    REP(i, N) {
        REP(j, N) {
            if (i == j) continue;

            int a = L[i];
            int b = L[j];
            int up = abs(a+b) - 1;
            int low = abs(a-b);

            int add = L_sum[up] - L_sum[low];
            if (low < a && a <= up) add--;
            if (low < b && b <= up) add--;

            ans += add;
        }
    }

    cout << ans / 6 << endl;

    return 0;
}

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

int main() {
  int K;
  int N;
  cin >> K >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  int dmax = K - vec[N - 1] + vec[0];

  for (int i = 0; i < N - 1; i++) {
    int d = vec[i + 1] - vec[i];
    dmax = max(d, dmax);
  }

  cout << K - dmax << endl;
}

Measured memory_bytes: 3952
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b, c;//入力
	int i = 0, j = 0, d = 0, kari = 0, old = 0, flag = 0; //内部で使用;
	int ans = 0; //出力

	cin >> a >> b >> c;
	rep(i, 100000000) {
		if ((a * i) % b == c) {
			cout << "YES" << "\n";
			return 0;
		}
	}
    cout << "NO" << "\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; ll a[N];
  map<ll, int>p; map<ll, int>q;
  rep(i, N){
      cin >> a[i]; p[a[i]+i]++; q[i-a[i]]++;
  }
  ll ans = 0;
  for(auto k: p){
      ans+=(ll)k.second*q[k.first];
      //cout << k.first << " " << k.second << " " << q[k.first] << endl;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 39404
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

using lint = long long;
constexpr lint INF = 1LL << 30;
constexpr int K = 40;

void solve() {
    int n;
    lint t;
    std::cin >> n >> t;

    std::vector<std::pair<lint, lint>> ps;
    std::vector<lint> ones;
    while (n--) {
        lint a, b;
        std::cin >> a >> b;
        if (a == 0) {
            ones.push_back(b);
        } else {
            ps.emplace_back(a + 1, a + b + 1);
        }
    }

    std::sort(ones.begin(), ones.end());

    n = ps.size();
    std::sort(ps.begin(), ps.end(),
              [](auto p, auto q) {
                  return (p.first - 1) * q.second > (q.first - 1) * p.second;
              });

    std::vector<lint> dp(K + 1, INF);
    dp[0] = 0;
    for (auto p : ps) {
        lint a, b;
        std::tie(a, b) = p;

        for (int k = K; k > 0; --k) {
            dp[k] = std::min(dp[k], dp[k - 1] * a + b);
        }
    }

    int ans = 0;
    for (int k = 0; k <= K; ++k) {
        if (dp[k] > t) break;

        int cnt = k;
        for (auto pt : ones) {
            dp[k] += pt + 1;
            if (dp[k] > t) break;
            ++cnt;
        }

        ans = std::max(ans, cnt);
    }

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

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

    solve();

    return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

class Solve
{
	public:

		int num1, num2;
		int m = -100;
		int ans[3];

		void input()
		{
			cin >> num1 >> num2;
		}

		void solve()
		{
			ans[0] = num1 + num2;
			ans[1] = num1 - num2;
			ans[2]= num1 * num2;

			rep(i, 3)
			{
				if(ans[i] > m)
				{
					m = ans[i];
				}
			}
		}

		void output()
		{
			cout << m << endl;
        }
};

Solve s;
int main()
{
    s.input();
	s.solve();
	s.output();
	return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    REP(i, N) {
        int v;
        cin >> v;
        V.at(i) = v;
    }
    int ans = 0;
    int O = min(N, K);
    for (int i = 1; i <= O; i++) {
        if (i * 2 < O)
            continue;
        for (int j = -i; j < 1; j++) {
            priority_queue<int, vector<int>, greater<int>> pq;
            for (int k = 0; k < i; k++) {
                pq.push(V.at((N + j + k) % N));
            }
            int sum = 0;
            REP(n, K - i) {
                if (pq.empty() || pq.top() >= 0)
                    break;
                else
                    pq.pop();
            }
            while (!pq.empty()) {
                sum += pq.top();
                pq.pop();
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

// PRACTICE //

int X;

int main() {
    cin >> X;
    if ( X == 7 or X == 5 or X == 3 ) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    REP(i,N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int mod = (int)1e9+7; 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		sc.close();
		
		long ans = 1;
		//素因数分解して、素数ごとに組み合わせ計算に持ち込む
		for(int i=2;i*i<=M;i++) {
			if(M % i==0) {
				int cnt = 0;
				while(M % i ==0) {
					cnt++; M /= i;
				}
				ans *= calcComb(N-1+cnt, N-1); 
				ans %= mod;
			}
		}
		if(M!=1)ans *= calcComb(N-1+1, N-1);
		ans %= mod;
		System.out.println(ans);
	}
	//aのp乗を求めるアルゴリズム(mod付き)
	static long modpow(long a,int p) {
		if(p==0)return 1;
		if(p%2==0) {
			int halfP = p/2;
			long root = modpow(a, halfP);
			return  root * root % mod;
		}else {
			return a*modpow(a,p-1)% mod;
		}
	}
	
	//逆元を用いた組み合わせ計算
	static long calcComb(int a, int b) {
		if(b > a-b)return calcComb(a,a-b);
		long ansMul = 1;
		long ansDiv = 1;
		for(int i=0;i<b;i++) {
			//組み合わせの分母分子をそれぞれ作っていく（毎回割るのはmod的に不可（割れるのは互いに素の時だけ））
			ansMul *= (a-i); ansMul %= mod;
			ansDiv *= (i+1); ansDiv %= mod;
		}
		//ansMul / ansDivを行いたいが、modの元で正しくするために、割り算は逆元を用いる。
		long ans = ansMul * modpow(ansDiv, mod-2)%mod;
		return ans;
	}
}

Measured memory_bytes: 22996
k = int(input())

L = list(range(10))
i = 1
while len(L) <= k:
    Li = L[i]
    a = Li % 10
    for b in range(a - 1, a + 2):
        if b < 0 or b > 9:
            continue
        L.append(Li * 10 + b)
    i += 1

print(L[k])


Measured memory_bytes: 13520
#include<iostream>
int a[101][101]={0};
int d[101]={0};//vを最初に発見した発見時刻
int f[101]={0};//vの隣接リストを調べ終えた完了時刻
int used[101]={0};//見つけたかどうか
int t=1;
int n;

void search(int i){
  d[i]=t++;
  used[i]++;
  int j;
  for(j=0; j<n; j++){
    if(a[i][j]==1 and used[j]==0){
      search(j);
    }
  }
  f[i]=t++;
}
int main(){
  int k;
  int u,v;
  std::cin>>n;
  int i,j;
  //行列の初期化
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      a[i][j]=0;
    }
  }
  for(i=0; i<n; i++){
    std::cin>>u;
    std::cin>>k;
    for(j=0; j<k; j++){
      std::cin>>v;
      a[u-1][v-1]=1;
    }
  }
  for(i=0; i<n; i++){
    if(used[i]==0){
      search(i);
    }
  }
  for(i=0; i<n; i++){
    std::cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
  return 0;
}


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

int main() {
    int d, n;
    cin >> d >> n;

    if (n != 100) {
        if (d == 0) {
            cout << n << endl;
        } else if (d == 1) {
            cout << n * 100 << endl;
        } else {
            cout << n * 10000 << endl;
        }
    } else {
        if (d == 0) {
            cout << n + 1 << endl;
        } else if (d == 1) {
            cout << (n + 1) * 100 << endl;
        } else {
            cout << (n + 1) * 10000 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
readline = sys.stdin.readline
dq = deque()
for _ in range(int(input())):
    ss = readline().strip()
    if ss == "deleteFirst":
        del dq[0]
    elif ss == "deleteLast":
        del dq[-1]
    else:
        c, s = ss.split()
        s = int(s)
        if c == "insert":
            dq.appendleft(s)
        elif c == "delete":
            if s in dq:
                dq.remove(s)
print(*dq)



Measured memory_bytes: 45944
#include <iostream>
#include <stack>
#include <complex>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,n) loop(i,0,n)
#define all(c) (c).begin(), (c).end()
typedef complex<int> P;

const int MAX_M = 1.5e6+10;
const int SIZE = 2000;
int ps[MAX_M/2];
bool isp[MAX_M];
int grid[SIZE][SIZE]={};
P itop[MAX_M];
pair<int,int> dp[SIZE][SIZE];

int cnt_p = 0;

void make_es(){
    fill(isp,isp+MAX_M,true);
    isp[0]=isp[1]=false;
    rep(i,MAX_M){
        if(!isp[i]) continue;
        ps[cnt_p++] = i;
        for(int j=i<<1; j<MAX_M; j+=i){
            isp[j] = false;
        }
    }
}

P const ii(0,1);

int n,m;

pair<int,int> rec(int y, int x){
    // cout << x << " " << y << endl;
    if(dp[y][x].first!=-1) return dp[y][x];

    pair<int,int> res(0,0);
    if(isp[grid[y][x]]){
        res.first = 1;
        res.second = grid[y][x];
    }

    pair<int,int> best(0,0);
    loop(i,-1,2){
        if(grid[y+1][x+i]<=m){
            auto t = rec(y+1,x+i);
            best = max(t,best);
        }
    }

    if(best.first != 0){
        res.first += best.first;
        res.second = best.second;
    }

    dp[y][x] = res;
    return res;

    // if(grid[y][x] > m) return 0;
    // int res = isp[grid[y][x]];
    // int k = 0;
    // loop(i,-1,2){
    //     k = max(k, rec(y+1,x+i));
    // }
    // res += k;
    // dp[y][x] = res;
    // return res;
}

pair<int,int> solve(int k){
    P p = itop[k];
    return rec(p.real(), p.imag());
}

int main(){
    make_es();

    P p(SIZE/2,SIZE/2);
    P dir(0,1);
    for(int i=1; i<MAX_M; i++){
        grid[p.real()][p.imag()] = i;
        itop[i]=p;
        p+=dir;
        P q = p+dir*ii;
        if(grid[q.real()][q.imag()] == 0){
            dir*=ii;
        }
    }

    while(cin>>m>>n, n+m){
        auto t = make_pair(-1,-1);
        rep(i,SIZE)rep(j,SIZE) dp[i][j] = t;
        auto ans = solve(n);
        cout << ans.first << " " << ans.second << endl;
    }
}

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

int main() {
  int n,q,count=0;
  string s;
  cin>>n>>q>>s;
  int p[n+1] = {0};
  vector<int> l(q),r(q);
  for(int i=0; i<n; i++){
    if(i>0 && s[i-1]=='A' && s[i]=='C') p[i+1] = p[i] + 1;
    else p[i+1] = p[i];
  }
  for(int i=0; i<q; i++){
    int l,r,ans;
    cin>>l>>r;
    ans = p[r] - p[l-1];
    if(p[l] - p[l-1] == 1) ans--;
    cout<<ans<<endl;
  }
}

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

using namespace std;

int main() {

    int n, x, l, count1=1, count2=0;
    cin >> n >> x;
    int listaL[n];

    for(int i=0; i<n; i++) {

        cin >> l;
        listaL[i] = l;
        count2 = count2 + listaL[i];

        if(count2 <= x){
            count1 = count1 + 1;
        }

    }

      
    cout << count1 << endl;

}

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

int main()
{
    int N, Alice=0, Bob=0;
  	cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    for(int j=0;j<a.size();j++) {
        if(j%2 == 0)    Alice += a.at(j);
        else Bob += a.at(j);
    }

    cout << Alice - Bob << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	string w;
	cin >> w;
	int lim = SZ(w) - 1;
	map<char,int> mp;
	FOR(i, 0, lim) {
		mp[w[i]]++;
	}
	for (auto m : mp) {
		if (m.second % 2 == 1) {
			ps(No);
			return 0;
		}
	}
	ps(Yes);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int k,sum=0;
  vector<int>a(3);
  for(int i=0; i<3; i++){
    cin >> a.at(i);
  }
  cin >> k;
  sort(a.begin(),a.end());
  for(int i=1; i<=k; i++){
    a.at(2)=a.at(2)*2;
  }
  sum=a.at(0)+a.at(1)+a.at(2);
  cout << sum << endl;
}


Measured memory_bytes: 256
open System

let primeFactors (n: int64)=
    let add (x: int64) (m: Map<int64, int>): Map<int64, int> =
        match Map.tryFind x m with 
        | Some(cnt) -> Map.add x (cnt+1) m
        | None -> Map.add x 1 m 
    let rec f n i acc =
        if n % i = 0L then
            f (n / i) i (add i acc)
        elif n < i * i && n <> 1L then 
            add n acc 
        elif n < i * i then 
            acc 
        else 
            f n (i + 1L) acc 
    f n 2L Map.empty

let getN (n: int): int =
    let rec f n proposed acc =
        if n >= proposed then 
            f (n - proposed) (proposed + 1) (acc + 1)
        else 
            acc 
    f n 1 0 

Console.ReadLine()
|> int64
|> primeFactors
|> Map.map(fun _ v -> getN v)
|> Map.toList 
|> List.map snd 
|> List.sum 
|> printfn "%i" 

Measured memory_bytes: 30268
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) ((v).begin()), ((v).end())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d});
    return 0;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
lis = list(map(int, input().split()))

roop = [1]
count = [0 for i in range(n)]
count[0] += 1

#start_index = 0
#end_index = n-1
for i in range(n):
    next_city = lis[roop[-1] - 1]
    if count[next_city-1]: #if already visit "next_city", "next_city" is start city of roop, roop[i] is end city of roop
        end_index = i
        for j, city in enumerate(roop):
            if city == next_city:
                start_index = j
        break
    else:
        roop.append(next_city)
        count[next_city-1] += 1

if k <= start_index:
    print(roop[k])
else:
    roop_len = end_index - start_index + 1 #length of roop
    distance = (k - start_index) % roop_len #distance betoween start_index and destination
    print(roop[start_index + distance])

Measured memory_bytes: 32380
#include <stdio.h>

int main()
{
    int N;
    double a,result;
    scanf("%d",&N);
    if(N % 2 == 0)result = (double)(N / 2) / N;
    else result = (double)(N / 2 + 1) / N;
    printf("%lf",result);
    return 0;
}

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

struct edge {
    int to;
    int id;
};

int N;
vector<vector<edge>> G;
vector<int> ans;

void dfs(int n, int p = 0, int bc = 0) {
    int nowColor = 1;
    rep(i, G[n].size()) {
        if(G[n][i].to == p) continue;
        if (nowColor == bc) nowColor++;
	    ans[G[n][i].id] = nowColor;
        dfs(G[n][i].to, n, nowColor);
        nowColor++;
    }
}

int main() {
    cin >> N;
    G.resize(N);
    ans.resize(N);

    rep(i, N - 1) {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        G[from].push_back({to, i});
        G[to].push_back({from, i});
    }
    dfs(0);

    int mx =0;
    rep(i,N-1) mx = max(mx,ans[i]);
    cout << mx << endl;
    rep(i,N-1){
        cout << ans[i] << endl;
    }
}


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

unordered_set<int> seen;

int dfs(int i, vector< vector<int> > &fr){
  seen.insert(i);
  int ret = 1;
  
  for(auto e : fr[i]){
    if(seen.find(e) == seen.end())
      ret += dfs(e, fr);
  }
  return ret;
}

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

  vector< vector<int> > fr = vector< vector<int> >(N, vector<int>());
  vector< vector<int> > br = vector< vector<int> >(N, vector<int>());
  
  for(int i = 0; i < M; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    fr[a].push_back(b);
    fr[b].push_back(a);
  }

  for(int i = 0; i < K; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    br[a].push_back(b);
    br[b].push_back(a);
  }

  vector<int> cl = vector<int>(N, -1);

  for(int i = 0; i < N; i++){
    if(cl[i] >= 0) continue;
    seen.clear();
    
    int tmp = dfs(i, fr);
    for(auto e: seen){
      cl[e] = tmp - fr[e].size() - 1;
      for(auto f: br[e]){
        if(seen.find(f) != seen.end()){
          cl[e]--;
        }
      }
    }
  }

  cout << cl[0];
  for(int i = 1; i < N; i++){
    cout << ' ' << cl[i];
  }
  cout << endl;
}

Measured memory_bytes: 16932
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cassert>
#include <iomanip>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double ld;
 
const ll inf=1000000000000000LL;
const int maxn=5e5+10;
const int mod=1000000007;
const int linf=10000000;


int main(){
    //freopen("b.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ao=0,a2=0,a4=0;
    for(int it:a){
        if(it%4==0)
            a4++;
        else if(it%2==0)
            a2++;
        else
            ao++;
    }
    if(ao<=a4) cout<<"Yes"<<endl;
    else if(ao-1==a4){
        if(a4==0){
            cout<<"No"<<endl;
            return 0;
        }
        if(a2==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
} 

Measured memory_bytes: 888
use proconio::input;
use std::vec::Vec;

fn main() {
	input! {
		n : usize,
		m: usize,
		v: [isize; n],
	}

	//
	let total: isize = v.iter().sum();
	let count = v.iter().filter(|e| 4 * (m as isize) * *e >= total).count();
	println!("{}", if count >= m { "Yes" } else { "No" });
}


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

int main()
{
  int i, j, k, b, d, n, m;
  char buf[16] = {0};
  buf[15] = '\0';
  buf[14] = '\n';
  char *line = NULL;
  size_t linecap = 0;

  fscanf(stdin, "%d\n", &n);
  int *a = (int*)malloc(sizeof(int)*n);
  getline(&line, &linecap, stdin);
  a[0] = 0;  
  i=0;
  for (char *p=line; *p!='\n'; p++) {
    if (*p == ' ') {
      i++;
      p++;
      a[i] = *p-'0';
    } else {
      a[i] = a[i] * 10 + *p - '0';
    }
  }
  
  fscanf(stdin, "%d\n", &m);
  
  getline(&line, &linecap, stdin);
  char *p=line;
  
  i = j = 0;
  for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
  p++;
  j++;  
  do {
    if (a[i]<b) {
      i++;
    } else if (a[i]>b) {
      j++;
      for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
      p++;
    } else {
      d = b;
      if (d==0) {
	fputs("0\n", stdout);
      } else {
	for (k=13; d>0; k--, d/=10)   buf[k] = '0' + (d%10);
	fputs(buf+k+1, stdout);
      }
      i++;
      for (b = 0; *p>='0'; b = b * 10 + *(p++) - '0');
      p++;
      j++;
      if (i>=n && j>=m) break;
    }
  } while (i<=n && j<=m);
  return 0;
}



Measured memory_bytes: 4468
<?php
list($n,$d)=explode(" ",trim(fgets(STDIN)));
$d=(int)$d*$d;
$ans=0;
while($n>0){
  list($x,$y)=explode(" ",trim(fgets(STDIN)));
  $sum=(int)($x*$x+$y*$y);
  if($d>=$sum){
    ++$ans;
  }
  --$n;
}
echo $ans;

Measured memory_bytes: 16172
N = int(input())
A = [int(i) for i in input().split()]

if N == 1:
    print(1)
else:
    pre = A[0]
    flg = 0
    ans = 1
    for i in range(1, N):
        now = A[i]
        diff = now - pre
        if flg == 1:
            if diff >= 0:
                pass
            else:
                ans += 1
                flg = 0
        elif flg == -1:
            if diff <= 0:
                pass
            else:
                ans += 1
                flg = 0
        else:
            if diff > 0:
                flg = 1
            elif diff < 0:
                flg = -1
            else:
                pass
        pre = now
        # print("i: {}, A[i]: {}, flg: {}, ans:{}".format(i, A[i], flg, ans))
    print(ans)


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

int main(){
  char s[100], t[100];
  scanf("%s %s", s, t);

  if(strncmp(s, t, strlen(s))!=0){
    printf("No\n");
  }else{
    if(strlen(t)!=strlen(s)+1)
      printf("No\n");
    else
      printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 1620
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!!

    val isFirst0 = S.first() == '0'
    val x0 = S.split("1").map { it.length }.filter { it != 0 }
    val x1 = S.split("0").map { it.length }.filter { it != 0 }

    val k = Math.min(K, x0.size)
    val result = mutableListOf<Int>()
    for (i in 0..(x0.size - k)) {
        val y0 = x0.subList(i, i + k)
        val y1 = if (isFirst0) {
            if (i == 0) {
                x1.subList(0, Math.min(k, x1.size))
            } else {
                x1.subList(Math.max(i - 1, 0), Math.min(i + k, x1.size))
            }
        } else {
            if (i == 0) {
                x1.subList(0, Math.min(k + 1, x1.size))
            } else {
                x1.subList(i, Math.min(i + k + 1, x1.size))
            }
        }
        result.add(y0.sum() + y1.sum())
    }
    println(result.max())
}

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

char str[105];
stack<char> s;

int main() {
	// freopen("input.in", "r", stdin);
	// freopen("output.o", "w", stdout);
	int n;
	scanf("%d", &n);
	scanf("%s", str + 1);
	int cnt = 0, cnt2 = 0;
	for (int i = 1; i <= n; i++) {
		if (str[i] == '(') {
			if (s.size() == 0) s.push('(');
			else if (s.top() == '(') s.push('(');
			else {
				cnt++;
			}
		} else {
			if (s.size() == 0) cnt2++;
			else if (s.top() == '(') s.pop();
			else {
				cnt2++;
			}
		}
	}
	cnt += s.size();
	for (int i = 0; i < cnt2; i++) printf("(");
	printf("%s", str + 1);
	for (int i = 0; i < cnt; i++) printf(")");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> sx(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
        sx[i] = x[i];
    }

    sort(sx.begin(),sx.end());
    int low = sx[n/2-1];
    int high = sx[n/2];

    for(int i = 0; i < n; i++){
        if(x[i]<=low){cout << high << endl;}
        else{cout << low << endl;}
    }


    return 0;

}


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

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

    if(h==1 || w==1){
        cout << 1 << endl;
        return 0;
    }


    ll ans;
    if((h*w)%2LL==0){
        ans = h*w;
        ans /= 2LL;
        cout << ans << endl;
    }
    else{
        ans = h*w;
        ans /= 2LL;
        ans += 1LL;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
int a[105][2];
int f[105][2];

int max(int a,int b){ return a>b?a:b; }

int main(){
    int n;
    scanf("%d",&n);
    for(int t = 0; t < 2; t++){
        for(int i = 1; i <= n; i++) scanf("%d",&a[i][t]);
    }
    f[0][0] = 0;
    for(int i = 1; i <= n; i++){
        f[i][0] = f[i-1][0]+a[i][0];
        f[i][1] = max(f[i-1][1],f[i][0])+a[i][1];
    }
    printf("%d\n",f[n][1]);
    return 0;
}


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

int dfs(int start, map<int, vector<int>> graph, set<int> visited, int N)
{

    // add to visited
    visited.insert(start);

    // base case
    if (visited.size() == N)
    {
        return 1;
    }

    // recursive

    int result = 0;
    for (int i : graph[start])
    {
        if (!visited.count(i))
        {
            result += dfs(i, graph, visited, N);
        }
    }

    return result;
}

int main()
{
    int N, M;
    cin >> N >> M;
    map<int, vector<int>> graph;

    // init connected list
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        if (!graph.count(a))
        {
            graph[a] = {};
        }
        graph[a].push_back(b);

        if (!graph.count(b))
        {
            graph[b] = {};
        }
        graph[b].push_back(a);
    }

    cout << dfs(1, graph, {}, N) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n,x,sum=0;
  cin >> n;
  x = n;

  while(x > 0){
    sum += (x % 10);
    x /= 10;
  }

  if(n % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

typedef std::pair<std::string, int> MP;

int n, q;
std::queue<MP> que;

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

	rep(i, n){
		std::string name;
		int t;
		std::cin >> name >> t;
		que.push(MP(name, t));
	}

	int now = 0;
	while (!que.empty()){
		MP mp = que.front();
		que.pop();

		if (mp.second > q)que.push(MP(mp.first, mp.second - q)), now += q;
		else {
			std::cout << mp.first << " " << now + mp.second << std::endl;
			now += mp.second;
		}
	}

	return 0;
}

Measured memory_bytes: 4404
var inputRaw = require('fs').readFileSync('/dev/stdin', 'utf8')
var rows = inputRaw.trim().split('\n');
var N = Number(rows[0]);
var h = rows[1].split(' ').map(Number);
var dp = Array(N).fill(0);

function solve() {
  for (var i = 0; i < N - 1; i++) {
    if (i <= 0) {
      dp[i + 2] = Math.abs(h[i] - h[i + 1]);
    } else {
      var a = dp[i + 1] + Math.abs(h[i] - h[i + 1]);
      var b = dp[i] + Math.abs(h[i - 1] - h[i + 1]);
      dp[i + 2] = Math.min(a, b);
    }
  }
  return dp[N];
}

console.log(solve());


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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int n;
    cin >> n;
    VI b(n-1,0);
    VI a(n,0);
    int count = 0;

    rep(i,n-1) {
        cin >> b[i];
    } 

    rep(i,n-1) {
        if(i==0) {
            a[i] = b[i];
            a[i+1] = b[i];
        }
        else {
            a[i] = min(a[i],b[i]);
            a[i+1] = b[i];
        }
    }

    rep(i,n) {
        count += a[i];
    }

    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,k,t=0;
vl a,b;

ll f(ll x){
	ll res=0,sa=a.size(),sb=b.size();
	if(x>=0){
		res+=sa*sb;
		for(int i=0;i<sa;i++){
			int it=upper_bound(a.begin(),a.end(),x/a[i])-a.begin();
			it=min(it,i);
			res+=it;
		}
		for(int i=0;i<sb;i++){
			int it=upper_bound(b.begin(),b.end(),(b[i]?x/b[i]:inf))-b.begin();
			it=min(it,i);
			res+=it;
		}
	}
	else{
		x*=-1;
		for(int i=0;i<sa;i++){
			int it=lower_bound(b.begin(),b.end(),(x+a[i]-1)/a[i])-b.begin();
			res+=sb-it;
		}
	}
	return res;
}

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x>0) a.push_back(x);
		else b.push_back(-x);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	ll l=-INF,r=INF;
	while(r-l>1){
		ll m=(l+r)/2;
		if(f(m)>=k) r=m;
		else l=m;
	}
	cout<<r<<endl;
}

Measured memory_bytes: 2420
#include<stdio.h>

typedef struct{
  char p;
  int nu;
}Trump;

void change(Trump *, Trump *);
void BubbleSort(Trump *, int);
void SelectionSort(Trump *, int);
void Print(Trump *, int);
int Compare(Trump *, Trump *, int);


int main(){
  int h,i,com;
  Trump P1[100];
  Trump P2[100];

  scanf("%d",&h);

  for(i = 0 ; i < h ; i++){
    scanf(" %c%d",&P1[i].p,&P1[i].nu);
    P2[i] = P1[i];
  }

  BubbleSort(P1,h);
  SelectionSort(P2,h);

  com = Compare(P1,P2,h);

  Print(P1,h);
  printf("Stable\n");
  Print(P2,h);
  if(com == 1) printf("Stable\n");
  else printf("Not stable\n");

 return 0;
}

void change(Trump *x, Trump *y){
  Trump z;

  z = *x;
  *x = *y;
  *y = z;
}

void BubbleSort(Trump A[], int x){
  int i,j;
  Trump a;
  for(i = 0 ; i < x ; i++){
    for(j = x - 1 ; j >= i + 1 ; j--){
      if(A[j].nu < A[j-1].nu) change(&A[j],&A[j-1]);
    }
  }
}

void SelectionSort(Trump A[], int x){
  int i,j,minj;
  Trump a;

  for(i = 0 ; i < x ; i++){
    minj = i;
    for(j = i ; j < x ; j++){
      if(A[j].nu < A[minj].nu) minj = j;
    }
    change(&A[i],&A[minj]);
  }
}

void Print(Trump A[], int x){
  int i;

  for(i = 0 ; i < x ; i++){
    if(i > 0) printf(" ");
    printf("%c%d",A[i].p, A[i].nu);
  }
  printf("\n");
}

int Compare(Trump A1[], Trump A2[], int x){
  int i;

  for(i = 0 ; i < x ; i++){
    if(A1[i].p != A2[i].p) return 0;
  }
  return 1;
}



Measured memory_bytes: 2056
b,o,s;main(a){for(scanf("%*d");~scanf("%s",&a);)
        {
                if(a%3){
                        if(a&1){
                                if(!(++o%3)){
                                        printf("%d\n",b>3?s+b-3:s),b=s=0;
                                }
                        }
                        else{
                                b++;
                        }
                }
                else{
                        s+=b+1,b=0;
                }
        }
}

Measured memory_bytes: 0
N = int(input())
S = input()

stk = []
for s in S:
    if len(stk) == 0 or stk[-1] == ')' or s == '(':
        stk.append(s)
    else:
        stk.pop()

print('(' * stk.count(')') + S + ')' * stk.count('('))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
// #define __builtin_popcount __popcnt
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
// mt19937 mrand(random_device{}());
const ll mod = 1000000007;
// int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
// head
void add_self(int& a, int b) {
	a += b;
	if (a >= mod) {
		a -= mod;
	}
}
const int mxN = 21;
int n, dp[1 << mxN];
bool can[mxN][mxN];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i, 0, n) rep(j, 0, n) cin >> can[i][j];

	dp[0] = 1;
	rep(mask, 0, (1 << n) - 1) {
		int man = __builtin_popcount(mask);
		rep(woman, 0, n) {
			if (can[man][woman] && !(mask & (1 << woman))) {
				int m2 = mask ^ (1 << woman);
				add_self(dp[m2], dp[mask]);
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;

	return 0;
}



Measured memory_bytes: 8448
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;

#define rep(i,l,r) for(int i=l;i<=r;i++)
#define dow(i,l,r) for(int i=r;i>=l;i--)
#define rep0(i,r) for(int i=0,rr=(int)r;i<rr;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second

typedef long long LL;

typedef pair<LL,int> piir;
const int N=200200;

int f[N],n;
vector<int> g[N];

void dfs(int x,int efa)
{
    f[x]=0;
    rep0(i,g[x].size()) {
        int too=g[x][i];
        if (too==efa) continue;
        dfs(too,x);
        f[x]+=f[too];
    }
    int now=0;
	rep0(i,g[x].size()) {
		int too=g[x][i];
		if (too==efa) continue;
		now+=(f[too]==0?1:0);
	}
	if (now) f[x]+=now-1;
}

void solve()
{
    scanf("%d",&n);
    rep(i,1,n-1) {
        int j,k;
        scanf("%d %d",&j,&k);
        g[j].pb(k);
        g[k].pb(j);
    }
  //  puts("");
    rep(i,0,n-1)
        if (g[i].size()>2) {
        //	printf("!%d\n",i);
            dfs(i,i);
            printf("%d\n",f[i]);
            return;
        }
	puts("1");
   // rep(i,0,n-1) printf("%d %d\n",i,f[i]);
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 12672