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

using namespace std;

int main() {
    while(true) {
        int W, H;
        cin >> W >> H;
        if(!W && !H) break;

        /*
         * 0: ツ陳シツ進ツつオツづ可コツつゥツづァ
         * 1: ツ陳シツ進ツつオツづ債カツつゥツづァ
         * 2: ツ凝按つェツづづ可コツつゥツづァ
         * 3: ツ凝按つェツづづ債カツつゥツづァ
         */
        vector<vector<vector<int> > > v(W, vector<vector<int> >(H, vector<int>(4, 0)));

        for(int x = 0; x < W; ++x)
            v[x][0][1] = 1;
        for(int y = 0; y < H; ++y)
            v[0][y][0] = 1;

        for(int x = 1; x < W; ++x) {
            for(int y = 1; y < H; ++y) {
                v[x][y][0] = (v[x][y-1][0] + v[x][y-1][2]) % 100000;
                v[x][y][1] = (v[x-1][y][1] + v[x-1][y][3]) % 100000;
                v[x][y][2] = v[x][y-1][1];
                v[x][y][3] = v[x-1][y][0];
            }
        }

        int sum = 0;
        for(int i = 0; i < 4; ++i)
            sum += v[W-1][H-1][i];

        cout << sum%100000 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int differ(int y){
  return 4280-y;
}

int fee(int w){
  int a[4]={0,125,140,160};
  int basic=1150;
  int addition=0;
  int i;
  int n=w;

  for(i=3;i>=0;i--){
    if(n>10*i){
      addition+=a[i]*(n-10*i);
      n=10*i;
    }
  }

  return basic+addition;
}

void doit(){
  int w;

  scanf("%d",&w);
  if(w!=-1){
    printf("%d\n",differ(fee(w)));
    doit();
  }
}

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

Measured memory_bytes: 604
import math
n=int(input())
s=0

for i in range(n):
    a=int(input())
    #b=int(a**0.5)
    b=math.ceil(a**0.5)
    #print(str(b), '??O') 
    if a==2:
        s+=1
   #     print(str(a),'!!!!')
    elif a%2==0 or a < 2:
        continue
    else:
        j=3
        c=0
        while j <= b:
            if a%j==0:
                c+=1
                break
            j+=2
        if c==0:
            s+=1
        """
        for j in range(3,b+1,2):
            if a%j==0:
                break
            if j==b:
                s+=1
                print(str(a),'!!!!')
"""
print(s)

Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    int sz=s.size()-1;
    if(s[0]==s[sz]&&(sz+1)%2==0) cout<<"First"<<endl;
    else if(s[0]!=s[sz]&&(sz+1)%2!=0) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}

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

vector<pair<int64_t, int64_t>> getBestSplit(vector<int> v) {
    int n = v.size();
    vector<pair<int64_t, int64_t>> ans(n);

    int split = -1;
    int64_t sum_i = 0, sum_split = 0;

    for(int i = 0; i < n; ++i) {
        sum_i += v[i];
        while(split + 1 < i and abs(sum_split + v[split + 1] - (sum_i - v[split + 1])) <
                                abs(sum_split - sum_i)) {
            split += 1;
            sum_split += v[split];
            sum_i -= v[split];
        }
        ans[i] = make_pair(sum_split, sum_i);
    }

    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> v(n, 0);

    for(int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    
    auto left_split = getBestSplit(v);
    
    auto w = v;
    reverse(w.begin(), w.end());

    auto right_split = getBestSplit(w);
    reverse(right_split.begin(), right_split.end());
    
    int64_t ans = numeric_limits<int64_t>::max();

    for(int mid = 1; mid < n - 1; mid += 1) {
        vector<int64_t> pieces = {
            left_split[mid].first, left_split[mid].second,
            right_split[mid + 1].first, right_split[mid + 1].second
        };
        sort(pieces.begin(), pieces.end());
        ans = min(ans, int64_t(pieces.back() - pieces[0]));
    }

    cout << ans << "\n";
}

Measured memory_bytes: 8816
#include <cstdio>
#include <algorithm>
using namespace std;
int p[8], t[8], u[8], c[8] = { 1, 4, 1, 4, 1, 2, 1, 2 };
bool comp() {
	for(int j = 0; j < 8; j++) {
		if(t[j] > u[j]) return true;
		if(t[j] < u[j]) return false;
	}
	return false;
}
int main() {
	while(~scanf("%d%d%d%d%d%d%d%d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7])) {
		int ret = 999999999;
		for(int i = 0; i < 8; i++) t[i] = 999999999;
		for(int i = 0; i < 8; i++) {
			int res = 0;
			for(int j = i; j < i + 8; j++) res += max(p[j - i] - c[j % 8], 0), u[j - i] = c[j % 8];
			if(res < ret) {
				ret = res;
				for(int j = 0; j < 8; j++) t[j] = u[j];
			}
			else if(res == ret && comp()) {
				for(int j = 0; j < 8; j++) t[j] = u[j];
			}
			//for(int j = 0; j < 8; j++) printf("%d ", u[j]);
			//printf("%d\n", res);
		}
		//printf("%d\n", ret);
		for(int j = 0; j < 8; j++) {
			if(j) printf(" ");
			printf("%d", t[j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2556
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for(int i = 2; i < MAX; ++i){
    if(!is_prime[i]) continue;
    for(int j = i*2; j < MAX; j += i) is_prime[j] = 0;
  }
  vector<int> a(MAX, 0);
  for(int i = 0; i < MAX; ++i){
    if(i%2 == 0) continue;
    if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
  }
  vector<int> s(MAX + 1, 0);
  for(int i = 0; i < MAX; ++i)s[i+1] = s[i] + a[i];

  int Q; cin >> Q;
  for(int q = 0; q < Q; ++q){
    int l, r;
    cin >> l >> r;
    cout << s[r+1] - s[l] << endl;
  }
}

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

const int INF = 1e9 + 5;
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;

	vector<int> all(n);
	for (int i = 0; i < n; i++)
		cin >> all[i];

	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j : {1, 2})
		{
			if (i + j < n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(all[i + j] - all[i]));
		}
	}
	cout << dp[n - 1] << "\n";
}

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

typedef long long LL;

void solve()
{
    vector<int> v(3);

    for(int i = 0; i < 3; i++) cin >> v[i];

    sort(v.begin(), v.end(), std::greater<int>());

    cout << abs((v[1] - v[0]) + (v[2] - v[1])) << endl;
}

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


Measured memory_bytes: 256
i = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[i-1])

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL << 60)
#define EPS (1e-10)
using namespace std;
typedef long long Int;
typedef pair<int, int> P;

int N;
int M;
Int X;

Int price[15];
Int books[15][15];
Int ms[15];

int main() {
  cin >> N >> M >> X;
  for(int i = 0; i < N; i++) {
    cin >> price[i];
    for (int j = 0; j < M; j++) {
      cin >> books[i][j];
    }
  }

  Int ans = INF;
  // 2 ** N通り
  for(int bits = 0; bits < (1 << N); bits++) {
    for(int j = 0; j < M; j++) {
      ms[j] = 0;
    }
    Int sum_price = 0;
    for(int i = 0; i < N; i++) {
      // 買わない場合
      if(!(bits & (1 << (i)))) {
        continue;
      }
      // 買う場合
      sum_price += price[i];
      for(int j = 0; j < M; j++) {
        ms[j] += books[i][j];
      }
    }
    bool ok = true;
    for(int j = 0; j < M; j++) {
      if (ms[j] < X) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, sum_price);
    }
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
/**
 * Created by hiramekun at 21:18 on 2019-09-28.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll ll_inf = ll(1e9) * ll(1e9);

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

int main() {

    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> key;
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        ll s = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            c--;
            s |= 1 << c;
        }
        key.emplace_back(s, a);
    }
    ll pow2 = 1 << n;
    vector<ll> dp(pow2, ll_inf); // dp[i]: 集合iの宝箱を開ける最小コスト
    dp[0] = 0;

    rep(s, pow2) {
        rep(i, m) {
            ll t = s | key[i].first; // 遷移先
            ll cost = dp[s] + key[i].second;
            dp[t] = min(dp[t], cost);
        }
    }
    ll ans = dp.back();
    if (ans == ll_inf) ans = -1;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  string str, current;
  cin >> str;
  auto solve = [&] () {
    ll ans = 0;
    int goal = current.size() - 1;
    for (int i = current.size() - 1; i >= 0; i--) {
      if (current[i] == '*') {
        ans += goal - i;
        goal--;
      }
    }
    return ans;
  };
  ll ans = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'A') {
      current += '*';
    } else if (str[i] == 'B' && i + 1 < str.size() && str[i + 1] == 'C') {
      current += '.';
      i++;
    } else {
      ans += solve();
      current.clear();
    }
  }
  cout << ans + solve() << endl;
  return 0;
}


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

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

 	long int N,Q;
    int *A;
    int A_count[100001]={0};
    int B,C;
    long int s=0;
    int diff;

    cin>>N;
    A=new int[N];
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
        s+=A[i];
    }
    for(int i=0;i<N;i++)
        A_count[A[i]]+=1;

    cin>>Q;
    for(int i=0;i<Q;i++)
    {
      	
        cin>>B>>C;
        diff=C-B;

        s+=diff*A_count[B];
        A_count[C]+=A_count[B];
        A_count[B]=0;
        cout<<s<<'\n';
    }
    
    delete[] A;

}

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

#define int        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<int>
#define v2d        vector<vector<int>>
#define vip        vector<pair<int,int> >
#define v1s        vector<string>
#define pa         pair<int,int>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<"\n";
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define endl       "\n"
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

void azmuth(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
   
}
int lb = 10000000;

//____________________________________________________________________________________


void solve(){
    string s,t;cin>>s>>t;
    int n = s.length(), m = t.length();
    v2d v(n,v1d(m,0));
    for(int i=0;i<m;i++)v[0][i] = (s[0] == t[i]);
    for(int i=0;i<n;i++)v[i][0] = (s[i] == t[0]);
    int x = 0;
    for(int i=0;i<m;i++){
        if(v[0][i])x = 1;
        v[0][i] = x;
    }
    x = 0;
    for(int i=0;i<n;i++){
        if(v[i][0])x = 1;
        v[i][0] = x;
    }

    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(s[i] == t[j])v[i][j] = 1+v[i-1][j-1];
            v[i][j] = max(v[i][j-1],v[i][j]);
            v[i][j] = max(v[i][j],v[i-1][j]);
        }
    }
    // p2d(v);
    string sum = "";
    int i = n-1, j = m-1;
    while(i >= 0 && j >= 0 && lb--){
        if(s[i] == t[j]){
            sum += s[i];
            i--;j--;
            continue;
        }
        if(i && v[i][j] == v[i-1][j]){
            i--;continue;
        }
        if(j && v[i][j] == v[i][j-1]){
            j--;continue;
        }
    }
    reverse(all(sum));
    cout<<sum;
}

int32_t main(){
    azmuth();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}

Measured memory_bytes: 70784
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n;
    long long sum;
    scanf("%d", &n);
    sum = n;
    for (int i = n-1; i >= 2; i--) {
        sum *= i;
    }
    printf("%lld\n", sum);
    return 0;
}



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

void insertionsort(vector<int> A,int n){
	for(int i=1;i<n;i++){
		int v=A[i];
		int j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
			cout<<A[1];
		for(int j=2;j<n;j++)
			cout<<" "<<A[j];
		cout<<endl;
	}
}

int main(){
	
	int n;
	cin>>n;
	vector<int>A(n+1);
	for(int i=1;i<n+1;i++)
		cin>>A[i];
	insertionsort(A,n+1);
	
}

Measured memory_bytes: 1212
n = int(input())

c = 0
for i in range(1,n+1):
  tmp = 0
  if(i%2 == 1):
    for j in range(1,i+1):
      if(i%j == 0):
        tmp += 1
  #print(tmp)
  if(tmp ==  8):
    c += 1
    
print(c)

Measured memory_bytes: 38640
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int n,i,a,b;
string s,t;
int main(void){
  cin>>n;
  for(i=0;i<n;i++){
    cin>>s>>t;
    if(s<t)b+=3;
    else if(s>t)a+=3;
    else a++,b++;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}



Measured memory_bytes: 3152
#include <stdio.h>

int main()
{
	int N, i;
	long long int m=0, a=0, r=0, c=0, h=0, ans;
	char s[100000][10];

	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%s", s[i]);
	}

	for(i=0; i<N; i++){
		if(s[i][0]=='M'){
			m++;
		}else if(s[i][0]=='A'){
			a++;
		}else if(s[i][0]=='R'){
			r++;
		}else if(s[i][0]=='C'){
			c++;
		}else if(s[i][0]=='H'){
			h++;
		}
	}
	ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  vector<int>abc(3,0);
  
  for(int i=0;i<3;i++){
    if(s[i] == 'a')
      abc[0]++;
    else if(s[i] == 'b')
      abc[1]++;
    else if(s[i] == 'c')
      abc[2]++;
  }
  
  if(abc[0] * abc[1] * abc[2] == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,n;
  cin>>n;

  vi a(n),order(n);
  rep(i,n)cin>>a[i];
  rep(i,n)order[a[i]-1]=i;

  set<int> st;
  st.insert(-1);
  st.insert(n);

  ll ans=0;
  rep(i,n){
    set<int>::iterator itr=st.lower_bound(order[i]);
    ll right=(*itr)-order[i];
    itr--;
    ll left=order[i]-(*itr);
    ll tmp=a[order[i]]*left*right;
    ans+=tmp;
    st.insert(order[i]);
  }
  cout<<ans<<endl;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 300003;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  int a = getInt();
  int b = getInt();
  int c = getInt();
  for (int i = 1; i < n; i++) {
    int ai = getInt() + max(b, c);
    int bi = getInt() + max(c, a);
    int ci = getInt() + max(a, b);
    a = ai, b = bi, c = ci;
  }
  printf("%d\n", max(a, max(b, c)));
  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 vi=vector<int>;
using vvi=vector<vector<int>>;

int main(){
  int n;cin>>n;
  vi v(n-1);
  rep(i,n-1)cin>>v[i];
  int a=v[0]+v[n-2];
  rep(i,n-2)a+=min(v[i],v[i+1]);
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100],b[100],n;
int main(){
 	cin>>n;
  	for (int i=1;i<=n;i++) cin>>a[i];
  	int ans = 0;
  	for (int i=1;i<=n;i++){
    	cin>>b[i];
      	if (a[i] > b[i]) ans += a[i] - b[i];
    }
  	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int a[100050];int n;
int main()
{
	int i,max=0,x=0;
	cin>>n;
	if(n<4){cout<<0;return 0;}
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n,cmp);
	for(i=0;i<n;i++)
	{
		if(max==0)
			max=a[i];
		else
			if(a[i]==max)
				if(x==0)
				{
					x=max;max=0;
				}
				else
				{
					cout<<(long long)max*(long long)x;return 0;
				}
			else
				max=a[i];
	}
	cout<<0;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N, M;
    cin >> N >> M;
    ll x[M];
    rep(i, M) cin >> x[i];
    ll ans;
    if(N >= M){
        ans = 0;
    }else{
        sort(x, x + M);
        ll sub[M];
        sub[0] = 0;
        for(int i = 1; i < M; i++) sub[i] = x[i] - x[i-1];
        sort(sub, sub + M, greater<ll>());
        ans = x[M-1] - x[0];
        rep(i, N-1) ans -= sub[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main() {
    string str, c, p;
    int q, a, b;
    cin >> str >> q;
    for(int i = 0; i < q; ++i) {
        cin >> c >> a >> b;
        if(c == "print") {
            for(; a <= b; ++a) {
                cout << str[a];
            }
            cout << endl;
        }
        else if(c == "reverse") {
            for(; a < b; ++a, --b) {
                char tmp = str[a];
                str[a] = str[b];
                str[b] = tmp;
            }
        }
        else if(c == "replace") {
            cin >> p;
            str.replace(a, b-a+1, p);
        }
    }

    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> edge(N);
    vector<set<int>> rails(N);
    for (int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        p--;q--;
        edge[p].push_back({c, q});
        edge[q].push_back({c, p});
        rails[p].insert(c);
        rails[q].insert(c);
    }
    for (int i = 0; i < N; i++) sort(edge[i].begin(), edge[i].end());
    
    deque<pair<int, pair<int, int>>> dq;
    vector<map<int, int>> vmp(N);
    
    vmp[0][-1] = 0;
    dq.push_back({0, {0, -1}});
    
    while (!dq.empty()) {
        int d = dq.front().first;
        int now = dq.front().second.first;
        int rail = dq.front().second.second;
        dq.pop_front();
        if (rail == -1) {
            for (int nrail : rails[now]) {
                if (vmp[now].find(nrail) != vmp[now].end() && vmp[now][nrail] <= d+1) continue;
                vmp[now][nrail] = d+1;
                dq.push_back({d+1, {now, nrail}});
            }
        }else {
            pair<int, int> pt = {rail, 0};
            auto it = lower_bound(edge[now].begin(), edge[now].end(), pt);
            while (it != edge[now].end() && (*it).first == rail) {
                int nxt = (*it).second;
                if (vmp[nxt].find(rail) != vmp[nxt].end() && vmp[nxt][rail] <= d) {
                    it++;
                    continue;
                }
                vmp[nxt][rail] = d;
                dq.push_front({d, {nxt, rail}});
                it++;
            }
            if (vmp[now].find(-1) != vmp[now].end() && vmp[now][-1] <= d) continue;
            vmp[now][-1] = d;
            dq.push_front({d, {now, -1}});
        }
    }
    if (vmp[N-1].empty()) {
        cout << -1 << endl;
        return 0;
    }
    int ans = N;
    for (auto p : vmp[N-1]) ans = min(ans, p.second);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 65804
N = int(input())
X = input()
p0 = X.count('1')
p1, p2 = p0-1, p0+1
mem = {0:0}
def f(n):
    if n in mem:
        return mem[n]
    else:
        p = bin(n).count('1')
        ret = f(n % p) + 1
        mem[n] = ret
        return ret
r1 = r2 = 0
k1 = k2 = 1
for i in range(N):
    if X[-i-1] == '1':
        if p1 > 0:
            r1 = (r1+k1) % p1
        r2 = (r2+k2) % p2
    if p1 > 0:
        k1 = k1 * 2 % p1
    k2 = k2 * 2 % p2

ans = [None]*N
k1 = k2 = 1
for i in range(N):
    if X[-i-1] == '0':
        r = (r2 + k2) % p2
        ans[-i-1] = f(r) + 1
    elif p1 > 0:
        r = (r1 - k1) % p1
        ans[-i-1] = f(r) + 1
    else:
        ans[-i-1] = 0
    if p1 > 0:
        k1 = k1 * 2 % p1
    k2 = k2 * 2 % p2
for i in range(N):
    print(ans[i])


Measured memory_bytes: 79436
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int c[5];

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

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


}

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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> l(m), r(m);
  rep(i, m) cin >> l[i] >> r[i];
  ll a = LLONG_MIN, b = LLONG_MAX;
  rep(i, m) updatemax(a, l[i]);
  rep(i, m) updatemin(b, r[i]);
  cout << max(0ll, b - a + 1) << endl;
}


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

int main() {
  long long n, k; cin >> n >> k;
  long long out;
  if(n>k){
    long long a = n % k;
    long long b = a + k;
    long long c = k - a;
    if(a < b) out = a;
    if(c < out) out = c;
  }else{
    out = k - n;
    if(n < out) out = n;
  }
  cout << out;
}


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

int main(){
  int h,w,k;
  while(cin>>h>>w){
  int l=h*h+w*w;
  k=0;
  if(h==0 && w==0){return 0;}
  for(int i=h+1;i<w;i++){
    for(int j=w;h<j;j--){
      if(l==i*i+j*j && i<j){
        cout<<i<<" "<<j<<endl;
        k=1;
        i=w;
      }
    }
  }
  
  while (k==0) {
    l++;
    for(h=1;h*h<l/2;h++){
      for(w=sqrt(l);h<w;w--){
        if(l==h*h+w*w && h<w){
          cout<<h<<" "<<w<<endl;
          k=1;
          h=l;
        }
      }
    }
  }
  
  }
  return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100001
int n;
double X[MAX_N],R[MAX_N];
 
bool check(double y){
  double l=-1e9;
  double r=1e9;
  for(int i=0;i<n;i++){
    double a=X[i]- sqrt(R[i]*R[i]-y*y);
    l=max(l,a);
    double b=X[i]+ sqrt(R[i]*R[i]-y*y);
    r=min(r,b);
  }
  return (l<r);
}
 
int main(){
  double left=0,right=1e9,mid;
   
  cin>>n;
  for(int i=0;i<n;i++){
    int x,r;
    cin>>x>>r;
    X[i]=x;
    R[i]=r;
 
    right=min(right,R[i]);
  }
 
  for(int i=0;i<100;i++){
    mid=(left+right)*0.5;
    if(check(mid))left=mid;
    else right=mid;
  }
 
  printf("%.10f\n",left);
}
   

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

int main()
{
	int N;
	cin >> N;
	vector<pair<string, int>> R;
	for(int i(0);i<N;++i){
		string S;
		int P;
		cin >> S >> P;
		if(100 - P < 100) S += '0';
		if(100 - P < 10) S += '0';
		S += to_string(100-P);
		R.push_back(make_pair(S, i+1));
	}
	sort(R.begin(),R.end());
	for(int i(0);i<N;++i){
		cout << R[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            char[][] arr = new char[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = in.next().toCharArray();
            }

            for (int i = -1; i <= n; i++) {
                for (int j = -1; j <= m; j++) {

                    if (i < 0 || j < 0) out.print("#");
                    else if (i == n || j == m) out.print("#");
                    else out.print(arr[i][j]);

                }
                out.println();
            }

        }

    }
}



Measured memory_bytes: 23444
##B
N = int(input())
A = list(map(int,input().split()))
ans = 0
ans1 = 0
for i in A:
    if i % 2 == 0:
        ans += 1
        if i % 3 == 0 or i % 5 ==0:
            ans1 += 1
if ans == ans1:
    print("APPROVED")
else:
    print("DENIED")

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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	ll X;
	cin >> X;
	for(ll a=-1000; a<=1000; a++){
		for(ll b=-1000; b<=1000; b++){
			if(a*a*a*a*a-b*b*b*b*b==X){
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,in[4];
  cin>>n;
  rep(i,4)cin>>in[i];
  int mini=1e9;
  loop(i,1,n+1){
    int x[4]={0};
    int y[4]={0};
    rep(j,4){
      if(in[j]%i!=0)x[j]=in[j]%i;
      else x[j]=i;
      if((in[j]/i)*i==in[j])y[j]=in[j]/i;
      else y[j]=in[j]/i+1;
    }
    /*    rep(i,4)cout<<" "<<x[i];
    cout<<endl;
    rep(i,4)cout<<" "<<y[i];
    cout<<endl<<endl;*/

    int xx,yy;
    xx=abs(x[0]-x[1])+abs(y[0]-y[1]);
    yy=abs(x[2]-x[3])+abs(y[2]-y[3]);
    //cout<<xx<<" "<<yy<<endl;
    mini=min(mini,xx+yy);
  }
  cout<<mini<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
    long n,a;
    long s = 0;
    long l = 0;
    long m = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a ;
        if(i == 0 || a < s){
            s = a;
        }
        if(i == 0 || a > l){
            l = a;
        }
        m += a;
    }
    cout << s << " " << l << " " << m << endl;
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(arg),key)-begin(arg)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

using namespace std;

template<class T>void reg(vector<T> &ary,const T &elem){ary.emplace_back(elem);}
template<class T>bool chmin(T &a, const T &b) {return (b<a)?(a=b,1):0;}
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}

using R=long double; // __float128
const R EPS = 1E-10; // [-1000:1000]->EPS=1e-8 [-10000:10000]->EPS=1e-7
const R EPS2 = 1E-4; // [-1000:1000]->EPS=1e-8 [-10000:10000]->EPS=1e-7
const R INF = 1E40;
constexpr R PI = acos(R(-1));
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}
inline int sgn(const R& a, const R &b){ return sgn(a-b); }
inline R sq(R x){return sqrt(max<R>(x,0.0));}

using P=complex<R>;
using C=struct{P c;R r;};
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

enum RCC{IN=1,ON_IN=2,ISC=4,ON_OUT=8,OUT=16,ONS=10};
int rcc(C a,C b){
	R d=abs(a.c-b.c);
	if(sgn(a.r+b.r-d)<0) return OUT;
	if(sgn(a.r+b.r-d)==0) return ON_OUT;
	if(sgn(abs(a.r-b.r)-d)<0) return ISC;
	if(sgn(abs(a.r-b.r)-d)==0) return ON_IN;
	return IN;
}

R area(C c1,C c2){
	R d=abs(c2.c-c1.c);
   	int r=rcc(c1,c2);
    if(r>=ON_OUT) return 0.0;  
    if(r==IN) return min(norm(c1.r),norm(c2.r))*PI;
    R rc=(norm(d)+ norm(c1.r) - norm(c2.r))/(2.0*d),theta=acos(rc/c1.r),phi=acos((d-rc)/c2.r);
    return norm(c1.r)*theta+norm(c2.r)*phi-d*c1.r*sin(theta);
}

C calc(C c1,C c2,R s){
	C ok=C({c1.c,c2.r}),ng=c2;
	rep(loop,200){
		const C mid=C({(ok.c+ng.c)/P(2,0),c2.r});
		R res=area(c1,mid);
		if(s<=res)
			ok=mid;
		else
			ng=mid;
	}
	return ok;
}

int main(void){
	int w,h,a,b,c;
	while(cin >> w >> h >> a >> b >> c,w){
		R ra=sq(1.0*a/PI),rb=sq(1.0*b/PI);
		bool ok=true;
		if(min(w,h)<2*max(ra,rb)) ok=false;
		C c1={P(ra,ra),ra},c2={P(w-rb,h-rb),rb};
		R limit=area(c1,c2);
		if(c<limit) ok=false;
		if(ok){
			cout.precision(20);
			if(c1.r>c2.r)
				c2=calc(c1,c2,c);
			else
				c1=calc(c2,c1,c);
			cout << fixed << c1.c << " " << c1.r << " " << c2.c  << " " << c2.r << endl;
		}else{
			cout << "impossible" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3492
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int V,D[1000][1000]={0};
int F[1000]={0};
int MF(int s,int t,int min){
  if(s==t)return min;
  int i,r;
  F[s]=1;//printf("\ns:%d ",s);
  for(i=0;i<V;i++){
    if(F[i]||D[s][i]==0)continue;//printf("i:%d ",i);
    r=MF(i,t,MIN(min,D[s][i]));
    D[s][i]-=r;
    D[i][s]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int s,int t){
  int i,a,b=0;
  for(;a=MF(s,t,10000000);b+=a){
    for(i=0;i<V;i++)F[i]=0;
    /*for(i=0;i<V*V;i++){
      if(i%V==0)printf("\n");
      printf("%d ",D[i/V][i%V]);
    }
    printf("\n");//*/
  }
  return b;
}
int main(){
  int m,a,b,c,i;
  scanf("%d %d",&V,&m);
  for(;m--;D[a][b]=c)scanf("%d %d %d",&a,&b,&c);
  /*for(i=0;i<V*V;i++){
      if(i%V==0)printf("\n");
      printf("%d ",D[i/V][i%V]);
    }
    printf("\n");//*/
  printf("%d\n",maxf(0,V-1));
  return 0;
}

Measured memory_bytes: 996
// C - Rectangle Cutting
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	long long w, h, x, y;
	cin >> w >> h >> x >> y;
	long long xx = w - x, yy = h - y;
	bool yes = (xx == x && yy == y);
	double a = w * h / 2.0;
	cout << setprecision(10) << ((long long) w * h / 2.0) << ' ' << (yes ? 1 : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
 
const int MOD = 1e9+7;
 
ll modpower(ll x, ll y) {
    ll res = 1;
    x %= MOD;
    if(!x) return 0;
    while(y) {
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}
 
int main() {
    FASTIO
 
    ll n;
    cin >> n;
    ll ans = modpower(10,n) - 2*modpower(9,n) + modpower(8,n);
    if(ans < 0) ans += 2*MOD;
    ans %= MOD;
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3612
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0 if i<k else i-k for i in range(2, n)]
    dp = [None]*n
    dp[0], dp[1] = 0, abs(h[0]-h[1])
    for i, (hi, mi) in enumerate(zip(h[2:], m), 2):
        di = 10**9
        for dj, hj in zip(dp[mi:i], h[mi:i]):
            d = dj + abs(hj-hi)
            if di > d:
                di = d
        dp[i] = di
    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 15848
import java.io.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s="";
		int n;
		int i,j,k,l,c;
		try {
			while(s!=null){
				s=r.readLine();
				n = Integer.parseInt(s);
				c=0;
				for(i=0;i<10;i++){
					for(j=0;j<10;j++){
						for(k=0;k<10;k++){
							for(l=0;l<10;l++){
								if(i+j+k+l==n)c++;
							}
						}
					}
				}
				System.out.println(c);
			}
		} catch (Exception err) {
			System.exit(0);
		}
	}
}

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

const ll mod = 1000000007;

ll n, a, b;

// return a ^ n;
ll fastpower(ll a, ll n) {
	ll ret = 1, p = a;
	while (n) {
		if (n & 1) ret *= p;
		p = p * p % mod;
		ret %= mod;
		n >>= 1;
	}
	return ret;
}

ll calc(ll a, ll b) {
	ll x, y; x = y = 1;
	for (ll i = 1; i <= b; ++i) {
		x *= i;
		x %= mod;
	}

	for (ll i = a; i > a - b; --i) {
		y *= i;
		y %= mod;
	}

	return y * fastpower(x, mod - 2) % mod;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	while (cin >> n >> a >> b) {
		ll v = fastpower(2, n) - 1ll;
		a = calc(n ,a);
		b = calc(n, b);
		v = (((v - a - b) % mod) + mod) % mod;
		cout << v << '\n';
	}
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int i,j,k,tmp;
ll ans = 0;
ll A[200000];

bool solve(int N, ll K, ll ans){
	ll tmp = 0;
	for(i=0;i<N;i++){
		if(A[i]<=ans){continue;}
		tmp += (A[i]+ans-1)/ans - 1;
		if(tmp>K){return false;}
	}
	return true;
}

int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);
	int N; cin >> N;
	ll K; cin >> K;
	ll max = 0;
	for(i=0;i<N;i++){cin >> A[i]; if(A[i]>max){max=A[i];}}
	if(K==0){cout << max << endl; return 0;}

	ll left = 0, right = max;
	while(right - left > 1){
		ll mid = left + (right - left) / 2;
		if(solve(N,K,mid)){right = mid;}else{left = mid;}
	}
	cout << right << endl;

  return 0;
}


Measured memory_bytes: 5140
using System;
using System.Collections.Generic;

namespace bla
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int n = int.Parse (Console.ReadLine ());
			values = new List<int> ();
			values.Add (1);
			int nine = 9;
			while (nine <= n) {
				values.Add (nine);
				nine *= 9;
			}
			int six = 6;
			while (six <= n) {
				values.Add (six);
				six *= 6;
			}
			values.Sort ();
			values.Reverse ();

			Console.WriteLine (coins(n));
		}
		static List<int> values;
		static int[] dp = new int[100001];

		public static int coins(int v){
			if (v == 0)
				return 0;
			if (dp [v] != 0)
				return dp [v];
			int r = 1234567890;
			int i = 0;
			while (i < values.Count) {
				if (values [i] <= v) {
					r = Math.Min (r, coins (v - values [i]));
				}
				i++;
			}
			dp [v] = r + 1;
			return r + 1;
		}
	}
}


Measured memory_bytes: 11604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a, b, c, d, e, f, g;
	cin>>a>>b>>c>>d>>e>>f>>g;
	ll ans = 0;

	/*
	if(f||g)
	{
		cout<<0<<'\n';
		return 0;
	}
	if(c) 
	{
		cout<<0<<'\n';
		return 0;
	}
	*/
	if(a&&d&&e)
	{
		ans=b+3+((a-1)/2)*2+((e-1)/2)*2+((d-1)/2)*2;
	}
	ans=max(ans,b+(a/2)*2+(e/2)*2+(d/2)*2);
	/*
	if(a||d||e)
	{
		cout<<0<<'\n';
		return 0;
	}
	*/
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
#include<queue>
using namespace std;
int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    queue<char> a, b, c;
    for(auto x : sa)
    {
        a.push(x);
    }
    for(auto x : sb)
    {
        b.push(x);
    }
    for(auto x : sc)
    {
        c.push(x);
    }
    char t = a.front();
    a.pop();
    if(a.empty())
    {
        cout << "A" << endl;
        return 0;
    }
    while(1)
    {
        if(t == 'a')
        {
            if(a.empty())
            {
                cout << "A" << endl;
                return 0;
            }
            t = a.front();
            a.pop();


        }
        else if(t == 'b')
        {
            if(b.empty())
            {
                cout << "B" << endl;
                return 0;
            }
            t = b.front();
            b.pop();

        }
        else if(t == 'c')
        {
            if(c.empty())
            {
                cout << "C" << endl;
                return 0;
            }
            t = c.front();
            c.pop();

        }
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1'000'000'000;
vector<ll> neg, pos;
ll zero_cnt;
ll get_negative(ll num) {
    ll cnt = 0;
    for (auto &val: neg) {
        ll pr = num / val;
        if (pr * val >= num) ++pr;
        cnt += pos.end() - lower_bound(pos.begin(), pos.end(), pr);
    }
    return cnt;
}
ll get_positive(ll num) {
    ll cnt = (ll)pos.size() * (ll)neg.size() + zero_cnt * (pos.size() + neg.size()) + zero_cnt * (zero_cnt - 1) / 2;
    for (int i = 1; i < neg.size(); ++i) {
        ll pr = (num - neg[i] - 1) / neg[i];
        auto ptr = upper_bound(neg.begin(), neg.begin() + i, pr);
        cnt += neg.begin() + i - ptr;
    }
    for (int i = 1; i < pos.size(); ++i) {
        ll pr = (num + pos[i] - 1) / pos[i];
        auto ptr = lower_bound(pos.begin(), pos.begin() + i, pr);
        cnt += ptr - pos.begin();
    }
    return cnt;
}
inline ll get_count(ll num) {
    if (num == 0) return (ll)neg.size() * (ll)pos.size();
    else if (num < 0) return get_negative(num);
    return get_positive(num);
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        ll tmp; cin >> tmp;
        if (tmp < 0) neg.push_back(tmp);
        else if (tmp == 0) ++zero_cnt;
        else pos.push_back(tmp);
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    ll left = -(INF * INF), right = INF * INF;
    while (left <= right) {
        ll mid = (left + right) / 2;
        ll cnt = get_count(mid);
        if (mid == left || mid == right) break;
        else if (cnt >= k) right = mid;
        else left = mid; 
    }
    cout << (get_count(left) >= k? right: left) << '\n';
    return 0;
}


Measured memory_bytes: 2420
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a-c) * (b-d);
    
    cout << endl;
}


Measured memory_bytes: 256
/**
 *	@file: D.cpp
 *	@author: Huy Le
 *	@created: 2020-08-29 19:48
**/

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

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\n';

void DEBUGLOCAL() { cerr << ")" << newl; }
template<class A, class... B> 
void DEBUGLOCAL(A argc, B... argv) {
	cerr << argc;
	if(sizeof...(argv))
		cerr << ", ";
	DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> (" << #__VA_ARGS__ << "): (",DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int ts;
int n,m;
const int mxN = 2e5+5;
vector<int> p(mxN, 0);

void make(int v) {
    p[v] = v;
}

int findS(int v) {
    if(v == p[v])
        return v;
    p[v] = findS(p[v]);
    return p[v];
}

void unionset(int a, int b) {
    a = findS(a);
    b = findS(b);
    if(a!=b) {
        p[b] = a;
    }
}

void solve() {
    cin >> n >>m;
    if(m==0) {
        cout << 1 << newl;
        return;
    }
    for(int i=0; i<=n; ++i)
        p[i] = i;
    for(int i=0; i<m; ++i) {
        int a,b;
        cin >> a >> b;
        unionset(a,b);
    }
    map<int,int> mp;
    int ans = 0;
    for(int i=1; i<=n; ++i) {
        int tmp = findS(i);
        if(tmp != i) {
            mp[tmp]++;
        }
    }
    for(auto it : mp) {
        ans = max(ans, it.second + 1);
    }
    cout << (ans ? ans : 1) << newl;
}

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

		//++i,cout << "Case #" << i << ": ",
		solve();
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    vector<pll> C(N);
    REP(i, N){
    	cin >> C[i].second >> C[i].first;
    }
    sort(C.begin(), C.end());

    bool ok = true;
    ll S = 0;

    REP(i, N){
    	S += C[i].second;
    	if(S>C[i].first) ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    int mx = max(a,max(b,c));
    int mn = min(a,min(b,c));
    if(c==mx || c==mn)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination

int main(){
    int n, d;
    cin >> n>> d;
    if(n%(2*d+1)==0){
        cout<<n/(2*d+1)<<endl;
        return 0;
    }else{
        cout<< n/(2*d+1)+1<<endl;
        return 0;
    }
}

Measured memory_bytes: 256