akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int next_like(int a, int *likes){
	int i;
	for(i = a; i < 10; i++){
		if(likes[i] != -1){
			return i;
		}
	}
	return -1;
}

int carry(int i, int *Ns, int *likes, int k){
	if(i == k){
		Ns[i] = next_like(1, likes);
		return k + 1;
	}
	else{
		if(next_like(Ns[i] + 1, likes) > Ns[i]){
			Ns[i] = next_like(Ns[i] + 1, likes);
			return k;
		}
		else{
			Ns[i] = next_like(0, likes);
			return carry(i + 1, Ns, likes, k);
		}
	}
}

int make_answer(int i, int *Ns, int *likes, int overflag, int k){
	if(overflag == 1){
		Ns[i] = next_like(0, likes);
		if(i == 0){
			return k;
		}
		else{
			return make_answer(i - 1, Ns, likes, 1, k);
		}
	}
	if(overflag == 0){
		if(next_like(Ns[i], likes) > Ns[i]){
			Ns[i] = next_like(Ns[i], likes);
			if(i == 0){
				return k;
			}
			else{
				return make_answer(i - 1, Ns, likes, 1, k);
			}
		}
		if(next_like(Ns[i], likes) == Ns[i]){
			if(i == 0){
				return k;
			}
			else{
				return make_answer(i - 1, Ns, likes, 0, k);
			}
		}
		if(next_like(Ns[i], likes) == -1){
			int l = make_answer(i, Ns, likes, 1, k);
			return carry(i + 1, Ns, likes, k);
		}
	}
}

int main(){
	int N, K, D, i, k, min, likes[10] = {0, 1, 2, 3, 4, 5 ,6 ,7 ,8, 9};
	scanf("%d%d", &N, &K);
	for(i = 0; i < K; i++){
		scanf("%d", &D);
		likes[D] = -1;
	}
	int Ns[6];
	for(k = 0; N != 0; k++, N /= 10){
		Ns[k] = N % 10;
	}
	k = make_answer(k - 1, &Ns[0], &likes[0], 0, k);
	int ans = 0;
	for(i = k - 1; i >= 0; i--){
		ans = 10 * ans + Ns[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
def solve(N):
    s=0
    length=1
    tmp=26
    while(s<=N):
        if s+tmp>=N:
            break
        length+=1
        s+=tmp
        tmp*=26
    X=[0 for i in range(length)]
    A=N-s-1
    k=0
    while(A>0):
        X[k]=A%26
        A//=26
        k+=1
    #print(X)
    ans=""
    for i in X:
        ans=chr(i+97)+ans
    return ans
print(solve(int(input())))

Measured memory_bytes: 9200
#include <stdio.h>
#include <stdlib.h>
int n, m;
void merge(int *u, int *net, int oldnet, int newnet);
int main(int argc, char *argv[]){
  int i, s, t, p, q;
  int *u;
  int *net;
  scanf("%d", &n);
  scanf("%d", &m);
  u = (int *)malloc(sizeof(int) * n);
  net = (int *)malloc(sizeof(int) * (m + 1));
  for (i = 0; i < n; i++){
    u[i] = -1;
  }
  for (i = 0; i <= m; i++){
    net[i] = 0;
  }  
  p = 1; 
  for (i = 0; i < m; i++) {
    scanf("%d", &s);
    scanf("%d", &t);
    if (s != t) {
      if (u[s] == -1 && u[t] == -1) {
	u[s] = p;
	u[t] = p;
	net[p] += 2;
	p++;
      } 
      else {
	if (u[s] != -1 && u[t] == -1) {
	  u[t] = u[s];
	  net[u[s]]++;
	}
	else if (u[s] == -1 && u[t] != -1) {
	  u[s] = u[t];
	  net[u[t]]++;
	} 
	else {
	  if (u[s] != u[t]) {
	    if (net[u[s]] > net[u[t]]){
	      merge(u, net, u[t], u[s]);
	    }
	    else{
	      merge(u, net, u[s], u[t]);
	    }
	  }
	}
      }
    }
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &s);
    scanf("%d", &t);
    if (s == t){
      printf("yes\n");
    }
    else {
      if (u[s] == u[t] && u[s] != -1 && u[t] != -1){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }
  return 0;
}
  
void merge(int *u, int *net, int oldnet, int newnet){
  int i; 
  for (i = 0; i < n; i++) {
    if (u[i] == oldnet){
      u[i] = newnet;
    }
  } 
  net[newnet] += net[oldnet];
  net[oldnet] = 0;
}

Measured memory_bytes: 1368
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
		int N, ans=0;
		long long int H,W,A,B;
		cin>>N>>H>>W;
		for(int i=0;i<N;i++){
			cin>>A>>B;
			if(A>=H && B>=W){
				ans++;
			}
		}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
#define ll long long

void init();
void solve();

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int n, k;

void init()
{
	cin >> n >> k;
}

ll m[300000];

void solve()
{
	reps(i, 1, n+1) {
		m[i%k]++;
	}
	ll res = 0;
	rep(i, n+1) {
		if ((i * 2) % k == 0) res += m[i] * m[i] * m[i];
	}
	cout << res << endl;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC107 B - Grid Compression
int main(){
  int h, w; // <=100
  cin >> h >> w;
  VECTOR_DIM2(bool, grid, h, w, false);
  rep(i,h) {
    string s;
    cin >> s;
    rep(j,w) {
      if (s[j] == '#') {
        grid[i][j] = true;
      }
    }
  }
  vector<bool> hValid(h, true), wValid(w, true);
  rep(i, h) {
    bool hasBlack = false;
    rep(j,w) {
      if (grid[i][j] == true) {
        hasBlack = true;
        break;
      }
    }
    if (!hasBlack) {
      hValid[i] = false;
    }
  }
  rep(j, w) {
    bool hasBlack = false;
    rep(i,h) {
      if (grid[i][j] == true) {
        hasBlack = true;
        break;
      }
    }
    if (!hasBlack) {
      wValid[j] = false;
    }
  }
  rep (i, h) {
    if (!hValid[i]) {
      continue;
    }
    rep(j, w) {
      if (!wValid[j]) {
        continue;
      }
      cout << (grid[i][j] ? '#' : '.');
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;
int main() {
    int N, K;
    cin >> K >> N;
    vector<int> home(N);
    int dist_max = 0;
    rep(i, 0, N)cin >> home[i];
    rep(i, 0, N){
        int a;
        if(i == 0){
            a = K + home[i] - home[N-1];
        }
        else{
            a = home[i] - home[i-1];
        }
        dist_max = max(dist_max, a);
    }
    cout << K - dist_max << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;
int main(void){
    int N,M;
    int p;
    string S;
    // kiroku[100000]={0};
    int wkiroku[100000]={0};
    bool flag[100000]={0};
    int ans=0,wans=0;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>p>>S;
        if(flag[p-1]==0){
            if(S=="AC"){
                flag[p-1]=1;
                ans++;
            }else{
                wkiroku[p-1]++;
            }
        }
    }
    
    for(int i=0;i<N;i++){
        if(flag[i]==1)wans+=wkiroku[i];
    }
    cout<<ans<<" "<<wans<<endl;
    
    
    return 0;
    
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
bool isprime(int p){
	if(p==1)return false;
	for(int i=2;i<p;i++)
		if(p%i==0)
			return false;
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int i=11;i<=55555;i++){
		if(isprime(i)==true){
			if(i%5==1){
				cout<<i<<' ';
				n--;
			}
			if(n==0)
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[100001];
int main(){
	int n;
	long long o;
	cin>>n;
	o=1;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if((__int128)o*a[i]>1000000000000000000LL){
			cout<<-1;
			return 0;
		}
		o*=a[i];
	}
	cout<<o;
	return 0;
}

Measured memory_bytes: 4424
#include<stdio.h>
#include<string.h>
int main() {
    char s[20], t[20];
    scanf("%s %s",s, t);
    for(int i=0; i<strlen(s);i++){
        if(s[i] != t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

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

int main(){
    int A,B;
    cin >> A >> B;
    cout << A * B << endl;;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<lu> vu;
typedef vector<v> vv;
typedef vector<vu> vvu;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
typedef pair<lu, lu> puu;
typedef vector<puu> vpuu;
const ll MOD = 1000000007;
const ld PI = 2 * acos(0.0);
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll n;
    cin >> n;
    v a = ga(n);
    v sum(n);
    sum[0] = a[0];
    for (ll i = 1; i < n; i++) {
        sum[i] = sum[i - 1] + a[i];
    }

    vv dp(n, v(n, 1e15));

    for (ll len = 1; len <= n; len++) {
        for (ll i = 0; i < n; i++) {
            ll j = i + len - 1;

            if (j >= n)
                break;
            if (len == 1) {
                dp[i][i] = 0;
            } else if (len == 2) {
                dp[i][j] = a[i] + a[j];
            } else {
                for (ll k = i; k < j; k++) {
                    ll c1 = dp[i][k];
                    ll c2 = dp[k + 1][j];
                    ll s1 = sum[k] - sum[i] + a[i];
                    ll s2 = sum[j] - sum[k];

                    amin(dp[i][j], c1 + c2 + s2 + s1);
                    amin(dp[i][j], c1 + c2 + s1 + s2);
                }
            }
        }
    }

    cout << dp[0][n - 1] << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
char s[500010];
int a[500010],f[500010];
int main(){
	int n,i,j,k,ans;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i++)a[i]=s[i]-'0';
	f[n]=n+1;
	for(i=n-1;i>0;i--)f[i]=a[i]==a[i+1]?f[i+1]:i+1;
	ans=0;
	for(i=1;i<=n;i=j+1){
		ans++;
		for(j=i;f[j]<=n&&a[j]<a[f[j]];j=f[j]);
		if(f[j]==n+1)break;
		a[n]++;
		for(k=n;k>j&&a[k]==10;k--){
			a[k-1]++;
			a[k]=0;
		}
		if(k>1)k--;
		while(k>1&&a[k]==a[k-1])k--;
		for(i=n-1;i>=k;i--)f[i]=a[i]==a[i+1]?f[i+1]:i+1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 4608
#include<stdio.h>

void trace(int A[], int N){
  int i;
  for ( i = 0; i < N; i++ ){
    if (i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void selectionSort(int A[], int N) {
  int k, i, j, minj, m;
  m = 0;
  for ( i = 0; i < N; i++ ) {
    minj = i;
    for ( j = i; j < N; j++ ) {
      if ( A[j] < A[minj] ) {
	minj = j;
      }
    }
    if (A[i] != A[minj]) {
      k = A[i];
      A[i] = A[minj];
      A[minj] = k;
      m++;
    }
  }
  trace(A, N);
  printf("%d\n", m);
}

int main(){
  int A[100], N, i;

  scanf("%d", &N);

  for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);
  
  selectionSort(A, N);
  return 0;
}



Measured memory_bytes: 2100
N,  M = map(int, input().split())
p = []; S = []
for _ in range(M):
    pi, Si = input().split()
    p.append(int(pi))
    S.append(Si)

wa_count = [0] * N
is_ac = [False] * N
ac = 0; wa = 0
for i in range(M):
    if is_ac[p[i]-1] == True:
        continue
    else:
        if S[i] == 'AC':
            ac += 1
            wa += wa_count[p[i]-1]
            is_ac[p[i]-1] = True
        else:
            wa_count[p[i]-1] += 1

print(ac, wa)

Measured memory_bytes: 14916
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[])
{
    int a, b;

    std::cin >> a >> b;

    if (a < b) {
        for (int i = 0; i < b; i++) {
            std::cout << a;
        }
    } else {
        for (int i = 0; i < a; i++) {
            std::cout << b;
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

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

const int MAXN = 2E5+2;

struct FenwickTree{
    vector<int> F;
    void init(int n){
      F.assign(n+1, 0);
        
    }
    void update(int p, int val){
        for(int i=p; i< F.size(); i+= i&(-i)) F[i]+= val;
    }
    int get(int p){
        if(p==0) return 0;
        return F[p]+ get(p-(p&(-p)));
    }
};


int n;
string S;
vector<int> pos[26];
vector<pair<int,int> >P;
int spec = -1;
FenwickTree fen;
long long ret = 0;

bool check(){
    int cnt = 0;
    for(int i=0; i< 26; ++i) cnt+= (int)(pos[i].size()%2);
    return (cnt <= 1);
}

void pairing(){
		
    for(int i=0; i< 26; ++i){
			//	cerr << i << " " << pos[i].size() << "\n";
        int half = (int)(pos[i].size()+1)/2;
        for(int j=0; j< half; ++j){
					int o =(int)pos[i].size()-j-1;
		 			if(o==j) spec = pos[i][j];
        	else P.push_back({pos[i][j], pos[i][o]});
				}
            
    }
		sort(P.begin(), P.end());
		if(spec != -1) for(pair<int, int> v : P){
			ret += (v.second < spec || v.first > spec);
		}
    /*int cur = 1;
    for(int i=0; i< P.size(); ++i){
			id[cur] = P[i].first;
			id[n+1-cur] = P[i].second;
			++cur;
		}*/
}

signed main()
{
		//freopen("input.txt", "r", stdin);
	//	freopen("output1.txt", "w", stdout);
    cin >>  S;
    n = S.length();
    for(int i=0; i< n; ++i){
        pos[S[i]-'a'].push_back(i+1);
    }
    if(!check()){
        cout << -1;
        return 0;
    }

    pairing();
    fen.init(n);
    vector<int> X(n+1, -1);
    for(int i=0; i< P.size(); ++i){
    	X[P[i].first] = fen.get(P[i].first);
    	X[P[i].second] = fen.get(P[i].second);
			ret += 1LL*(X[P[i].first] + X[P[i].second]);
			fen.update(P[i].second, 1);
		}
	//cout << i << " " << X[i] << "\n";
		//cout << ret;
    //according to the first element
    /*fen.init(n);
    for(int i=n; i>= 1; --i){
			ret += 1LL*fen.get(id[i]);
			fen.update(id[i], 1);
		}*/
		cout << ret;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++)
			par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

	int size(int N) {
		set<int> ret;
		for (int i = 0; i < N; i++)
			ret.insert(par[i]);
		return ret.size();
	}
};

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

	int n, m; cin >> n >> m;
	UnionFind tree(n);

	set<int> s;
	REP(i, m) {
		int a, b; cin >> a >> b;
		s.insert(a - 1);
		s.insert(b - 1);
		tree.unite(a - 1, b - 1);
	}

	map<int, int> cnt;
	for (auto x : s) {
		// cout << x << " " << tree.root(x) << '\n';
		cnt[tree.root(x)]++;
	}
	int maxi = 0;
	for (auto x : cnt)
		maxi = max(maxi, x.second);
	if (m == 0) maxi = 1;
	cout << maxi << '\n';
	return 0;
}

Measured memory_bytes: 19556
import sys
from collections import deque


def resolve():
    input = sys.stdin.readline
    N,A,B=map(int,input().rstrip().split())

    if (B-A)%2==0:
        p1=(B-A)//2
        #p2=min(B-1,N-A)
        #print(min(p1,p2))
        print(int(p1))
    else:
        #p1=(min(int(B-1),int(N-A)))
        """
        if B-1>N-A:
            bufA=N-B+1
            bufB=N-A+1
            A=bufA
            B=bufB
        """
#        if B-1<N-A:
        #if (B-(A-1+1)-1)%2==0:
            #ans=int(A+int((B-(A-1+1)-1)/2))
        #ans=int(min(A-1,N-B)+1+(B-A-1)/2)
        ans=min(A-1,N-B)+1+(B-A-1)//2
    
        print(int(ans))

"""
        else:
            if (A-(B-N+1)-1)%2==0:
                ans=int(N-B+1+(N-(A+(N-B+1)))/2)
                ans=min(ans,N-A)
            else:
                ans=N-A
"""

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 2 4"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 2 3"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 51564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,m,L[200001],R[200001];
  cin>>n>>m;
  rep(i,m) cin>>L[i]>>R[i];
  sort(L,L+m);
  sort(R,R+m);
  if(L[m-1]>R[0]) cout<<0;
  else cout<<R[0]-L[m-1]+1;
}

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

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

typedef long long LL;

int main(){
  int n;
  cin >> n;
  int y,m,d;
  int a,x;
  x=(1000-1)*195+(1000-1)/3*5;
  for(int i=0;i<n;i++){
    cin >> y >> m >> d;
    a=(y-1)*195+(y-1)/3*5;
    if(y%3){
      a+=(m-1)*19+((m-1)-(m-1)/2);
    }else{
      a+=(m-1)*20;
    }
    a+=d-1;
    cout << x-a << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

int main(){
    int a, b, c, x, y;
    std::cin >> a >> b >> c >> x >> y;

    int ans1 = a * x + b * y;
    int ans2 = 2 * c * std::min(x, y) + ((y < x) ? a * (x - y) : b * (y - x));
    int ans3 = 2 * c * std::max(x, y);

    std::cout << std::min({ans1, ans2, ans3}) << std::endl;
    
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int n, k;
vector< vs32 > g;
vs64 d;
vector< bool > reached;

void dfs(int u, int p)
{
    if (reached[u]) return;
    reached[u] = true;

    int sub = (p == -1 ? 1 : 2);
    for (auto& v : g[u])
    {
        if (!reached[v]) { d[v] -= sub; ++sub; }
        dfs(v, u);
    }
}

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

    cin >> n >> k;

    g.resize(n);
    int u, v;
    rep (i, n - 1)
    {
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    d.resize(n, k);
    reached.resize(n, false);
    dfs(0, -1);

    s64 ans = 1;
    rep (i, n)
    {
        ans = (ans * d[i]) % MOD;
    }

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



Measured memory_bytes: 9984
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int a,b,c;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  
  p=strtok(str," \n");
  a=atoi(p);
  p=strtok(NULL," \n");
  b=atoi(p);
  p=strtok(NULL," \n");
  c=atoi(p);
  
  if(a-b>=c){
    printf("0\n");
  }else{
    printf("%d\n",c-(a-b));
  }
  
  
  return 0;
}

Measured memory_bytes: 128
# input
N, M = map(int, input().split())
H = list(map(int, input().split()))

cnt = N
road = {}
for i, h in zip(range(1, N + 1, 1), H):
    road[i] = {
        "high": h,
        "good": True
    }

for i in range(M):
    Ai, Bi = map(int, input().split())

    if road[Ai]["good"] is True and road[Ai]["high"] <= road[Bi]["high"]:
        road[Ai]["good"] = False
        cnt -= 1

    if road[Bi]["good"] is True and road[Bi]["high"] <= road[Ai]["high"]:
        road[Bi]["good"] = False
        cnt -= 1

print(cnt)

Measured memory_bytes: 46084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, val;
set< int > s;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> val;
		s.insert( val );		
	}
	cout << ( s.size() == n ? "YES" : "NO" ) << "\n";
	return 0;
}

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

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

    int n ;

    cin >> n ;
    int x=n%10 ;

    if(x==2 || x==4 || x==5 || x==7 || x==9)
        cout << "hon" ;
    if(x==0 || x==1 || x==6 || x==8)
        cout << "pon" ;
    if(x==3)
        cout << "bon" ;


    return 0 ;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

bool ok(int x, const vi &v){
	for(int i : v) if(x % i == 0) return 0;
	return 1;
}
int ind[101];
int n, a[100];
ll rec(int c, vi &v){
	if(c > n) return 0;
	if(!ok(c, v)) return rec(c + 1, v);
	
	if(!ind[c]){
		ll res = rec(c + 1, v) + a[c - 1];
		v.pb(c);
		res = max(res, rec(c + 1, v));
		v.pop_back();
		return res;
	}
	if(ind[c] != c) return rec(c + 1, v);
	ll mx = -1e18;
	vi mul;
	for(int i = c; i <= n; i += c) if(ok(i, v)) mul.pb(i);
	rep(i, 1 << mul.size()){
		vi u, d;
		ll sum = 0;
		bool skip = 0;
		
		rep(j, mul.size()) if(i & 1 << j) u.pb(mul[j]); else d.pb(mul[j]);
		rep(j, u.size()) rep(k, d.size()) if(u[j] % d[k] == 0) { skip = 1; break; }
		if(skip) continue;
		for(int j : u) sum += a[j - 1];
		mx = max(mx, sum);
	}
	return mx + rec(c + 1, v);
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	for(int i = 2; i <= 100; i++) if(!ind[i]){
		int mn = inf;
		for(int j = i + 1; j <= 100; j++) if(j % i){
			int lcm = i * j / __gcd(i, j);
			if(lcm <= 100) mn = min(mn, j);
		}
		if(mn == inf) for(int j = i; j <= 100; j += i) ind[j] = i;
	}
	
	//rep(i, 100) dbg(i, ind[i]);
	
	vi v;
	cout << max(0ll, rec(2, v) + a[0]) << endl;
	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    candidate = [i for i in range(-100, 200)]

    ans = list()

    for c in candidate:
        if c not in p:
            diff = abs(c - x)

            ans.append((diff, c))

    print(sorted(ans)[0][1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;

int main(){
  string s;
  string s_r1,s_r2,s_c1,s_c2;
  cin >> s;
  int n = (s.size()-1) /2;
  int next = ((s.size()+3)/2-1);
  s_c1 = s.substr(0,n);
  s_c2 = s.substr(next,s.size());
  s_r1 = s.substr(0,n);
  s_r2 = s.substr(next,s.size());
  string s_r = s;
  reverse(s_r.begin(),s_r.end());
  reverse(s_r1.begin(),s_r1.end());
  reverse(s_r2.begin(),s_r2.end());
  bool ans = true; 
  for(int i=0;i<n;i++){

    if(s_c1[i] != s_r1[i]) ans = false;
    if(s_c2[i] != s_r2[i]) ans = false;
  }
  if(s != s_r) ans = false;
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
    
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 10;
int n;
char tab[nax];
vector<string> results;

void generuj(int pos, int moz) {
	if (pos == n) {
		string res;
		rep(i,0,n) {
			res += (tab[i] + 'a');
		}
		results.pb(res);
		return ;
	}
	rep(i, 0, moz + 2) {
		tab[pos] = i;
		generuj(pos + 1, max(i, moz));
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	generuj(0, -1);
	for (auto res : results) {
		cout << res << '\n';
	}
}

Measured memory_bytes: 9716
#include <iostream>
#include "bits/stdc++.h"
#define ll long long int 
using namespace std;
ll dfs(ll pos,ll n, bool flag,string s,ll count,vector<vector<vector<ll>>>& dp,ll k){
        if(pos >= n) return(count == k);
        if( count > k) return 0;
        if(dp[pos][count][flag] != -1) return dp[pos][count][flag];
        ll limit=9;
        if(flag ) limit = s[pos]-'0';
        ll res=0;
        for(ll i=0;i<=limit;i++){
            if(!flag || i < limit){
                if(i != 0) res+=dfs(pos+1,n,0,s,count+1,dp,k);
                else res+=dfs(pos+1,n,0,s,count,dp,k);
            }
            else{
               if(i != 0) res+=dfs(pos+1,n,1,s,count+1,dp,k);
                else res+=dfs(pos+1,n,1,s,count,dp,k);
            }
        }
        return dp[pos][count][flag]=res;
    }
int main()
{
        ll n,k;
        string s;
        cin>>s>>k;
        vector<vector<vector<ll>>> dp(s.size(),vector<vector<ll>>(162,vector<ll>(2,-1)));
        cout<<dfs(0,s.size(),1,s,0,dp,k)<<endl;
    return 0;
}

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

using namespace std;

int main() {
	string s;
	cin>>s;
	int h=1;
	if(s[0]!='A') h=0;
	if(s[1]=='C' or s[s.size()-1]=='C') h=0;
	int c=0;
	for(int i=2; i<=s.size()-2; i++){
	    if(s[i]=='C') c++;
	    if(c>1){h=0;break;}
	}
	if(c<1) h=0;
	for(int i=1; i<s.size(); i++){
	    if(s[i]!='C' and (s[i]<'a' or s[i]>'z')){h=0; break;} 
	}
	if(h) cout<<"AC";
	else cout<<"WA";
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""参考文献
http://ja.wikipedia.org/wiki/クラスカル法
"""
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

while True:
    num_node = int(stdin.readline())
    if not num_node:
        break

    S = []
    for _ in range(int(stdin.readline())):
        S.append([int(s) for s in stdin.readline().split(',')])
    S.sort(key=lambda (n1, n2, d): d, reverse=True)

    forest = {frozenset([i]) for i in range(num_node)}
    spanning = []
    while S:
        node1, node2, distance = S.pop()
        a, b = None, None
        for tree in forest:
            if node1 in tree:
                a = tree
            if node2 in tree:
                b = tree
            if a and b:
                break
        if a != b:
            forest.add(a | b)
            forest.remove(a)
            forest.remove(b)
            spanning.append(distance)
    print(sum((distance // 100) - 1 for distance in spanning))

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

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

    int N; cin >> N;
    int ans = 0, maxH = 0;
    for (int i = 0; i < N; i++) {
        int H; cin >> H;
        if (H >= maxH) {
            maxH = H;
            ans++;
        }
    }
    cout << ans << "\n";
}

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

void nnode(vector<vector<int> > &node,vector<int> &c,vector<int> &value, int pos){
  value[pos]=c[c.size()-1];
  c.pop_back();
  int i;
  for(i=0;i<node[pos].size();i++){
    if(value[node[pos][i]]==0){
      nnode(node,c,value,node[pos][i]);
    }
  }
}
int main(){
  int a,b,n,i,m;
  cin>>n;
  vector<vector<int> > node(n);
  vector<int> value(n);

  for(i=0;i<n;i++) value[i]=0;
  for(i=0;i<n-1;i++){
    cin>>a>>b;
    a--;
    b--;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  vector<int> c(n);
  for(i=0;i<n;i++){
    cin>>c[i];
    m+=c[i];
  }
  sort(c.begin(),c.end());
  m-=c[c.size()-1];
  
  nnode(node,c,value,0);

  cout<<m<<endl<<value[0];
  for(i=0;i<n-1;i++) cout<<" "<<value[i+1];
  cout<<endl;

  return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		System.out.println(new PrimeIterator(100003).bitset.nextSetBit(s.nextInt()));
	}
}

class PrimeIterator implements Iterable<Integer>,PrimitiveIterator.OfInt{
	BitSet		bitset;
	private int	currentvalue,limit;

	public PrimeIterator(int limit){
		currentvalue=0;
		bitset=new BitSet(limit+1);
		this.limit=limit;
		construct();
	}
	/** Atkin's sieve */
	private final void construct(){
		int sqLim=(int)Math.sqrt(limit+0.5);
		{
			int n;
			for(int z=1;z<=5;z+=4){
				for(int y=z;y<=sqLim;y+=6){
					int ysq=y*y;
					for(int x=1;x<=sqLim&&(n=4*x*x+ysq)<=limit;++x)
						bitset.flip(n);
					for(int x=y+1;x<=sqLim&&(n=3*x*x-ysq)<=limit;x+=2)
						bitset.flip(n);
				}
			}
			for(int z=2;z<=4;z+=2){
				for(int y=z;y<=sqLim;y+=6){
					int ysq=y*y;
					for(int x=1;x<=sqLim&&(n=3*x*x+ysq)<=limit;x+=2)
						bitset.flip(n);
					for(int x=y+1;x<=sqLim&&(n=3*x*x-ysq)<=limit;x+=2)
						bitset.flip(n);
				}
			}
			for(int y=3;y<=sqLim;y+=6){
				int ysq=y*y;
				for(int z=1;z<=2;++z)
					for(int x=z;x<=sqLim&&(n=4*x*x+ysq)<=limit;x+=3)
						bitset.flip(n);
			}
		}
		{
			//remove square
			for(int n=5;n<=sqLim&&n!=-1;n=bitset.nextSetBit(n+1)){
				int nsq=n*n;
				for(int k=nsq;k<=limit;k+=nsq)
					bitset.clear(k);
			}
		}
		bitset.set(2);
		bitset.set(3);
	}

	@Override
	public boolean hasNext(){
		int r=getNextValue();
		return 0<=r&&r<=limit;
	}
	private int getNextValue(){
		return bitset.nextSetBit(currentvalue+1);
	}
	@Override
	public int nextInt(){
		int r=getNextValue();
		if(r<0||limit<r) throw new NoSuchElementException();
		return currentvalue=r;
	}
	@Override
	public OfInt iterator(){
		return this;
	}
	public BitSet getClonedBitSet(){
		return (BitSet)bitset.clone();
	}
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n; cin >> n;
    ll fib[n+1];
    fib[0] = 1; fib[1] = 1;
    for(int i = 2; i <= n; i++) fib[i] = fib[i-1] + fib[i-2];
    cout << fib[n] << endl;
}



Measured memory_bytes: 3116
inp = [x for x in input()]
cnt = len(inp)-1
sum_ = []

for c in range(2**cnt):
  inp_ = inp.copy()
  for j in range(cnt):
    if ((c >> j)&1):
      inp_[cnt-j-1]+='+'
      
  a = eval(''.join(inp_))
  sum_.append(a)
print(sum(sum_))

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


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

    int ans = 0;
    for (int i = 1; i < n; i++) {
        int x = n / i;
        if (n % i == 0) x--;
        ans += x;
    }
    cout<<ans<<endl;

  


    return 0; 
}

Measured memory_bytes: 3644
#include <stdio.h>

int main()
{
    int n,l,max,sum;

    scanf("%d %d",&n,&l);
    max = l + n - 1;
    sum = (max + l) * n / 2;

    if (max < 0)
    {
        printf("%d",sum - max);
    }
    else if ((l <= 0) && (0 <= max))
    {
        printf("%d",sum);
    }
    else
    {
        printf("%d",sum - l);
    }
}


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

int main(){
	/*input*/
	int a, b, c, k;	cin >> a >> b >> c >> k;
	/*calculation*/
	int ans = 0;
	int Max = max({a, b, c});
	ans += a + b + c - Max;
	for(int i = 0; i < k; i++){
		Max *= 2;
	}
	ans += Max;
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))

int main(){
    ll N,K;
    cin>>N>>K;
    double a,cnt=1,sum=0;
    for(int i=1;i<=N;i++){
        a=i;
        while(a<=K-1){
            cnt/=2;
            a*=2;
        }
        sum+=cnt/N;
        cnt=1;

    }
    cout << std::fixed << std::setprecision(15) << sum<< endl;
}

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


Measured memory_bytes: 5188
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

bool Compare(int a, int b)
{
   return a < b;
}
std::priority_queue<int, std::vector<int>, std::function<bool(int, int)>> pq(Compare);

vi pr;
void seive(){
	int p[100005]={0};
	f(i,2,100005){
		if(p[i]==0){
			pr.pb(i);
			for(int j=i*2;j<100005;j+=i) p[i]=1;
		}
	}
}


void solve(){
	int a,b; cin>>a>>b;
	if(a<=8 && b<=8) cout<<"Yay!\n";
	else cout<<":(\n";
}


int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!

Measured memory_bytes: 3580
n1 = int(input())
n2 = [int(i) for i in input().split()]
n3 = [int(j) for j in input().split()]

c1 = 0
s1 = 0
for i1 in range(n1 + 1):
    if i1 == n1:
        if c1 >= n2[i1]:
            s1 += n2[i1]
        else:
            s1 += c1
    elif c1 >= n2[i1]:
        s1 += n2[i1]
        c1 = n3[i1]
    else:
        if (c1 + n3[i1]) >= n2[i1]:
            s1 += n2[i1]
            c1 = (c1 + n3[i1]) - n2[i1]
        else:
            s1 += (c1 + n3[i1])
            c1 = 0

print(s1)

Measured memory_bytes: 19156
#include <stdio.h>

#define N 100000
#define Q 1000

void enq1(int);
int deq1(void);
void enq2(int);
int deq2(void);

int head=0,tail=0,p;
int S1[N],S2[N];

int main(){

  int n,q,i,T=0,a,b,c=0;
  char name[N][10];
  int time[N];

  scanf("%d %d",&n,&q);

  for(i=0 ; i<n ; i++){
    scanf("%s %d",name[i],&time[i]);
    enq1(time[i]);
    enq2(i);
  }


  while(1){
    a=deq1();
    b=deq2();

    if(head==N) head=0;
    if(tail==N) tail=0;

    if(a-q<=0){
      T+=a;
      printf("%s %d\n",name[b],T);
      c++;
      if(c==n) break;
    }
    else{
      T+=q;
      a-=q;
      enq1(a);
      enq2(b);
    }
  }

  return 0;
}

void enq1(int n){
  S1[tail]=n;
  tail++;
}

int deq1(){
  head++;
  return S1[head-1];
}

void enq2(int n){
  S2[tail]=n;
  tail++;
}

int deq2(){
  head++;
  return S2[head-1];
}

Measured memory_bytes: 2076
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;


int main(){

	int N,M;
	cin>>N>>M;
	int c[22]={};
	for(int i=0;i<M;i++)
		cin>>c[i];
	int n[50002]={};
	//for(int i=0;i<=N;i++)
		//cout<<n[i]<<" "<<i<<endl;
	for(int i=0;i<M;i++){//cout<<endl;
		for(int j=0;j<=N;j++)
		{
			if(n[j]==0&&j%c[i]==0)n[j]=j/c[i];
			else if(n[j]==0&&n[j-c[i]]>=0&&j-c[i]>0)n[j]=n[j-c[i]]+1;
			 if(n[j]>n[j-c[i]]+1&&j-c[i]>=0)n[j]=n[j-c[i]]+1;
			//cout<<n[j];
		}}
	/*
		for(int i=0;i<=N;i++)
		cout<<n[i]<<" "<<i<<endl;
		*/
	cout<<n[N]<<endl;
	
	return 0;
}

Measured memory_bytes: 1364
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}

	mon := 0
	amari := 0
	for i := 0; i < n+1; i++ {
		ableToKill := amari
		if i < n {
			ableToKill += b[i]
		}

		if a[i] >= ableToKill {
			mon += ableToKill
			amari = 0
		} else {
			if amari >= a[i] {
				if i < n {
					amari = b[i]
				}
			} else {
				amari = ableToKill - a[i]
			}
			mon += a[i]
		}
	}

	fmt.Println(mon)
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"No"<<endl;return 0;}
//template
//main
signed main(){
  int N;cin>>N;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(i>=1e4&&i<1e5)ans++;
    else if(i>=1e2&&i<1e3)ans++;
    else if(i<10)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define N 200010
int main() {
	int n,ch=1,start,end,a[N],b[N]={0},c[N];long long k;scanf("%d %lld",&n,&k);
	Rep(i,1,n+1)scanf("%d",&a[i]);
	Rep(i,1,N+10){
		if(b[ch]!=0){start=b[ch];end=i;break;}
		b[ch]+=i;
		ch=a[ch];
    }
	c[0]=ch;
	Rep(i,1,end-start+1) {
		c[i]=a[ch];
		ch=a[ch];
	}
	if (k<=start) {
		ch=1;
		rep(i,k)ch = a[ch];
		printf("%d",ch);
	}
	else if(end-start==1)printf("%d", ch);
	else{
		k-=start-1;
		k%=(end-start);
		printf("%d",c[k]);
	}
}

Measured memory_bytes: 3920
import math

N = int(input())
X = list(map(int, input().split()))

#  O(100N)とかになりそうだし全探索で良さげ

xmin = 10 ** 7

for i in range(1, 101):
    xsum = 0
    for j in range(N):
        xsum += (X[j] - i) ** 2
    xmin = min(xmin, xsum)

print(xmin)

Measured memory_bytes: 9144
#include<stdio.h>

int bubbleSort(int n, int *a)
{
	int count = 0;
	int flag = 1;
	int i, temp;
	while(flag) {
		flag = 0;
		for(i=n-1;i>0;i--) {
			if(a[i] < a[i-1]) {
				temp = a[i];
				a[i] = a[i-1];
				a[i-1] = temp;
				flag = 1;
				count++;
			}
		}
	}
	return count;
}

void print_array(int n, int *a)
{
	int i;
	for(i=0;i<n;i++) {
		if(i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

int main(void)
{
	int n, a[100], i, count;
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
    count = bubbleSort(n, a);
    print_array(n, a);
    printf("%d\n", count);
    return 0;
}
	


Measured memory_bytes: 2104
#include <cmath>
#include <cstdlib>
#include <cstdio>

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>



int main() {

  bool isPrime[1000000];
  int  num[1000000];
  int  temp;
  int  n;

  for(int i = 0; i < 1000000; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < 1000; ++i) {
    if( isPrime[i] ) {
      for(int j = i+i; j < 1000000; j += i) {
	isPrime[j] = false;
      }
    }
  }

  num[0] = num[1] = 0;
  temp = 0;
  for(int i = 2; i < 1000000; ++i) {
    if( isPrime[i] ) ++temp;
    num[i] = temp;
  }

  while( std::cin >> n ) {
    std::cout << num[n] << std::endl;
  }
  
  return 0;
}

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

string S;

int main() {
    cin >> S;

    string ans = "AC";

    // p1
    if (S[0] != 'A') {
        ans = "WA";
    }

    // p2, p3
    int c_count = 0;
    int upper_count = 0;
    for (int i = 1; i < S.size(); i++) {
        if (S[i] == 'C' && i >= 2 && i <= S.size() - 2) c_count++;

        if (!islower(S[i])) upper_count++;
    }

    if (c_count != 1 || upper_count != 1) ans = "WA";

    cout << ans << endl; 
}

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

using namespace std;

struct BIT {
  vector<int> bit;

  BIT() : bit(202020) {}

  void add(int k, int v) {
    k += 101010;
    while (k < 202020) {
      bit[k] += v;
      k += k & -k;
    }
  }

  int query(int k) {
    k += 101010;
    int res = 0;
    while (k > 0) {
      res += bit[k];
      k -= k & -k;
    }
    return res;
  }
};

int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(a);
  sort(b.begin(), b.end());
  int l = 0;
  int r = n;
  while (r - l > 1) {
    BIT bit;
    int x = (l + r) / 2;
    int z = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < b[x]) {
        z--;
      } else {
        z++;
      }
      bit.add(z, 1);
    }
    z = 0;
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += bit.query(-1 + z);
      if (a[i] < b[x]) {
        z--;
      } else {
        z++;
      }
      bit.add(z, -1);
    }
    if (cnt > n * (n + 1) / 4) {
      r = x;
    } else {
      l = x;
    }
  }
  cout << b[l] << endl;
}

Measured memory_bytes: 1792
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))
n = int(input())
A = [int(input()) for _ in range(n)]
l4 = []
l5 = []
l6 = []
l7 = []
l8 = []
l4 += [l1[0],l2[0],l3[0]]
l5 += [l1[1],l2[1],l3[1]]
l6 += [l1[2],l2[2],l3[2]]
l7 += [l1[0],l2[1],l3[2]]
l8 += [l1[2],l2[1],l3[0]]
l = []
l += [l1,l2,l3,l4,l5,l6,l7,l8]
for i in A:
    for k in l:
        if i in k:
            k.remove(i)

count=0
for j in l:
    if len(j)==0:
        count += 1
if count == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int q,p,d;
	q='?';
	p='P';
	d='D';

	int c;
	c=getchar();
	while(c!=EOF){
		if(c==q){
			c=d;
		}
		putchar(c);
		c=getchar();
	}
	return 0;
}

Measured memory_bytes: 1492
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}

int main(void){
    int n;
    long long ans=1;
    scanf("%d",&n);
    int a[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    qsort (a,n,sizeof(int),sort);

    if (n%2==0){
        for (int i=0; i<n; i++){
            if (i%2==0 && a[i]==i+1){
            } else if (i%2==1 && a[i]==i){
                ans=(ans*2)%1000000007;
            } else {
                printf("0\n");
                exit(0);
            }
        }
    } else {
        for (int i=0; i<n; i++){
            if (i==0 && a[i]==0){
            } else if (i==0 && a[i]!=0){
                printf("0\n");
                exit(0);
            } else if (i%2==1 && a[i]==i+1){
            } else if (i%2==0 && a[i]==i && i!=0){
                ans=(ans*2)%1000000007;
            } else {
                printf("0\n");
                exit(0);
            }
        }
    }
    printf ("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 892