akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int A[N+1];
    int B[N];
    for(int i = 0; i < N+1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    ll cnt = 0;
    for(ll i = 0; i < N; i++) {
        if(A[i] < B[i]) {
            B[i] -= A[i];
            cnt += A[i];
            A[i] = 0;
        } else if(A[i] == B[i]) {
            cnt += A[i];
            A[i] = 0;
            B[i] = 0;
        } else {
            A[i] -= B[i];
            cnt += B[i];
            B[i] = 0;
        }
        // while(A[i] > 0) {
        //     A[i]--;
        //     B[i]--;
        //     cnt++;
        //     if(B[i] == 0) break;
        // }
        if(B[i] != 0) {
            if(A[i+1] < B[i]) {
                B[i] -= A[i+1];
                cnt += A[i+1];
                A[i+1] = 0;
            } else if(A[i+1] == B[i]) {
                cnt += A[i+1];
                A[i+1] = 0;
                B[i] = 0;
            }  else {
                A[i+1] -= B[i];
                cnt += B[i];
                B[i] = 0;
            }
            // while(A[i+1] > 0) {
            //     A[i+1]--;
            //     B[i]--;
            //     cnt++;
            //     if(B[i] == 0) break;
            // }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	long N, M, max;

	long ans = 1;

	cin >> N >> M;

	if (N == 1) {
		cout << M << endl;
		return 0;
	}
	max = (M / N);

	for(long i = 2; i <= max; i++){
		if(M % i == 0) ans = i;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import heapq

n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))
cs = [tuple(map(int, input().split())) for _ in range(m)]
cs = sorted(cs, key=lambda c: c[1], reverse=True)

heapq.heapify(xs)
for c in cs:
    bi, ci = c
    updated = False
    for _ in range(bi):
        v = heapq.heappop(xs)
        if v < ci:
            heapq.heappush(xs, ci)
            updated = True
        else:
            heapq.heappush(xs, v)
            break

    if not updated:
        break

print(sum(xs))

Measured memory_bytes: 97588
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 100001
using namespace std;
void add_self(int &a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}
void sub_self(int &a,int b){
	a-=b;
	if(a<0) a+=mod;
    if(a>=mod) a-=mod;
}
int main() {
	FIO;
	int n,k;
	cin>>n>>k;
	vector<int> vec(n);
	for(int i=0;i<n;i++) cin>>vec[i];
	vector<int> dp(k+1,0);
	//dp[i]->total number of ways to distribute i number of candies
	dp[0]=1;
	for(int i=0;i<n;i++){
		vector<int> fake(k+2,0);
		for(int j=k;j>=0;j--){
			// for(int l=1;l<=vec[i];l++){
			// 	if(j+l<=k) dp[j+l]+=dp[j];
			// }
			int L=j+1,R=min(j+vec[i],k);
			//for(int l=L;l<=R;l++) dp[l]+=dp[j];
			add_self(fake[L],dp[j]);
			sub_self(fake[R+1],dp[j]);
		}
		int pre_sum=0;
		for(int i=0;i<=k;i++){
			add_self(pre_sum,fake[i]);
			add_self(dp[i],pre_sum);
		}
	}
	cout<<dp[k]<<endl;
}

Measured memory_bytes: 1024
import sys
A,B,C,D,E,F = map(int,input().split())

AMAX = F // (A * 100)
BMAX = F // (B * 100)
sugar = 0
water = min(A,B)*100

res = 0
for i in range(AMAX + 1):
	for j in range(BMAX + 1):
		if i == 0 and j == 0:
			continue
		cwater = A * i + B * j
		CMAX = (F - cwater * 100) // C
		DMAX = (F - cwater * 100) // D
		for k in range(CMAX + 1):
			for l in range(DMAX + 1):
				csugar = k * C + l * D
				if cwater * E < csugar:
					break;
				if F < cwater * 100 + csugar:
					break;
				curr = csugar / (cwater * 100 + csugar)
				if curr > res:
					water = cwater * 100
					sugar = csugar
					res = curr

print(water + sugar, sugar)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N, K;
	scanf("%d", &N);
	scanf("%d", &K);

	if ((N + 1) / 2 >= K) {
		int B = K + N;
		int C = K + N + N;
		int b = N / 2;
		int n = !(N & 1);

		rep(i, (N + 1) / 2) {
			putint(K + i);
			putint(B + b + i);
			putint(C + i * 2);
		}
		for (int i = (N + 1) / 2; i < N; i++) {
			putint(K + i);
			putint(K + b + i);
			putint(B + i * 2 + n);
		}
		fwrite(dn, 1, di - dn, stdout);
	}
	else {
		printf("-1");
		return 0;
	}


	Would you please return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
ll n,k;
vector<ll>v;
map<ll,ll>val;
ll a1[N],a2[N],a3[N];
ll res[N],tot;
int main()
{
	int flag=1;
	cin>>n>>k;
	for(ll i=k+2*n-1,j=1;i>=k+n&&j<=n;i--,j++)
	a2[j]=i;
	int z=1;
	for(ll i=k;i<k+n&&z<=n;i+=2,z++)
	a1[z]=i;
	for(ll i=k+1;i<k+n&&z<=n;i+=2,z++)
	a1[z]=i;
	for(int i=1;i<=n;i++)
	{
		a3[i]=a1[i]+a2[i];
		if(a3[i]>=k+2*n&&a3[i]<k+3*n)
		val[a3[i]]++;
	}
	for(ll i=k+2*n;i<k+3*n;i++)
	{
		if(!val.count(i))
		res[++tot]=i;
	}
	int pos=1;
	for(int i=1;i<=n;i++)
	{
		if(a3[i]>=k+3*n)
		{
			cout<<-1<<endl;
			return 0;
		}
		if(!val.count(a3[i]))
		{
			a3[i]=res[pos++];
			if(!(a3[i]>=k+2*n&&a3[i]<k+3*n&&a3[i]>=a1[i]+a2[i]))
			{
				cout<<-1<<endl;
				return 0;
			}
			continue;
		}
		else
		{
			if(val[a3[i]]>1)
			{
				val[a3[i]]--;
				a3[i]=res[pos++];
				if(!(a3[i]>=k+2*n&&a3[i]<k+3*n&&a3[i]>=a1[i]+a2[i]))
				{
					cout<<-1<<endl;
					return 0;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	cout<<a1[i]<<" "<<a2[i]<<" "<<a3[i]<<endl;
}

Measured memory_bytes: 10880
object Main {

  val amari = 1000000007

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val A, B, K = sc.nextInt()
    var x = 0
    var i = Math.max(A, B) + 1
    while (x != K) {
      i = i - 1
      if (A % i == 0 && B % i == 0) {
        x = x + 1
      }
    }
    println(i)
  }
}


Measured memory_bytes: 25536
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(int)rept;++i)
typedef long long ll;
using namespace std;
const int mod = 1e+9 + 7;

std::vector<bool> IsPrime;



int main() {
	//14日目

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

	int n = 0, x = 0;
	cin >> n >> x;
	int a[100] = {};
	rep(i, n) {
		cin >> a[i];
	}
	std::sort(a, a + n);

	int count_kasi = 0;
	int i = 0;
	while (1) {
		count_kasi += a[i];
		if (count_kasi > x) {
			cout << i << endl;
			return 0;
		}
		if (i == (n - 1)) {
			if (count_kasi != x) {
				cout << i << endl;
			}
			else {
				cout << i + 1<< endl;
			}
			return 0;
		}
		i++;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t)
        cout<<"Yes\n";
    else 
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
class Graph(): #directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.rev = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append(e[1] - indexed)
            self.rev[e[1] - indexed].append(e[0] - indexed)
            self.deg[e[1] - indexed] += 1

    def strongry_connected(self):
        group = [None for _ in range(self.n)]
        used = [0 for _ in range(self.n)]
        order = []
        for s in range(self.n):
            if not used[s]:
                stack = [s]
                used[s] = 1
                while stack:
                    node = stack.pop()
                    movable = False
                    for adj in self.graph[node]:
                        if not used[adj]:
                            movable = True
                            used[adj] = 1
                            stack.append(node)
                            stack.append(adj)
                            break
                    if not movable:
                        order.append(node)
        used = [0 for _ in range(self.n)]
        count = 0
        for s in order[::-1]:
            if not used[s]:
                stack = [s]
                group[s] = count
                while stack:
                    node = stack.pop()
                    used[node] = 1
                    for adj in self.rev[node]:
                        if not used[adj]:
                            group[adj] = count
                            stack.append(adj)
                count += 1
        return group, count

import sys
input = sys.stdin.buffer.readline

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, E, 0)
group, count = g.strongry_connected()

res = [[] for _ in range(count)]

for i, k in enumerate(group):
    res[k].append(i)

print(count)

for r in res:
    print(len(r), *r)

Measured memory_bytes: 308972
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007 
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 100001


 
int min(int a, int b)
{
    if(a>b)
        return b;
    return a;
}
     
int max(int a, int b)
{    
    if(a>b)
        return a;
    return b;
}


int32_t main()
{
    int n,x;
    cin>>n;

    float sum=0.0;

    while(n--)
    {
        cin>>x;

        sum += 1.0/x;
    }

    cout<<setprecision(15)<<fixed<<(1.0/sum);

return 0;
}   

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

struct Edge {
    ll from, to;
    string s;
};
ll L = 250;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, s, g;
    while (cin >> n >> a >> s >> g, n || a || s || g) {
        string infstr = ""; infstr += 'z'+1;
        vector<Edge> edges;
        rep(i, a) {
            ll x, y; string lab; cin >> x >> y >> lab;
            edges.pb({x, y, lab});
        }
        vector<string> dist(n, infstr);
        dist[g] = "";
        auto update = [&]() {
            ll res = 0;
            each(e, edges) {
                if (dist[e.to] == infstr) continue;
                if (e.s + dist[e.to] < dist[e.from]) {
                    dist[e.from] = e.s + dist[e.to];
                    chmax(res, 1LL);
                    if (e.from == s) chmax(res, 2LL);
                }
            }
            return res;
        };
        try {
            rep(t, L) {
                if ( update() == 0 ) break;
            }
            rep(t, n) {
                if ( update() == 2 ) throw 1;
            }
            if (dist[s] == infstr) throw 1;
            cout << dist[s] << endl;
        }
        catch (int err) {
            cout << "NO" << endl;
        }
    }
}

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

typedef long long ll;

// string s = "atcoder";
string s;

int main() {
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
}

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

    using namespace std;

  //  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
    #define rep(i,n) FOR(i,0,n)
  //  #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
  //  #define SZ(a) (int)a.size()
  //  #define ALL(a) a.begin(),a.end()
    #define PB push_back

    typedef long long LL;

    //const double PI = acos(-1.0);
    //const int INF = 1000 * 1000 * 1000 + 7;
    const LL LINF = 1e18 + 7;
   // const int MAS =4e5; //5;
   // const int MOD = 1e9 + 7;
    //const double EPS = 1e-8;


    vector<LL> pre ;
    vector<LL >dp;
    // O( 2^ n)
    void rec(int idx, const vector<int >& not_taken ,LL score,int mask, int group)
    {
        if (idx == (not_taken.size()))
        {
         dp[mask] = max(dp[mask],score  + pre[group]);
         return ;
        }
        rec(idx+1, not_taken , score,mask,group);
        rec(idx+1,not_taken , score,mask ^(1  << not_taken[idx]),group  ^ (1 << not_taken[idx ]));

    }
    int main() {

// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        //   freopen("series.in","r",stdin);
        //   freopen("series.out","w",stdout);
        int n;
        cin >> n;
        vector<vector<LL >>  a (n,vector < LL > (n))  ;
        rep(i,n) {
            rep(j, n)
            {
                cin >> a[i][j] ;
             }
        }
       // return 0;
       // cout << "runtime = " << clock()/1000.0 << endl;

       // return 0;
        pre.resize(1 << n);
       //  O(2^n * n ^ 2)
        rep(msk,(1 << n ))
        {
            rep(i,n)
            {
                if(msk & ( 1 <<i))
                {
                    for(int j =  i + 1; j < n ; j ++)
                    {
                        if(msk  & ( 1 << j))
                        {
                            pre[msk]+=a[i][j] ;
                        }
                    }
                }
            }
        }
        //O(n^2 * n )
        dp.resize(1 << n,-LINF );
        dp[0] = 0 ;
        rep(msk,(1 << n ))
        {
            vector<int> not_taken;
            rep(i,n)
            {
                if(!(msk & ( 1 << i)))
                {
                    not_taken.PB(i);
                }
            }
            rec(0,not_taken,dp[msk],msk,0);

        }
        cout << dp[(1 << n )- 1] << endl;



    }

Measured memory_bytes: 1280
// -*- mode: cpp; coding=utf-8-unix; -*-
// vim: filetype=cpp fileencoding=utf-8 fileformat=unix
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define INTMAX  99999999

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (1000*100)
#define MAX_M (1000*100)

int	M, N;
int A[MAX_N];
int B[MAX_M], C[MAX_M];
vector<int> Avec;
vector<pair<int,int> > BCvec;

bool myfunction(pair<int,int> &i, pair<int,int> &j) {
	return (i.second>j.second);
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for (int n=0; n<N; n++) {
		cin >> A[n];
		Avec.push_back(A[n]);
	};
	sort(Avec.begin(), Avec.end());
	for (int m=0; m<M; m++) {
		cin >> B[m] >> C[m];
		BCvec.push_back(make_pair(min(B[m],N),C[m]));
	}
	sort(BCvec.begin(), BCvec.end(),myfunction);
#if DEBUG
#endif

	ll sum=0;
	vector<int>::iterator itA = Avec.begin();
	vector<pair<int,int> >::iterator itBC = BCvec.begin();
	// int count = 0;
	for(;
		itA!=Avec.end();
		itA++) {

		if(itBC==BCvec.end()) {
			DOUT << "C run out: "<<(*itA)<<" added"<<endl;
			sum += (*itA);
		}
		else {
			if((*itBC).second<=(*itA)) {
			DOUT << "C smaller: "<<(*itA)<<" added"<<endl;
				sum += *itA;
			}
			else {
			DOUT << "C larger : "<<(*itBC).second<<" added"<<endl;
				sum += (*itBC).second;
			}
		}
		itBC->first--;
		if(itBC->first==0) {
			itBC++;
		}
	}

	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 2804
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int INF = 1001001001;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> key(m);
	rep(i, m) {
		int ai, bi;
		cin >> ai >> bi;
		key[i].second = ai;
		rep(j, bi) {
			int ki;
			cin >> ki;
			ki--;
			key[i].first |= (1 << ki);
		}
	}
	vector<int> dp(1 << n,INF);
	dp[0] = 0;
	rep(i, m) {
		for (int bit = 0; bit < (1 << n); bit++) {
			dp[bit | key[i].first] = min(dp[bit | key[i].first], dp[bit] + key[i].second);
		}
	}
    if(dp[(1<<n)-1]!=INF){
	  cout << dp[(1 << n) - 1] << endl;
    }else{
      cout<<-1<<endl;
    }
}

Measured memory_bytes: 256
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll n, x, k, z, m, a[200500], b[200500], ra[200500], rb[200500], pa, pb;
vector<vector<ll>> f;
vector<ll> g;
int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == t[i]) {
            k++;
        }
    }
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
int main(){
   int n,c,k;
   cin >>n >>c >>k;
   vector<int> t(n);
   int ans=0;
   int head=0;
   rep(i,n) cin >>t.at(i);
   sort(all(t));
   int i=0;
   while(true){
      i++;
      if(head==n-1){
         ans++;
         break;
      }
      if(head+i>n-1){
         ans++;
         break;
      }
      if(t.at(head+i)>t.at(head)+k||i+1>c){
         head+=i;
         ans++;
         i=0;
      }
   }
   cout <<ans <<endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;

namespace dp
{
  class Solution
  {
      static void Main()
      {
        var n = int.Parse(Console.ReadLine());
        var heights = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
        Console.WriteLine(Solve(n,heights));
      }

      static int Solve(int n, int[] heights)
      {
        if (heights.Length < 2)
          return 0;
        else if (heights.Length == 2)
          return Math.Abs(heights[1]- heights[0]);

        int[] paths = new int[heights.Length];
        paths[heights.Length - 1] = 0;
        paths[heights.Length - 2] = Math.Abs(heights[heights.Length - 1]- heights[heights.Length - 2]);

        for (int i = heights.Length-3; i>=0; i--)
        {
          // +1
          int p1Cost = Math.Abs(heights[i + 1] - heights[i]) + paths[i + 1];

          // +2
          int p2Cost = Math.Abs(heights[i + 2] - heights[i]) + paths[i + 2];

          paths[i] = Math.Min(p1Cost,p2Cost);
        }
        return paths[0];
      }
  }
}

Measured memory_bytes: 35888
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
//最大公約数
template<typename T>
constexpr T gcd(T a, T b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
constexpr T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
int main() {
	int n;
	cin >> n;
	PRI(n / 3);
	return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

class Combination {
    vector<ll> factorial;
    vector<ll> fact_inverse;
    vector<ll> inverse;
    int mod;

    void init(int size) {
        factorial[0] = 1;
        factorial[1] = 1;
        fact_inverse[0] = 1;
        fact_inverse[1] = 1;
        inverse[1] = 1;

        for (int i = 2; i < size; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inverse[i] = mod - inverse[mod % i] * (mod / i) % mod;
            fact_inverse[i] = fact_inverse[i - 1] * inverse[i] % mod;
        }
    }

    public:
        Combination(int size, int m) {
           factorial = vector<ll>(size);
           fact_inverse = vector<ll>(size);
           inverse = vector<ll>(size, 0);
           mod = m;
           init(size);
        }
    
        ll calc(int n, int k) {
            if (n < k) {
                return 0;
            }
            if (n < 0 || k < 0) {
                return 0;
            }
            return factorial[n] * (fact_inverse[k] * fact_inverse[n - k] % mod) % mod;
        }

        ll inv(int n) {
            return inverse[n];
        }
};

long long pow_mod(long long n, long long p, long long mod) {
    if (p == 0) {
        return 1;
    } else if (p % 2 == 1) {
        return pow_mod(n, p - 1, mod) * n % mod;
    } else {
        long long s = pow_mod(n, p / 2, mod);
        return s * s % mod;
    }
}

int main() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    Combination com = Combination(max(a + b, n) * 2, MOD);

    ll pa = a * com.inv(a + b) % MOD;
    ll pb = b * com.inv(a + b) % MOD;
    ll p = 0;
    REP(i, n) {
        p += com.calc(i + n - 1, i) * pow_mod(pb, i, MOD) % MOD * pow_mod(pa, n, MOD) % MOD * (i + n) % MOD;
        p += com.calc(i + n - 1, i) * pow_mod(pa, i, MOD) % MOD * pow_mod(pb, n, MOD) % MOD * (i + n) % MOD;
        p %= MOD;
    }
    p = p * com.inv(a + b) % MOD * 100 % MOD;
    cout << p << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(b-a)<=d&&abs(c-b)<=d)||abs(c-a)<=d)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3644
from collections import Counter

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

A.sort(reverse=True)
# print(A)
lines = []

cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
    if ai == before:
        cnt += 1
    else:
        if cnt >= 4:
            lines.append(before)
            lines.append(before)
        elif cnt >=2:
            lines.append(before)

        if len(lines) >= 2:
            break
        
        cnt = 1
        before = ai


if len(lines) >= 2:
    print(lines[0] * lines[1])
else:
    print(0)

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

int main() {
  int N;
  cin >> N;
  string s = "No";

  for (int i=0; i<100; i++){
    for (int j=0; j<100; j++){
      if (4*i + 7*j == N){
        s = "Yes";
      }
    }
  }
  cout << s << endl;
        

        
  
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())
tree = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

ans = [0]*(N-1)
next_root = [0]
zumi = {}
while True:
    # 次のルートが全部探索済みなら終わり
    for root in next_root:
        if not(root in zumi):
            break
    else:
        break

    tmp_next_root = []
    for root in next_root:
        if root in zumi:
            continue
        for v in tree[root]:
            if v in zumi:
                continue
            if ans[v-1] == 0:
                ans[v-1] = root+1
                tmp_next_root.append(v)
        zumi[root] = True
    next_root = tmp_next_root

if ans.count(0) == 0:
    print('Yes')
    for a in ans:
        print(a)
else:
    print('No')


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

using lint = int64_t;
#define bit(n) (lint(1) << n)
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);

        cout << fixed << setprecision(12);
    }
} iosetup;

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }

    int ans = INF;
    for (int i = 0; i < n; i++) {
        if (i) {
            w[i] += w[i - 1];
        }
        ans = min(ans, abs(sum - 2 * w[i]));
    }

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

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


int main()
{
    int n;
    cin>>n;
    vector<vector<int>> ar(n,vector<int>(3));
    for(int i=0;i<n;++i)
    {
        cin>>ar[i][0]>>ar[i][1]>>ar[i][2];

    }
    vector<vector<int>> dp(n,vector<int>(3,0));
    dp[0][0]=ar[0][0];
    dp[0][1]=ar[0][1];
    dp[0][2]=ar[0][2];
    for(int i=1;i<n;++i)
    {
        for(int j=0;j<3;++j)
        {
            for(int k=0;k<3;++k)
            {    if(j==k)
                continue;
                
                dp[i][j]=max(dp[i][j],ar[i][j]+dp[i-1][k]);
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<'\n';
 }



Measured memory_bytes: 14324
#include<iostream>
#include<map>
#include<string>
#include<deque>
#include<algorithm>

using namespace std;


int main(){

	int N;
	cin >> N;

	std::map<string, int> data;
	string word;
	string most_often_word;
	int most_often = 1;

	cin >> word;
	data[word] = 1;
	most_often_word = word;

	for(int i=1; i<N; ++i){
		cin >> word;
		if(data.count(word) > 0){
			data[word] += 1;
			if(data[word] > most_often){
				most_often = data[word];
				most_often_word = word;
			}
		}
		else{
			data[word] = 1;
		}
	}

	deque<string> f_words;

	for( const auto &myPair : data){
		if(data[myPair.first] == most_often){
			f_words.push_back(myPair.first);
		}
	}

	sort(f_words.begin(), f_words.end());
	for(int i = 0; i < f_words.size(); ++i){
		cout << f_words[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 28928
import java.util.*;

class Main{
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int[]a=new int[n],b=new int[n],min=new int[n],max=new int[n];
	
	public static void main(String[]$){
		new Main().main();
	}
	void main() {
		Arrays.setAll(a,i->s.nextInt());
		Arrays.setAll(b,i->s.nextInt());
		Arrays.fill(min,1);
		Arrays.fill(max,1000000000);
		
		long r=f(a,0,n,1)*f(b,n-1,-1,-1);
		
		for(int i=0;i<n;++i) {
			r*=Math.max(0,max[i]-min[i]+1);
			r%=1000000007;
		}
		System.out.println(r);
	}
	int f(int[]b,int f,int t,int d) {
		for(int i=f;i!=t;i+=d) {
			if(i==f||b[i]!=b[i-d]) {
				if(min[i]>b[i]||max[i]<b[i])
					return 0;
				max[i]=min[i]=b[i];
			}else
				max[i]=Math.min(max[i],b[i]);
		}
		return 1;
	}
}


Measured memory_bytes: 88224
fn solve() {
    let n = read();
    let mut csf = vec![];
    for i in 0..n - 1 {
        let (c, s, f): (usize, usize, usize) = (read::<usize>(), read::<usize>(), read::<usize>());
        csf.push((c, s, f));
    }
    let mut res = vec![0; n - 1];
    for i in 0..n - 1 {
        let mut tmp = 0;
        for j in i..n - 1 {
            if tmp < csf[j].1 {
                tmp = csf[j].1;
            } else if tmp % csf[j].2 != 0 {
                tmp = tmp + csf[j].2 - tmp % csf[j].2;
            }
            tmp += csf[j].0;
            // println!("{:?}", (i, j));
            // println!("{:?}", csf[j]);
            // println!("{:?}", tmp);
        }
        res[i] = tmp;
    }
    res.push(0);
    for i in 0..n {
        println!("{}", res[i]);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<long long> A(N);
    long long L = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        L += A[i];
    }
    long long M = 0;
    long long ans = L;
    for(int i = 0; i < N; i++){
        M += A[i];
        ans = min(ans, abs(L - 2 * M));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

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


Measured memory_bytes: 6792
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, S: int):
    MX = 10 ** 9
    ret = []
    for i in range(K):
        ret.append(str(S))
    tmp = S + 1 if S < MX else S - 1
    for i in range(N - K):
        ret.append(str(tmp))
    print(' '.join(ret))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13464
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	long long int n,i,a,b,ans=0;
	cin>>n;
	for(i=sqrt(n);i>0;i--)
	{
		if(n%i==0)
		{	a=i;
			b=n/i;
			break;
		}
	}
	ans=a-1+b-1;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc145/tasks/abc145_d


class Combination:                                      # 計算量は O(n_max + log(mod))
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):                     # 階乗(= n_max !)の逆元を生成
            f = f * i % mod                             # 動的計画法による階乗の高速計算
            fac.append(f)                               # fac は階乗のリスト
        f = pow(f, mod-2, mod)                          # 階乗から階乗の逆元を計算。フェルマーの小定理より、　a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
                                                        # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):                   # 上記の階乗の逆元から階乗の逆元のリストを生成（＝ facinv ）
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

X, Y = map(int, input().split())

if (2*Y- X) % 3 or (2*X- Y) % 3:
    print(0)
    exit()

x = (2*Y - X) // 3
y = (2*X - Y) // 3

n = x + y
r = x


mod = 10**9 + 7
f = 1
for i in range(1, n + 1):
    f = f*i % mod
fac = f
f = pow(f, mod-2, mod)
facinv = [f]
for i in range(n, 0, -1):
    f = f*i % mod
    facinv.append(f)
facinv.append(1)

comb = Combination(n)
print(comb.C(n,r))

Measured memory_bytes: 101564
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int p, n, mi = 99999999;
    cin >> n;
    REP(i, n){
        cin >> p;
        if(mi >= p){
            ans++;
        }
        mi = min(p, mi);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
  ll n;
  sf(n);
  ll ar[n+1];
  for(ll i=1;i<=n;i++) sf(ar[i]);
   sort(ar+1,ar+n+1);
  ll ans=0;
  for(ll i=1;i<=n;i++)
  {
   for(ll j=i+1;j<=n;j++)
   {
      if(ar[i]==ar[j]) continue;
      for(ll k=j+1;k<=n;k++)
      {
         if(ar[i]==ar[k] || ar[j]==ar[k]) continue;
         if(ar[i]+ar[j]>ar[k]) ans++;
      }
   }
  }
  pf(ans);
}

Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
    std::string str;
    std::cin >> str;
    int count = 0;
    for(const char c:str){
        if(c=='p'){
            ++count;
        }
    }
    
    std::cout << str.size() / 2 - count << std::endl;

    return 0;
}


Measured memory_bytes: 512
Scanf.scanf "%d %d" (fun h w ->
    let s = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
    let hw = h * w in
    let par = Array.init hw (fun i -> i) in

    let rec root x =
        if x = par.(x) then par.(x) else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in

    let merge a b = if root a <> root b then par.(par.(b)) <- par.(a) in

    let (@) y x = y * w + x in

    for y = 0 to h - 1 do
        for x = 0 to w - 1 do
            if s.(y).[x] = '#' then (
                if x > 0     && s.(y).[x - 1] = '.' then merge (y @ (x - 1)) (y @ x);
                if x < w - 1 && s.(y).[x + 1] = '.' then merge (y @ (x + 1)) (y @ x);
                if y > 0     && s.(y - 1).[x] = '.' then merge ((y - 1) @ x) (y @ x);
                if y < h - 1 && s.(y + 1).[x] = '.' then merge ((y + 1) @ x) (y @ x);
            )
        done
    done;
    let bl = Array.make hw 0 in
    let wh = Array.make hw 0 in
    for i = 0 to hw - 1 do
        let j = root i in
        let y = i / w in
        let x = i mod w in
        if s.(y).[x] = '#' then bl.(j) <- bl.(j) + 1
                           else wh.(j) <- wh.(j) + 1
    done;
    let rec loop i acc =
        if i = hw then acc else
            let acc = if bl.(i) >= 1 && wh.(i) >= 1 then acc + bl.(i) * wh.(i) else acc in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

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

#define Bye return 0

void solve(){
    long long n; cin>>n;

    string str;
    while(n){
        n = n - 1;
        str += 'a' + n%26;
        n /= 26;
    }
    reverse(begin(str), end(str));
    cout<<str<<endl;
}

int main()
{
    solve();
    Bye;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int d[2010][2010];
int cnt[2010];
int main() {
    int n,x,y;
    cin >> n >> x >> y;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (j <= x || i >= y) {
                d[i][j] = j - i;
                continue;
            }
            if (i <= x && j >= y) {
                d[i][j] = x - i + j - y + 1;
                continue;
            }
            if (i <= x) {
                d[i][j] = min(j - i, y - j + 1 + x - i);
                continue;
            }
            if (j >= y) {
                d[i][j] = min(j - i, j - y + 1 + i - x);
                continue;
            }
            d[i][j] = min(j - i, i - x + y - j + 1);
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            cnt[d[i][j]]++;
        }
    }
    for (int i = 1; i <= n - 1; i++) cout << cnt[i] << endl;
    return 0;
}

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

int main() {
  int na = 0, nb = 0;
  string s, a, b;
  cin >> s;
  for (int i=0; i <s.size(); i++) {
    if (i % 2 == 0) {a += "1"; b += "0";}
    else {a += "0"; b+= "1";}
  }
  for (int i=0; i<s.size(); i++) {
  	if (s[i] != a[i]) na++;
  	if (s[i] != b[i]) nb++;
  }
  cout << min(na, nb) << endl;
  return 0;
}


Measured memory_bytes: 768
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 5005 /*rem*/
#define mod 1000000007
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int fa[maxn], sz[maxn], fl[maxn];
ll mt[maxn];
int gfa(int a) {
	if (fa[a] == a) return a;
	return fa[a] = gfa(fa[a]);
}
ll jc[maxn];
int main() {
	jc[0] = 1;
	for (int i = 1; i < maxn; i++) jc[i] = jc[i - 1] * i % mod;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) 
		fa[i] = i, sz[i] = 1, fl[i] = 0;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int p;
		scanf("%d", &p);
		if (p == -1) cnt++;
		else {
			int pf = gfa(p), af = gfa(i);
			if (af == pf) fl[af] = 1;
			else {
				fa[pf] = af, fl[af] |= fl[pf];
				sz[af] += sz[pf];
			}
		}
	}
	mt[0] = 1;
	ll ans = 0;
//	cout << "!!!" << cnt << endl;
	ll bk = ksm(n - 1, mod - 2);
	for (int i = 1; i <= n; i++) {
		if (fa[i] != i) continue;
		if (fl[i]) {
			ans += ksm(n - 1, cnt);
			ans %= mod;
		}
		else {
			for (int j = n; j >= 1; j--)
				mt[j] = (mt[j] + mt[j - 1] * sz[i]) % mod;
			ans += ksm(n - 1, cnt - 1) * (sz[i] - 1);
			ans %= mod;
		}
	}
	for (int j = 2; j <= cnt; j++)
		ans += ksm(n - 1, cnt - j) * mt[j] % mod * jc[j - 1], 
		ans %= mod;
	ans = n * ksm(n - 1, cnt) % mod - ans;
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3900
#include <stdio.h>
#include <string.h>

int main (void)
{
    char S[11];
    scanf("%s", &S);
    int maxACGT = 0;

    int lenACGT = 0;
    int i;
    for (i = 0; i < strlen(S); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            lenACGT++;
        } else {
            if (maxACGT < lenACGT) maxACGT = lenACGT;
            lenACGT = 0;
        }
    }
    if (maxACGT < lenACGT) maxACGT = lenACGT;
    printf("%d", maxACGT);

    return 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
    n, m = map(int, input().split())
    students, checkpoints = (tuple(tuple(map(int, input().split())) for _ in range(x)) for x in (n, m))

    for x1, y1 in students:
        t = 0
        for i in range(m):
            (x2, y2), (x3, y3) = checkpoints[t], checkpoints[i]
            if abs(x1 - x2) + abs(y1 - y2) > abs(x1 - x3) + abs(y1 - y3): t = i

        print(t + 1) 


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;

void input() {
  cin >> n;
}

void solve() {
  cout << (n + 1) / 2 << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();

  int t = 1;

#ifdef _DEBUG
  t = 3;
#endif

  //  cin >> t;

  while (t--) {
    input();
    solve();
  }
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n;
int w[1010];
vector<pair<int, int>> v;
vector<int> G[1010];
bool used[1010];
int main() {
	cin >> n;
	int minl = INF<int>();
	REP(i, n) {
		cin >> w[i];
		minl = min(minl, w[i]);
	}
	REP(i, n) {
		v.emplace_back(w[i], i);
	}
	sort(ALL(v));
	REP(i, n) {
		G[v[i].second].emplace_back(i);
	}
	queue<int> q;
	int sum = 0;
	int cnt = 0;
	LL ans = 0;
	int minll = INF<int>();
	REP(i, n) {
		if (!used[i])q.push(i);
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			used[cur] = true;
			sum += v[cur].first;
			minll = min(minll, v[cur].first);
			cnt++;
			if (!used[G[cur][0]])q.push(G[cur][0]);
			else {
				ans += min(sum + (cnt - 2)*minll, sum + minll + minl*(cnt + 1));
				sum = 0;
				cnt = 0;
				minll = INF<int>();
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#pragma warning (disable:4996)
using namespace std;


int main() {
	set<string> s;
	int n;
	string a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size();

}

Measured memory_bytes: 19104
A = list(map(int, input().split()))

tasks = [
    (0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0)
]

min_c = 1000
for t1,t2,t3 in tasks:
    c = abs(A[t2]-A[t1])+abs(A[t3]-A[t2])
    min_c = min(min_c, c)
print(min_c)


Measured memory_bytes: 3064
from random import randrange


def eratosthenes(size):
    table = [True] * (size + 1)
    table[0] = table[1] = True
    for i in range(2, int(round(pow(size+1, 0.5)))):
        if not table[i]:
            continue
        for j in range(i + i, size+1, i):
            table[j] = False
    return table


def miller_rabin(n, k=20):
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    d = n - 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = randrange(1, n)
        y = pow(a, d, n)
        t = d
        while t != n - 1 and y != 1 and y != n - 1:
            y = pow(y, 2, n)
            t <<= 1
        if y != n - 1 and (t & 1) == 0:
            return False
    return True

if __name__ == "__main__":
    N = int(input())
    print(sum(map(miller_rabin, [int(input()) for _ in range(N)])))

Measured memory_bytes: 11776