akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
const int N=1e5+10,M=2e3+10;

char a[M],b[M],c[M];
int A,B,C,ans;
bool ab[N],ac[N],bc[N];
//ab[i]表示以a[i..(A-1)]是否与b[0,B)有冲突 

bool pd(char a,char b) {
	return a=='?'||b=='?'||a==b;
}

int main() {
	scanf("%s %s %s",a,b,c);
	A=strlen(a);
	B=strlen(b);
	C=strlen(c);
	for(int i=0;i<A;i++) for(int j=0;j<B;j++) if(!pd(a[i],b[j])) ab[i-j+M*4]=1;
	for(int i=0;i<A;i++) for(int j=0;j<C;j++) if(!pd(a[i],c[j])) ac[i-j+M*4]=1;
	for(int i=0;i<B;i++) for(int j=0;j<C;j++) if(!pd(b[i],c[j])) bc[i-j+M*4]=1;
	
	ans=A+B+C;
	for(int i=-2*M;i<=2*M;i++) for(int j=-2*M;j<=2*M;j++) if(!ab[i+M*4]&&!ac[j+M*4]&&!bc[j-i+M*4]) {
		int L=min(0,min(i,j)),R=max(A,max(i+B,j+C));
		ans=min(ans,R-L);
	}
	printf("%d\n",ans); return 0;
}


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

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define ull unsigned long long
#define ut uint64_t

#define pb push_back
#define ins insert
#define er erase

#define fi(i, b) for (int i=0;i<b;i++)
#define fll(i, b) for (ll i=0;i<b;i++)
#define fla(i,a,b) for (ll i=a;i<b;i++)

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvl vector<vector<ll>> 


#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element

#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second

#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>

#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>

#define pqi priority_queue<int>
#define pqll priority_queue<ll>

 #define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)

#define nl "\n"
using namespace std;

double PI = (acos(-1));

ll md = 1000000007;
ll ma = 998244353;

ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b){
        if (b & 1)c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}

ll pwmd(ll a, ll b){
    ll c = 1, m = a;
    while (b){
        if (b & 1)
            c = ((c * m)) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}


ll modinv(ll n)
{
    return pwmd(n, md - 2);
}
ll min(ll a,ll b){
    if(a>=b)return b;
    return a;
}
//vst vect={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};




// AB DEKHO JAADU...

void solve(){
    ll x,n;
    cin>>x>>n;
    ll l[n];
    fi(i,n)cin>>l[i];
    map<ll,ll>mp;
    fi(i,n)mp[l[i]]++;
    ll j=0;
    while(true){
        if(mp[x-j]==0){cout<<x-j;break;}
        if(mp[x+j]==0){cout<<x+j;break;}
        j+=1;
    }
}

    
    


int main(){
    fast;
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }

    return 0;
    }

// KHATAM HO GAYA:)...





Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int maxn=2e5+100;
ll fac[maxn],f[maxn];
ll fpow(ll x, ll c) { ll res = 1; for (; c > 0; c >>= 1) { if (c & 1) res = res * x % mod; x = x * x % mod; }return res; }

ll comb(ll x, ll y) {
	return fac[x] * fpow(fac[y] * fac[x - y] % mod, mod - 2) % mod;
}

void init(int n) { fac[0] = fac[1] = 1; for(int i=2;i<=n;i++) fac[i] = i * fac[i - 1] % mod; }
int main(){
	init(200010);
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	int x=n-a,y=b+1;
	ll ans=0;
  while(x>=1&&y<=m){
		ans=(ans+comb(x+y-1-1,x-1)*comb(n+m-x-y,n-x))%mod;
		x--,y++;
	}
	cout<<ans<<'\n';
}
		

Measured memory_bytes: 5208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	int A, B, T;

	cin >> A >> B >> T;

	int cnt = (T + 0.5f) / A;
	cout << cnt * B << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int money = N - (500 * (N / 500));
            Console.WriteLine(money <= A ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
N = int(input())
S = input()
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)


Measured memory_bytes: 9188
import itertools

N, M, Q = map(int, input().split())
ABCD = []
for _ in range(Q):
    ABCD.append(list(map(int, input().split())))
M_list = [i+1 for i in range(M)]
N_list = itertools.combinations_with_replacement(M_list, N)
max_point = 0
for n in N_list:
    point = 0
    for abcd in ABCD:
        if n[abcd[1]-1] - n[abcd[0]-1] == abcd[2]:
            point += abcd[3]
    if max_point < point:
        max_point = point
print(max_point)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void  solve(){
    int cnt=0,n;
    string s;
    cin>>n;
    vl a(n),b(n),c(n);
    
    for(int i=0;i<n;i++)
        c[i] = i;
    
    for(int i=0;i<n;i++){
        cin>>a[i];a[i]--;
    }    
    
    for(int i=0;i<n;i++){
        cin>>b[i];b[i]--;
    }    
    cnt=1;
    int an=0,bn=0,i;
    do{
        for(i=0;i<n;i++){
            if(a[i] != c[i]) break;
        }
        if(i==n) an = cnt;
        for(i=0;i<n;i++){
            if(b[i] != c[i]) break;
        }
        if(i==n) bn = cnt;
        cnt++; 
    }while(next_permutation(c.begin(),c.end()));
    cout<<abs(an-bn);
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

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

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

    vector<bool> vec(n);
    for(int i = 0; i < k; ++i)
    {
        int d;
        cin >> d;
        for(int j = 0; j < d; ++j)
        {
            int idx;
            cin >> idx;
            --idx;
            vec[idx] = true;
        }
    }
    int ans = 0;
    for(bool flag : vec)
    {
        if(!flag)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
N,M = map(int,input().split())

S=[list(map(int,input().split()))[1:] for i in range(M)]
p = list(map(int,input().split()))
ans = 0

for i in range(1<<N): #スイッチのオンオフ状態
    
    for m in range(M):  #電球の状態 
        count = 0
        for s in S[m]:
            if i & (1<<(s-1)) != 0:
                count += 1
        if count%2 != p[m]:
            break
    else:
        ans +=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
//B - K-th Common Divisor
int main(void){
    int a,b,k;
    std::cin >> a >> b >> k;
    if(a>b)swap(a,b);
    
    int cnt=0;
    for(int i=a;i>0;i--){
        if(a%i==0 && b%i==0){
            cnt++;
        }
        if(cnt==k){
            std::cout << i << std::endl;
            break;
        }
    }
    return 0;    
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP2(i,n,s) for(int i=(int)s;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

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

    int s = 0;
    REP(i, n) {
        int a;cin>>a;
        if(a%2==1)s++;
    }
    if(s%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

	public static void main(String[] args) {
		Scanner hoge = new Scanner(System.in);

		int[] a = new int [3];
	   
		a[0] = hoge.nextInt();
		a[1] = hoge.nextInt();
		a[2] = hoge.nextInt();

		int h;
		
		if(a[0]>a[1]&&a[0]>a[2]){
			h = a[0];
			a[0]=a[1];
			a[1]=a[2];
			a[2]=h;			   
		}else if(a[1]>a[0]&&a[1]>a[2]){
			h=a[1];
			a[1]=a[2];
			a[2]=h;
		}
		//a[2] became the maximum

		if(a[0]>a[1]){
			h = a[0];
			a[0]=a[1];
			a[1]=h;		  
		}

		System.out.println(a[0]+" "+a[1]+" "+a[2]);

	}



}

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

const int N = 1050, PW = 31;

int n;
int pw2[PW];
char ans[PW];
int x[N], y[N];
int dx[4] = {0,0,-1,1}, dy[4] = {1,-1,0,0};
char drc[4] = {'D','U','R','L'};


bool in_bound(int x, int y, int pi){
    return x + y <= (pw2[pi]-1) && x + y >= -(pw2[pi]-1) && y - x <= (pw2[pi]-1) && y - x >= -(pw2[pi]-1);
}

int main(){
    pw2[0] = 1;
    for(int i = 1; i < PW; i++) pw2[i] = pw2[i-1] * 2;

    cin >> n;
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    for(int i = 0; i < n; i++){
        if(((x[i] + y[i]) % 2 + 2) % 2 != ((x[0] + y[0]) % 2 + 2) % 2) return !printf("-1");
    }

    bool even = ((x[0] + y[0]) % 2 + 2) % 2 == 0;
    if(even){for(int i = 0; i < n; i++) x[i]--;}

    cout << (even ? PW+1 : PW) << endl;
    for(int i = 0; i < PW; i++) cout << pw2[i] << " ";
    if(even) cout << 1;
    cout << endl;
    for(int i = 0; i < n; i++){
        for(int pi = PW-1; pi >= 0; pi--){
            for(int d = 0; d < 4; d++){
                if(in_bound(x[i] + dx[d] * pw2[pi], y[i] + dy[d] * pw2[pi], pi)){
                    ans[pi] = drc[d];
                    x[i] += dx[d] * pw2[pi];
                    y[i] += dy[d] * pw2[pi];
                    break;
                }
            }
        }
        for(int j = 0; j < PW; j++) cout << ans[j];
        if(even) cout << 'R';
        cout << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	void main() {
		Scanner sc = new Scanner(System.in);
		while(true) {
			String str = sc.nextLine();
			if(str.equals("0")) break;
			int l = str.length();
			int sum = 0;
			for(int i=0;i<l;i++) {
				char c = str.charAt(i);
				sum += c - '0';
			}
			System.out.println(sum);
		}
	}
	
	public static void main(String[] args) {
		new Main().main();
	}

}





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

typedef long long int ll;

int main()
{
    ll a[3];
    for(ll i = 0;i < 3;i++){
        cin >> a[i];
    }
    ll t = 0;

    for(ll i = 0;i < 2;i++){
        for(ll j = i + 1;j < 3;j++){
            if(a[i] != a[j]){
                t++;

            }
        }
    }

    if(t == 2){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main(){
	int n,x;
	cin>>n;
	cin>>x;
	if(x==1||x==2*n-1)cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		int ans[214514];
		ans[n-1]=x;
		ans[n]=1;
		ans[n-2]=2*n-1;
		int ma=2*n-2,mi=2;
		for(int i=0;i<n-2;i++){
			if(mi==x)mi++;
			ans[n-3-i]=mi;
			if(ma==x)ma--;
			ans[n+1+i]=ma;
			
			mi++;
			ma--;
		}
		rep(i,2*n-1){
					cout<<ans[i]<<endl;
		}
	}
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;
	if (N <= K)
	{
		cout << min(N, K - N) << endl;
	}
	else
	{
		N = N - (N - K) / K * K;
		cout << min(N - K, K - (N - K)) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B;
    cin >> A >> B;
    cout << max(max(A+B,A-B),A*B) << endl;



}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> K(N);
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    cin >> K.at(i);
    for (int j = 0; j < K.at(i); j++) {
      cin >> A.at(i).at(j);
    }
  }
  int answer = 0;
  for (int i = 0; i < M; i++) {
    int count = 0;
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < K.at(j); k++) {
        if (i + 1 == A.at(j).at(k)) {
          count++;
        }
      }
    }
    if (count == N) {
      answer++;
    }
  }
  cout << answer << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i >=(b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll n;ll k;
    cin>>n>>k;
    ll h[n+1];
    FOR(i,1,n+1)
    {
        cin>>h[i];
    }
    ll dp[n+1];
    FOR(i,0,n+1)
    {
        dp[i]=INF;
    }
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    FOR(i,3,n+1)
    {
        FOR(j,1,k+1)
        {
            if((i-j)>0)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n]<<'\n';
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
struct data{
    ll x,y,h;
};

int main(){
    ll n,ansh;
    cin >> n;
    vector<data> v(n);
    for(ll i=0;i < n;i++)
    {
        cin >> v.at(i).x>>v.at(i).y>>v.at(i).h;
        if(v.at(0).h == 0 && v.at(i).h != 0){
            swap(v.at(0).x,v.at(i).x);
            swap(v.at(0).y,v.at(i).y);
            swap(v.at(0).h,v.at(i).h);//
        }
        
    }
    
    for(ll i=0;i < 101;i++)
    {
        for(ll j=0;j < 101;j++)//各点を頂点にしてみる
        {
            bool flag = false,t=true;            
            
            for(ll k=0;k < n;k++)
            {
                if(t==true){//
                    ansh=v.at(0).h+abs(i-v.at(0).x)+abs(j-v.at(0).y);
                    t=false;
                    continue;
                }
                if(v.at(k).h==0){
                    if(abs(v.at(k).x-i)+abs(v.at(k).y-j)>=ansh){
                        continue;
                    }else{
                        flag=true;
                        break;
                    }
                }//

                if(ansh != v.at(k).h+abs(v.at(k).x-i)+abs(v.at(k).y-j)){
                    flag = true;
                    break;
                }
            }

            if(flag==true){
                continue;
            }else{
                cout << i << " " << j << " " << ansh << endl;
                return 0;
            }
        }
    }
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int A[n];
	auto output = [](int *A, int n){
		for(int i=0;i<n;++i){
			if(i)cout << " ";
			cout << A[i];
		}
		cout << endl;
	};
	for(auto &i:A)cin>>i;
	for(int j=1;j<n;++j){
		output(A, n);
		int key = A[j];
		int i = j - 1;
		while(i>=0&&A[i]>key){
			A[i+1] = A[i];
			--i;
		}
		A[i+1] = key;
	}
	output(A, n);
	return 0;
}



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

int main(){
    int n;  cin >> n;   long long int ans = 10000000000000000, sum = 0;
    vector<long long int> vec(n);
    for(int i = 0;n > i;i++){
        cin >> vec[i];  sum += vec[i];
    }
    for(int i = 0;n-1>i;i++){
        sum -= 2*vec[i];  ans = min(ans, abs(sum));
        // cout << i << " " << sum << " " << ans << "\n";
    }
    // ans = min(ans, abs(sum));
    cout << ans;
    
}

Measured memory_bytes: 1792
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const B = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = [];
    
    answer[0] = B[0];
    answer[1] = B[0];
    
    for(let i=1; i<N-1; i++) {
        if(answer[i] > B[i]) {
            answer[i] = B[i];
        }
        
        answer[i + 1] = B[i];
    }
    
    console.log(answer.reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b){
	if (a < b) swap(a, b);
	if (b == 0) return a;
	ll r = a%b;
	while (r != 0){
		a = b;
		b = r;
		r = a%b;
	}
	return b;
}

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	vector<ll> x;
	ll i, X, N, D;
	cin >> N >> X;
	for (i = 0; i < N; i++){
		ll a;
		cin >> a;
		x.push_back(a);
	}
	D = abs(X - x[0]);
	for (i = 1; i < N; i++){
		D = gcd(D, abs(X - x[i]));
	}
	cout << D << endl;
	return 0;
}

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

typedef long long ll;

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

	ll K;
	cin >> K;

	ll count = 0;

	ll N = 1;

	while(true) {
		bool checker = false;
		string y = to_string(N);
		for(int i = 0; i < y.length() - 1; i++) {
			int f = static_cast<int>(y[i]);
			int s = static_cast<int>(y[i + 1]);
			if(f - s > 1) {
				//cerr << N << " " << f << " " << s << endl;
				//cerr << pow(10LL, (y.length() - 2 - i));
				N += pow(10LL, (y.length() - 2 - i));
				checker = true;
				break;
			} else if(s - f > 1) {
				//cerr << N << " " << f << " " << s << endl;
				//cerr << pow(10LL, (y.length() - 2 - i));
				N += pow(10LL, (y.length() - 2 - i));
				checker = true;
				break;
			}
		}
		if(checker) continue;
		count++;
		if(count == K) break;
		N++;
	}

	cout << N << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int a[100][100];
  int r,c,i,j,sum=0,ans=0;

  scanf("%d %d",&r,&c);

  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      scanf("%d",&a[i][j]);
      ans += a[i][j];
    }
  }
  for(i = 0;i < r;i++){
    for(j =0;j < c;j++){
      printf("%d ",a[i][j]);
      sum += a[i][j];
    }
    printf("%d\n",sum);
    sum = 0;
  }
  
  for(j = 0;j < c;j++){
    for(i = 0;i < r;i++){
      sum += a[i][j];
    }
    printf("%d ",sum);
    sum = 0;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2116
from collections import Counter
n,p=map(int,input().split())
a=Counter([int(i) % 2 for i in input().split()])

if a[1]==0 and p==0:
  print(2**n)
elif a[1]==0 and p==1:
  print(0)
else:
  print(2**(n-1))

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<functional>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>PLL;
typedef pair<int,ll>Pil;
const ll INF = 0x3f3f3f3f;
const double inf=1e8+100;
const double eps=1e-8;
const ll maxn =1e3+200;
const int N = 1e4+10;
const ll mod=1000007;
//
int dx[]={0,1,-1,0};
int dy[]={1,0,0,-1};
int fld[2*maxn][2*maxn];
int X1[maxn],X2[maxn],Y1[maxn],Y2[maxn];
int W,H,n;
//
int compress(int *x1,int *x2,int w) {
	vector<int>xs;
	//
	for(int i=0;i<n;i++){
		int tx1=x1[i],tx2=x2[i];
		if(1<=tx1&&tx1<w)
		xs.push_back(tx1);
		if(1<=tx2&&tx2<w)
		xs.push_back(tx2);
	}
	xs.push_back(0);
	xs.push_back(w);
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i<n;i++){
		x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
		x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
	}
	return xs.size()-1;
}
//
int bfs() {
	int ans=0;
	//
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(fld[i][j])
			continue;
			ans++;
			queue<pair<int,int> >q;
			q.push(make_pair(j,i));
			while(!q.empty()){
				int sx=q.front().first,sy=q.front().second;
				q.pop();
				//
				for(int k=0;k<4;k++){
					int tx=sx+dx[k],ty=sy+dy[k];
					if(tx<0||W<tx||ty<0||H<ty||fld[ty][tx]>0)
					continue;
					q.push(make_pair(tx,ty));
					fld[ty][tx]=1;
				}
			}
		}
	}
	return ans;
}
//
void solve() {
	int i,j,tt=1;
	while(cin>>W>>H&&W&&H){
		cin>>n;
		for(i=0;i<n;i++){
			cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
		}
		memset(fld,0,sizeof(fld));
		//
		W=compress(X1,X2,W);
		H=compress(Y1,Y2,H);
		//
		for(i=0;i<n;i++){
			fld[Y1[i]][X1[i]]++;
			fld[Y2[i]][X2[i]]++;
			fld[Y1[i]][X2[i]]--;
			fld[Y2[i]][X1[i]]--;
		}
		//
		for(i=0;i<H;i++){
			for(j=1;j<W;j++){
				fld[i][j]+=fld[i][j-1];
			}
		}
		for(i=1;i<H;i++){
			for(j=0;j<W;j++){
				fld[i][j]+=fld[i-1][j];
			}
		}
		//
		cout<<bfs()<<endl;
	}
}

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


Measured memory_bytes: 25564
# は？
# 挿入とか言っときながら両端に加えることしかできなさそう(理屈は不明)
# 479836982452回やってもわからん ほぼ勘とサンプルの試行錯誤でガチャっただけ
n = int(input())
s = list(input())
surplus_left, surplus_right = 0, 0
right_count, left_count = 0, 0
for i in range(n - 1, -1, -1):
    if s[i] == "(":
        if left_count > 0:
            left_count -= 1
        else:
            surplus_left += 1
    else:
        left_count += 1
for i in range(n):
    if s[i] == ")":
        if right_count > 0:
            right_count -= 1
        else:
            surplus_right += 1
    else:
        right_count += 1

print("(" * surplus_right + "".join(s) + ")" * surplus_left)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct UnionFind {
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  ll n;
  ll m = 1e5 + 10;
  cin >> n;
  UnionFind uf(m * 2);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    uf.unite(x, y + m);
  }
  map<ll, ll> mx, my;
  rep(i, m) {
    mx[uf.root(i)]++;
    my[uf.root(i + m)]++;
  }
  ll ans = 0;
  rep(i, m) ans += mx[i] * my[i];
  cout << ans - n << endl;
}

Measured memory_bytes: 19840
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		long k = Long.parseLong(scan.next());
		int a,b;
		long[] count = new long [100000];
		Arrays.fill(count, 0);
		for (int i =  0;i < n ;++i ){
			a = Integer.parseInt(scan.next());
			b = Integer.parseInt(scan.next());
			count[a-1]+=b;
		}

		long ans=0;
		for(int i = 0;i < 100000; ++i){
			ans+=count[i];
			if (ans>=k){
				System.out.print(i+1);
				break;
			}
		}

	}
}
//end


Measured memory_bytes: 50984
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    N = N % 10;
    if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
        cout << "hon" << endl;
    }
    else if (N == 3) {
        cout << "bon" << endl;
    }
    else {
        cout << "pon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	int N; cin >> N;
	V<ll> x(N), y(N), h(N);
	REP(i, N) cin >> x[i] >> y[i] >> h[i];
	int idx = max_element(ALL(h)) - h.begin();
	REP(Cx,101){
		REP(Cy,101){
			ll H = h[idx] + abs(x[idx] - Cx) + abs(y[idx] - Cy);
			bool flg = true;
			REP(k,N) if (h[k] != max(H - abs(x[k] - Cx) - abs(y[k] - Cy), 0LL)) flg = false;
			if(flg) {
				print(Cx, Cy, H);
				return 0;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>

#define cmax(_a, _b) (_a < (_b) ? _a = (_b), 1 : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b), 1 : 0)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))

#define maxn 
typedef long long ll;
typedef double ld;

int main()
{
	int d, N; scanf("%d%d", &d, &N); N == 100 ? ++N : 0;
	printf("%d", N);
	for (int i = 1; i <= d; ++i) printf("00");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#define P pair<int, int>

using namespace std;

int nx[5] = {-1, 0, 1, 0};
int ny[5] = {0, -1, 0, 1};

int main(){
    int h, w, mx = 0;
    int dist[29][29];
    queue<P> q;
    string s[29];
    cin >> h >> w;
    for(int i=0;i<h;i++)cin >> s[i];
    for(int gi=0;gi<h;gi++){
        for(int gj=0;gj<w;gj++){
            if(s[gi][gj]=='#')continue;
            memset(dist, -1, sizeof(dist));
            while(!q.empty())q.pop();
            q.push(P(gi, gj));
            dist[gi][gj] = 0;
            while(!q.empty()){
                int nx_x, nx_y;
                int fr_y = q.front().first;
                int fr_x = q.front().second;
                q.pop();
                for(int i=0;i<4;i++){
                    nx_x = fr_x + nx[i]; 
                    nx_y = fr_y + ny[i];
                    if(0<=nx_x&&nx_x<=w-1&&0<=nx_y&&nx_y<=h-1&&dist[nx_y][nx_x]==-1&&s[nx_y][nx_x]=='.'){
                        dist[nx_y][nx_x] = dist[fr_y][fr_x] + 1;
                        q.push(P(nx_y, nx_x));
                    }
                }
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(s[i][j] == '.')mx = max(mx, dist[i][j]);
                }
            }
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
N,M=map(int, input().split())

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
        return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if (x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        #rnkが大きい方に結合
        elif (self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
        # rnkが同じ（深さに差がない場合）は1増やす
        if(self.rnk[x] == self.rnk[y]):
            self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

uni=UnionFind(N)

for i in range(M):
    a,b=map(int, input().split())
    a-=1
    b-=1
    uni.Unite(a,b)

ans=0
for i in range(N):
    ans=max(ans, uni.Count(i))

print(ans)

Measured memory_bytes: 78408
#include <cstdio>
int main() {
	int n;
	while(scanf("%d",&n),n) {
		int y;
		scanf("%d",&y);
		double Max=0;
		int idx=0;
		for(int i=0;i<n;i++) {
			int b,r,t;
			scanf("%d %d %d",&b,&r,&t);
			double x=0;
			if(t==1) {
				x=1+y*r/100.0;
			}else {
				x=1;
				for(int j=0;j<y;j++) {
					x*=(1+r/100.0);
				}
			}
			if(Max<x) {
				Max=x;
				idx=b;
			}
		}
		printf("%d\n",idx);
	}
}

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

int main(){
  char s; cin>>s;
  bool ans=1;
  if(s=='a'){
    ans=0;
  }
  if(s=='b'){
    ans=0;
  }
  if(s=='c'){
    ans=0;
  }
  if(s=='d'){
    ans=0;
  }
  if(s=='e'){
    ans=0;
  }
  if(s=='f'){
    ans=0;
  }
  if(s=='g'){
    ans=0;
  }
  if(s=='h'){
    ans=0;
  }
  if(s=='i'){
    ans=0;
  }
  if(s=='j'){
    ans=0;
  }
  if(s=='k'){
    ans=0;
  }
  if(s=='l'){
    ans=0;
  }
  if(s=='m'){
    ans=0;
  }
  if(s=='n'){
    ans=0;
  }
  if(s=='o'){
    ans=0;
  }
  if(s=='p'){
    ans=0;
  }
  if(s=='q'){
    ans=0;
  }
  if(s=='r'){
    ans=0;
  }
  if(s=='s'){
    ans=0;
  }
  if(s=='t'){
    ans=0;
  }
  if(s=='u'){
    ans=0;
  }
  if(s=='v'){
    ans=0;
  }
  if(s=='w'){
    ans=0;
  }
  if(s=='x'){
    ans=0;
  }
  if(s=='y'){
    ans=0;
  }
  if(s=='z'){
    ans=0;
  }
  if(ans){
    cout<<'A'<<endl;
  }else{
    cout<<'a'<<endl;
  }

}


Measured memory_bytes: 3616
#include <iostream>
#include <cmath>

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

int main()
{
	int N;
	cin >> N;
	int digits = log10(N) + 1;
	int ans = 0;
	int pow10 = 1;

	rep(i, digits / 2) {
		ans += 9 * pow10;
		pow10 *= 100;
	}

	if (digits % 2) ans += N - pow10 + 1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

const int maxn = 100005;
vector<int> adj[maxn];
bool vis[maxn];
int cnt = 0;
void dfs(int node)
{
	vis[node] = true;
	cnt++;
	for (auto child : adj[node])
	{
		if (vis[child] == false)
			dfs(child);
	}
}

vector<int> ans(maxn);

void bfs(int src = 1)
{
	memset(vis, false, sizeof(vis));
	queue<int> que;

	que.push(src);

	while (!que.empty())
	{
		int par = que.front();
		que.pop();
		vis[par] = true;
		for (auto child : adj[par])
		{
			if (vis[child] == false)
			{
			    ans[child] = par;
				que.push(child);
				vis[child] = true;
			}
		}
	}
}


void solve()
{
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	memset(vis, false, sizeof(vis));
	cnt = 0;
	dfs(1);
	if (cnt != n)
	{
		cout << "No" << "\n";
		return;
	}
	bfs();
	cout << "Yes" << "\n";
	for (int i = 2; i <= n; i++)
		cout << ans[i] << "\n";


}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 14752
n = int(input())
x = list(map(int, input().strip().split()))
sum=0
minsum=0
for i in range(0,n):
    minsum += x[i]
for i in range(0,n-1):
    minsum-=x[i]
    sum += x[i]*minsum
    if(sum>10**9+7):
        sum%=(10**9+7)
print(sum)

Measured memory_bytes: 31396
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

inline bool r(char a) {
   if (a >= '0' && a <= '9') return true;
   else return false;
}

inline bool x(string a, string b) {
    if (a.size() > b.size()) return true;
    else if (a.size() == b.size() && a > b) return true;
    else return false;
}

int main(void){
    int w, h;
    while (cin>>w>>h && w) {
        vector<string> g(h);
        for (int i = 0; i < h; i++) cin >> g[i];
        
        vector<vector<string> > dp(h, vector<string>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (r(g[i][j])) dp[i][j] = g[i][j];
            }
        }
        
        for (int i = h-1; i >= 0; i--) {
            for (int j = w-1; j >= 0; j--) {
                if (!r(g[i][j])) continue;
                if (j-1 >= 0 && r(g[i][j-1])) {
                    string t = g[i][j-1] + dp[i][j];
                    if (x(t, dp[i][j-1])) dp[i][j-1] = t;
                }
                if (i-1 >= 0 && r(g[i-1][j])) {
                    string t = g[i-1][j] + dp[i][j];
                    if (x(t, dp[i-1][j])) dp[i-1][j] = t;
                }
            }
        }
        
        string ans = "";
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                while (dp[i][j][0] == '0') dp[i][j].erase(dp[i][j].begin());
                if (x(dp[i][j], ans)) ans = dp[i][j];
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3260
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define TRACE
 
#ifdef TRACE
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& a){out<<"["<<a.first<<" "<<a.second<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const multiset<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const map<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const multimap<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define praa(a,n,m) cerr<<#a<<" : "<<endl;for(int i=0;i<n;++i){for(int j=0;j<m;++j)cerr<<a[i][j]<<" ";cerr<<endl;}
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
} 
#else
#define pr(...)
#define pra(a,n)
#define praa(a,n,m)
#endif
#define int long long

void Main()    {
    int ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;
    vector<int> x = {ai, aj, al};
    vector<int> a = {0, 1, 2, 3};
    int ans = 0;
    do {
        auto y = x;
        int tans = 0;
        for (int it : a) {
            if (it <= 2) {
                tans += y[it] - y[it] % 2;
                y[it] %= 2;
            } else {
                int z = min({y[0], y[1], y[2]});
                for (int & itt: y) itt -= z;
                tans += 3*z;
            }
        }
        ans = max(ans, tans);
    }while (next_permutation(a.begin(), a.end()));
    cout << ao + ans << "\n";
}

#undef int
int main()    {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    Main();
}



























Measured memory_bytes: 256
// header file
#include <iostream>
#include <cstdio>
#include <vector>  //vector<T> vec; ランダムアクセスが速い、挿入は線形時間
#include <list>  //list<T> ls; 挿入・消去速い、アクセスは線形時間
#include <algorithm>  // max, min
#include <functional> // greater<int>()を使える
#include <utility>
#include <string>
#include <map>
// macro
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int div_count(int);

int main(void) {
    int N, count = 0;
    cin >> N;

    vector<int> A;
    REP(i, N) {
        int A_i;
        std::cin >> A_i;
        
        if (A_i % 2 == 0) {
            A.push_back(div_count(A_i));
        } else {
            // 割り切れないものが一つでもあれば 0 を挿入
            A.push_back(0);
            break;
        }
    }
    // min_element() はイテレータを返すため、* で受け取る
    // 最小値: *min_element(vec.begin(), vec.end())
    std::cout << *min_element(A.begin(), A.end()) << std::endl;

    return 0;
}

int div_count(int num) {
    int count = 0;
    while(num % 2 == 0) {
        num /= 2;
        count++;
    }
    return count;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

vector<vector<P>> v(10);

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

    REP(i, 10){
        int now = i;
        int cou = 0;
        v[i].PB(MP(now, cou));
        while(1){
            now += i;
            cou++;
            if(now > 9){
                cou++;
                now = (now % 10) + 1;
            }
            v[i].PB(MP(now, cou));
            if(now == i)break;
        }
    }

    ll ans = -1;
    ll now = 0;
    ll m;cin >> m;
    REP(i, m){
        ll a, b;cin >> a >> b;b--;
        ll syo = b / (v[a].size() - 1);
        ans += syo * v[a].back().SE;
        b %= (v[a].size() - 1);
        ll tmp = v[a][b].FI;
        ans += v[a][b].SE + 1;
        now += tmp;
        if(now > 9){
            ans++;
            now = (now % 10) + 1;
        }
        //cout << endl << ans << " " << now << " " << syo << " " << tmp << endl;
    }

    cout << ans << endl;

	return 0;
}


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

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

    vector< vector<short> > dish;
    vector<short> diff;
    dish.assign(5, vector<short>(2,0));
    int servetime = 0;
    for(int i = 0 ; i < 5; i++){
        cin >> dish[i][1];
        if(dish[i][1] % 10 == 0){
            dish[i][0] = 0;
        }
        else {
            dish[i][0] = (dish[i][1] / 10 + 1) * 10 - dish[i][1];
        }
    }
    
    sort(dish.begin(), dish.end());
    // for(int i=0; i< 5;i++){
    //     cout << dish[i][0] << " " << dish[i][1] << endl;
    // }
    
    for(int i = 0; i < 5; ++i){
        if(dish[i][0] == 0 || i == 4){
            servetime += dish[i][1];
        }
        else {
            servetime += (dish[i][0] + dish[i][1]);
        }
        // cout << servetime << endl;
    }

    cout << servetime << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define int long long

const int N = 3e5;

int seg[N << 2], a[N + 1], dp[N + 1];

void update(int i, int j, int l, int n, int v) {
  if (i > l || j < l) {
    return;
  }
  if (i == j && i == l) {
    seg[n] = v;
    return;
  }
  int mid = (i + j) >> 1;
  update(i, mid, l, n << 1, v);
  update(mid + 1, j, l, n << 1 | 1, v);
  seg[n] = max(seg[n << 1], seg[n << 1 | 1]);
}

int query(int i, int j, int l, int r, int n) {
  if (i > r || j < l) {
    return 0;
  }  
  if (i >= l && j <= r) {
    return seg[n];
  }
  int m = (i + j) >> 1;
  return max(query(i, m, l, r, n << 1), query(m + 1, j, l, r, n << 1 | 1));
}


int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    int x = query(0, N, max(0LL, a[i] - k), min(N, a[i] + k), 1);
    dp[i] = x + 1;
    ans = max(ans, dp[i]);
    update(0, N, a[i], 1, dp[i]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 16536
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,sum=0;
  cin >> n;
  ll a[n],b[n],c[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
    sum += b[i];
  }
  for(int i=0;i<n-1;i++){
    cin >> c[i];
  }
  for(int i=1;i<n;i++){
    if(a[i-1]==a[i]-1){
      sum += c[a[i-1]-1];
    }
  }
  cout << sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int cnt[N];
    fill(cnt, cnt+N, 0);
    for(int i=0; i<K; i++){
        int d;
        cin >> d;
        for(int j=0; j<d; j++){
            int a;
            cin >> a;
            a--;
            cnt[a]++;
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(cnt[i] == 0) ans++;
    }

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


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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)) puts("A");
    else puts("B");
    return 0;
}

Measured memory_bytes: 256