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

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

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}


int main() {
  string(st);
  set<char> a;

  REP(i,st.size()){
    auto r = a.insert(st[i]);
    if(r.second == false){
      cout << "no" << endl;
      return 0;
    }
  }
  
  cout << "yes" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    List<int>[] es;
    int[] cnt;
    int[] depth;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = new int[N];
        A[0] = -1;
        for (int i = 1; i < N; i++)
        {
            A[i] = cin.nextInt() - 1;
        }
        
        es = new List<int>[N];
        depth = new int[N];
        cnt = new int[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }
        for (int i = 1; i < N; i++)
        {
            es[A[i]].Add(i);
            cnt[A[i]]++;
        }

        Queue<int> q = new Queue<int>();
        for (int i = 0; i < N; i++)
        {
            if (cnt[i] == 0) q.Enqueue(i);
        }

        while (q.Count >= 1)
        {
            int now = q.Dequeue();

            List<int> l = new List<int>();
            foreach (var p in es[now])
            {
                l.Add(depth[p]);
            }
            l.Sort(); l.Reverse();
            int ans = 0;
            for (int i = 0; i < l.Count; i++)
            {
                ans = Math.Max(l[i] + i + 1, ans);
            }
            depth[now] = ans;

            if (now != 0)
            {
                cnt[A[now]]--;
                if(cnt[A[now]] == 0)
                {
                    q.Enqueue(A[now]);
                }
            }
        }
        Console.WriteLine(depth[0]);
    }

}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 29464
#include<cstdio>
#include<cstdlib>

int n,deta[30],kon,pon;
int sa = 1000000;
int max;
void flat(int joutai,int kon,int pon);

using namespace std;
int main(void)
{
	while(scanf("%d",&n))
	{
		max = 0;
		sa = 1000000;
		if(n == 0) break;
		for(int i = 1;i<=n;i++)
		{
			scanf("%d",&deta[i]);
			max += deta[i];
		}
			flat(0,0,0);
			printf("%d\n",sa);
	}
	return 0;
}

void flat(int joutai,int pon,int kon)
{
	if(pon + kon == max)
	{
		if(sa > abs(pon-kon)) sa = abs(pon - kon);
		return;
	}
		int kari = joutai;
		flat(joutai+1,kon+deta[kari],pon);
		flat(joutai+1,kon,pon+deta[kari]);
}

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

int main(){
    int N; cin >> N;
    int check = 1;
    bool jud = false;
    int sum = 0;

    rep(i,5){
        check *= 10;
        if(check == N){
            jud = true;
        }
    }

    if(jud){
        cout << 10 << endl;
    }

    else{
        while(N!=0){
            sum += N%10;
            N /= 10;
        }

        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int color[3][30] = {0};
	int D[30][30];
	int N, C;

	cin >> N >> C;
	for(int i = 0; i < C; i++) {
		for(int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			int c;
			cin >> c;
			color[(i+j)%3][c-1]++;
		}
	}

	long long summin = 1100000000000000LL;
	for(int a = 0; a < C; a++) {
		for(int b = 0; b < C; b++) {
			if(b != a) {
				for(int c = 0; c < C; c++) {
					if(c != b && c != a) {
						long long sum = 0;
						for(int i = 0; i < C; i++) sum += color[0][i]*D[i][a];
						for(int i = 0; i < C; i++) sum += color[1][i]*D[i][b];
						for(int i = 0; i < C; i++) sum += color[2][i]*D[i][c];
						summin = min(sum, summin);
					}
				}
			}
		}
	}
	cout << summin << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX_INT 10e9
int main()
{
  	ll i,j,k,n;
  cin>>n;
  if(n<=9){
      cout<<n<<endl;
    return 0;
}
  ll sum=0;
  ll ans=10;
  while(ans<=n){
   	sum+=ans -(ans/10);
      ans=(ans*100);
  }
  //cout<<ans<<" "<<sum<<endl;
  int dig=0,m;
  m=n;
  while(m>0){
    dig++;
    m/=10;
  }
  if(dig%2==0)
  cout<<sum<<endl;
  else{
    dig--;
  	sum+=n-pow(10,dig)+1;
    cout<<sum<<endl;
  }
    return 0;
    
}


Measured memory_bytes: 384
// C - Forbidden List
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int x, n; cin>>x>>n;
	vi C(101+1, 0); // candidate:[0,101]
	rep(i, n){
		int p; cin>>p;
		C[p] = 1;
	}
	int ans = x, d = 1e9;
	rep(c, 101+1){
		if(!C[c] && d > abs(x-c)){
			d = abs(x-c);
			ans = c;
		}
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 998244353
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#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 << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll maxn=600001;
ll seg[4*maxn];
void build(ll v,ll l,ll r)
{
    if(l==r)
    {
        seg[v]=0;
        return;
    }
    ll mid=(l+r)/2;
    build(2*v,l,mid);
    build(2*v+1,mid+1,r);
    seg[v]=max(seg[2*v],seg[2*v+1]);
}
void update(ll v,ll l,ll r,ll pos,ll val)
{
    if(l==r)
    {
        seg[v]=val;
        return;
    }
    ll mid=(l+r)/2;
    if(pos<=mid)
    {
        update(2*v,l,mid,pos,val);
    }
    else
    {
        update(2*v+1,mid+1,r,pos,val);
    }
    seg[v]=max(seg[2*v],seg[2*v+1]);
}
ll query(ll v,ll l,ll r,ll x,ll y)
{
    if(y<x)
    {
        return 0;
    }
    if(x<=l && r<=y)
    {
        return seg[v];
    }
    ll mid=(l+r)/2;
    ll val,val1;
    val=query(2*v,l,mid,x,min(mid,y));
    val1=query(2*v+1,mid+1,r,max(mid+1,x),y);
    return max(val,val1);
}
int main()
{
    fastIO;
    ll n,k;
    cin>>n>>k; 
    vector<ll>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    build(1,0,n-1);
    ll x,y,val,val1;
    for(int i=0;i<n;i++)
    {
        x=max((ll)0,a[i]-k);
        y=a[i]+k;
        val=query(1,0,maxn,x,y);
        update(1,0,maxn,a[i],val+1);
    }
    cout<<seg[1]<<endl;
}

Measured memory_bytes: 17992
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

void print_seq(int n, int ds[]) {
  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", ds[i]);
  }
  putchar('\n');
}

/* main */

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

  for (int i = 0; i < n; i++) cin >> as[i];
  print_seq(n, as);
  
  for (int i = 1; i < n; i++) {
    int key = as[i];
    int j = i - 1;
    while (j >= 0 and as[j] > key) {
      as[j + 1] = as[j];
      j--;
    }
    as[j + 1] = key;

    print_seq(n, as);
  }

  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl __int128
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

ll n, an;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void gcd(ll a, ll b, ll &c, ll &d, ll &e) {
	if (b) {
		gcd(b, a%b, d, c, e);
		d -= a / b*c;
	}
	else c = 1, d = 0, e = a;
}

ll pw(ll x, ll p, ll md){
	ll an = 1;
	while(p){
		if (p & 1)an = (vl)an * x % md;
		x = (vl)x * x % md;
		p >>= 1;
	}
	return an;
}

bool ok(ll x) { return x && !((vl)x * (x + 1) / 2 % n); }

void go(ll x){
	ll y = n / gcd(x, n);
	ll z, t, g;
	gcd(y, x, z, t, g);
	if (g > 1)return;
	if (z < 0)z += x;
	if (ok(y * z - 1))an = min(an, y * z - 1);
	else if (y * z > 1)go(x * 2);
}

int main(){
	scanf("%lld", &n);
	if (n == 1){
		printf("1\n");
		return 0;
	}
	if (n & 1)an = n - 1;
	else an = 2 * n - 1;
	for (int i = 2; (ll)i * i <= n; ++i)if (n % i == 0){
		go(i);
		if ((ll)i * i != n)go(n / i);
	}
	printf("%lld\n", an);
}

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

using namespace std;

#define int long long

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

const int inf = 3e18;

int dp[2010][2010];

int N, A[2010];

int rec(int l, int r, int k=0)
{
	if (k == N) return 0;
	
	int &res = dp[l][r];
	
	if (res != -1) return res;
	
	int nl = (l - 1 < 0 ? N - 1 : l - 1);
	int nr = (r + 1 >= N ? 0 : r + 1);
	
	if (k % 2 == 0) {
		res = max(rec(nl, r, k + 1) + A[l], rec(l, nr, k + 1) + A[r]);
	} else {
		if (A[l] < A[r]) res = rec(l, nr, k + 1);
		else res = rec(nl, r, k + 1);
	}
	
	return res;
}

signed main()
{
	cin >> N;
	
	rep(i, N) cin >> A[i];
	
	int ma = 0;
	
	memset(dp, -1, sizeof(dp));
	
	rep(i, N) {
		ma = max(ma, rec((i-1<0?N-1:i-1), (i+1==N?0:i+1),1) + A[i]);
	}
	
	cout << ma << endl;
}

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

int main(){
  
  int N,M;
  
  cin>>N>>M;
  
  int ALL = 0;
  
  for(int i = 0;i < M;i++){
    int a;
   cin>>a;
    ALL += a;
  }
  
  int res;
  
  if(ALL > N){
    cout<<-1;
  }else{
    res = N - ALL;
    cout<<res;
    }
 
  
  
  
 return 0; 
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
struct BinaryIndexedTree{
    vector<int> bit;
    BinaryIndexedTree(int siz){
        bit.assign(++siz,0);
    }
    void add(int k,int x){
        for(++k;k<bit.size();k+=k&-k){
            bit[k]+=x;
        }
    }
    int sum(int k){
        int res=0;
        for(++k;k>0;k-=k&-k){
            res+=bit[k];
        }
        return res;
    }
};
vector<tuple<int,int,int>> v;
int main(){
    int n,m;cin>>n>>m;
    for(int i=0;i<n;i++){
        int l,r;cin>>l>>r;
        v.push_back(make_tuple(r-l+1,l,r));
    }
    sort(all(v));
    BinaryIndexedTree bit(2*m);
    int id=0;
    for(int i=1;i<=m;i++){
        while(get<0>(v[id])<i&&id<n){
            bit.add(get<1>(v[id]),1);
            bit.add(get<2>(v[id])+1,-1);
            id++;
        }
        int res=n-id;
        for(int j=i;j<=m;j+=i){
            res+=bit.sum(j);
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int a, b,c, d;
		cin >> a >> b >> c >> d;
        int i=0;
        while(a>0 && c>0){
            if(i%2==0){
                c = c-b;
            }
            else{
                a = a-d;
            }
            i++;
        }

        if(a<=0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }

		
		return 0;
	}


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

using namespace std;

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

int main()
{
  ll n,k;
  cin >> n >> k;
  ll ar[n];
  ld maxavg = 0;
  ld tmp = 0;
    rep(i,n){
    cin >> ar[i];
  }
  
  ll maxn = 1000 + 10;
  ld avg[maxn];
  ld sum = 0;
  repl(x, maxn)
  {
    avg[x] = (ld)(((ld)x + 1.0) / 2.0);
  }
  
  repl(x, k){
    tmp += avg[ar[x]];
  }
  maxavg = tmp;
  
  for(ll x=k; x < n; x++)
  {
    tmp = tmp + avg[ar[x]] - avg[ar[x-k]];
    if(tmp > maxavg)
    {
      maxavg = tmp;
    }
  }

  cout.setf(ios::dec, ios::basefield);
  cout << fixed << maxavg << endl;
  
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    long long a,b;
    cin>>a>>b;
    long long sum = a+b;
    if(a%3==0) cout<<"Possible"<<endl;
    else if (b%3==0) cout<<"Possible"<<endl;
    else if(sum%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}


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



#define int long long
struct NODE{
	vector<pair<int,int>> seg;
	vector<int> special;
	bool sorted;
	NODE *l,*r;
	NODE(){
		l = r = NULL;
		sorted = false;
	}
};

#define N_MAX (1073741824ll)
NODE* add(int l,int r,int v,NODE *root,int a=1,int b=N_MAX){
	if( r < a || b < l ) return root;
	if( root == NULL ) root = new NODE();
	if( l <= a && b <= r ){
		root->special.push_back(v);
		return root;
	}else{
		root->seg.push_back({v,min(r,b)-max(l,a)+1});
		int m = (a+b)/2;
		
		root->l = add(l,r,v,root->l,a,m);
		root->r = add(l,r,v,root->r,m+1,b);
	}
	return root;
}
void init(NODE *root){
	if( root == NULL ) return;
	sort(root->seg.begin(),root->seg.end());
	sort(root->special.begin(),root->special.end());
	for(int i = 1 ; i < root->seg.size() ; i++){
		root->seg[i].second += root->seg[i-1].second;
	}
	init(root->l);
	init(root->r);
	return;
}

int get(int l,int r,int v,NODE *root,int a=1,int b=N_MAX){
	if( r < a || b < l ) return 0;
	if( root == NULL ) return 0;
	int ans = 0;
	ans += (min(r,b)-max(l,a)+1) * (upper_bound(root->special.begin(),root->special.end(),v)-root->special.begin());
	if( l <= a && b <= r ){
		int idx = upper_bound(root->seg.begin(),root->seg.end(),make_pair(v+1,-1ll)) - root->seg.begin() - 1;
		if( idx >= 0 ){
			ans += root->seg[idx].second;
		}
	}else{
		int m = (a+b)/2;
		ans += get(l,r,v,root->l,a,m);
		ans += get(l,r,v,root->r,m+1,b);
	}
	return ans;
}


signed main(){
	NODE *root = new NODE();
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<int> val;
	while(M--){
		int a,b,v;
		scanf("%lld%lld%lld",&a,&b,&v);
		add(a,b,v,root);
		val.push_back(v);
	}
	init(root);
	// for( auto &it : seg ){
		// sort(it.second.begin(),it.second.end());
		// for(int i = 1 ; i < it.second.size() ; i++){
			// it.second[i].second += it.second[i-1].second;
		// }
	// }
	// for( auto &it : special ){
		// sort(it.second.begin(),it.second.end());
	// }
	//cout << get(1,1000,1,root) << endl;
	sort(val.begin(),val.end());
	val.erase(unique(val.begin(),val.end()),val.end());
	while(Q--){
		int a,b,j;
		scanf("%lld%lld%lld",&a,&b,&j);
		int l = 0 , r = val.size()-1;
		while( l != r ){
			int m = (l+r)/2;
			if( get(a,b,val[m],root) < j ){
				l = m+1;
			}else{
				r = m;
			}
		}
		printf("%lld\n",val[l]);
	}
}

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

int main(){
    //入力
    int N,M;
    cin >> N >> M;
    vector<int> k(M);
    vector<int> p(M);
    vector<vector<int>> s(M,vector<int>(N));
    for(int i=0;i<M;i++){
        cin >> k.at(i);
        for(int j=0;j<k.at(i);j++){
            cin >> s.at(i).at(j);
            s.at(i).at(j)--;//0-indexed
        }
    }

    for(int i=0;i<M;i++){
        cin >> p.at(i);
    }

    //ビット全探索
    int ans=0;
    for(int bit=0;bit<(1<<N);bit++){
        //電球1からMまで確認
        bool flag=true;
        for(int i=0;i<M;i++){
            int count=0;
            for(int j=0;j<k.at(i);j++){
                if(bit&(1<<s.at(i).at(j))) count++;
            }

            if(count%2!=p.at(i)){
                flag=false;
                break;
            }
        }
        if(flag==true) ans++;
    }

    cout << ans <<endl;

}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int N = sc.nextInt();
      	int res = 0;

       if(N == 0){
         System.out.println(x); 
         return;
       }
      
      	//set
        Set<Integer> s = new HashSet<Integer>();     
        for (int i=0; i<N; i++) {
            int p = sc.nextInt();
          s.add(p);
        }        
      	//while x 0
      	int t = x;
      	int resA = 0;
      	while(t > 0){
          if(!s.contains(t)){
            resA = t;
            break;
          }
          t--;
        }
      
      	//while x 100
        int k = x;
        int resB = 101;
      	while(k <= 100){
          if(!s.contains(k)){
            resB = k;
            break;
          }
          k++;
        }

      	if(Math.abs(resA) == Math.abs(resB)){
		  if(resA > resB){
            res = resB;
          }else { res = resA;}
        }
      	else if(Math.abs(x - resA) > Math.abs(x - resB)){
          res = resB;
        }else{
          res = resA;
        }
        //System.out.println(resA+" "+resB);

        System.out.println(res);
    }
}

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

using namespace std;

typedef long long ll;

const int mod = 998244353;

int add(int a, int b) {
  a += b;
  if (a >= mod) {
    return a - mod;
  }
  if (a < 0) {
    return a + mod;
  }
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % mod;
}

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return r;
}

const int N = 3000 + 7;
int n;
int s;
int a[N];
int cnt[N];
int sum[N];
int sol;

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

  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] > s) {
      continue;
    }
    if (a[i] == s) {
      sol = add(sol, mul(i, n + 1 - i));
    } else {
      int val = s - a[i];
      sol = add(sol, mul(n + 1 - i, sum[val]));
    }
    for (int x = s - a[i]; x >= 1; x--) {
      cnt[x + a[i]] = add(cnt[x + a[i]], cnt[x]);
      sum[x + a[i]] = add(sum[x + a[i]], sum[x]);
    }
    cnt[a[i]] = add(cnt[a[i]], 1);
    sum[a[i]] = add(sum[a[i]], i);
  }
  cout << sol << "\n";

}


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

int main() {
  int num;
  
  cin >> num;
  vector<int> vec(num,0);
  
  int tmp = 0;
  for(int i = 0; i < num-1; i++){
    cin >> tmp;
    vec.at(tmp-1) += 1;
  }
  
  for(int i = 0; i < num; i++) cout << vec.at(i) << endl;
}


Measured memory_bytes: 3996
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	string s;
	getline(cin,s);
	transform(s.begin(),s.end(),s.begin(),::toupper);
	cout << s << endl;
	return 0; 
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

ll v[3005][3005], dp[3005][3005][4];
int n,m;

ll solve(int x, int y, int used){
    if(x > n or y > m)
        return 0;
    if(dp[x][y][used] != -1ll)
        return dp[x][y][used];
    ll ans = 0;
    ans = max(ans, solve(x, y+1, used));
    ans = max(ans, solve(x+1, y, 0));
    if(used < 3){
        ans = max(ans, solve(x, y+1, used+1) + v[x][y]);
        ans = max(ans, solve(x+1, y, 0) + v[x][y]);
    }
    return dp[x][y][used] = ans;
}

int main(){
	fastio;
    memset(dp, -1, sizeof(dp));
    int k;
    cin >> n >> m >> k;
    while(k--){
        int x, y, p;
        cin >> x >> y >> p;
        v[x][y] = p;
    }
    cout << solve(1, 1, 0) << '\n';
	return 0;
}


Measured memory_bytes: 356632
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A = i()
B = i()
C = i()
D = i()
print(min(A,B)+min(C,D))

Measured memory_bytes: 9916
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
ll dp[41][(1<<17)]={};
int main() {
	int n,x,y,z;
	cin>>n>>x>>y>>z;

	dp[0][0]=1;
	ll d107=1000000007;
	ll k=(1<<(x+y+z-1))+(1<<(y+z-1))+(1<<(z-1));
	for(int i=0;i<n;++i){
		for(int j=0;j<(1<<(x+y+z));++j){
			if(dp[i][j]>0){
				for(int h=1;h<11;++h){
					ll k2=(j<<h)+(1<<(h-1));
					k2%=(1<<(x+y+z));
					if((k2&k)!=k){
						dp[i+1][k2]+=dp[i][j];
						dp[i+1][k2]%=d107;
//						cout<<dp[i+1][k2];
					}
				}
			}
		}
	}
	ll t=1;
	for(int i=0;i<n;++i){
		t*=10;
		t%=d107;
	}
	ll t2=0;
	for(int i=0;i<(1<<(x+y+z));++i){
		t2+=dp[n][i];
		t2%=d107;
	}
	t=(t+d107-t2)%d107;
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 40192
object Main {
  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  class SegmentTree[A](val numOfNode: Int, val M: Monoid[A]){

    sealed trait Tree{ val value: A }
    case object Leaf extends Tree{ val value: A = M.zero }
    case class Node(value: A, left: Tree, right: Tree) extends Tree
    object Node {
        def apply(value: A) = new Node(value, Leaf, Leaf)
        def apply(l: Tree, r: Tree) = new Node(M.op(l.value,r.value),l,r)
    }

    private val empty: Node = Node(M.zero,Leaf,Leaf)
    private[this] var root: Tree = empty

    private def updateRec(id: Int, x:A, l: Int = 0, r: Int = numOfNode, t: Tree = root): Tree = {
        def branch(now: Node): Node = {
            val m = (l + r)>>1
            if(r-l<=1)Node(x)
            else if(id < m)Node(updateRec(id,x,l,m, now.left), now.right)
            else Node(now.left,updateRec(id,x,m,r,now.right))
        }
        t match {
            case now: Node => branch(now)
            case _ => branch(empty)
        }
    }

    def update(id: Int, x: A): Unit = {
        root = updateRec(id, x)
    }

    def query(a: Int, b: Int, l: Int = 0, r: Int = numOfNode, t: Tree = root): A = {
      val m = (l + r)>>1
      t match {
        case now: Node =>
          if(b<=l || r<=a)M.zero
          else if(a<=l && r<=b)now.value
          else M.op(query(a,b,l,m,now.left),query(a,b,m,r,now.right))
        case _ => M.zero
      }
    }
  }

  def main(args: Array[String]): Unit = {
    val line = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val n = line(0)
    val q = line(1)
    val m = new Monoid[Int]{
        def op(a1: Int, a2: Int): Int = a1 min a2
        def zero: Int = Int.MaxValue
    }

    val segtree = new SegmentTree[Int](n,m)

    for(i <- 1 to q){
        val input = scala.io.StdIn.readLine.split(" ").map(_.toInt)
        val x = input(1)
        val y = input(2)
        if(input(0)==0)segtree.update(x,y)
        else println(segtree.query(x,y+1))
    }
  }
}

Measured memory_bytes: 192724
#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()

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

    // start
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n > k)
        cout << k * x + (n - k) * y << endl;
    else
        cout << n * x << endl;
    // end

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
int main(){
  int count=0, i, N, n, x, *A;
  scanf("%d",&N);
  A = (int *)malloc(sizeof(int) * N);
  for(i=0; i<N; i++)
    scanf("%d",&A[i]);
  n = N;
  while(n){
    for(i=0; i<n-1; i++)
      if(A[i] > A[i+1]){
	x = A[i+1];
	A[i+1] = A[i];
	A[i] = x;
	count++;
      }
    n = n - 1;
  }
  for(i=0; i<N; i++){
    printf("%d",A[i]);
    i < N-1 ? printf(" "):printf("\n");
  }
    printf("%d\n",count);
  free(A);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, r;
	while (1) {
		cin >> n >> r;
		if (!n) break;
		vector<int> card(n);
		REP(i, n) {
			card[i] = n - i;
		}
		REP(i, r) {
			int p, c;
			cin >> p >> c;
			int *tmp = new int[c];
			REP(j, c) tmp[j] = card[p - 1 + j];
			RREP(j,p-1 ) card[j+c] = card[j];
			REP(j, c) card[j] = tmp[j];
		}
		cout << card[0] << endl;


	}
	return 0;
}

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

using namespace std;

int main(){
	int N;
	int count = 0;

	cin >> N;
	int a[200];

	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	while(true){
		bool odd = false;
		for(int j = 0; j < N; j++){
			if(a[j]%2 == 0) a[j] /= 2;
			else odd = true;
		}
		if(odd) break;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

bool D[10] = { false }; // D[i]がtrueならiが嫌い
bool satisfyCondition(int n) {
  while (n > 0) {
    int  m = n % 10;
    if (D[m])
      return false;
    n /= 10;
  }
  return true;
}
int main() {
  IN(N); IN(K);


  REP(i, K) {
    IN(d);
    D[d] = true;
  }
  FOR(i, N, N*10+1) {
    if (satisfyCondition(i)) {
      OUT(i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll n;
    cin >> n;
    ll ans=0;
    vector<ll> a(n*3);
    for(ll i=0; i<n*3; i++){
        cin >> a.at(i);
    }
    
    sort(a.begin(),a.end());
    
    
    for(ll i=1; i<n+1; i++){
        ans += a.at(3*n-2*i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = s.filter { it != 'x' }

    var ans = 0
    if (t == t.reversed()) {
        var i = 0
        var j = s.lastIndex
        while (i < j) {
            if (s[i] == s[j]) {
                i++
                j--
                continue
            }

            if (s[i] == 'x') {
                ans++
                i++
                continue
            }

            if (s[j] == 'x') {
                ans++
                j--
                continue
            }
        }
    } else {
        ans = -1
    }

    println(ans)
}


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

using namespace std;

priority_queue<double, vector<double>, greater<double> > heap;
int n;

int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    double x;
    scanf("%lf", &x);
    heap.push(x);
  }
  while (heap.size() > 1) {
    double x = heap.top();
    heap.pop();
    double y = heap.top();
    heap.pop();
    heap.push((x + y) / 2);
  }
  printf("%.10lf\n", heap.top());
  return 0;
}


Measured memory_bytes: 256
// HardWork And Faliures will Collide,
// But There is nothing more stronger then You and I.

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x,v) memset((x),(v),sizeof((x)));
#define A(x) (x).begin(),(x).end()
#define re(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define erp(i,k,n) for(int i=n;i>=k;i--)
#define input(v,n) re(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vi>;
using tp = tuple<int,int,int>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
// ===================== MANASH =================== //

int n;
bool can( int a, int b, int c ) {
      return a + b > c;
}
bool ok ( int a, int b , int c ) {
      set<int> k = {a,b,c};
      if(sz(k) != 3 ) return false;
      return can(a,b,c) and can(a,c,b) and can(b,c,a);
}
void test() {

      cin >> n;
      vi v(n);
      re(i,n) {
            int x;
            cin >> x;
            v[i] = x;
      }
      int ans = 0;
      for( int i = 0; i < n; i++) {
            for( int j = i+1; j < n; j++) {
                  for( int k = j+1; k < n; k++) {
                        if(ok(v[i],v[j],v[k])) {
                              // cerr << i+1 << ' ' << j+1 << ' ' << k+1 << '\n';
                              ans++;
                        };
                  }
            }
      }
      cout << ans;
}

signed main() {

      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
      int T = 1;
      //cin >> T;
      for( int tt = 1; tt <= T; tt++) {
            //cout << "Case #" << tt << " ";
            test();
            cout << "\n";
      }
      return 0;

}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d, e);
    Cout(15-a-b-c-d-e);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;



const ll MOD = 1e9+7;
ll fac(ll n){
    ll ret=1;
    for(ll i=1;i<=n;i++){
        ret*=i;
        ret%=MOD;
    }
    return ret;
}
signed main(){
    ll n,m; cin >> n >> m;
    if(n==m){
        ll ans=fac(n);
        ans*=fac(m);
        ans*=2;
        ans%=MOD;
        cout << ans << endl;
    }else if(n+1==m){
        ll ans=fac(n);
        ans*=fac(m);
        ans%=MOD;
        cout << ans << endl;
    }else if(n==m+1){
        ll ans=fac(m);
        ans*=fac(n);
        ans%=MOD;
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    PriorityQueue pq=new PriorityQueue();
    int N=sc.nextInt();
    
    for(int i=0;i<N;i++){
      pq.add(sc.nextLong());
    }
    
    int count=0;
    
    Long s=(Long)(pq.poll());
    while(!pq.isEmpty()){
      count++;
      Long t=(Long)(pq.poll());
      if(s.equals(t)){
        System.out.print("NO");
        break;
      }
      if(pq.isEmpty()) System.out.print("YES");
      s=t;
    }
  }
}

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

int main(){
    string t = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<array>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const int INF = 9999999;

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    int ans;
    double min = INF;
    rep(i, n) {
        int h;
        cin >> h;

        double tem = abs(a - (t - h * 0.006));
        //cout << tem << endl;

        if (tem < min) {
            min = tem;
            ans = i + 1;
        }
    }
    cout << ans;
}

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

int main(){
  bool flag = false;
  string s; cin >> s;

    for(int i = 0; i < s.size(); i++){
      for(int j = i+1; j < s.size(); j++){
      if(s[i]==s[j]){
        flag = true;
  }
  }
    }
  if(flag){
    cout << "no" << endl;
  }
  else
  {
    cout << "yes" <<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

class UnionFind {
    vector<int> parent;

    public:
        UnionFind(int size) {
            parent = vector<int>(size, -1);
        }

        int find(int x) {
            if (parent[x] < 0) {
                // parent itself
                return x;
            } else {
                return parent[x] = find(parent[x]);
            }
        }

        bool unite(int x, int y) {
            int rX, rY;
            if ((rX = find(x)) == (rY = find(y))) {
                // already united
                return false;
            }
            if (size(rX) < size(rY)) {
                int tmp = rX;
                rX = rY;
                rY = tmp;
            }
            parent[rX] += parent[rY];
            parent[rY] = rX;
            return true;
        }

        int size(int x) {
            return -parent[find(x)];
        }

        bool is_same(int x, int y) {
            return find(x) == find(y);
        }

        // CAUTION!! : This method is heavy due to scanning linearly.
        int component_count() {
            int c = 0;
            for (const int x : parent) {
                if (x < 0) {
                    c++;
                }
            }
            return c;
        }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    REP(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    int ans = 0;
    REP(i, m) {
        UnionFind uf(n);
        REP(j, m) {
            if (i == j) continue;
            uf.unite(a[j], b[j]);
        }
        if (uf.size(0) != n) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, m;
	cin >> n >> m;
	vector<P> ab(n);
	REP(i, n)
		cin >> ab[i].first >> ab[i].second;
	sort(ALL(ab));
	ll ans = 0;
	REP(i, n) {
		if (m - ab[i].second <= 0) {
			ans += m * ab[i].first;
			cout << ans;
			return 0;
		}
		ans += ab[i].first * ab[i].second;
		m -= ab[i].second;
	}
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <stack>
using namespace std;
//常に心してかかれ
int main(){
	int n;
	int q;
	int tmp;
	int C=0;
	int num_to_check;
	int S[10001];
	stack<int> T;

	cin >>n;

	for(int i=0;i<n;i++){
		scanf("%d",&S[i]);
	}

	/*確認
	for(int i=0;i<n;i++){
		cout <<S[i] <<" ";
	}
	cout <<endl;
	*/

	cin >>q;

	for(int i=0;i<q;i++){
		scanf("%d",&tmp);
		T.push(tmp);
	}

	/*確認
	while(!T.empty()){
		cout <<T.top() <<" ";
		T.pop();
	}
	cout <<endl;
	*/

	while(!T.empty()){
		num_to_check = T.top();
		T.pop();

		for(int i=0;i<n;i++){
			if(num_to_check == S[i]){
				C++;
				break;
			}
		}
	}
	cout <<C <<endl;

	return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 5003
bool dp[SIZE][SIZE];
ll c(ll a,ll b){
	if(a%b==0)
		return a/b;
	else
		return a/b+1;
}
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	string str;
	cin>>str;
	ll dp[n+1];
	ll ans=0;
	for(ll gap=1;gap<n;gap++){
		for(ll j=0;j<=n;++j){
			dp[j]=0;
		}
		for(ll j=n-gap-1;j>=0;--j){
			if(str[j]==str[j+gap]){
				dp[j]=min(dp[j+1]+1,gap);
			}
			else{
				dp[j]=0;
			}
			// cout<<j<<","<<gap<<" "<<dp[j]<<endl;
			ans=max(dp[j],ans);
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
const int MAX_N = 110000;
 
int dp[MAX_N]; // dp[i] が i についての答え
 
int main(){
  int N; cin >> N;
  for(int i=0; i<MAX_N; i++) dp[i] = N;
  dp[0] = 0;
  
  for(int n=1; n<N+1; n++){
    for(int pow6=1; pow6<=n; pow6*=6){
      dp[n] = min(dp[n], dp[n-pow6]+1);
    }
    for(int pow9=1; pow9<=n; pow9*=9){
      dp[n] = min(dp[n], dp[n-pow9]+1);
    }
    
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  double x1,x2,x3,y1,y2,y3,x,y;
  double a,b,c,d,ans;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x>>y){
    a=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
    b=x*(y1-y2)+x1*(y2-y)+x2*(y-y1);
    c=x*(y2-y3)+x2*(y3-y)+x3*(y-y2);
    d=x*(y3-y1)+x3*(y1-y)+x1*(y-y3);
    if((a<0 && b<0 && c<0 && d<0) || (a>0 && b>0 && c>0 && d>0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n) for(int i=z;i<n;i++)
#define forii(z,n) for(int i=z;i<=n;i++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    int first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,w;cin>>n>>w;
    vector<PII> v(n+1);
    fori(1,n+1)
    {
        ll a,b;cin>>a>>b;
        v[i]={a,b};
    }
    ll dp[w+1][n+1];
    fori(0,n+1)
        dp[0][i]=0;
    fori(0,w+1)
        dp[i][0]=0;
    fori(1,w+1)
    {
        for(int k=1;k<=n;k++)
        {
            if(i-v[k].ff>=0)
                dp[i][k]=max(v[k].ss+dp[i-v[k].ff][k-1],dp[i][k-1]);
            else
                dp[i][k]=dp[i][k-1];
        }
    }
    cout<<dp[w][n]<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


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

int main() {
    int A, B, C, X; cin >> A >> B >> C >> X;
    int cnt = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int money = 500 * i + 100 * j + 50 * k;
                if (money == X) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import math
h,w=(map(int,input().split()))
i=0
n=0
if h%2==0 and w%2==0:
  print(int(h/2*w))
elif h==1 or w==1:
  print(1)
elif h%2==1 and w%2==1:
    i=(h/2+0.5)+(h/2-0.5)
    n=math.floor(w/2)
    print(int(i*n+(h/2+0.5)))
elif h%2==0 and w%2==1:
  print(int(h/2*w))
elif h%2==1 and w%2==0:
  print(int(w/2*h))


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

map<ll,ll> pfmp; //各素因数の冪指数の総和を格納
vector<ll> pfv(0); //異なる素因数を昇順に格納

void pf(ll N){
  ll n=N;
  if(n<=0) return;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    while(n%2==0){
      n/=2;
      pfmp[2]++;
    }
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      while(n%i==0){
        n/=i;
        pfmp[i]++;
      }
    }
  }
  if(n!=1){
    if(pfmp[n]==0) pfv.push_back(n);
    pfmp[n]++;
  } 
  //sort(all(pfv));
}

int main(){
  ll n; cin >> n;
  pf(n-1);
  ll ans=1;
  rep(i,pfv.size()){
    ans*=pfmp[pfv[i]]+1;
  }
  ans--;
  //cout << ans << endl;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0){
      ll N=n;
      while(N%i==0){
        N/=i;
      }
      if((N-1)%i==0){
        //cout << i << endl;
        ans++;
      }
    }
  }
  ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256