akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll x;cin>>x;
  ans1(x>=30);
  return 0;
}

Measured memory_bytes: 3672
#!/usr/bin/env python

t = input().split()
k = int(t[0])
n = int(t[1])

a = []
t = input().split()
for c in t:
    a.append(int(c))

d = a[0] + k - a[-1]

for i in range(1, n):
    dd = a[i] - a[i-1]
    if dd > d:
        d = dd
print(k-d)


Measured memory_bytes: 78284
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int s = 0;
  rep(i, n) s += a[i];
  int ans = 0;
  rep(i, n) {
    if (abs(a[i] * n - s) < abs(a[ans] * n - s)) ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    cnt=[0]*100
    for i in range(n):
        arr=list(map(int, readline().rstrip().split()))
        for j in range(1,len(arr)):
            cnt[arr[j]]+=1
    ans=0
    for c in cnt:
        if c==n:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 5564
n = int(input())
num_list = list(map(int, input().split()))
# n = 6
# num_list = [5,6,4,2,1,3]

num_swap = 0
for i in range(n):
    index = -1
    mini = num_list[i]
    for j in range(i, n):
        if mini > num_list[j]:
            index = j            
            mini = num_list[j]
    if index > -1:
        num_swap += 1
        num_list[i], num_list[index] = num_list[index], num_list[i]
print(' '.join(map(str, num_list)))
print(num_swap)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,a[N],b[N],i,j,d[N],st[N],stt[N],w,mx;
vector<int>e[N];
bool vi[N],bb[N];
bool dfs(int x,int fe){
	vi[x]=1;st[++w]=fe;stt[w]=x;
	for(int i:e[x])if(i!=fe && !bb[i]){
		int y=a[i]^b[i]^x;
		if(vi[y]){
			bb[i]=1;for(;stt[w]!=y;)bb[st[w--]]=1;
			return 1;
		}
		if(dfs(y,i))return 1;
	}
	--w;
}
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)scanf("%d%d",a+i,b+i),d[a[i]]++,d[b[i]]++,e[a[i]].push_back(i),e[b[i]].push_back(i);
	for(i=1;i<=n;mx=max(mx,d[i++]))if(d[i]&1)break;
	bool ans=i>n && m-n>1;
	if(mx==4 && m-n==2){
		for(i=0;i<3;++i){
			memset(vi+1,0,n);
			for(j=1;j<=n;++j)if(w=0,dfs(j,0))break;
			if(j>n)break;
		}
		if(i<3)ans=0;
	}
	puts(ans?"Yes":"No");
	return 0;
}

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

int main() {
  int W, a, b;
  cin >> W >> a >> b;
  if (a < b) {
    if (a+W < b) cout << b - a - W << endl;
    else cout << 0 << endl;
  } else {
    if (b+W < a) cout << a - b - W << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 256
ns = input()
n = int(ns)

ans = 0
c = [[0 for j in range(10)] for i in range(10)]

for k in range(1,n+1):
    pre = k
    now = k
    j = k%10
    while now>=1:
        pre = now
        now //= 10
    c[pre][j] += 1    


ans = 0

for i in range(1,10):
    for j in range(1,10):
        ans += c[i][j]*c[j][i]
print(ans)
    

Measured memory_bytes: 40300
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;cin>>N;
    vector<pair<int,int>> a(5);
    for(int i=0;i<2;i++){
        a.at(i) = make_pair(i+1,i+2);
        a.at(i+3) = make_pair(i+N+1,i+N+2);
    }
    a.at(2) = make_pair(3, 1+N);
    if(N<3){
        cout<<"No"<<endl;
    }
    else if(N%2!=0){
        cout<<"Yes"<<endl;
        for(int i=4;i<N;i+=2){
            a.push_back(make_pair(i, i+1));
            a.push_back(make_pair(i+N,i+1+N));
            a.push_back(make_pair(i+1, 1+N));
            a.push_back(make_pair(i+N,1+N));
        }
        for(int i=0;i<a.size();i++){
            cout<<a.at(i).first<<" "<<a.at(i).second<<endl;
        }
    }
    else{
        int c=N;
        while(true){
            if(c%2 !=0) break;
            else{
                c/=2;
                if(c==1){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Yes"<<endl;
        for(int i=4;i<=N-1;i+=2){
            a.push_back(make_pair(i, i+1));
            a.push_back(make_pair(i+N,i+1+N));
            a.push_back(make_pair(i, 1+N));
            a.push_back(make_pair(i+N+1,1+N));
        }
        
        bool b = false;
        for(int i=2;i<N;i++){
            for(int j=i+1;j<N;j++){
                int m,l,k; m=i; l=j; k=N;
                //最大値は言わずもがなk
                int n=1;
                while(true){
                    if((n%2 + m%2 + l%2 + k%2)%2 != 0) break;
                    
                    else{
                        n/=2;m/=2;l/=2;k/=2;
                    }
                    
                    if(k == 0){
                        if(i==2)i+=N;
                        else if(i%2!=0 && i != 3) i+= N;
                        if(j%2!=0&&j!=3)j+=N;
                        a.push_back(make_pair(N,i));
                        a.push_back(make_pair(2*N,j));
                        b = true;
                        break;
                    }
                }
                if(b) break;
            }
            if(b) break;
        }
        
        for(int i=0;i<a.size();i++){
        cout<<a.at(i).first<<" "<<a.at(i).second<<endl;
        }
    }
}


Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll H = in(),W = in();
    cout << (H == 1 || W == 1 ? 1 : ((H+1)/2) * ((W+1)/2) + (H/2) * (W/2))<< "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int N;cin >> N;
  string S;cin >> S;
  int max = 0;
  for(int i=1;i<N;i++){
    map<int,bool> m;
    int count = 0;
    for(int j=0;j<i;j++){
      m[S[j]] = true;
    }
    for(int j=i;j<N;j++){
      if(m.count(S[j]) && m[S[j]]){
        m[S[j]] = false;
        count++;
      }
    }
    if(count > max)max = count;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;


int main(){
	int n;
	cin>>n;
	REP(i,n){
		int num[10];
		REP(j,10)cin>>num[j];
		bool flag;
		REP(j,1023){
			bitset<10>bs(j);
			int n1=0,n2=0;
			flag=true;
			REP(k,10){
				if(bs[k]==0){
					
					if(n1<num[k])n1=num[k];
					else{
						flag=false;
						break;
					}
				}else{
					if(n2<num[k])n2=num[k];
					else{
						flag=false;
						break;
					}
				}
			}
			if(flag)break;
		}
		if(flag){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}
/*

*/

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> G(n);
  rep(i,m){
    int a,b;cin >> a >> b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  vector<int> perm;
  rep(i,n-1) perm.push_back(i+1);
  bool flag;
  do{
    // rep(i,n-1) cout << perm[i] << " ";
    // cout << endl;
    flag = true;
    int ind = 0;
    for(int i = 0;i < perm.size();i++){
      bool ok = false;
      for(auto nv:G[ind]) {
        //cout << nv <<" "<< perm[i] <<" " <<ind << endl;
        if(nv==perm[i]) ok = true;
      }
      if(!ok){
        flag = false;
        break;
      }
      ind = perm[i];
    }
    if(flag) {
      ans++;
      // rep(i,n-1) cout << perm[i] << " ";
      // cout << endl;
    }

  }while(next_permutation(perm.begin(),perm.end()));

  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define OUT(x) cout << x << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main(){
  int n;
  cin >> n;
  int ans=0;
  while(n>0){
    if(n%10==2) ans++;
    n/=10;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
char s[10];
scanf("%s", s);
if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
else printf("No\n");
}

Measured memory_bytes: 1648
import itertools
n, m, q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(q)]
c = [i for i in range(1, m+1)]

i = list(itertools.combinations_with_replacement(c, n))

ans = 0
for j in i:
    temp = 0
    for k in l:
        if j[k[1]-1]-j[k[0]-1] == k[2]:
            temp += k[3]
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 84588
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int N;
ll twi(ll a){ return a*a; }
int main(){
  cin >> N;
  for(int t=0;t<N;t++){
    int x=0,y=0;
    int dx,dy;
    ll maxk = 0;
    int ax=0,ay=0;
    while(1){
      cin >> dx >> dy;
      if( !dx && !dy ) break;
      x+=dx; y+=dy;
      ll at = twi((ll)x) + twi((ll)y);
      if( maxk < at ){
	maxk = at;
	ax = x; ay = y;
      } else if( maxk == at && ax < x ){
	maxk = at;
	ax = x; ay = y;
      }

    }
    cout << ax << " " << ay << endl;
  }
}

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

using namespace std;

using ll = long long;
using ld = long double;

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

    int a, p;
    cin >> a >> p;

    int sum = 3 * a + p;
    cout << sum / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    
    cin >> a >> b >> c;
    
    if(a < b){
        
        if(b < c){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        int const N=100;
        int n,m,q;
        int a[N],b[N],c[N],d[N],arr[N];       
        int ans=0;

        void dfs(int idx){

            if(idx>n){

                int temp=0;
                for(int i=0;i<q;i++){
                    if(arr[b[i]]-arr[a[i]]==c[i]){
                        temp+=d[i];
                    }
                }
                ans=max(ans,temp);
                return ;
            }

            for(int i=arr[idx-1];i<=m;i++){
                arr[idx]=i;
                dfs(idx+1);
            }
        }

        signed main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        cin>>n>>m>>q;
        for(int i=0;i<q;i++){
            cin>>a[i]>>b[i]>>c[i]>>d[i];
        }

        arr[0]=1;
        dfs(1);
        cout<<ans;
        

        return 0;
    }

Measured memory_bytes: 3628
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

class RangeAddRangeMax {
    public:
        int N;
        vector<LL> dat, sum_dat;
        RangeAddRangeMax(int n) {
            N = 1;
            while(N < n) N <<= 1;
            dat.assign(2*N-1, 0);
            sum_dat.assign(2*N-1, 0);
        }

        void add(int a, int b, LL x) { add(a,b,x,0,0,N); }
        LL add(int a, int b, LL x, int k, int l, int r) {
            if(b <= l or r <= a) return dat[k];
            if(a <= l and r <= b) {
                sum_dat[k] += x;
                return dat[k] += x;
            }
            const int m = (l+r)/2;
            return dat[k] = max(add(a,b,x,2*k+1,l,m),add(a,b,x,2*k+2,m,r))+sum_dat[k];
        }

        LL rangeMax(int a, int b) { return rangeMax(a,b,0,0,N); }
        LL rangeMax(int a, int b, int k, int l, int r) {
            if(b <= l or r <= a) return 0;
            if(a <= l and r <= b) return dat[k];
            const int m = (l+r)/2;
            return max(rangeMax(a,b,2*k+1,l,m),rangeMax(a,b,2*k+2,m,r))+sum_dat[k];
        }
};


int N;
LL A[200000+1];

int main(void){
    GI(N);
    RangeAddRangeMax RMQ(N);
    REP(i,N)GLL(A[i]);
    LL ans=0;
    for(int i=N-1;0<=i;i--){
        // printf("RMQ.rangeMax(%d,%d) = %lld\n",i,i+1,RMQ.rangeMax(i,i+1));
        if(i==N-1){
            if((LL)i-A[i]<0){
                ans = -1;
                break;
            }else{
                ans += A[i];
                RMQ.add(i-A[i]+1,i+1,1);
                // printf("RMQ.add(%lld,%d,1)\n",i-A[i]+1,i+1);
            }
        }else{
            if(A[i] < A[i+1]-1){
                ans = -1;
                break;
            }else if(A[i] == A[i+1]-1)
                ;
            else{
                if((LL)i-A[i]<0){
                    ans = -1;
                    break;
                }else{
                    ans += A[i];
                    RMQ.add(i-A[i]+1,i+1,1);
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 9984
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstdlib>
#include <random>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cassert>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = (int)1e5 + 1;
const ld EPS = 1e-9;
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9 + 10;
const ld PI = acosl(-1);
const int N = (int)1e6 + 2;


int a[N][2];

int cnt_bits(int x) {
	int ans = 0;
	while (x) {
		ans += (x & 1);
		x >>= 1;
	}
	return ans;
}

int v1[N], v2[N];


int solve1(vector<pair<int, int>>& v1, vector<pair<int, int>>& v2, int n) {
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; i += 2) {
		v[i] = v1[i / 2];
	}
	for (int i = 1; i < n; i += 2) {
		v[i] = v2[i / 2];
	}
	for (int i = 0; i + 1 < n; i++) {
		if (v[i].first > v[i + 1].first) {
			return INF;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (v[i].second > v[j].second) {
				ans++;
			}
		}
	}
	return ans;
}

void solve() {
	int n;
	cin >> n;
	for (int j = 0; j < 2; j++) {
		for (int i = 0; i < n; i++) {
			cin >> a[i][j];
		}
	}

	int ans = INF;

	for (int mask = 0; mask < (1 << n); mask++) {
		if (cnt_bits(mask) != (n + 1) / 2) {
			continue;
		}
		
		vector<pair<int, int>> v1, v2;
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				if (i % 2) {
					v1.push_back({ a[i][1], i });
				}
				else {
					v1.push_back({ a[i][0], i });
				}
			}
			else {
				if (i % 2) {
					v2.push_back({ a[i][0], i });
				}
				else {
					v2.push_back({ a[i][1], i });
				}
			}
		}
		ans = min(ans, solve1(v1, v2, n));
	}
	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	
}

int main() {
	//auto trash = freopen("a.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

Measured memory_bytes: 2304
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)



from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

s = input()
print('x' * len(s))

Measured memory_bytes: 63084
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
ll two[70];

vector <ll> binary(ll bina){
    vector <ll> ans;
    for (ll i = 0; bina>0;i++)
    {
        ans.push_back((bina%2));
        bina = bina/2;
    }
    return ans;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
  for(ll i = 0;i<62;i++){
    two[i] = 0;
  }
  ll N;
  cin>>N;
  ll kazu[N];
  for(ll i = 0;i<N;i++){
    cin>>kazu[i];
  }
  for(ll i = 0;i<N;i++){
    vector <ll> tow = binary(kazu[i]);
    for(ll k = 0;k<tow.size();k++){
      if(tow[k] == 1){
        two[k]++;
      }
    }
  }
  ll ans = 0;

  
  
  for(ll i = 0;i<70;i++){
    ll temp = pow(2,i);
    temp = temp%MOD;
    ans += (N-two[i])*two[i]%MOD*temp%MOD;
    ans = ans%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
n = gets.to_i
hs = gets.split(" ").map{|n|n.to_i}
ans = 0
cut_start = -1
cut_end = -1
while !hs.all?{|nn|nn == 0}
(0).upto(hs.size - 1) do|n|
  if cut_start == -1
    if(hs[n] > 0)
      cut_start = n;
    end
    if (n == hs.size-1)
    cut_end = n
    (cut_start..cut_end).each do|nn|
      hs[nn] -= 1
    end
    ans += 1
    cut_start = -1
    cut_end = -1
    break;
    end
    next
  end


  # もう水やりしなくていいor端まで来た
  if(hs[n] == 0)
    cut_end = n-1
    (cut_start..cut_end).each do|nn|
      hs[nn] -= 1
    end
    ans += 1
    cut_start = -1
    cut_end = -1
    break;
  end
  if (n == hs.size-1)
  cut_end = n
  (cut_start..cut_end).each do|nn|
    hs[nn] -= 1
  end
  ans += 1
  cut_start = -1
  cut_end = -1
  break;
  end

  
  if(hs[n] > 0)
    next
  end
end
end
puts ans.to_s

Measured memory_bytes: 1788
import java.io.*;
import java.util.*;

class Main{

  final static int MAX=3000;

  public static void main(String[] args)throws java.lang.Exception {
    Scanner scan=new Scanner(System.in);
    while(true){
      int x=Integer.parseInt(scan.next());
      int y=Integer.parseInt(scan.next());
      if(x==0 && y==0)break;
      System.out.println(Math.min(x,y)+" "+Math.max(x,y));
    }
  }
}


Measured memory_bytes: 35612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<int> dp(n, INF);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        *lower_bound(dp.begin(), dp.end(), a) = a;
    }
    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
}


Measured memory_bytes: 3356
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MOD 1000000007
long long inverse_element_table[2001] = {};

long long my_pow(long long a,int n){
    long long ret=1;
    for(; n>0 ; n>>=1 ){
        if(n%2)ret *= a;
        ret %= MOD;
        a = a * a % MOD;
    }
    return ret % MOD;
}

void init_table(void){
    for (int i = 1; i < 2000; i++) {
        inverse_element_table[i] =  my_pow((long long)i,MOD - 2);
    }
}

long long comb(int n, int r){
    long long ret = 1;
    for (int i = n-r+1; i <= n; i++) {
        ret *= i;
        ret %= MOD;
    }
    for (int i = 1; i <= r; i++) {
        ret *= inverse_element_table[i];
        ret %= MOD;
    }
    return ret;
}

int main(void){
    init_table();
    int N,K;
    scanf("%d %d", &N, &K);
    for (int i = 1; i <= K; i++) {
        long long ans = comb(1+N-K,i) * comb(K-1,K-i);
        printf("%lld\n", ans%MOD);
    }
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;

int main() {
string s;
cin >> s;
int cnt = 0;
int ans = 0;
rep(i,s.size()){
  if(s.at(i) == 'A' || s.at(i) == 'C' ||s.at(i) == 'G' || s.at(i) == 'T'){
    cnt++;
    ans = max(cnt,ans);
  }
  else{
    cnt = 0;
  }
}
  cout << ans << endl;
}


Measured memory_bytes: 3616
# https://atcoder.jp/contests/arc091/tasks/arc091_a

n, m = map(int, input().split())

peremeter = 0
if n == 1 and m == 1:
    pass 
elif n == 1 or m == 1:
    peremeter += 2
else:
    peremeter += (n - 1) * 2
    peremeter += (m - 1) * 2
ans = n * m - peremeter
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<typename T>
struct LowLink {
private:
    const vector<vector<T>> &g;
    vector<int> used, ord, low;
    
    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for(auto &to : g[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
            }
            else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    }
    
public:
    vector<int> articulation;
    vector<pair<int, int>> bridge;
    
    LowLink(const vector<vector<T>> &g) : g(g) {}
    
    void build() {
        used.assign(g.size(), 0);
        ord.assign(g.size(), 0);
        low.assign(g.size(), 0);
        int k = 0;
        for(int i = 0; i < g.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll v, e;
    cin >> v >> e;
    vector<vector<ll>> g(v);
    rep(i, e) {
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    LowLink<ll> link(g);
    link.build();
    vector<pair<int, int>> ans = link.bridge;
    sort(all(ans));
    for(auto x : ans) printf("%d %d\n", x.first, x.second);
    return 0;
}



Measured memory_bytes: 5264
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    n, a, b = map(int, input().strip().split())
    x = list(map(int, input().strip().split()))
    ans = 0
    for i in range(1, n):
        ans += min((x[i] - x[i-1]) * a, b)
    print(ans)
if __name__ == '__main__':
    main()


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll ans = -INF;

  string s;
  cin >> s;

  ll sum = 0;
  for (ll i = 0; i < s.size(); i++) {
    ll n = s[i] - '0';
    sum += n;
  }

  // cout << (sum) << endl;

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


Measured memory_bytes: 3748
import sys
letras= list()
lines = sys.stdin.readlines()
for linea in lines:
    c = linea.split()
    c = list(map(str,c))
list(c)
if c[0] == "D":
  if c[1]== "D":
    print("H")
  elif c[1] == "H":
    print("D") 
if c[0]== "H":
  print(c[1])

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

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x,v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector <vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

ll h[N], dp[N];
int n,k;

ll calldp(ll pos){
    if(pos < 1) return INF;
    if(pos == 1) return dp[pos] = 0;
    if(~dp[pos]) return dp[pos];
    ll minnow = LINF;
    for(int i=1;i<=k;i++){
        ll aux = calldp(pos-i) + abs(h[pos] - h[pos-i]);
        if(aux <= minnow) minnow = aux;
    }
    return dp[pos] = minnow;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> h[i];
    }
    cout << calldp(n) << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template <class T> bool chmax(T &a, const T &b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if(b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int n, m;
vector<vector<int>> g;

bool rec(int now, int prev, int d) {
  if(d == 2) {
    return now == n - 1;
  }
  bool ok = false;
  for(auto next : g[now]) {
    if(next == prev) continue;
    ok |= rec(next, now, d + 1);
  }
  return ok;
}

int main() {
  cin >> n >> m;
  g = vector<vector<int>>(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bool ok = rec(0, -1, 0);
  if(ok) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 12016
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<ld> p(n);
    rep(i, n) {
        cin >> p[i];
    }
    static ld dp[3000][3000];
    rep(i, 3000) {
        rep(j, 3000) {
            dp[i][j] = 0.0;
        }
    }
    dp[0][0] = 1.0;
    rep(i, n) {
        for(int j = 0; j <= i; ++ j) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }
    ld ans = 0.0;
    rep(j, n + 1) {
        if(j > n - j) {
            ans += dp[n][j];
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main(){
  long long n;
  const long long max_n = 3 * 1e5;
  long long a[max_n + 1];
  cin >> n;
  for(long long i = 0; i < n; i++) cin >> a[i];

  // long long num[62] = {};
  // for(long long i = 0; i <= 60; i++){
  //   for(long long j = 0; j < n; j++){
  //     if(a[j]&(1LL<<i)) num[i] += 1;
  //   }
  // }
  
  long long ans = 0;
  long long now = 1;
  for(long long i = 0; i <= 60; i++){
    // long long now = (1LL << i);
    // now %= MOD;
    long long x = 0;
    for(int j = 0; j < n; j++) if (a[j]>>i&1) x++;
    now = 1;
    now = x * (n-x) % MOD;
    for(int j = 0; j < i; j++) {
      now = now * 2 % MOD;
    }
    // ans += x * (n-x) * now;
    ans += now;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

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

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>

const int MOD=1000000007; //10^9+7

int main() {
    int N;
    cin>>N;
    vector<vector<int>> node(N,vector<int>(0));
    vector<pii> edge(N-1);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        node[a].push_back(i);
        node[b].push_back(i);
        edge[i]=make_pair(a,b);
    }
    int max_index=0;
    vector<int> color(N-1,-1);
    queue<int> Q;
    Q.push(0);
    color[0]=0;
    while(!Q.empty()){
        int fr=Q.front();
        Q.pop();
        int mycolor=color[fr];
        for(int i=0;i<2;i++){
            int nd=i?edge[fr].first:edge[fr].second;
            int ndL=node[nd].size();
            int myindex=0;
            for(int j=0;j<ndL;j++){
                int nidx=node[nd][j];
                if(nidx==fr)continue;
                if(color[nidx]>=0)continue;
                if(myindex==color[fr])myindex++;
                color[nidx]=myindex;
                myindex++;
                Q.push(nidx);
            }
            max_index=max(max_index,myindex-1);
        }
    }
    cout<<max_index+1<<endl;
    for(int i=0;i<N-1;i++){
        cout<<color[i]+1<<endl;
    }
}


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

#define debug(x) cout<<#x<<"="<<x<<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int) (x).size())
#define pii pair<int,int>
#define PQ priority_queue
#define sqr(x) (x)*(x)
#define ll long long
#define pb push_back
#define mp make_pair
#define re return

const int INF=0x7fffffff;

int n,k;
ll ans=1;

int main(){
	cin>>n>>k;
	while(n--){
		if (ans>k){
			ans+=k;
		}else{
			ans*=2;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans;
int n,m,f[105][100005],w[1000],v[1000];
int maxa=0;
main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];cin>>v[i];
        maxa=max(maxa,v[i]);
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=n*maxa;j++)f[i][j]=1e10;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n*maxa;j++)
        {
            if(j-v[i]<0)f[i][j]=f[i-1][j];
            else{
                f[i][j]=min(f[i-1][j],f[i-1][j-v[i]]+w[i]);
            }
            if(i==n&&f[i][j]<=m)ans=max(ans,j);
        }
    }
    cout<<ans;
}


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

int main() {
	int n; cin >> n;
	vector<int>a1(n), a2(n);
	for (auto&& x : a1)cin >> x;
	for (auto&& x : a2)cin >> x;

	for (int i = 0; i < n - 1; i++)a1[i + 1] += a1[i];
	for (int i = 0; i < n - 1; i++)a2[i + 1] += a2[i];
	
	int ans = a1[0] + a2[n - 1];
	for (int i = 1; i < n; i++) {
		int tmp = a1[i] + a2[n - 1] - a2[i - 1];
		if (ans < tmp)ans = tmp;
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int N, W;
int value[110], weight[110];
int dp[110][10100];

int main() {
   cin >> N >> W;
   rep (i, 0, N) {
      cin >> value[i] >> weight[i];
   }
   rep (w, 0, W+1) {
      dp[0][w] = 0;
   }
   rep (i, 0, N) {
      rep (w, 0, W+1) {
         if (w >= weight[i]) {
            dp[i+1][w] = 
               max(dp[i][w-weight[i]]+value[i], dp[i][w]);
         } else {
            dp[i+1][w] = dp[i][w];
         }
      }
   }
   cout << dp[N][W] << endl;

   return 0;
}


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

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

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    string S; cin >> S;
    
    char color;
    ll n = S.length();
    
    ll left = 0;
    color = S[0];
    rep(i, n) {
        if (S[i] == color) continue;
        left++;
        color = color == 'W' ? 'B' : 'W';
    }
    
    reverse(S.begin(), S.end());
    ll right = 0;
    color = S[0];
    rep(i, n) {
        if (S[i] == color) continue;
        right++;
        color = color == 'W' ? 'B' : 'W';
    }
    
    cout << min(left, right) << endl;
    
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N) {
    if (N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9) cout << "hon" << endl;
    if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon" << endl;
    if (N % 10 == 3) cout << "bon" << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>

#include <string>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::string;

using std::strncmp;

static bool
check(char const *s)
{
  return (s[0] == '\0' ? true
          : strncmp(s, "dreamerase", 10) == 0 ? check(s + 5)
          : strncmp(s, "dreamer", 7) == 0 ? check(s + 7)
          : strncmp(s, "dream", 5) == 0 ? check(s + 5)
          : strncmp(s, "eraser", 6) == 0 ? check(s + 6)
          : strncmp(s, "erase", 5) == 0 ? check(s + 5)
          : false);
}

static string
solve(string S)
{
  return check(S.c_str()) ? "YES" : "NO";
}

int
main()
{
  string S;
  cin >> S;
  cout << solve(S) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>

const ll INF = pow(10, 9) + 7;

int main() {
  int n;
  cin >> n;
  char a = '7';
  int sum = 0;
  rep(i,n){
    char b;
    cin >> b;
    if(a==b) continue;
    if(a!=b){
      sum++;
      a = b;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(3);
  REP(i, 3) { cin >> a[i]; }
  string t;
  cin >> t;
  vector<ll> b(n);
  REP(i, n) {
    if (t[i] == 'r') {
      b[i] = 2;
    } else if (t[i] == 's') {
      b[i] = 0;
    } else {
      b[i] = 1;
    }
  }
  ll ans = 0;
  REP(i, k) {
    bool ren = true;
    for (ll j = i; j < n; j += k) {
      ll l = b[j];  // += a[l]
      if (j < k) {
        ans += a[l];
        continue;
      }
      if (b[j] == b[j - k]) {
        if (ren) {
          ren = false;
        } else {
          ans += a[l];
          ren = true;
        }
      } else {
        ren = true;
        ans += a[l];
      }
    }
  }
  cout << ans << endl;
}

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

int main()
{
    long N;
    cin>>N;
    for(int i=1; i<=3500; ++i) {
        for(int j=1; j<=3500; ++j) {
            auto x=4*i*j-N*(i+j);
            auto y=i*j*N;
            if (x>0 and y%x==0) {
                cout<<i<<' '<<j<<' '<<y/x<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
p = 0
for n in range(1,N+1):
  i = -1
  for j in range(0,K+1):
    if n*(2**j) >= K:
      i = j
      break
  #print(n, i)
  p += 1/(N*(2**i))
print(p)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int s;
    cin >> s;
    vector<int> visited(1000001, -1);

    int index = 1;
    visited[s] = index;
    index++;
    while (true)
    {
        s = (s % 2 == 0 ? (s / 2) : (3 * s + 1));
        if (visited[s] >= 0)
        {
            break;
        }
        visited[s] = index;
        index++;
    }
    cout << index << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0,lim-1);
  return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

void solve() {
  int i, j, n, m, t;
  unsigned ll int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0]%2==0 || a[1]%2==0 || a[2]%2==0) cout << 0;
  else cout << a[0]*a[1];
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c - 1) {
    cout << b + c << '\n';
  } else {
    cout << a + 2 * b + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256