akhauriyash/Code-Regression huggingface dataset:
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long k,a,b;
    scanf("%lld%lld%lld",&k,&a,&b);
    k-=a;
    if(k<=0){printf("1\n");return 0;}
    if(a<=b){printf("-1\n");return 0;}
    printf("%lld\n",1+2*llceil(k,a-b));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int omote(int a,int b) {
	int rec = a;
	int count = 0;
	while (rec < b) {
		rec = rec * 2;
		count++;
	}
	return count;
}
int main() {
	double N;
	int K;
	cin >> N >> K;
	double ans = 0;
	for (int i = 1; i <= N; i++) {
		ans+=(1/N)*pow(0.5,omote(i, K));
	}
	cout << setprecision(14) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a[200010];
int main(){
	int k,n,i,mx=-1;
	scanf("%d%d",&k,&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=2;i<=n;i++)
		mx=max(mx,a[i]-a[i-1]);
	mx=max(mx,k-a[n]+a[1]);
	printf("%d\n",k-mx);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, std::vector<long long> A){
    vector<LL> seq = {-A[0]};
    for(LL i=1; i<N; i++){
        LL tmp = -A[i];
        if(tmp >= *seq.rbegin()){
            seq.emplace_back(tmp);
        }else{
            auto it = upper_bound(seq.begin(), seq.end(), tmp);
            *it = tmp;
        }
    }
    cout << seq.size() << endl;
}

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


Measured memory_bytes: 2168
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int N,A,B,C;
int pA[MAXN],pB[MAXN],fact[MAXN],invf[MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int comb(int n,int k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
int main()
{
    fact[0]=invf[0]=pA[0]=pB[0]=1;
    for(int i=1;i<=200000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[200000]=pow_mod(fact[200000],MOD-2);
    for(int i=199999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%d%d%d%d",&N,&A,&B,&C);
    A=1LL*A*pow_mod(A+B,MOD-2)%MOD;
    B=(MOD+1-A)%MOD;
    C=1LL*C*pow_mod(100,MOD-2)%MOD;
    for(int i=1;i<=200000;i++) pA[i]=1LL*pA[i-1]*A%MOD;
    for(int i=1;i<=200000;i++) pB[i]=1LL*pB[i-1]*B%MOD;
    int ans=0;
    int last=0;
    for(int i=0;i<=N-1;i++)
    {
        int prob=1LL*comb(N+i,N)*pA[N]%MOD*pB[i]%MOD,tmp=prob;
        dec(prob,1LL*last*B%MOD);
        last=tmp;
        add(ans,1LL*prob*(N+i)%MOD);
    }
    last=0;
    for(int i=0;i<=N-1;i++)
    {
        int prob=1LL*comb(N+i,N)*pB[N]%MOD*pA[i]%MOD,tmp=prob;
        dec(prob,1LL*last*A%MOD);
        last=tmp;
        add(ans,1LL*prob*(N+i)%MOD);
    }
    C=(MOD+1-C)%MOD;
    ans=1LL*ans*pow_mod(C,MOD-2)%MOD;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 3328
#include <iostream>

typedef long long ll;

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

#define debug(x) cout << #x << "=" << x << endl;

#define MAX_N 300

using namespace std;

int d[MAX_N+1][MAX_N+1];

int v;

void warshall_floyd(){
  FOR(k,1,v+1){
      FOR(i,1,v+1){
          FOR(j,1,v+1){
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
          }
      }
  }
}

int main(void){

  cin >> v;

  int a[MAX_N+1][MAX_N+1];

  FOR(i,1,v+1){
    FOR(k,1,v+1){
      cin >> d[i][k];
      a[i][k] = d[i][k];
    }
  }

  warshall_floyd();

  FOR(i,1,v+1){
    FOR(k,1,v+1){
      if(a[i][k] != d[i][k]){
        cout << -1 << endl;
        return 0;
      }
    }
  }

  ll ans = 0;

  FOR(i,1,v+1){
    FOR(j,1,v+1){
      bool isShortest = true;
      FOR(k,1,v+1){
        if(i != k && j != k && d[i][j] == d[i][k] + d[k][j]) isShortest = false;
      }
      if(isShortest) ans+=d[i][j];
    }
  }

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


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    map<string, ll> mp;
    ll N; cin >> N;
    REP(i, N) {
        string tmp; cin >> tmp;
        mp[tmp]++;
    }
    cout << mp.size() << endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int H;
    vector<int> res;
    while(cin >> H, H) {
        vector<vector<int>> B(H,vector<int>(5));
        REP(i,H) REP(j,5) cin >> B[i][j];
        int ans = 0;
        bool flag ;
        do {
            vector<vector<bool>> ers(H,vector<bool>(5,false));
            flag = false;
            REP(i,H) {
                int t = B[i][2];
                if (t == 0) continue;
                bool f5;
                f5 = true;
                REP(j,5) {
                    if (B[i][j] != t) f5 = false;
                }
                if (f5) {
                    REP(j,5) ers[i][j] = true;
                    ans += t * 5;
                    flag = true;
                }
                else if (B[i][0] == B[i][1] && B[i][1] == B[i][2] && B[i][2] == B[i][3]) {
                    REP(j,4) ers[i][j] = true;
                    ans += t * 4;
                    flag = true;
                }
                else if (B[i][3] == B[i][4] && B[i][1] == B[i][2] && B[i][2] == B[i][3]) {
                    for (int j=1;j<5;j++) ers[i][j] = true;
                    ans += t * 4;
                    flag = true;
                }
                else if (B[i][0] == t && B[i][1] == t) {
                    for (int j = 0; j <= 2; j++) ers[i][j] = true;
                    ans += t * 3;
                    flag = true;
                }
                else if (B[i][1] == t && B[i][3] == t) {
                    for (int j = 1; j <= 3; j++) ers[i][j] = true;
                    ans += t * 3;
                    flag = true;
                }
                else if (B[i][3] == t && B[i][4] == t) {
                    for (int j = 2; j <= 4; j++) ers[i][j] = true;
                    ans += t * 3;
                    flag = true;
                }
            }
            
            REP(j,5) {
                vector<int> hh(H);
                REP(i,H) {
                    int d = H - i - 1;
                    if (ers[d][j]) hh[i] = -1;
                    else hh[i] = B[d][j];
                }
                bool g = true;
                while(g) {
                    g = false;
                    REP(i,H) {
                        if (hh[i] == -1) {
                            g = true;
                            hh.erase(hh.begin() + i);
                            hh.pb(0);
                            break;
                        }
                    }
                }
                REP(i,H) {
                    B[H-i-1][j] = hh[i];
                }
            }
 
        } while(flag);
        res.pb(ans);
    }
    REP(i,res.size()) cout << res[i] << endl;
    return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int a, b, k;
    cin >> a >> b >> k;

    vector<int> n;
    for (int i = 1; i <= 100; i++) {
        if (a % i == 0 && b % i == 0) n.push_back(i);
    }

    reverse(n.begin(), n.end());

    cout << n[k-1] << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n+m == 15) {
            System.out.println("+");
        } else if(n*m == 15) {
            System.out.println("*");
        } else {
            System.out.println("x");
        }
    }
}

Measured memory_bytes: 22100
n = int(input())
ans = ""
c = 1
a = []
for i in range(9):
    if i == 0:a.append(26)
    else:a.append(a[i-1]+26**(i+1))
if n <= 26:
    print(chr(n+96))
else:
    while n >= 1:
        if n%26 == 0:
            ans += "z"
        else:
            ans += chr(n%26+96)
        n -= 1
        n = n//26
        c += 1
    print(ans[::-1])

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int mp[2][2005][2005]={};
int sum[2][2005][2005]={};
int main(){
	//ios_base::sync_with_stdio(false);
	int N, K;

	cin >> N >> K;

	int L = 2*K;
	rep(i,N){
		int x, y;
		char c;
		cin >> x >> y >> c;
		mp[c=='W'][x%L][y%L]++;
	}
	rep(k,2) rep(i,L+1) rep(j,L+1){
		sum[k][i][j] += mp[k][i][j];
		sum[k][i+1][j] += sum[k][i][j];
		sum[k][i][j+1] += sum[k][i][j];
		sum[k][i+1][j+1] -= sum[k][i][j];
	}
//	rep(k,2){
//		rep(i,L+1){
//			rep(j,L+1) cout << sum[k][i][j] << " ";
//			cout << endl;
//		}
//		cout << endl;
//	}

	int ans = 0;
	rep(k,2) rep(i,K) rep(j,K){
		int ret = 0;
		ret += sum[k][i][j];
		ret += sum[k][i+K][j+K] - sum[k][i][j+K] - sum[k][i+K][j] + sum[k][i][j];
		ret += sum[k][L][L] - sum[k][L][j+K] - sum[k][i+K][L] + sum[k][i+K][j+K];
		ret += sum[k][i][L] - sum[k][i][j+K];
		ret += sum[k][L][j] - sum[k][i+K][j];
		ret += sum[k^1][i][j+K] - sum[k^1][i][j];
		ret += sum[k^1][i+K][j] - sum[k^1][i][j];
		ret += sum[k^1][i+K][L] - sum[k^1][i][L] - sum[k^1][i+K][j+K] + sum[k^1][i][j+K];
		ret += sum[k^1][L][j+K] - sum[k^1][L][j] - sum[k^1][i+K][j+K] + sum[k^1][i+K][j];
		chmax(ans, ret);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 62976
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
int main()
{
    int N, W;
    std::cin >> N >> W;
    std::vector<ll> dp(W + 1, 0);
    for (int i = 0; i < N; i++) {
        int w, v;
        std::cin >> w >> v;
        for (int j = W - w; j >= 0; j--) { dp[j + w] = std::max(dp[j + w], dp[j] + v); }
    }
    std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}



int main(){
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    vector<VI> dp(n, VI(3));
    dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
    FOR(i, 1, n){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];

    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << "\n";
    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T; cin >> S; T=S;
    reverse(T.begin(),T.end());
    int n=S.size(),ans=0,ok=1;
    for (int i=0,j=0;i+j<n;++i,++j){
        if (S[i]==T[j]) continue;
        if (S[i]=='x'){
            int now=i;
            while(S[i]=='x') ++i;
            if (S[i]==T[j]) ans+=i-now;
            else ok=0;
        } else if (T[j]=='x'){
            int now=j;
            while(T[j]=='x') ++j;
            if (S[i]==T[j]) ans+=j-now;
            else ok=0;
        } else ok=0;
    }
    cout << (ok?ans:-1) << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

struct mint {
	typedef long long ll;
	ll x, m;
	mint(ll x=0, ll m=1e9+7): x(x%m), m(m) {}
	mint operator-() const { return mint(m-x, m); }
	mint operator+(const mint o) const { return mint(x+o.x, m); }
	mint operator-(const mint o) const { return mint(x-o.x+m, m); }
	mint operator*(const mint o) const { return mint(x*o.x, m); }
	mint& operator+=(const mint o) { x = (x+o.x)%m; return *this; }
	mint& operator-=(const mint o) { x = (x-o.x+m)%m; return *this; }
	mint& operator*=(const mint o) { x = x*o.x%m; return *this; }
	bool operator==(const mint o) const { return x==o.x; }
	bool operator!=(const mint o) const { return x!=o.x; }
	template<typename T> mint& operator=(const T o) { x = o%m; return *this; }
	template<typename T> mint operator+(const T o) const { return mint(x+o, m); }
	template<typename T> mint operator-(const T o) const { return mint(x-((ll)o)%m+m, m); }
	template<typename T> mint operator*(const T o) const { return mint(x*o, m); }
	template<typename T> mint& operator+=(const T o) { x = (x+(ll)o%m)%m; return *this; }
	template<typename T> mint& operator-=(const T o) { x = (x-((ll)o)%m+m)%m; return *this; }
	template<typename T> mint& operator*=(const T o) { x = x*((ll)o%m)%m; return *this; }
	template<typename T> bool operator==(const T o) const { return x==o%m; }
	template<typename T> bool operator!=(const T o) const { return x!=o%m; }

	mint pow(ll k) const {
		if(k==0) return mint(1, m);
		if(k%2) return pow(k-1)*x;
		mint z = pow(k/2);
		return z*z;
	}
};

mint dp[63][2][2][2];
int main(){
	ll L, R;
	cin >> L >> R;

	dp[62][0][0][0] = 1;
	for(int k=61; k>=0; k--){
		int l = (L>>k)&1;
		int r = (R>>k)&1;
		for(int p=0; p<2; p++) for(int q=0; q<2; q++) for(int s=0; s<2; s++){
			mint a = dp[k+1][p][q][s];
			debug(any{k+1, l, r, p, q, s, a.x});
			for(int x=0; x<2; x++) for(int y=0; y<2; y++){
				if(x && !y) continue;
				if(!s && x!=y) continue;
				int np = p;
				int nq = q;
				int ns = s;
				if(x && y) ns = 1;
				if(!p && l < x) np = 1;
				if(!p && x < l) continue;
				if(!q && y < r) nq = 1;
				if(!q && r < y) continue;
				dp[k][np][nq][ns] += a;
			}
		}
	}

	mint ans(0);
	for(int p=0; p<2; p++) for(int q=0; q<2; q++) for(int r=0; r<2; r++){
		ans += dp[0][p][q][r];
	}

	cout << ans.x << endl;

	return 0;
}


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

using namespace std;

int const N = 20;
long long const MAX = 1e18 + 1;

int n;
long long a[N];

long long calc(int l, int r, long long costL, long long costR) {
	if (r - l <= 1) {
		return 0;
	}
	long long res = MAX;
	for (int mid = l + 1; mid < r; mid++) {
		res = min(res, a[mid] * (costL + costR) + calc(l, mid, costL, costR + costL) + calc(mid, r, costL + costR, costR));
	}
	return res;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	cout << calc(1, n, 1, 1) + a[1] + a[n] << endl;
}

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

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

    set <string> a;
    bool g = 1;
    string s; cin >> s;
    a.emplace(s);
    char l = s[s.size() - 1]; 
    for (int i = 1; i < n; i++) {
        cin >> s;
        if ((s[0] != l) || (a.count(s)))
            g = 0;
        l = s[s.size() - 1];
        a.emplace(s);
    }

    if (g)
        cout << "Yes";
    else
        cout << "No";
}   

Measured memory_bytes: 3616
# https://atcoder.jp/contests/abc063/tasks/arc075_b
# 問題文あなたが散歩していると、突然 N 体の魔物が出現しました。
# それぞれの魔物は 体力 という値を持ち、i 体目の魔物の出現時の体力は hi です。
# 体力が 0以下となった魔物は直ちに消滅します。
# 幸い、あなたは熟練の魔法使いであり、爆発を引き起こして魔物を攻撃できます。
# 一回の爆発では、以下のように魔物の体力を減らすことができます。
# 生存している魔物を一体選び、その魔物を中心に爆発を引き起こす。
# 爆発の中心となる魔物の体力は A 減り、
# その他の魔物の体力はそれぞれ B 減る。
# ここで、A と B はあらかじめ定まった値であり、A>B である。
# すべての魔物を消し去るためには、最小で何回の爆発を引き起こす必要があるでしょうか？
# 制約入力値はすべて整数である。
# 1≤N≤10^5
# 1≤B<A≤10^9
# 1≤hi≤10^9

# N A B
# h1
# h2
# :
# hN

# 4 5 3
# 8
# 7
# 4
# 2

# 2

# 2 10 4
# 20
# 20

# 4

# 5 2 1
# 900000000
# 900000000
# 1000000000
# 1000000000
# 1000000000

# 800000000

N, A, B = gets.split.map(&:to_i)
H = []
N.times {
  H << gets.to_i
}

A_B = A - B

class Integer
  def able?
    counter = self
    bself = B * self
    b2 = - bself + A_B - 1
    H.each do |value|
      next if value <= bself
      counter -= ((value + b2)/(A_B))
      break if counter < 0
    end
    counter >= 0
  end
end

# T回で倒しきれるか？ を二分探索
# ng = 0, ok = h.max
ng = 0
ok = H.max/B + 1
mid = 0
while (ok - ng) > 1
  mid = (ng + ok)/2
  if mid.able?
    ok = mid
  else
    ng = mid
  end
end
puts ok

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

void print(int N, vector<int> A){
    rep(i,N-1){
        cout << A[i] << " ";
    }
    cout << A[N-1];
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N){
        int v = A[i];
        int j = i -1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        print(N,A);
    }
    return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<math.h>
#include<iomanip>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
const int INF = 1<<30;
int main(){
  long double n, m, d;cin>>n>>m>>d;
  long double ans;
  if(d==0){
    ans = (m-1)/n;
  }else{
    ans = 2*(n-d)*(m-1)/(n*n);
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 256
#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 <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll c[101010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>S;
    if(S=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if (S == "Rainy"){
        cout<<"Sunny"<<endl;
    }else{
        cout<<"Rainy"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m, K = map(int, input().split())
mod = 998244353

fac = [1] * (n + 1)
inv = [1] * (n + 1)

for j in range(1, n + 1):
    fac[j] = fac[j - 1] * j % mod

inv[n] = pow(fac[n], mod - 2, mod)
for j in range(n - 1, -1, -1):
    inv[j] = inv[j + 1] * (j + 1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


def paint(k):
    res = (m * comb(n-1, k)) % mod * pow(m-1, n-1-k, mod)
    res %= mod
    return res

ans = 0
for k in range(K+1):
    ans += paint(k)
    ans %= mod
print(ans)

Measured memory_bytes: 79164
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long 
#define jaldi_chal  ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c,i) for(auto i=(c).begin(); i != (c).end(); i++)
#define REP(i,k) for( ll i=0;i<k;i++)
#define REW(i,a,b) for(ll i=a;i<=b;i++)
#define M 1000000007
#define F first
#define dbg(x)  cout<<#x<<" " <<x<<endl;
#define S second
#define inf 1e10
#define endl "\n"


int main() {
jaldi_chal
ll n,w;
cin>>n>>w;
ll v[n+1],wa[n+1];
REW(i,1,n)
{
    cin>>wa[i]>>v[i];
}
wa[0]=0;
v[0]=0;
ll dp[n+1][w+1];

memset(dp,0,sizeof(dp));

REW(j,1,w)
{
    if(j>=wa[1]) dp[1][j]=v[1];
}

REW(i,2,n)
{
    REW(j,1,w)
    {
        if(wa[i]<=j)
        {
            dp[i][j]=max(v[i]+dp[i-1][j-wa[i]],dp[i-1][j]);
        }
        else dp[i][j]=dp[i-1][j];
       // cout<<dp[i][j]<<" ";
    }
   // cout<<endl;
}

cout<<dp[n][w];

	return 0;
}

Measured memory_bytes: 79232
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B;
	vector<int> sum(0);
	int AC = 0;
	B.resize(M);
	sum.resize(N);
	for (int i = 0; i < M; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i < N; ++i) {
		int buf;
		for (int j = 0; j < M; ++j) {
			cin >> buf;
			sum[i] += buf * B[j];
		}
		sum[i] += C;
		if (sum[i] > 0)++AC;
	}

	cout << AC << endl;
	return 0;
}

Measured memory_bytes: 256
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#define INF 100000
//#include <chrono>
using namespace std;

int main()
{
  string s;cin >> s;
  int n0, n1;
  n0 = n1 = 0;
  for(int i = 0; i < s.size(); i++){
  	if(s[i] == '0')
      n0++;
    else
      n1++;
  }
  cout << min(n0,n1)*2 << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int x[5];
	rep (i, 5) cin >> x[i];
	rep (i, 5) {
		if (x[i] == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3620
import scala.util.control.Breaks

object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val Y = sc.nextLong
    val b = new Breaks
    var flag = false
    b.breakable {
      for (i <- 0 to N)
        for (j <- 0 to N - i)
          for (k <- 0 to N - i - j)
            if (Y == 10000 * k + 5000 * j + 1000 * i && N == k + j + i) {
              flag = true
              println(k + " " + j + " " + i)
              b.break()
            }
    }
    if (!flag) println("-1 -1 -1")
  }
}

Measured memory_bytes: 40792
int main(int argc, char *argv[])
{
	int a;
	int b;
	int c;
	scanf("%d %d %d\n", &a, &b, &c);
	if ((a < b) && (b < c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 100000000
#define mod 1000000007
#define INF2 1000000000000000000

int d[200][200];
int N;
void warshall_floyd(void) {
    rep(k ,N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, R;
    cin >> N >> M >> R;
    int r[R];
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    rep(i, 200) {
        rep(j, 200) {
            if (i != j) d[i][j] = INF;
        }
    }
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd();
    sort(r, r + R);
    int m = INF;
    do{
        int tmp = 0;
        rep(i, R-1) {
            tmp += d[r[i]][r[i+1]];
        }
        m = min(m, tmp);
    }while(next_permutation(r, r + R));
    cout << m << endl;

    return 0;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    string s;
    cin>>s;
    int n=s.size();
    ll ans=0;
    rep(i,1<<(n-1)){
        int k=0;
        ll v=0;
        int ii=i;
        rep(j,n){
            v=v*10+(s[j]-'0');
            if(ii%2==1){
                ans+=v;
                v=0;
            }
            ii/=2;
        }
        ans+=v;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

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

using ll = long long;

vector<ll> factor(ll x) {
  vector<ll> res;
  for (ll i = 1L; i * i <= x; i++) {
    if (x % i == 0) {
      res.emplace_back(i);
      res.emplace_back(x/i);
    }
  }
  return res;
}

// 8 / 7 == 8 % 7
// 1     == 1

// 8 / 3 == 8 % 3
// 2     == 2

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

  ll res = 0L;
  vector<ll> fs = factor(N);
  REP(i,fs.size()) {
    ll x = fs[i];
    ll m = (N - x) / x;
    if (m != 0 && N / m == N % m)  {
      res += m;
    }
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

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

    if (n == 2) {
        cout << 1 << '\n';
        return;
    }

    vector<ll> res;
    res.push_back(n);
    ll m1 = n-1;
    for (ll i=1; i*i<=m1; ++i) {
        if (m1%i == 0) {
            if (i != 1) res.push_back(i);
            res.push_back(m1/i);
        }
    }
    for (ll i=2; i*i<=n; ++i) {
        if (n%i == 0) {
            ll tmp = n/i;
            while (tmp%i == 0) tmp /= i;
            if ((tmp-1)%i == 0) res.push_back(i);
        }
    }
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    cout << (int)res.size() << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e6+100;
string str;
string tmp;
int main(){
	cin>>str;
	int len = str.length();
	for(int i=0;i<len;i++){
		if(str[i]=='B'){
			if(tmp.size()>0)
			tmp.pop_back();
			else continue;
		}
		else {
			tmp.append(1,str[i]);
		}
		//cout<<tmp<<endl;
	}	
	cout<<tmp<<endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d",&a);
    if(a-1==0||a-1==100||a-1==110||a-1==10){
        b=1;
    }else{
        b=0;
    }
    if(a-10==0||a-10==100||a-10==1||a-10==0||a-10==101){
        c=1;
    }else{
        c=0;
    }
    if(a-100==0||a-100==10||a-100==1||a-100==11){
        d=1;
    }else{
        d=0;
    }
    a=c+b+d;
    printf("%d",a);
    return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	int ar[3];
	cin >> ar[0] >> ar[1] >> ar[2];
	swap(ar[0], ar[1]);
	swap(ar[0], ar[2]);
	cout << ar[0] << " " << ar[1] << " " << ar[2];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N;
cin >> N;
vl A(N);
rep(i,N) cin >> A[i];

ll cnt = 0;
ll sum = 0;
rep(i,N) {
    sum += A[i];
    if(i % 2 == 0) {
        if(sum > 0) continue;
        cnt += 1 - sum;
        sum = 1;
    }
    if(i % 2 == 1) {
        if(sum < 0) continue;
        cnt += sum + 1;
        sum = -1;
    }
}

ll cnt1 = 0;
ll sum1 = 0;
rep(i,N) {
    sum1 += A[i];
    if(i % 2 == 1) {
        if(sum1 > 0) continue;
        cnt1 += 1 - sum1;
        sum1 = 1;
    }
    if(i % 2 == 0) {
        if(sum1 < 0) continue;
        cnt1 += sum1 + 1;
        sum1 = -1;
    }
}
cout << min(cnt, cnt1) << endl;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  vector<string> a(h);
  rep(i, h) cin >> a[i];

  cout << string(a[0].size() + 2, '#') << endl;

  rep(i, h) {
    cout << '#' << a[i] << '#' << endl;
  }

  cout << string(a[0].size() + 2, '#') << endl;

  return 0;
}


Measured memory_bytes: 3492
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(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 modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll fact[N];
ll invfact[N];
ll inv[N];
void factorialsComputation()
{
    inv[0]=inv[1]=1;
    fact[0]=fact[1]=1;
    invfact[0]=invfact[1]=1;
    for(int i=2;i<N;i++)
    {
        inv[i]=(inv[mod%i]*(mod-mod/i))%mod;
        fact[i]=(fact[i-1]*i)%mod;
        invfact[i]=(invfact[i-1]*inv[i])%mod;
    }
}
void solve()
{
    ll n;
    cin>>n;
    vl v;
    v.pb(0);
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    ll presum[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        presum[i]+=presum[i-1];
        presum[i]+=inv[i];
        presum[i]%=mod;
    }
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        ans+=((v[i+1]-v[i])*(presum[i]));
        ans%=mod;
    }
    ans*=fact[n-1];
    ans%=mod;
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    factorialsComputation();
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 28464
# include <cstdio>
# include <iostream>
# include <vector>
# include <map>
# include <set> 
# include <algorithm> 
# include <string>
# include <cstring>
# include <queue> 
# include <stack> 
# include <cstdlib> 

using namespace std ; 

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

	if(y < 2*x)
	{
		cout << "No\n" ; 
		return 0 ; 
	}
	if((y-2*x)%2)
	{
		cout <<  "No\n" ;
		return 0 ; 
	}
	int c = x - (y-2*x)/2 ; 
	if(c<0){
		cout <<  "No\n";
		return 0 ; 
	}
	cout << "Yes\n"; 

	// cout << "Hello World\n" ; 
	return 0 ; 
}

Measured memory_bytes: 3100
s = input()

t, a = 0, 1
mod = [0]*2019
mod[0] = 1
s = s[::-1]
n = len(s)
for i in range(n):
    t = (t + int(s[i]) * a) % 2019
    a = (a * 10) % 2019
    mod[t] += 1
ans = 0

for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)

Measured memory_bytes: 68324
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx")
 
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define f first
#define s second
#define y1 asafsaf
#define kz ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
using namespace std;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
 
const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll linf = 1e18;
const double pi = acos(-1.0);

int n;
 
int main(){
    cin >> n;
    if(n % 10 == 9 || n / 10 == 9)
        cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n; cin >> n;
  vector<int> a(n);
  double sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  double ave = (double)sum / n, tmp;
  ll ans = 150;

  tmp = abs(a[0] - ave);
  ans = 0;

  for (int i = 1; i < n; ++i) {
    if (abs(a[i] - ave) < tmp){
      tmp = abs(a[i]- ave);
      ans = i;
    }
  }

  cout << ans << endl;
}


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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif


double Distance(ll i, ll j, ll d, vector<vector<ll>>& x)
{
	double ans = 0;
	rep(k, 0, d)
	{
		ans += pow(x[i][k] - x[j][k], 2);
	}

	return sqrt(ans);
}

int main(void)
{
	ll n, d; cin >> n >> d;
	vector<vector<ll>> x(n, vector<ll>(d));
	rep(i, 0, n)
	{
		rep(j, 0, d)
			cin >> x[i][j];
	}

	double ans = 0;
	ll count = 0;
	rep(i, 0, n-1)
	{
		rep(j, i+1, n)
		{
			ans = Distance(i, j, d, x);

			if (ceil(ans) == floor(ans))
				count++;
		}
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;


class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		ArrayList<Integer> height = new ArrayList<Integer>();
        ArrayList<Integer> width = new ArrayList<Integer>();
         
        int H,W;
         
        while(true){
            H = sc.nextInt();
            W = sc.nextInt();
             
            if(H == 0 && W == 0)
                break;
             
            height.add(H);
            width.add(W);
             
        }
        
        int countH = 0;
        int countW = 0;

        for(countH = 0; countH < height.size(); countH++){
        	
        	for(int i = 0; i < height.get(countH); i++)
            {
            	for(int t = 0; t < width.get(countW); t++)
            	{
            		if(t < width.get(countW) -1)
            		{
            			if(0 < t && 0 < i && i < height.get(countH) - 1){
            				System.out.print(".");
            			}
            			else{
            				System.out.print("#");
            			}
            		}
            		else if(t == width.get(countW) -1)
            		{
            			System.out.println("#");
            		}
            	}
            }
        	System.out.println("");
        	countW++;
        }

		
		
		
	}

}

Measured memory_bytes: 34804
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();
    int c = scan.nextInt();
    int k = scan.nextInt();
    if (k <= a){
      System.out.println(k);
    }else if (k <= a+b){
      System.out.println(a);
    }else{
      System.out.println(a-(k-a-b));
    }
  }
}

Measured memory_bytes: 35628
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;

int main(){

	scanf("%d",&N);

	int tmp;
	int num_GU = 0,num_KI = 0;

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

		scanf("%d",&tmp);

		if(tmp%2 == 0){

			num_GU++;

		}else{

			num_KI++;
		}
	}

	if(num_GU == 0 || num_KI == 0){

		printf("0\n");

	}else{

		if(num_KI%2 == 0){

			printf("%d\n",N-2);

		}else{

			printf("%d\n",N-1);
		}
	}

	return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long a,b;
  cin>>a>>b;
  long long c=b-a+1;
  if(c>=673){
    cout<<0<<endl;
  }
  else {
    long long d=(a*b)%2019;
  for(long long i=a;i<b;i++){
    for(long long j=i+1;j<b+1;j++){
      long long x=i*j;
      d=min(d,x%2019);
    }
  }
  cout<<d<<endl;
  }
      
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
const int inf=1e9;
int n,m,num;
struct edge
{
	int to,next;
}e[maxn];
int head[maxn],dis[maxn],pre[maxn],vis[maxn];
void edge_add(int u,int v)
{
	e[++num].to=v;
	e[num].next=head[u];
	head[u]=num;
}
void spfa()
{
	for (int i=1;i<=n;i++) dis[i]=inf;
	queue<int> q;
	dis[1]=0;q.push(1);
	while (!q.empty())
	{
		int u=q.front();q.pop();
		for (int i=head[u];i;i=e[i].next)
		{
			int v=e[i].to;
			if (dis[v]>dis[u]+1)
			{
				pre[v]=u;
				dis[v]=dis[u]+1;
				if (!vis[v])
				{
					vis[v]=1;
					q.push(v);
				}
			}
		}
		vis[u]=0;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		edge_add(u,v);edge_add(v,u);
	}
	spfa();
	for (int i=1;i<=n;i++)
		if (dis[i]==inf)
		{
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	for (int i=2;i<=n;i++) cout<<pre[i]<<'\n';
	return 0;
}


Measured memory_bytes: 8396
<?php
$f = fopen( 'php://stdin', 'r' );
$line = fgets($f);
$date_array = explode('/', $line);
if ($date_array[0] < '2019'){
    echo ('Heisei');
} elseif ($date_array[0] === '2019' && $date_array[1] <= 4){
    echo ('Heisei');
} else {
    echo ('TBD');
}


Measured memory_bytes: 4856
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> B(N-1);
	rep(i,N-1)cin>>B[i];
	int ans = 0;
	ans += B[0];
	for(int i = 1; i<N-1; ++i){
		ans += min(B[i], B[i-1]);
	}
	ans += B[N-2];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628