akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

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

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;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


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

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

    for (;;) {
        int w, h; cin >> w >> h;
        if (w == 0) break;

        vvi s(h, vi(w));
        REP(i, h) REP(j, w) cin >> s[i][j];

        vvi vis(h, vi(w));
        function<void(int,int)> dfs = [&](int i, int j) {
            vis[i][j] = 1;
            REP(k, 8) {
                int y = i + dy[k], x = j + dx[k];
                if (y < 0 or x < 0 or y >= h or x >= w) continue;
                if (s[y][x] == 0) continue;
                if (vis[y][x]) continue;
                dfs(y, x);
            }
        };

        int ans = 0;
        REP(i, h) REP(j, w) if (s[i][j] == 1 and !vis[i][j]) {
            ++ans;
            dfs(i, j);
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3348
#include <stdio.h>
int main(){
    int x, y;
    while(1){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }else if(x > y){
            printf("%d %d\n", y, x);
        }else{
            printf("%d %d\n", x, y);
        }
    }
    return 0;
}

Measured memory_bytes: 1740
n = int(input())
B = list(map(int, input().split(" ")))
A = B[0]
An = B[0]
C = B[0]
for i in range(1,n-1):
  if An <= B[i]:
    C += An
  else:
    C+= B[i]
  An = B[i]

C += An
print(C)

Measured memory_bytes: 3060
from math import gcd
import itertools

k = int(input())

lst = [int(i) for i in range(1, k+1)]
all_array = list(itertools.combinations_with_replacement(lst, 3))
num = 0
for element in all_array:
  a = element[0]
  b = element[1]
  c = element[2]
  d = gcd(gcd(a, b), c)
  if a != b and b != c:
    num += d * 6
  elif a == b and b != c:
    num += d * 3
  elif a != b and b == c:
    num += d * 3
  elif a == b and b == c:
    num += d
print(num)

Measured memory_bytes: 105336
#include <stdio.h>

int main(void){
  int x,y,size,map[13][13],cnt,max,i,j;

  cnt = max = 0;

  for( i = 0 ; i < 13 ; i++ )
    for( j = 0 ; j < 13 ; j++ )
      map[i][j] = 0;  

  while(scanf("%d,%d,%d" ,&x ,&y ,&size ) != EOF ){
    x+=2; y+=2;
    switch(size){
    case 3:
      map[x][y-2]++; map[x][y+2]++;
      map[x-2][y]++; map[x+2][y]++;
    case 2:
      map[x-1][y-1]++; map[x+1][y+1]++;
      map[x-1][y+1]++; map[x+1][y-1]++;
    case 1:
      map[x][y]++; map[x-1][y]++; map[x][y-1]++; 
      map[x+1][y]++; map[x][y+1]++;
      break;
    }
    
  }

  for( i = 2 ; i < 12 ; i++ ){
    for( j = 2 ; j < 12 ; j++ ){
      if( max < map[i][j] ) max = map[i][j];
      if( map[i][j] == 0 ) cnt++;
    }
  }

  printf("%d\n%d\n" ,cnt, max );

  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputData = Console.ReadLine().Split(' ');


            Int64 orgData = Int64.Parse(inputData[0]);
            Int64 cnt = Int64.Parse(inputData[1]);


            Int64 tmpData = orgData % cnt;
            Int64 stdData = Math.Abs(tmpData - cnt);
            if (tmpData < stdData)
            {
                Console.WriteLine(tmpData);
            } else
            {
                Console.WriteLine(stdData);
            }
            Console.ReadLine();
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define DBG 0

int N=50;
int K=250;
int A[50][50];

int cnt;

int q(int y1,int x1,int y2,int x2){
    if((y2-y1)*(x2-x1)==0)return 0;

    if(DBG){
        int res=0;
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)res+=A[y][x];
        return res;
    }

    else{
        cout<<"? "<<y1<<" "<<x1<<" "<<y2-1<<" "<<x2-1<<endl;
        int p;cin>>p;
        return p;
    }
}


vector<int>lis[2555];
int dfs(int y1,int x1,int y2,int x2,int p){
    if(y1==y2)return 0;
    if(x1==x2)return 0;

    if((y2-y1)*(x2-x1)==p){
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)A[y][x]=1;
        return 0;
    }

    if(p==0)return 0;
    int y3=(y1+y2)/2;
    int x3=(x1+x2)/2;

    int pl=q(y1,x1,y2,x3);
    int pu=q(y1,x1,y3,x2);

    int p11,p12,p21,p22;

    int cnt=2;

    if(pl==0){
        p11=p21=0;
        p12=pu;
        p22=p-pu;
    }
    else if(pl==p){
        p12=p22=0;
        p11=pu;
        p21=p-pu;
    }
    else if(pu==0){
        p11=p12=0;
        p21=pl;
        p22=p-pl;
    }
    else if(pu==p){
        p21=p22=0;
        p11=pl;
        p12=p-pl;
    }
    else{
        p11=q(y1,x1,y3,x3);
        p12=pu-p11;
        p21=pl-p11;
        p22=p-p11-p12-p21;
        cnt++;
    }

    cnt+=dfs(y1,x1,y3,x3,p11);
    cnt+=dfs(y1,x3,y3,x2,p12);
    cnt+=dfs(y3,x1,y2,x3,p21);
    cnt+=dfs(y3,x3,y2,x2,p22);

    lis[(y2-y1)*(x2-x1)].pb(cnt);
    return cnt;
}
const int B=16;

signed main(){
    if(DBG){
        vector<pint>v;
        rep(i,N)rep(j,N)v.pb({i,j});
        srand((unsigned)time(NULL));
        random_shuffle(all(v));

        for(int i=0;i<K;i++){
            A[v[i].fi][v[i].se]=1;
        }
        int sum=0;
        for(int i=0;i<N/B;i++){
            for(int j=0;j<N/B;j++){
                int y=(i+1)*B;
                int x=(j+1)*B;
                if(i+1==N/B)y=N;
                if(j+1==N/B)x=N;
                int p=q(i*B,j*B,y,x);
                sum++;
                sum+=dfs(i*B,j*B,y,x,p);
            }
        }
        int cnt=0;
        rep(i,N)rep(j,N)cnt+=A[i][j];
        cout<<cnt<<endl;
        cout<<sum<<endl;

        cout<<dfs(0,0,N,N,K)<<endl;
    }

    else{
        int tmp;
        cin>>tmp;cin>>tmp;cin>>tmp;
        int mod;cin>>mod;

        for(int i=0;i<(N+B-1)/B;i++){
            for(int j=0;j<(N+B-1)/B;j++){
                int p=q(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B));
                dfs(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B),p);
            }
        }

        int p=1;
        int res=0;
        rep(i,N)rep(j,N){
            res=(res+p*A[i][j])%mod;
            p=p*2%mod;
        }

        cout<<"! "<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 848
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<double,ll> pdi;
typedef pair<double,pii> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
typedef pair<point,int> ppi;
#define mod (int)(1e9+7)
#define eps (1e-9)
#define oo (ll)(0x3f3f3f3f)
#define pi acos(-1)
#define MAXN (ll)(1e3+5)

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

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

    sort(allr(a));

    ll res=0;
    vector<int> act={a[0]};
    int po=2;
    while(po<=n)
    {
        vector<int> b(po);
        for(int i=0;i<po;i+=2)
            b[i]=act[i/2];
        for(int i=po/2;i<po;i++)
        {
            b[1+2*(i-(po/2))]=a[i];
            res+=min(b[2*(i-(po/2))],b[(2+2*(i-(po/2)))%po]);
        }
        act=b;
//        for(auto y : act)
//            cout << y << ' ';
//        cout << '\n';
        po*=2;
    }

    po/=2;
    int faltan=n-po;
    for(int i=1;i<=faltan;i++)
        res+=min(act[i-1],act[i]);
    db(res)

    return 0;
}
/**
7
1 1 1 1 1 1 1
**/


Measured memory_bytes: 5332
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <stdlib.h>
#include <deque>
#include <cstdint>
using namespace std;

int main () {
  int n;
  cin >> n;
  double v[n];
  for (int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    v[i] = tmp;
  }
  sort(v, v + n);
  for (int i = 0; i < n-1; i ++){
    v[i+1] = (v[i] + v[i+1])/2;
  }
  cout << v[n-1];
  return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int n;
   cin>>n;
   ll sum=0;
   for(int i=1; i<=n; i++){
      if(i%3!=0 && i%5!=0) sum+=i;
   }
   cout << sum << endl;
   return 0;
}


Measured memory_bytes: 3556
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
const int N=100005, P=1000000007;
int sum[26]; char s[N];

inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

int main()
{
	int n=read(); scanf("%s", s+1);
	long long ans=0;
	for (int i=1; i<=n; i++)
	{
		int c=s[i]-'a'; sum[c]++;
		long long tmp=1;
		for (int i=0; i<26; i++) 
			if (i^c) tmp=1ll*tmp*(sum[i]+1)%P;
		ans=(ans+tmp)%P;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define LEN 1000005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail=0, n;

void enqueue(P x){

  Q[tail]=x;
  tail++;
}

P dequeue(){
  P x;

  x=Q[head];
  head++;

  return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  tail=n+1;

  while(1){

    u=dequeue();

    u.t=u.t-q;

    if(u.t>0) {enqueue(u); elaps=elaps+q;}

    if(u.t<=0) {elaps=elaps+(u.t+q); printf("%s %d\n",u.name,elaps);

      c++;}

  if(c==n) break;

 }

  return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

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

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll n, m;
    cin >> n >> m;
    vi ans(n, -1);
    ll s, c, flg = 1;
    REP(i, 0, m) {
        cin >> s >> c;
        s--;
        if (ans[s] == -1)
            ans[s] = c;
        else if (ans[s] != c)
            flg = 0;
        if (s == 0 && c == 0 && n > 1)
            flg = 0;
    }
    if (flg) {
        REP(i, 0, n) {
            if (ans[i] == -1) {
                if (i == 0 && n > 1)
                    ans[i] = 1;
                else
                    ans[i] = 0;
            }
            cout << ans[i];
        }
        cout << endl;
    }
    else
        cout << -1 << endl;
}


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

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 1e5 + 20;

int a[N], dp[N];

int32_t main(){

    sync;

    int n; cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    dp[2] = abs(a[1] - a[2]);
  	for(int i = 3; i <= n; i++) dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
  	cout << dp[n] << endl;

    return 0;
}

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

int main(){
  int n,m;
  while(1){
  int  ans=0,p[10001]={};
  cin>>n>>m;
  if(n+m==0)break;
  for(int i=1;i<=n;i++){
    cin>>p[i];
  }

  for(int j=0;j<n;j++)
    for(int i=1;i<=n;i++)
      if(p[i]<p[i+1])swap(p[i],p[i+1]);


  for(int i=1;i<=n;i++){
    if(i%m==0)p[i]=0;
    ans+=p[i];
  }


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

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

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

struct Line{
	int u, v, t;
};

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

	int N, M, Q;
	cin >> N >> M >> Q;

	Line l[200005];

	for (int i = 0;i < M;i++){
		int u,v; cin >> u >> v;
		l[i] = {u,v,-1};
	}

	for (int i = 0;i < Q;i++){
		int q; cin >> q;
		q--;
		l[q].t = i;
	}

	vector<P> G[100005];

	for (int i = 0;i < M;i++){
		//cout << l[i].u << " " << l[i].v << " " << l[i].t << endl;
		G[l[i].u].push_back(P(l[i].v,l[i].t));
		G[l[i].v].push_back(P(l[i].u,l[i].t));
	}

	priority_queue<P, vector<P>, greater<P> > que; //(dist, node)
	que.push(P(0,1));
	int dist[100005]; 
	int time[100005]; 

	for (int i = 0;i < N+3;i++){
		dist[i] = INT_MAX;
		time[i] = INT_MAX;
	}

	dist[1] = 0;

	while(que.size()){
		P p = que.top(); que.pop();
		int now = p.second;
		int d = p.first;
		if(dist[now] < d) continue;
		for (int i = 0;i < G[now].size();i++){
			int to = G[now][i].first;
			int tt = G[now][i].second;
			if(dist[to] == d+1){
				if(time[now] != -1 && tt != -1)time[to] = max(time[to],min(time[now],tt));
				else if( time[now] == -1 && tt != -1)time[to] = max(time[to],tt);
				else if(time[now] != -1 && tt == -1) time[to] = max(time[to],time[now]);
			}
			else if(dist[to] > d+1 ){
				if(time[now] != -1 && tt != -1)time[to] = min(time[now],tt);
				else if( time[now] == -1 && tt != -1)time[to] = tt;
				else if(time[now] != -1 && tt == -1) time[to] = time[now];
				dist[to] = d+1;
				que.push(P(dist[to], to));
			}
		}
	}

	int ans[200005]; memset(ans, 0, Q+3);

	for (int i = 1;i <= N;i++){
		//cout << time[i] << " " << i << endl;
		if(time[i] == INT_MAX) continue;
		ans[time[i]]++;
	}

	int sum = 0;

	for (int i = 0;i < Q;i++){
		sum += ans[i];
		cout << sum << endl;
	}

	return 0;

}



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

int main(){
    int n;
    cin>>n;
    int st,sh;
    st=0;
    sh=0;
    rep(i,n){
        string S,T;
        cin>>S>>T;
        vector<string> V;
        V.push_back(S);
        V.push_back(T);
        sort(V.begin(),V.end());
        if(S==T)st++,sh++;
        else if(V.at(1)==S)st+=3;
        else if(V.at(1)==T)sh+=3;
    }
    cout<<st<<" "<<sh<<endl;
    return 0;
}


Measured memory_bytes: 3220
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int a, b, c, k;

	cin >> a >> b >> c;

	cin >> k;

	for (int i = 0; i < k; i++) {
		if (a >= b) {
			b *= 2;
		}
		else {
			c *= 2;
		}
	}

	if (a < b && b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3632
S = input()
if S[0] != 'A':
    print('WA')
    exit()
S.replace(S[0],'')
a=0
for i in range(2, len(S) - 1):
    if S[i]=='C':
        j=i
        S.replace(S[i],'')
        a+=1
if a!=1:
    print('WA')
    exit()
for i in range(len(S)):
    if (i!=0)&(i!=j):
        a=S[i]
        if a.isupper():
            print('WA')
            exit()
print('AC')

Measured memory_bytes: 3064
from collections import deque
s = deque(list(input()))
q = int(input())

rev = 0
for i in range(q):
  tfc = list(input().split())
  if tfc[0] == "1":
    rev = abs(rev-1)
  else:
    t,f,c = tfc
    if rev:
      if f == "1":
        s.append(c)
      else:
        s.appendleft(c)
    else:
        if f == "1":
          s.appendleft(c)
        else:
          s.append(c)
if rev:
  t = []
  for i in range(len(s)):
    t.append(s.pop())
  print("".join(t))
else:
  print("".join(s))

Measured memory_bytes: 9180
//dijkstra算法 
#include <iostream>

using namespace std;

const int N = 100;
//INFTY要足够大 
const int INFTY = 1 << 21;

int Graph[N][N];

int n;

void dijkstra(int u0) {
	int *d = new int[n];
	char *color = new char[n];
	for (int i=0;i<n;i++) {
		d[i] = INFTY;
		color[i] = 'W';
	}
	
	d[u0] = 0;
	color[u0] = 'G';
	
	while (1) {
		int mincost = INFTY;
		int u = -1;
		for (int i = 0;i<n;i++) {
			if (color[i] != 'B' && mincost > d[i]) {
				mincost = d[i];
				u = i;
			}
		}
		

		
		if (mincost == INFTY) { //说明节点已经全部访问完毕 
			break;
		}
		
		color[u] = 'B';
		
		for (int v=0;v<n;v++) {
			if (color[v] != 'B' && Graph[u][v] != INFTY) {
				if (d[v] > d[u] + Graph[u][v]) {
					d[v] = d[u] + Graph[u][v];
					color[v] = 'G'; 
				}
			}
		}
	}
	for (int i=0;i<n;i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {
	
	cin >> n;
	//注意初始化 
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			Graph[i][j] = INFTY;
		}
	}
	
	for (int i=0;i<n;i++) {
		int u,k;
		cin >> u >> k;
		
		for (int j = 0;j<k;j++) {
			int v,c;
			cin >> v >> c;
			Graph[u][v] = c;
		}
	}
	dijkstra(0);
	return 0;
}


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



#define SIZE 200005


char buf[SIZE];


int main(){

	stack<ll> S,POP,pre_TOP;
	S.push(0);

	scanf("%s",buf);

	ll ans = 0;

	for(int i = 0; buf[i] != '\0'; i++){

		if(buf[i] == '('){

			S.push(0);
			POP.push(-1);

		}else if(buf[i] == ')'){

			if(S.size() == 1){

				POP.push(-2);
				pre_TOP.push(S.top());
				S.top() = 0;

			}else{

				ll tmp = S.top();
				S.pop();
				POP.push(tmp);
				S.top() += 1;
				ans += S.top();
			}

		}else{ //buf[i] == '-'

			if(POP.top() < 0){

				if(POP.top() == -1){ //開きカッコ

					S.pop();

				}else{ //POP.top() == -2 無視する閉じカッコ

					S.top() = pre_TOP.top();
					pre_TOP.pop();
				}

			}else{

				ans -= S.top();
				S.top() -= 1;
				S.push(POP.top());
			}
			POP.pop();
		}

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

	return 0;
}



Measured memory_bytes: 6360
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    if a[i] > b[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        ans += min(a[i + 1], b[i])
        a[i + 1] = max(0, a[i + 1] - b[i])
print(ans)

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int D, G;
	cin >> D >> G;
	int p[D], c[D];
	int problem_num = 0;
	rep(i, 0, D) {
		cin >> p[i] >> c[i];
		problem_num += p[i];
	}

	ll dp[D + 1][problem_num + 1];
	memset(dp, 0, sizeof(dp));

	rep(i, 0, D) rep(j, 0, problem_num + 1) {
		rep(k, 0, p[i] + 1) {
			if(j - k >= 0) {
				if(k == p[i]) dp[i + 1][j] = max(dp[i + 1][j], max(dp[i][j - k] + k * 100 * (i + 1) + c[i], dp[i][j]));
				else dp[i + 1][j] = max(dp[i + 1][j], max(dp[i][j - k] + k * 100 * (i + 1), dp[i][j]));
			} else {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
		}
	}

	rep(j, 0, problem_num + 1) {
		if(dp[D][j] >= G) {
			cout << j << endl;
			return 0;
		}
	}


}


Measured memory_bytes: 384
def p_c():
    n, k = map(int, input().split())
    ans = 0
    m = min(n, k - 1)
    for i in range(1, m + 1):
        x = 0
        while k > i << x:
            x += 1
        ans += (1 / n) * (1 / (1 << x))
    if m == k - 1:
        ans += (n - k + 1) / n

    print(ans)
    
p_c()

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A>B) swap(A, B);
    if (B>C) swap(B, C);
    if (A>B) swap(A, B);
    
    int ans;
    
    if ((B-A)%2 == 0){
        ans = (C - B) + (B - A)/2;
    }
    else{
        ans = (2 *C - A - B + 3) / 2;
    }
    
    cout << ans << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if(N==M){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

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

std::vector<std::pair<int64_t, int64_t>> v(100010, std::pair<int64_t, int64_t>(0, 9223372036854775807));
std::vector<int64_t> prefix_sum(100010, 9223372036854775807);
bool ok[100010];

bool comp(const std::pair<const int64_t, int64_t> &a, const std::pair<const int64_t, int64_t> &b)
{
    return a.second < b.second;
}

int main()
{
    int64_t N, tmp;
    cin >> N;
    for (int64_t i = 0; i < N; ++i)
    {
        cin >> tmp;
        v[i] = std::make_pair(i, tmp);
        prefix_sum[i] = tmp;
    }
    std::sort(v.begin(), v.end(), [](const std::pair<int64_t, int64_t> &a, const std::pair<int64_t, int64_t> &b){ return a.second < b.second; });
    std::sort(prefix_sum.begin(), prefix_sum.end());
    for (int64_t i = 1; i < N; ++i)
    {
        prefix_sum[i] += prefix_sum[i-1];
    }
    int64_t cnt = 0;
    int64_t min = 0;
    for (int64_t i = 0; i < N - 1; ++i)
    {
        if (prefix_sum[i] * 2 < v[i+1].second)
        {
            min = i + 1;
        }
    }
    cout << N - min << endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for (int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}

		int sum = 0;
		for (int i = 0; i < n; i++) {
			int minIndex = 0;
			for (int j = 0; j < m; j++) {
				int tmp1 = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				int tmp2 = Math.abs(a[i] - c[minIndex]) + Math.abs(b[i] - d[minIndex]);
				if (tmp1 < tmp2) {
					minIndex = j;
				}
			}
			System.out.println(++minIndex);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll k, a, b;
    cin >> k >> a >> b;

    if(a+2 >= b){
        ppp(k+1);
        return 0;
    }
    if(k <= a){
        ppp(a+1);
        return 0;
    }

    ll change = (k-a+1)/2;

    ll bis = change*b - (change-1)*a;

    if((k-a-1)%2) bis++;
    ppp(bis);






    return 0;
}


Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    C = [int(c) for c in input().split()]
    C.sort()
    mod = 7 + 10 ** 9

    SumC = 0

    for i in range(N):
        SumC += (C[i] * (N - i + 1)) % mod
        SumC %= mod
    SumC *= pow(4, N - 1, mod)
    SumC %= mod
    print(SumC)


    return 0

if __name__ == "__main__":
    solve()

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

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll n;
vector<string> mem;
void fuck(string s, ll u, ll len){
        if (len == (n + 1)){
                mem.push_back(s);
                return;
        }
        for (int i = 1; i <= (u + 1); i++){
                s[len - 1] = char(i - 1 + 'a');
                fuck(s, max(u, 1ll * i), len + 1);
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        string s;
        s.resize(n);
        for (int i = 1; i <= n; i++) {
                s[i - 1] = 'a';
        }
        fuck(s, 0, 1);
        sort(mem.begin(), mem.end());
        cout << mem[0] << endl;
        for (int i = 1; i < mem.size(); i++) if (mem[i] != mem[i - 1]) cout << mem[i] << endl;
}


Measured memory_bytes: 7796
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int n, k, a, f= 1, t;
 
int main(){

    cin >> n >> k;

    set<int> s;
    vector<int> h;
    vector<int> v;

    for(int i = 0; i < n; i++){
        cin >> a;
        s.insert(a);
        h.push_back(a);
    }

    sort(h.begin(), h.end());

    for(int i = 0; i < h.size()-1; i++){
        if(h[i] == h[i+1]){
            f++;
        } else{
            v.push_back(f);
            f = 1;
        }
    }

    if(f != 0){
        v.push_back(f);
        f = 1;
    }

    sort(v.begin(), v.end());

    // for(int i = 0; i < v.size(); i++){
    //     cout << v[i] << nl;
    // }

    if(s.size() > k){
        for(int i = 0; i < s.size()-k; i++){
            t = t + v[i];
        }
        cout << t;
    } else{
        cout << 0;
    }
 

 
 
}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 11892
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[1 << 12], nxt[1 << 12];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, 0, m){
        int c;
        cin >> a[i] >> c;
        rep(j, 0, c){
            int in;
            cin >> in;
            in--;
            b[i] |= 1 << in;
        }
    }
    rep(i, 0, 1 << n) dp[i] = INF;
    dp[0] = 0;
    rep(i, 0, m){
        rep(j, 0, 1 << n) nxt[j] = dp[j];
        rep(j, 0, 1 << n){
            nxt[j | b[i]] = min(nxt[j | b[i]], dp[j] + a[i]); 
        }
        swap(dp, nxt);
    }
    int ans = dp[(1 << n) - 1];
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	bool ans = false;

	for (int i = 1; i <= 100; i++) {
		if ((i*A) % B == C) {
			ans = true;
			break;
		}
	}

	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    set<char>set;
    rep(i,n){
        char t;cin>>t;
        set.insert(t);
    }
    if(set.size()==3)cout<<"Three";
    else cout<<"Four";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, l;cin>>n>>l;
	int arr[n], sum = 0;
	for(int i = 0; i < n; ++i){
		arr[i] = l + i;
		sum += arr[i];
	}
	int dist = INT_MAX, ans = 0;
	for(int i = 0; i < n; ++i){
		int temp = sum - arr[i];
		if(abs(arr[i]) < dist){
			dist = abs(arr[i]);
			ans = sum - arr[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    int64 ans = 0;
    VI n = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cii(k);

    ans = n[k-1];

    co(ans);
    return 0;
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int h,w,cx,cy;

bool in(int x,int y){return 0<=x && x<w && 0<=y && y<h;}

int calc2(int x1,int y1,int x2,int y2){
  if(x1 > x2) swap(x1, x2), swap(y1, y2);  
  if(x1 >= w) return 0;

  if(x1 < 0){
    if(y1 - y2 < 0) y1 += abs(x1) ,x1 = 0;
    if(y1 - y2 > 0) y1 -= abs(x1) ,x1 = 0;
  }

  if(x2 >= w){
    if(y1 - y2 < 0) y2 -= abs(x2-(w-1)) ,x2 = w-1;
    if(y1 - y2 > 0) y2 += abs(x2-(w-1)) ,x2 = w-1;
  }
  if(y1 > y2) swap(x1, x2), swap(y1, y2);
  if(y1 >= h) return 0;

  if(y1 < 0){
    if(x1 - x2 < 0) x1 += abs(y1) ,y1 = 0;
    if(x1 - x2 > 0) x1 -= abs(y1) ,y1 = 0;
  }

  if(y2 >= h){
    if(x1 - x2 < 0) x2 -= abs(y2-(h-1)) ,y2 = h-1;
    if(x1 - x2 > 0) x2 += abs(y2-(h-1)) ,y2 = h-1;
  }
  
  if(!in(x1,y1) || !in(x2,y2)) return 0;
  return abs(x2 - x1)+1;
}

int calc(int d){
  if(d == 0) return 1;
  return 
    calc2(cx,cy+d,cx+d,cy) + 
    calc2(cx+d,cy,cx,cy-d) +
    calc2(cx,cy-d,cx-d,cy) +
    calc2(cx-d,cy,cx,cy+d) -
    (in(cx,cy+d) + in(cx+d,cy) + in(cx,cy-d) + in(cx-d,cy));
}


template< class T >
void printVec(T a,char ch = ' '){
  for(int i=0;i<a.size();i++){
    if(i)cout<<ch;
    cout<<a[i];
  }
  cout<<endl;
}

signed main(){

  int X,Y,Z,A,B,C,n;
  cin>>X>>Y>>Z>>A>>B>>C>>n;
  w = X;
  h = Y;
  cx = A;
  cy = B;
  int D[N]={};
  for(int i=0;i<=X+Y;i++){
    D[i%n] += calc(i);
  }

  //for(int i=0;i<n;i++) cout<<D[i]<<" ";cout<<endl;  


  int ans = 0;
  int L1 = 0, R1= 0;
  int L2 = 0, R2= n-1;
  for(int i=0;i<Z-C;i++){
    int c = i%n;
    ans += D[(n-c)%n];
    L1 = (n - c)%n;
  }

  for(int i=1;i<=C;i++){
    int c = i%n;
    ans += D[(n-c)%n];
    L2 = (n - c)%n;
  }
  
  vector<int> Ans(1,ans);
  
  //swap(L1,R1);
  //swap(L2,R2);
  for(int i=1;i<n;i++){
    // cout<<"i="<<i<<endl;
    //cout<<L1<<" "<<R1<<endl;
    //cout<<L2<<" "<<R2<<endl;
    
    /*
      ans -= D[L1];
    L1++;L1%=n;

    R1++;R1%=n; 
    ans += D[R1];
    
    
    ans -= D[L2];
    L2++;L2%=n;

    R2++;R2%=n; 
    ans += D[R2];
    */

    ans -= D[L1];
    L1+=1;L1%=n;
    
    R1+=1;R1%=n;     
    ans += D[R1];
    
    ans -= D[L2];    
    L2+=1;L2%=n;
    
    R2+=1;R2%=n; 
    ans += D[R2];

    
    Ans.push_back(ans);
  }

  //reverse(Ans.begin()+1,Ans.end());
  printVec(Ans);
  return 0;
}

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

void swap(int *x, int*y)
{
    int t;
    t = *x;
    *x = *y;
    *y = t;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
   int A, B; cin >> A >> B;

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

}

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

typedef long long ll;
ll a[41],b[41],c[41],n,ma,mb,minv=(int)1e9,suma,sumb,sumc,gcdv;

int main(void){
    cin>>n>>ma>>mb;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
    map<pair<int, int>, int> m1,m2;
    for(ll i=0;i<1<<n/2;i++){
        suma=0,sumb=0,sumc=0;
        for(int j=0;j<n/2;j++)if(i & 1<<j){
            suma+=a[j];sumb+=b[j];sumc+=c[j];
        }
        
        if(m1.count(make_pair(suma,sumb))){
            auto it = m1.find((make_pair(suma,sumb)));
            if(sumc < it->second)m2[make_pair(suma,sumb)]=sumc;    
        }
        else m1[make_pair(suma,sumb)]=sumc;
    }
    for(ll i=0;i<1<<(n-n/2);i++){
        suma=0,sumb=0,sumc=0;
        for(int j=0;j<(n-n/2);j++)if(i & 1<<j){
            suma+=a[j+n/2];sumb+=b[j+n/2];sumc+=c[j+n/2];
        }
        if(m2.count(make_pair(suma,sumb))){
            auto it = m2.find((make_pair(suma,sumb)));
            if(sumc < it->second)m2[make_pair(suma,sumb)]=sumc;
        }
        else m2[make_pair(suma,sumb)]=sumc;
    }
    for(auto x: m1){
        suma=x.first.first;
        sumb=x.first.second;
        sumc=x.second;
        for(int i=1;i*max(ma,mb)<405;i++)
        if(m2.count(make_pair(i*ma-suma,i*mb-sumb)))
            minv=min(minv,sumc+m2[make_pair(i*ma-suma,i*mb-sumb)]);
        
    }
    cout<<(minv==(int)1e9 ? -1 : minv)<<endl;
}


Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	N, A, B int
	g, h    [154321]int
)

func readVariables() {
	N, A, B = nextInt(), nextInt(), nextInt()
	for i := 0; i < N; i++ {
		h[i] = nextInt()
	}
}

func main() {
	readVariables()
	ok, ng := 1234567890, 0
	for AbsInt(ok-ng) > 1 {
		mid := (ok + ng) / 2
		if judge(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	fmt.Println(ok)
}

func judge(t int) bool {
	for i, v := range h {
		g[i] = v - t*B
	}
	cnt := 0
	for _, v := range g {
		if v > 0 {
			cnt += v / (A - B)
			if v%(A-B) > 0 {
				cnt++
			}
		}
	}
	// fmt.Println(t, cnt, cnt <= t, g[0:N])
	return cnt <= t
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
char a;
string s="";
int main()
{
	l n,k;
	cin>>n>>k;
	while(n>0)
	{
		a=n%k+'0';
		s+=a;
		n=n/k;
	}
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long a, b, c, k, sum, x;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);

    if(k <= a){
        sum = k;
    }

    else if( k <= (a + b)){
        sum = a;
    }

    else if( k <= (a + b + c)){
        x = k - (a + b);
        sum = a - x;
    }

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

    return 0;
}


Measured memory_bytes: 1736
n, c = gets.split.map(&:to_i)
d = c.times.map { |i| gets.split.map(&:to_i) }
color = n.times.map { |i| gets.split.map(&:to_i) }
 
color_map = [*0...n].repeated_permutation(2).group_by{|i, j| (i + j) % 3}
(0..2).each do |i|
  color_map[i] = [] unless color_map[i]
end
zero, one, two = color_map.values.map do |i|
  c.times.map do |j|
    i.inject(0) { |mem, (x, y)| mem + d[color[x][y]-1][j] }
  end
end
 
r = [*0...c].repeated_permutation(3).map do |i, j, k|
  if [i, j, k].uniq.size == 3
    zero[i].to_i + one[j].to_i + two[k].to_i
  else
    nil
  end
end
 
p r.compact.min

Measured memory_bytes: 19580
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
using namespace std;
const int MOD=998244353;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> c(n),d(n);
    REP(i,n) cin >> d[i], c[d[i]]++;
    if ( d[0]!=0 || c[0]>1 ) { cout << 0 << '\n'; return 0; }
    int ans=1;
    REP1(i,1,n-1) {
        if ( c[i-1]==0 && c[i]==0 ) continue;
        REP(j,c[i]) ans=(long long)ans*c[i-1]%MOD;
    }
    cout << ans << '\n';
    return 0;
}

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

int main() {
  while (true) {
    int a, b;
    string op;
    cin >> a >> op >> b;
    if (op == "?") {
      break;
    }
    int ans = 0;
    if (op == "+") {
      ans = a + b;
    }
    if (op == "-") {
      ans = a - b;
    }
    if (op == "*") {
      ans = a * b;
    }
    if (op == "/") {
      ans = a / b;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3148
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    if (n < 105){
        cout << 0 << endl;
        return 0;
    }
    int total = 0;
    for(int i = 105; i <= n; i += 2){
        int count = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) count++;
        }
        if(count == 8) total++;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
   int n, k; cin >> n >> k;
   vector<ll> P, M;
   ll res = 1;
   bool sei = false, zero = false;
   rep(i, n){
       ll a; cin >> a;
       if(a>0){sei = true; P.push_back(a);}
       if(a==0)zero = true;
       if(a<0)M.push_back(a);
       if(n==k)res = (res * a) % MOD;
   }
   if(n==k){
       if(res>=0)
       cout << res << ln;
       else
           cout << MOD - abs(res) << ln;     
     }
   else{
       if(k%2==1 && sei == false){
           if(zero)cout << 0 << ln;
           else{
               sort(all(M), greater<ll>());
               rep(i, k) res = res * M[i] % MOD;
               cout << MOD - abs(res)<< ln;
           }
       }else{
           sort(all(P));
           sort(all(M), greater<ll>());
           if(k%2==1){
               k--;
               if(P.size()>0){res = res * P.back() % MOD; P.pop_back();}
               else res = 0;
           }
           for(int i=0; i<k; i+=2){
               if(res == 0)break;
               if(P.size()<2 && M.size()< 2 && zero){
                   res = 0; break;
               }
               if(P.size()>=2 && M.size()>=2){
                   ll a = P.back() * P[P.size()-2];
                   ll b = M.back() * M[M.size()- 2];
                   if(a >= b){
                       res = res * (a % MOD) % MOD;
                       P.pop_back(); P.pop_back();
                   }else{
                       res = res * (b % MOD) % MOD;
                       M.pop_back(); M.pop_back();
                   }
               }else if(P.size()>1){
                   res = res * P.back() % MOD; P.pop_back();
                   res = res * P.back() % MOD; P.pop_back();
               }else if(M.size()>1){
                   res = res * abs(M.back()) % MOD; M.pop_back();
                   res = res * abs(M.back()) % MOD; M.pop_back();                   
               }
           }
           cout << res % MOD << ln;
       }
   }
}


Measured memory_bytes: 5608