akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int w[200];

bool judge(int num, int length, int height){
	int count = 0;
	int sum = 0;
	for(int i = 0; i < length; i++){
		if(w[i] > num){
			return false;
		}
		if(sum + w[i] > num){
			count++;
			sum = w[i];
		}else{
			sum += w[i];
		}
	}
	count++;
	if(count <= height){
		return true;
	}
	return false;
}

int binary_search(int lef, int rig, int m, int n){
	int middle = (lef + rig) / 2;
	if(rig - lef <= 1){
		if(!judge(rig, n, m)){
			return lef;
		}else{
			return rig;
		}
	}
	if(judge(middle, n, m)){
		rig = middle;
		return binary_search(lef, rig, m, n);
	}else{
		lef = middle;
		return binary_search(lef, rig, m, n);
	}
}

int main(){
	
	int m, n;
	
	while(true){
		
		cin >> m >> n;
		
		if(m == 0 && n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> w[i];
		}
		
		cout << binary_search(0, 1600000, m, n) << endl;
		
	}
	return 0;
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int ss;cin >> ss;ss--;
      s[i].push_back(ss);
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }

  int ret = 0;
  for (int i = 0; i < (1 << N); i++) {
    int lighton = 0;
    for (int j = 0; j < M; j++) {
      int on = 0;
      for (int ss : s[j]) {
        if (i & (1 << ss)) on++;
      }
      if (on % 2 == p[j]) lighton++;
    }
    if (lighton == M) ret++;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, K, ans = 0, max = 0, count ;
  cin >> N >> K ;
  int A[N] ;
  for(int i=0;i<N;i++){
    cin >> A[i] ;
    if(A[i] > max) max = A[i] ;
  }
  int left = 0, right = max, nib = max / 2 ;
  while((left != right) && (left+1 != right)){
    count = 0 ;
    for(int i=0;i<N;i++){
      count += (A[i]-1) / nib ;
    }
    if(count > K){
      left = nib ;
    }
    else{
      right = nib ;
    }
    nib = (left + right) / 2 ;
  }
  cout << right << endl ;
  return 0 ;
}  

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

int main()
{
    solve();
}

void solve()
{
    string s;
    in(s);
    if (s[0] != s[1] || s[1] != s[2] || s[2] != s[0])
    {
        out("Yes");
    }
    else
    {
        out("No");
    }
}

Measured memory_bytes: 256
N = int(input())
P = [int(i) for i in input().split()]
Par = [int(i) for i in range(1,N+1)]

cnt = 0
for i in range(N):
    if P[i]!=Par[i]:
        cnt += 1

if cnt <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pir pair<int,int>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define rsort(x,y) sort(x,y),reverse(x,y)
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int Maxn=2100000;
const int inf=0x3f3f3f3f;

int n,x[Maxn],y[Maxn],p[Maxn],bj[Maxn],a[Maxn];
ll ans[Maxn];
pair<int,int> px[Maxn],py[Maxn];

void dfs(int now) {
    if(now>n) {
        int zhy=0;
        for(int i=1;i<=n;i++)
            if(a[i]) bj[i]=0,zhy++;
            else bj[i]=min(abs(x[i]),abs(y[i]));
        int temp=0;
        for(int i=1;i<=n;i++) {
            if(a[px[i].se]==1) temp=i;
            else qmin(bj[px[i].se],abs(px[i].fr-px[temp].fr));
        }
        temp=0;
        for(int i=n;i>=1;i--) {
            if(a[px[i].se]==1) temp=i;
            else qmin(bj[px[i].se],abs(px[i].fr-px[temp].fr));
        }
        temp=0;
        for(int i=1;i<=n;i++) {
            if(a[py[i].se]==2) temp=i;
            else qmin(bj[py[i].se],abs(py[i].fr-py[temp].fr));
        }
        temp=0;
        for(int i=n;i>=1;i--) {
            if(a[py[i].se]==2) temp=i;
            else qmin(bj[py[i].se],abs(py[i].fr-py[temp].fr));
        }
        ll sxz=0;
        for(int i=1;i<=n;i++) sxz+=1ll*bj[i]*p[i];
        qmin(ans[zhy],sxz);
        return ;
    }
    a[now]=0;
    dfs(now+1);
    a[now]=1;
    dfs(now+1);
    a[now]=2;
    dfs(now+1);
}

signed main() {
    // freopen("test.in","r",stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&x[i],&y[i],&p[i]);
    for(int i=1;i<=n;i++) px[i]=make_pair(x[i],i),py[i]=make_pair(y[i],i);
    sort(px+1,px+n+1),sort(py+1,py+n+1);
    for(int i=0;i<=n;i++) ans[i]=1ll*inf*inf;
    dfs(1);
    for(int i=0;i<=n;i++) printf("%lld\n",ans[i]);
    return 0;
}

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

#include <algorithm>
#include <cmath>
#include <map>
#include <string>

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

int main(){
	string s;
	int cnt = 0;
	char st;
	cin >> s;
	st = s[0];
	for (int i = 1; i < s.length(); i++){
		
		if (st != s[i])
			cnt++;
		st = s[i];


	}
	cout << cnt<<endl;

}

Measured memory_bytes: 512
main = do
       x<-getLine
       let (a:b:c:d:[])=map read (words x)::[Integer]
           e=c * d `div` (gcd c d)
       print $ (f b c d e)-(f (a-1) c d e)
       where f s c d e=s-(s `div` c) -(s `div` d) + (s `div` e)

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 
 
 
int main(){
    int K, X;
    cin >> K >> X;
    int ans = X-(K-1);
    rep(i,K*2-1) {
        if(i!=0) cout << " ";
        cout << ans;
        ++ans;
    }
    cout << endl; 
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define umap unordered_map
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


//————————BFSグラフ————————————————

using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int n;
    cin >> n;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(n);
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        G[a-1].pb(b-1);
        G[b-1].pb(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    deque<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.pb(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop_front();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.pb(nv);
        }
    }

    vector<int> dist2(n, -1); // 全頂点を「未訪問」に初期化
    
    // 初期条件 (頂点 0 を初期ノードとする)
    dist2[n-1] = 0;
    que.pb(n-1); // 0 を橙色頂点にする
    
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop_front();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist2[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist2[nv] = dist2[v] + 1;
            que.pb(nv);
        }
    }   
  
  int fe=0;
  rep(i,n) {
    if(dist[i]<=dist2[i]) fe++;
  }
  
  cout << (fe>n-fe?"Fennec":"Snuke") << endl;
  
}


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

typedef long long ll;

#define max(a,b) (a>b?a:b)

ll solve(int n) {
	if(n<=3) {
		return n<2?0:1;
	}
	ll ret=0;
	if(n%3==0) {
		ret = solve(n/3);
	}else if(n%3==1) {
		ret = max(solve(n/3), solve(n/3+1));
	}else if(n%3==2) {
		ret = max(solve(n/3+1), solve(n/3));
	}
	return ret+1;
}

int main() {
	ll n;
	cin >> n;
	cout << solve(n) << endl;
	return 0;
}

Measured memory_bytes: 1160
n,p = map(int,input().split())
a_list = list(map(int,input().split()))
dp = [[0,0] for i in range(n+1)]
dp[0][0] = 1
dp[0][1] = 0
for i in range(n):
  if a_list[i] % 2 == 0:
    dp[i+1][0] = dp[i][0] + dp[i][0] 
    dp[i+1][1] = dp[i][1] + dp[i][1]
  if a_list[i] % 2 == 1:
    dp[i+1][0] = dp[i][0] + dp[i][1] 
    dp[i+1][1] = dp[i][1] +dp[i][0] 
    
print(dp[-1][p])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
 
const ll MOD = 1000000007;
 
const int SZ = 1 << 18;
 
struct segtree {
	vector<ll> dat;
 
	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = LLONG_MAX;
	}
 
	void update(int pos, ll x) {
		pos += SZ - 1;
		dat[pos] = x;
 
		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = min(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}
 
	ll get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return LLONG_MAX;
		if (a <= l && r <= b) return dat[k];
		return min(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
} seg;
 
int N;
ll A[2];
ll a[100010];
ll dp[3][100010];
int l[2][100010];
ll ac[3][100010];
 
int main() {
	cin >> N >> A[0] >> A[1];
	if (A[0] > A[1]) swap(A[0], A[1]);
	rep(i, N) cin >> a[i];
 
	seg.init();
 
	rep(i, N-1) {
		seg.update(i, a[i+1] - a[i]);
	}
 
	rep(i, N) {
		rep(j, 2) {
			int lb = 0, ub = i;	
			if (seg.get(0, i) >= A[j]) {
				ub = 0;
			}
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				if (seg.get(m, i) >= A[j]) {
					ub = m;
				} else {
					lb = m;
				}
			}
			l[j][i] = ub;
		}
	}
 
	dp[1][0] = 1;
 
	for (int i = 1; i < N; ++i) {
		ac[2][i] = (ac[2][i-1] + dp[2][i-1]) % MOD;
		ac[1][i] = ac[1][i-1];

		if (i == 1 || a[i] - a[i-2] >= A[0]) {
			ac[1][i] = (ac[1][i] + dp[1][i-1]) % MOD;
		}

		if (a[i] - a[i-1] >= A[1]) {
			dp[2][i] = (dp[1][i-1] + dp[2][i-1]) % MOD;
		}
 
		int can = l[0][i-1];
		int r = upper_bound(a, a + i - 1, a[i] - A[1]) - a;

		ll t = 0;

		if (can == 0) {
			t = 1;
			can = 1;
		}

		if (can <= r) {
			t = (t + ac[2][r] - ac[2][can - 1] + MOD) % MOD;
			t = (t + ac[1][r] - ac[1][can - 1] + MOD) % MOD;
		}
 
		dp[1][i] = t;
	}
 
	ll ret = (dp[1][N-1] + dp[2][N-1]) % MOD;
 
	for (int i = l[0][N-1]; i < N; ++i) {
		if (i == 0) {
			++ret;
		} else {
			ret = (ret + dp[2][i-1]) % MOD;
			if (i >= 2 && a[i] - a[i-2] < A[0]) {
				continue;
			}
			ret = (ret + dp[1][i-1]) % MOD;
		}
	}
 
	cout << ret << endl;
 
	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

vector<LL> v;

int main(){
    int N,K;
    cin >> N >> K;
    for(int i=0;i<N;i++){
        LL t;
        cin >> t;
        v.pb(t);
    }
    sort(ALL(v));
    int l=0,r=N;
    while(l<r){
        vector<vector<bool>> dp(N+1,vector<bool> (K+1));
        int mid=(r+l)/2;
        LL t=v[mid];
        if(t>=K){
            if(r==mid){
                break;
            }
            r=mid;
            continue;
        }
        v[mid]=0;
        dp[0][0]=true;
        for(int i=0;i<N;i++){
            for(int j=0;j<K;j++){
                if(dp[i][j]){
                    dp[i+1][j]=true;
                    if(j+v[i]<=K) dp[i+1][j+v[i]]=true;
                }
            }
        }
        bool c=false;
        for(int i=K-t;i<K;i++){
            if(dp[N][i]){
                c=true;
            }
        }
        if(c){
            if(r==mid){
                break;
            }
            r=mid;
        }
        else{
            if(l==mid){
                break;
            }
            l=mid;
        }
        v[mid]=t;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int N,m[111111];
int f(int x){
    if(x<0)return 1e9;
    if(x<6)return x;
    if(!m[x]){
        int r=1e9;
        for(int i=6;i<=x;i*=6)
            r=min(r,f(x-i)+1);
        for(int i=9;i<=x;i*=9)
            r=min(r,f(x-i)+1);
        m[x]=r;
    }
    return m[x];
}
int main(){
    cin>>N;
    cout<<f(N);
    return 0;
}

Measured memory_bytes: 1408
N, M, X = map(int, input().split(' '))
cost = []
A = []

for _ in range(N):
    l = list(map(int, input().split(' ')))
    cost.append(l[0])
    A.append(l[1:])

ans = 10 ** 10

for state in range(1 << N):
    price = 0
    compre = [0 for _ in range(M)]
    for i in range(N):
        if ((state >> i) & 1) == 1:
            # use
            price += cost[i]
            for j in range(M):
                compre[j] += A[i][j]

    check = True
    for i in range(M):
        check &= (compre[i] >= X)
    if check:
        ans = min(ans, price)

if ans == 10 ** 10:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9220
from heapq import *
from math import sqrt

def finddist(a,b):
    x1,y1,r1=a
    x2,y2,r2=b
    dx = x1 - x2
    dy = y1 - y2
    d = sqrt(dx*dx + dy*dy)
    return max(0, d - r1 -r2)


def dijkstra(c,s,t):
    found = set([(s,0)])
    dist ={s:0}
    notfound=set(c[1:])
    edgesinheap=[]
    newvert = s
    while notfound:
        if newvert == t:
            return dist[t]

        for x in notfound:
            heappush(edgesinheap, (dist[newvert]+finddist(newvert ,x), x, newvert))

        nextvertexfound = False
        while not nextvertexfound:
            d,nextvert, priv = heappop(edgesinheap)
            if nextvert not in found:
                nextvertexfound = True
                dist[nextvert] = d
                found.add(nextvert)
                notfound.remove(nextvert)
                newvert = nextvert

    return dist[t]





if __name__=="__main__":
    xs,ys,xt,yt=list(map(int,input().split()))
    N = int(input())
    circles = [(xs,ys,0), (xt,yt,0)]
    for _  in range(N):
        c=tuple(map(int, input().split()))
        circles.append(c)

    edges = []

    print(dijkstra(circles,circles[0],circles[1]))
    


Measured memory_bytes: 54004
#include <stdio.h>
#include <math.h>

#define EPS 1e-10
#define INF 1000000000

typedef struct {
	int x1, y1, x2, y2;
} Line;

Line line[102][3];

int rel_s_s(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *x, double *y) {
	const double dn = (x2 - x1) * (y4 - y3) - (x4 - x3) * (y2 - y1);

	if (fabs(dn) < EPS)
		return 2;
	else {
		const double s = ((x3 - x1) * (y4 - y3) - (x4 - x3) * (y3 - y1)) / dn;
		const double t = ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)) / dn;

		if (-EPS < s && s < 1.0 + EPS && -EPS < t && t < 1.0 + EPS) {
			*x = x1 + s * (x2 - x1);
			*y = y1 + s * (y2 - y1);
			return 0;
		} else
			return 6;
	}
}

int main(void) {
	int n, t[103], v[102];

	scanf("%d", &n);

	t[0] = -INF;
	t[1] = 0;
	t[n + 2] = INF;
	v[0] = 0;
	v[n + 1] = 0;
	for (int i = 1; i <= n; i++) {
		int tmp;
		scanf("%d", &tmp);
		t[i + 1] = t[i] + tmp;
	}
	for (int i = 1; i <= n; i++)
		scanf("%d", v + i);

	for (int i = 0; i <= n + 1; i++) {
		line[i][0] = (Line){0, v[i] + t[i], t[i], v[i]};
		line[i][1] = (Line){t[i], v[i], t[i + 1], v[i]};
		line[i][2] = (Line){t[i + 1], v[i], t[n + 1], v[i] + t[n + 1] - t[i + 1]};
	}

	double cur_x = 0, cur_y = 0;
	int cur_idx = 0, cur_type = 2;
	double sum = 0;
	while (cur_x < t[n + 1]) {
		const Line l = line[cur_idx][cur_type];
		double x, y;
		double min_x = l.x2, min_y = l.y2;
		int min_idx = -1, min_type = -1;

		if (cur_type == 0)
			cur_type = 1;
		else if (cur_type == 1) {
			for (int i = cur_idx + 1; i <= n + 1; i++) {
				const Line m = line[i][0];
				int rel = rel_s_s(l.x1, l.y1, l.x2, l.y2, m.x1, m.y1, m.x2, m.y2, &x, &y);
				if (rel == 0)
					if (x < min_x) {
						min_x = x;
						min_idx = i;
					}
			}

			if (min_x < l.x2) {
				cur_idx = min_idx;
				cur_type = 0;
			} else
				cur_type = 2;
		} else {
			for (int type = 0; type <= 1; type++)
				for (int i = cur_idx + 1; i <= n + 1; i++) {
					const Line m = line[i][type];
					int rel = rel_s_s(l.x1, l.y1, l.x2, l.y2, m.x1, m.y1, m.x2, m.y2, &x, &y);
					if (rel == 0)
						if (x < min_x) {
							min_x = x;
							min_y = y;
							min_idx = i;
							min_type = type;
						}
				}

			cur_idx = min_idx;
			cur_type = min_type;
		}

		sum += (cur_y + min_y) * (min_x - cur_x) / 2.;

		cur_x = min_x;
		cur_y = min_y;
	}

	printf("%f\n", sum);

	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> V(3);
  V.at(0) = A - B;
  V.at(1) = A + B;
  V.at(2) = A * B;
  sort(V.begin(), V.end());
  cout << V.at(2) << endl;
}

Measured memory_bytes: 3488
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		Arrays.parallelSort(s);
		if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n);
  a[0] = 7 % n;
  if(a[0] == 0){
    print(1);
    return 0;
  }
  for(int i = 1;i < n;++i){
    a[i] = a[i-1]* 10 + 7;
    a[i] %= n;
    if(a[i] == 0){
      print(i+1);
      return 0;
    }
  }
  print(-1);
  
  return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

const ll mod = 1'000'000'007;
ll fact[2000005];

ll bm(ll b, ll p, ll m) {
	ll r = 1;
	for (; p; p >>= 1, b = b * b % m) if (p & 1) r = r * b % m;
	return r;
}

ll modinv(ll b) {
	return bm(b, mod - 2, mod);
}

ll ncr(ll n, ll r) {
	return fact[n] * modinv(fact[n - r]) % mod * modinv(fact[r]) % mod;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	fact[0] = 1;
	rep(i, 1, 2000005) fact[i] = fact[i - 1] * i % mod;

	ll x, y; read(x, y);
	ll a = 2 * y - x;
	ll b = 2 * x - y;
	if (a % 3 != 0 || b % 3 != 0 || a < 0 || b < 0) die(0);
	a /= 3, b /= 3;

	die(ncr(a + b, a));
}


Measured memory_bytes: 15872
def inpl(): return list(map(int, input().split()))
L = input()
MOD = 10**9 + 7

OK = [0]*(len(L))
NG = [0]*(len(L))

if L[-1] == "0":
    OK, NG = 1, 2
else:
    OK, NG = 3, 0

for i in range(len(L)-2, -1, -1):
    if L[i] == "1":
        OK, NG = (3*OK + NG)%MOD, 2*NG%MOD
    else:
        OK, NG = OK%MOD, (2*OK + 3*NG)%MOD

print(OK)

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

const int DIM = 1e3 + 5;
const double PI = acos(-1.0);

int main( void ) {
    
    int x, y, z;
    cin >> x >> y >> z;
    
    cout << ( ( (x * 100 + y * 10 + z) % 4 == 0 ) ? "YES" : "NO" );
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
    int n;
    int a,b,c;
    cin >> n;
    if(n%10==1){
        a=9;
        n-=1;
    } else {
        a=1;
        n-=9;
    }
    if(n%100==10){
        b=90;
        n-=10;
    } else {
        b=10;
        n-=90;
    }
    if(n%1000==100){
        c=900;
        n-=100;
    } else {
        c=100;
        n-=900;
    }
    cout << a+b+c << endl;



}

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

using namespace std;

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

const int MAX_N = 101;
const ll MOD = (ll)1e9 + 7LL;

ll fib[MAX_N];
ll dp[101][10];

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

	memset(fib, 0LL, sizeof(fib));
	memset(dp, 0LL, sizeof(dp));
	fib[0] = 1LL;
	fib[1] = 1LL;
	for (int i = 2; i < MAX_N; ++i){
		fib[i] = fib[i-1] + fib[i-2];
		fib[i] %= MOD;
	} // end for

	int N, W, K; cin >> N >> W >> K;
	
	dp[0][0] = 1LL;
	for (int h = 0; h < N; ++h){
		for (int i = 0; i < W; ++i){
			// down 
			dp[h+1][i] += fib[i] * fib[W - i - 1] * dp[h][i];
			dp[h+1][i] %= MOD;
			// right
			if (i == 0){
				dp[h+1][i+1] += fib[i] * fib[W - i - 2] * dp[h][i];
				dp[h+1][i+1] %= MOD;
			}else // left
			if (i == W - 1){
				dp[h+1][i-1] += fib[i-1] * fib[W - i - 1] * dp[h][i];
				dp[h+1][i-1] %= MOD;
			}else{
				dp[h+1][i+1] += fib[i] * fib[W - i - 2] * dp[h][i];
				dp[h+1][i+1] %= MOD;
				dp[h+1][i-1] += fib[i-1] * fib[W - i - 1] * dp[h][i];
				dp[h+1][i-1] %= MOD;
			} // end if
		} // end for
	} // end for

	cout << dp[N][K-1] << endl;

	return 0;
}

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

int main() {
    int n; cin >> n;
    int b, f, r, v;
    int count[4][3][10] = {};
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        count[b - 1][f - 1][r - 1] += v;
    }
    
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int m = 0; m < 10; m++) {
                cout << ' ' << count[i][j][m];
            }
            cout << endl;
        }
        if (i != 3) cout << "####################" << endl;
    }
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define inf (int)(1e8)
using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int h, w, k;
int d[] = {0, 1, 0, -1};
P st, go;
vector<string> s;
vector<vector<int>> memo;

int solve();
bool isvalid(P &now) {
  return now.first >= 0 && now.first < h && now.se >= 0 && now.se < w &&
         s[now.fi][now.se] == '.';
}

int main() {
  cin >> h >> w >> k;
  cin >> st.first >> st.second >> go.first >> go.second;
  s.resize(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  queue<P> qu;
  --st.first, --st.second, --go.first, --go.second;
  memo.assign(h, vector<int>(w, inf));
  memo[st.fi][st.se] = 0;
  qu.push(st);
  while (qu.size()) {
    P now = qu.front();
    int cos = memo[now.fi][now.se] + 1;
    qu.pop();
    for (int i = 0; i < 4; ++i) {
      P to = now;
      for (int j = 0; j < k; ++j) {
        to.fi += d[i];
        to.se += d[1 ^ i];
        if (!isvalid(to) || memo[to.fi][to.se] < cos) break;
        if (memo[to.fi][to.se] > cos) {
          memo[to.fi][to.se] = cos;
          qu.push(to);
        }
      }
    }
  }
  return memo[go.fi][go.se] == inf ? -1 : memo[go.fi][go.se];
}

Measured memory_bytes: 12160
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[100100], d, t;

signed main() {
	cin >> n;
	reps(i,1,n+1) {
		cin >> a[i];
		d += abs(a[i]-a[i-1]);
	}
	d += abs(a[n]);
	reps(i,1,n+1) {
		t = d;
		t -= abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]);
		t += abs(a[i-1]-a[i+1]);
		cout << t << endl;
	}
}


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

L, R = 0, 0
cnt = 0
for s in S:
    if s == '(':
        cnt += 1
    else:
        if cnt > 0:
            cnt -= 1
        else:
            L += 1

R = cnt
print(L * '(' + S + R * ')')

Measured memory_bytes: 38384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int N = in.nextInt();
            Integer B[] = in.nextIntArray(N - 1);
            Integer A[] = new Integer[N];
            A[0] = A[1] = B[0];
            for (int i = 2; i < N; i++) {
                A[i] = B[i - 1];
                A[i - 1] = Math.min(A[i - 1], B[i - 1]);
            }
            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += A[i];
            }
            out.printLine(sum);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public Integer[] nextIntArray(int size) {
            Integer array[] = new Integer[size];
            for (int i = 0; i < size; i++) {
                array[i] = nextInt();
            }
            return array;
        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}



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

int main() {
  string s,t;
  cin >> s >> t;
  int c = t.size(),b,d,e;
  for(int i=0; i < s.size() - t.size() +1; i++){
    b=i;
    d = t.size();
    e = t.size();
    for(int j=0; j < t.size(); j++){
      if(s.at(b)==t.at(j)){
        d--;
        if(e >= d) e = d;
      }
      if(d == 0) e = d;
      if(e == 0) break;
      b++;
    }
    if(c >= e) c = e;
    if(c == 0) break;
  }
  cout << c;
}


Measured memory_bytes: 3560
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

struct BipartiteMatching {
	int n;
	vector<vector<int>> g;
	vector<int> match;
	vector<int> used;
	BipartiteMatching(int n) : n(n), g(n), match(n), used(n) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		fill(match.begin(), match.end(), -1);
		for (int v = 0; v < n; v++) {
			if (match[v] == -1) {
				fill(used.begin(), used.end(), false);
				if (augment(v)) cnt++;
			}
		}
		return cnt;
	}
	bool augment(int v) {
		used[v] = true;
		for (int u : g[v]) {
			int w = match[u];
			if (w == -1 || (!used[w] && augment(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y, E; cin >> X >> Y >> E;
	BipartiteMatching bm(X + Y);
	rep(i, 0, E) {
		int x, y; cin >> x >> y;
		bm.addEdge(x, X + y);
	}
	cout << bm.maximumMatching() << endl;
	return 0;
}

Measured memory_bytes: 3320
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	for(int d;cin>>d;){
		int sum=0;
		for(int i=0;i<600;i+=d)
			sum+=i*i*d;
		cout<<sum<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long
vector<pair<int, int>> ans;
int A[51];
int32_t main(){ fast;
	
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i)
        cin>>A[i];
    int mi = 0, ma = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(A[mi]>A[i])
            mi = i;
        if(A[ma]<A[i])
            ma = i;
    }
    if(ma && abs(A[ma])>=abs(A[mi]))
    {
        for(int i = 2; i <= n; ++i)
        {
            while(A[i]<A[i-1])
            {
                A[i] += A[ma];
                ans.emplace_back(ma, i);
                if(A[i]>A[ma])
                    ma = i;
            }
        }
    }
    else if(abs(A[mi])>A[ma])
    {
        for(int i = n-1; i >= 1; --i)
        {
            while(A[i]>A[i+1])
            {
                A[i] += A[mi];
                ans.emplace_back(mi, i);
                if(A[i]<A[mi])
                    mi = i;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto i: ans)
        cout<<i.first<<' '<<i.second<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define all(a)      a.begin(),a.end()
#define getc getchar_unlocked
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  int x[6],ans=0;
  fp(i,1,5)
    {
        cin >> x[i];
    if(x[i]==0)
        ans=i;
    }
    cout << ans << '\n'; 
  return;
} 

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define ll          long long
#define all(a)      (a).begin(),(a).end()
#define pb          push_back
#define INF         10000000000000000
using namespace std;
ll i,j,k,n,x,mid,sum1=0,sum2=0,ans,l[300005],r[300005];
vector<ll> v(300005);
int main()
{
    cin>>n;
	for(i=0;i<3*n;i++){
		cin>>v[i];
	}
	priority_queue<int> pq; //max_heap for first half
	priority_queue<int,vector<int>,greater<int> > pq2; //min_heap for second half
	ll csum=0;
	for(i=0;i<3*n;i++){
		pq2.push(v[i]);
		csum+=v[i];
		if(pq2.size()>n){
			csum-=pq2.top();pq2.pop();
		}
		if(pq2.size()==n)l[i]=csum;else l[i]=-INF; //maximum  possible sumof n numbers till ith index so, 
	}											//if i<n or pq2.size<n set it to -inf cause it is not favourable
	csum=0;
	for(int i=3*n-1;i>=0;i--){
		pq.push(v[i]);
		csum+=v[i];
		if(pq.size()>n){
			csum-=pq.top();pq.pop();
		}
		if(pq.size()==n) r[i]=csum;else r[i]=INF;//minimum  possible sumof n numbers till ith index from back so, 
	}											//if i<2*n or pq2.size<n set it to inf cause it is not favourable
	ll ans=-INF;
	for(i=0;i<3*n-1;i++){
		ans=max(ans,l[i]-r[i+1]); //checking at where the partition would be for maximum ans
							      // u can also loop from n to 2*n because l[i]is -inf before n and r[i]is inf after 2*n
	}
	cout<<ans<<endl;
 
    return 0;
}


Measured memory_bytes: 8184
q, h, s, d = [int(x) for x in input().split()]
n = int(input())

h = min(h, 2*q)
s = min(s, 2*h)
d = min(d, 2*s)

ans = n // 2 * d
if n % 2 == 1:
    ans += s

print(ans)


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int N; cin >> N;
	vector<int> A(N);
	REP(i,N) cin >> A[i];

	int _max = -1;
	REP(i,N) _max = max(_max, A[i]);

	vector<int> cnt(_max+1, 0);

	REP(i,N){
		int tmp = A[i];
		while(tmp <= _max){
			cnt[tmp]++;
			tmp += A[i];
		}
	}

	int ans = 0;
	REP(i,N) if(cnt[A[i]] == 1) ans++;

	cout << ans << endl;

	return 0;

}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string s, t; 
    cin>> s >> t;
    int ans = t.size();
    for(int i = 0; i <= s.size() - t.size(); i++){
        int count = 0;
        for(int j = 0; j < t.size(); j++){
            //cout << s[j+i] << " " << t[j] << endl;
            if(s[j+i] != t[j]) count++;
        }
        //cout << count << endl;
        ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
N, K = map(int, input().split())
p = list(map(int, input().split()))
a = [0] * (N+1)
for i in range(N):
    a[i+1] = a[i] + p[i]
result = [a[i+K] - a[i] for i in range(N-K+1)]
print((max(result)+K)/2)


Measured memory_bytes: 25064
"use strict"
function main(arg) {
    //とりあえず行を分割
    var input = arg.split(' ');
    var ki = input[0];
    var mieru = input[1];

    var kakeru2 = mieru * 2 ;
    var kakeru = kakeru2 + 1;


    var kotae = Math.ceil(ki / kakeru);


    console.log(kotae);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	char x;
	cin >> x;
	if(x >= 'A' && x <= 'Z')
		cout << 'A';
	else
		cout << 'a';
}

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS;
     int t = 1;
     //cin >> t;
     while(t--){
     	solve();
     }
     return 0;
    
}

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

struct Problem {

    void Solve() {
        UL N, S; scanf("%d%d", &N, &S);
        vector<UL> A(N); rep(i, N) scanf("%d", &A[i]);
        UL Z = 0; UL q = 0;
        UL ans = -1;
        rep(p, N) {
            Z += A[p];
            while (S + A[q] <= Z) { Z -= A[q]; q++; }
            if (Z >= S) ans = min(ans, p - q + 1);
        }
        if (ans == -1) printf("0\n");
        else printf("%d\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    //cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}




Measured memory_bytes: 3416
N = int(input())
A = list(map(int, input().split()))

flag = 0
for i in range(N):
	if A[i] % 2 == 0:
		if A[i] % 3 != 0 and A[i] %5 != 0:
			flag = 1

if flag == 0:
	print('APPROVED')
else:
	print('DENIED')

Measured memory_bytes: 38384
N, K = map(int, input().split())
P = list(map(int, input().split()))

for i in range(N):
    P[i] = (P[i] + 1) / 2

tmp = 0
for i in range(K):
    tmp += P[i]
ans = tmp

for i in range(K, N):
    tmp += P[i] - P[i - K]
    ans = max(ans, tmp)

print (ans)

Measured memory_bytes: 71792
/* -------------------------------- */
/* Name: MD. Khairul Basar          */
/* Institute: HSTU                  */
/* Dept: CSE                        */
/* Email: khairul.basar93@gmail.com */
/* -------------------------------- */

#include <bits/stdc++.h>
/* all header files */

#define fs            first
#define sc            second
#define sp            printf(" ")
#define nl            printf("\n")
#define pb(a)         push_back(a)

#define setzero(a)    memset(a,0,sizeof(a))
#define setneg(a)     memset(a,-1,sizeof(a))
#define setinf(a)     memset(a,126,sizeof(a))

#define tc1(x)        printf("Case %d: ",x)
#define tc2(x)        printf("Case #%d: ",x)
#define tc3(x)        printf("Case %d:\n",x)
#define tc4(x)        printf("Case #%d:\n",x)

#define iin(x)        scanf("%d",&x)
#define din(x)        scanf("%lf",&x)
#define lin(x)        scanf("%lld",&x)
#define clin(x)       scanf("%I64d",&x)

#define pr1(x)        cout<<x<<"\n"
#define pr2(x,y)      cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z)    cout<<x<<" "<<y<<" "<<z<<"\n"
#define pr4(w,x,y,z)  cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define fast          ios::sync_with_stdio(0)
#define read          freopen("input.txt","r",stdin)
#define write         freopen("output.txt","w",stdout)
#define prflag1(flag) printf("%s\n",(flag)?"YES":"NO")
#define prflag2(flag) printf("%s\n",(flag)?"Yes":"No")
#define prflag3(flag) printf("%s\n",(flag)?"yes":"no")
/* macro definitions */

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int>pii;
typedef pair<LL, LL>pll;
typedef vector<int>vi;
typedef vector<LL>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
/* type definitions */

LL MOD_EXPO(LL b, LL p, LL m)
{
    if(p==0) return 1;
    LL ret=MOD_EXPO(b,p/2,m)%m;
    ret=(ret*ret)%m;
    return ((p&1) ? (ret*b)%m : ret%m);
}
LL POWER(LL N, LL K)
{
    LL i,ans=1;
    for(i=1;i<=K;i++) ans*=N;
    return ans;
}
int SET(int N, int pos)
{
    return (N | (1<<pos));
}
int RESET(int N, int pos)
{
    return (N & !(1<<pos));
}
bool CHECK(int N, int pos)
{
    return (N & (1<<pos));
}
/* necessary functions */

int dx4[]= {1,-1,0,0};
int dy4[]= {0,0,1,-1};
int dx6[]= {0,0,1,-1,0,0};
int dy6[]= {1,-1,0,0,0,0};
int dz6[]= {0,0,0,0,1,-1};
int dx8[]= {1,-1,0,0,-1,1,-1,1};
int dy8[]= {0,0,1,-1,1,1,-1,-1};
int dkx8[]= {-1,1,-1,1,-2,-2,2,2};
int dky8[]= {2,2,-2,-2,1,-1,1,-1};
/* direction arrays */

int tc=1;
const double eps=1e-9;
const double pi=acos(-1.0);
const long long int mx=1e5;
const long long int mod=1e9+7;
/* global declarations */

LL arr[mx+5];

int main()
{
    LL i,n,x,a,ans,b;
    while(cin>>n>>x)
    {
        for(i=0;i<n;i++) lin(arr[i]);
        ans=0;
        for(i=1;i<n;i++)
        {
            a=arr[i-1]+arr[i];
            if(a>x)
            {
                b=a-x;
                ans+=b;
                if(b<=arr[i]) arr[i]-=b;
                else b-=arr[i],arr[i]=0,arr[i-1]-=b;
            }
        }
        pr1(ans);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
   int a, b, k, i, j = 0;
 
   scanf("%d %d %d",&a,&b,&k);
 
   for(i=a;i<=b;i++){
     if((i<= a+k-1)||(i >= b+1-k)){
         printf("%d\n", i);
    }   
   }

   return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        var a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        var b = new int[n];
        for(int i = 1; i < n; i++){
            b[i] = a[i] - a[i-1];
        }
        long money = 1000;
        long stock = 0;
        for(int i = 0; i < n; i++){
            if(stock == 0){
                for(int j = i+1; j < n; j++){
                    if(b[j] < 0){
                        i = j-1;
                        break;
                    }
                    if(b[j] > 0){
                        long k = money / a[i];
                        money -= a[i] * k;
                        stock = k;
                        i = j-1;
                        break;
                    }
                }
            }else{
                for(int j = i+1; j < n; j++){
                    if(b[j] > 0){
                        i = j-1;
                        break;
                    }
                    if(b[j] < 0){
                        money += stock * a[i];
                        stock = 0;
                        i = j-1;
                        break;
                    }
                }
            }
        }
        money += stock * a[n-1];
        System.out.println(money);
    }
}

Measured memory_bytes: 35568