akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

int n;
double minimum;

using namespace std;

struct Data{
	char name[21];
	int self_weight,bearable_weight,index;
	bool FLG;
};

Data final_data[10];

void recursive(Data data[10],int sum,int index){

	if(index == n){
		double bunshi = 0,bunbo = 0,result;

		for(int i = 1; i <= n-1; i++){
			for(int k = n-1; k >= i; k--){
				if(data[k].index > data[k-1].index)swap(data[k],data[k-1]);
			}
		}


		for(int i = 0; i < n; i++)bunshi += (i+1)*data[i].self_weight;
		for(int i = 0; i < n; i++)bunbo += data[i].self_weight;
		result = bunshi/bunbo;

		if(result < minimum){
			minimum = result;
			for(int k = 0; k < n; k++)final_data[k] = data[k];
		}
		return;
	}

	bool tmpFLG;

	for(int i = 0; i < n; i++){
		if(data[i].FLG == false && data[i].bearable_weight >= sum){
			tmpFLG = true;
			for(int k = 0; k < n; k++){
				if(i != k && data[k].FLG == false && data[k].bearable_weight < sum + data[i].self_weight){
					tmpFLG = false;
					break;
				}
			}

			if(tmpFLG){
				Data new_data[10];
				for(int k = 0; k < n;k++)new_data[k] = data[k];
				new_data[i].FLG = true;
				new_data[i].index = index;
				recursive(new_data,sum+data[i].self_weight,index+1);
			}
		}
	}
}

int main(){

	Data data[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		minimum = 2000000000;

		for(int i = 0; i < n; i++){
			data[i].FLG = false;
			scanf("%s %d %d",data[i].name,&data[i].self_weight,&data[i].bearable_weight);
		}

		recursive(data,0,0);

		for(int i = 0; i < n; i++){
			printf("%s\n",final_data[i].name);
		}

	}

    return 0;
}

Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main()
{
	int n, w, d;
	while (cin >> n >> w >> d, n | w | d) {
		vector<P> v; v.push_back(P(w, d));
		for (int i = 0, p, s; i < n; i++) {
			cin >> p >> s;
			auto t = v[p - 1];
			v.erase(v.begin() + (p - 1));
			s %= (t.first + t.second) * 2;
			if (s < t.first) {
				if (s * 2 < t.first) {
					v.push_back(P(s, t.second));
					v.push_back(P(t.first - s, t.second));
				}
				else {
					v.push_back(P(t.first - s, t.second));
					v.push_back(P(s, t.second));
				}
			}
			else if (s < t.first + t.second) {
				s -= t.first;
				if (s * 2 < t.second) {
					v.push_back(P(t.first, s));
					v.push_back(P(t.first, t.second - s));
				}
				else {
					v.push_back(P(t.first, t.second - s));
					v.push_back(P(t.first, s));
				}
			}
			else if (s < t.first * 2 + t.second) {
				s -= t.first + t.second;
				if (s * 2 < t.first) {
					v.push_back(P(s, t.second));
					v.push_back(P(t.first - s, t.second));
				}
				else {
					v.push_back(P(t.first - s, t.second));
					v.push_back(P(s, t.second));
				}
			}
			else {
				s -= t.first * 2 + t.second;
				if (s * 2 < t.second) {
					v.push_back(P(t.first, s));
					v.push_back(P(t.first, t.second - s));
				}
				else {
					v.push_back(P(t.first, t.second - s));
					v.push_back(P(t.first, s));
				}
			}
		}
		sort(v.begin(), v.end(), [](P l, P r) {
			return l.first * l.second < r.first * r.second;
		});
		for (int i = 0; i < n + 1; i++) {
			cout << v[i].first * v[i].second << " \n"[i == n];
		}
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int N;
	int res = 1e5;
	cin >> N;
	for(int A = 1; A < N; A++) {
		int B = N-A;
		int a = A, b = B;
		int tmp = 0;
		while(a) {
			tmp += a % 10;
			a /= 10;
		}
		while(b) {
			tmp += b % 10;
			b /= 10;
		}
		res = min(res, tmp);
	}
	cout << res << endl;
	return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,t;
	cin >> n >> t;
	ll ans = 0;
	int lastTime = 0;
	cin >> lastTime;
	FOR(i,1,n){
		int ti;
		cin >> ti;
		ans += min(t, ti - lastTime);
		lastTime = ti;
	}
	ans += t;
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
a, b, c = [int(x) for x in input().split()]
import math
#a_ = math.sqrt(a)
#b_ = math.sqrt(b)
#c_ = math.sqrt(c)

if 4*a*b < (c-a-b)**2 and c-a-b>0:
  print('Yes')
else:
  print('No')

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


void dfs(int a, int p, const vector<vector<pair<int, int>>>& adj, vector<int>& color) {
        for (const auto b: adj[a]) {
                if (b.first == p) continue;
                if (b.second % 2 == 0) color[b.first] = color[a];
                else color[b.first] = 1 - color[a];
                dfs(b.first, a, adj, color);
        }
}


void _main() {
        int n; cin >> n;
        vector<vector<pair<int, int>>> adj(n + 1);
        for (int i = 1; i <= n - 1; i++) {
                int a, b, w; cin >> a >> b >> w;
                adj[a].emplace_back(b, w);
                adj[b].emplace_back(a, w);
        }

        vector<int> color(n + 1, -1);
        color[1] = 0;
        dfs(1, 0, adj, color);
        for (int i = 1; i <= n; i++) cout << color[i] << '\n';
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 12700
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

int main(){
  long long int N,K;
  std::cin >> N >> K;
  std::vector<long long int> A_arr(N), F_arr(N);
  for(long long int i = 0; i < N; i++) std::cin >> A_arr[i];
  for(long long int i = 0; i < N; i++) std::cin >> F_arr[i];

  std::sort(A_arr.begin(), A_arr.end());
  std::sort(F_arr.begin(), F_arr.end());

  long long int sa = 0;
  for(long long int i = 0; i < N; i++){
    sa += A_arr[i];
  }
  if(sa <= K){
    std::cout << 0 << std::endl;
    return 0;
  }

  long long int l=0, r=10000000000000;
  while(r-l > 1){
    long long int m = (l+r)/2;
    long long int nk = 0;
    for(long long int i = 0; i < N; i++){
      long long int f = F_arr[i];
      long long int a = A_arr[N-1-i];
      long long int req_a = m/f;
      if(req_a < a){
        nk += a-req_a;
      }
    }
    if(nk <= K) r = m;
    else l = m;
  }

  std::cout << r << std::endl;

  return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;
int main()
{
  long long X;
  cin >> X;
  
  long long ans = 0, money = 100;
  while (money < X)
  {
    money += money / 100;
    ++ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int MAX = 100010;
const int INFTY = 1<<21;
const int WHITE = 1;
const int BLACK = 2;
const int GRAY = 3;
vector<int> list[MAX];
int N;

vector<int> bfs(int s){
    vector<int> d(N,INFTY);
    queue<int> Q;
    d[s] = 0;
    Q.push(s);
    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        for(auto v : list[u]){
            if(d[v] > d[u] + 1){
                d[v] = d[u] + 1;
                Q.push(v);
            }
        }
    }
    return d;
}

vector<int> dijkstra(int s){
    vector<int> d(N,INFTY);
    vector<int> color(N, WHITE);
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > Q;

    d[s] = 0;
    color[s] = GRAY;
    Q.push({d[s], s});
    while(!Q.empty()){
        auto tmp = Q.top(); Q.pop();
        int u = tmp.second;
        color[u] = BLACK;
        
        if(d[u] < tmp.first) continue;

        for(auto v : list[u]){
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + 1){
                d[v] = d[u] + 1;
                color[v] = GRAY;
                Q.push({d[v],v});
            }
        }
    }
    return d;
}

int main(){
    cin >> N;
    if(N == 2){
        cout << "Snuke" << endl;
        return 0;
    }

    int a,b;
    for(int i=0;i<N-1;i++){
        cin >> a >> b;
        a--; b--;
        list[a].push_back(b);
        list[b].push_back(a);
    }

    vector<int> d_1 = dijkstra(0);
    vector<int> d_N = dijkstra(N-1);
    int count_1 = 0;
    int count_N = 0;
    for(int i=1;i<N-1;i++){
        if(list[i].size() == 0){  // i-th node is a leaf
            int j = list[i][0];  // j is i-th's parent
            if(d_1[j] > d_N[j]){
                count_N++;
            }else{
                count_1++;
            }
        }else{
            if(d_1[i] > d_N[i]){
                count_N++;
            }else{
                count_1++;
            }
        }
    }

    if(count_1 > count_N){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }
    return 0;
}

Measured memory_bytes: 7288
#include <stdio.h>

int width,height;
char map[20][21];

int tansaku(int x,int y) {
	int result=1;
	if(x<0 || x>=width || y<0 || y>=height)return 0;
	if(map[y][x]=='#')return 0;
	map[y][x]='#';
	result+=tansaku(x-1,y);
	result+=tansaku(x+1,y);
	result+=tansaku(x,y-1);
	result+=tansaku(x,y+1);
	return result;
}

int main(void) {
	int i,j;
	int sx,sy;
	while(1) {
		scanf("%d%d",&width,&height);
		if(width==0 && height==0)break;
		for(i=0;i<height;i++) {
			scanf("%s",map[i]);
			for(j=0;j<width;j++) {
				if(map[i][j]=='@'){sx=j;sy=i;}
			}
		}
		printf("%d\n",tansaku(sx,sy));
	}
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,m;
  cin>>n>>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  }

  vector<int> ans(n,-1);
  queue<pair<int,int>> que;
  que.emplace(0,-2);
  while(!que.empty()){
    auto [v,p] = que.front();
    que.pop();
    if(ans[v]!=-1)continue;
    ans[v] = p;
    for(auto to:adj[v]){
      if(to==p)continue;
      if(ans[to]!=-1)continue;
      que.emplace(to,v);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<n;++i)cout<<ans[i]+1<<endl;

}

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

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    int br0=0,br1=0;
    cin >> s;
    for (int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
            br0++;
        else
            br1++;
    }
    cout << 2*min(br0,br1);
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main() {
    int X, P; cin >> X >> P;
    int a = (X + 1) / 2;
    double p = P / 100.0;
    cout << fixed << setprecision(9) << 1 / p * a << endl;
    return 0;
}

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

int n;

struct node
{
	int id, k, d, pid;
	int* cid;
	string type;
}N[100005];

void GetDepth(node& GN)
{
	GN.d = 0;
	node temp = GN;

	while (temp.pid != -1)
	{
		GN.d++;
		temp = N[temp.pid];
	}
}

void GetType(node& GN)
{
	if (GN.pid == -1)
		GN.type = "root";
	else if (GN.k == 0)
		GN.type = "leaf";
	else
		GN.type = "internal node";
}

void print()
{
	for (int i = 0; i < n; i++)
	{
		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";

		if (N[i].k != 0)
		{
			for (int j = 0; j < N[i].k - 1; j++)
				cout << N[i].cid[j] << ", ";
			cout << N[i].cid[N[i].k - 1];
		}

		cout << "]" << endl;
	}	
}

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

	int place;
	cin >> n;
	
	for (int i = 0; i < n; i++)
		N[i].pid = -1;
	
	for (int i = 0; i < n; i++)
	{
		cin >> place;
		N[place].id = place;
		cin >> N[place].k;

		if (N[place].k > 0)
			N[place].cid = (int*)malloc(sizeof(int) * N[place].k);

		for (int j = 0; j < N[place].k; j++)
		{
			cin >> N[place].cid[j];
			for (int t = 0; t < n; t++)
			{
				if (N[place].cid[j] == t)
				{
					N[t].pid = N[place].id;
					break;
				}	
			}
		}			
	}

	for (int i = 0; i < n; i++)
		GetDepth(N[i]);

	for (int i = 0; i < n; i++)
		GetType(N[i]);	

	print();

	return 0;
}


Measured memory_bytes: 11404
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 0) {
        cout << "Positive" << endl;
    } else if (a == 0) {
        cout << "Zero" << endl;
    } else {
        if (b >= 0) {
            cout << "Zero" << endl;
        } else if ((abs(a) - abs(b) + 1) % 2 == 0) {
            cout << "Positive" << endl;
        } else {
            cout << "Negative" << endl;
        }
    }
    return 0;
}

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

#define BUF_SIZE 1000000

int main(void) {
  char line[BUF_SIZE];
  FILE *fp = stdin;
  int num;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d", &num);

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  int i;
  int hist[100001] = {0};
  int ma = 0;
  int mi = 100001;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    int n = strtol(tmp, NULL, 10);
    hist[n]++;
    if(n > ma) ma=n;
    if(n < mi) mi=n;
    tmpbuf = NULL;
  }
  int max = 0;
  for(i = mi; i <= ma; i++) {
    int change = hist[i];
    if(i-1>=0) change += hist[i-1];
    if(i+1<=100000) change += hist[i+1];
    if(change > max) max = change;
  }

  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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


signed main() {
	string A, B;
	cin >> A >> B;

	int lenA, lenB;

	lenA = A.length();
	lenB = B.length();

	int ans;

	bool flag = 0;
	if (lenA > lenB) ans = 1;
	else if (lenA < lenB) ans = -1;
	else {
		REP(i, lenA) {
			if (A[i] > B[i]) {
				ans = 1;
				flag = 1;
				break;
			}
			else if (A[i] < B[i]) {
				ans = -1;
				flag = 1;
				break;
			}
		}

		if (flag == 0) ans = 0;
	}


	if (ans == 0) cout << "EQUAL" << endl;
	else if (ans == 1) cout << "GREATER" << endl;
	else cout << "LESS" << endl;

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int main(){
    int a,p;
    cin>>a>>p;
    int ringo=a*3+p;
    int res=ringo/2;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <climits>
#include <functional>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
#define dbg(...) fprintf(stderr,__VA_ARGS__)
struct range{
	int e,b=0,s=1;range(int b,int e,int s):e(e),b(b),s(s){} range(int b,int e): e(e), b(b){} range(int e):e(e){}
	struct it{int v,s; it(int v,int s):v(v),s(s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

_T using V = vector<T>;

struct E {
	int t, d;
};

int main() {
	int n {in}, e {in};
	V<V<E>> G(n);
	times (i, e) {
		int s {in};
		G[s].push_back({in, in});
	}
	V<V<int>> d(1 << n, V<int>(n, -1));
	int inf {INT_MAX / 2};
	function<int(int, int)> rec = [&] (int S, int v) {
		if (d[S][v] >= 0)
			return d[S][v];
		if (S == (1 << n) - 1 && !v)
			return d[S][v] = 0;
		int r {inf};
		for (E u: G[v])
			if (!(S >> u.t & 1))
				r = min(r, rec(S | 1 << u.t, u.t) + u.d);
		return d[S][v] = r;
	};
	int r {rec(0, 0)};
	outl(r > inf / 2 ? -1 : r);
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
const int maxn = 4e5+5;
const int MOD = 1e9+7;
#define mod(x) x % MOD
#define INF 0x3f3f3f3f

vector<int> G[maxn];
int tot;
int ans;
bool vis[maxn];
int dp[maxn];

void dfs(int s){
    vis[s] = 1;
    if(G[s].size() == 0){
        dp[s] = 0;
        return;
    }
    for(int i = 0;i < G[s].size();i++){
        if(vis[G[s][i]] == 1){
            dp[s] = max(dp[s], dp[G[s][i]] + 1);
        }
        else{
            dfs(G[s][i]);
            dp[s] = max(dp[s], dp[G[s][i]] + 1);
        }
    }
}

int main(){
    int n = 0, m = 0;
    while(~scanf("%d %d", &n, &m)){
        for(int i = 1;i <= m;i++){
            int x, y = 0;
            scanf("%d %d", &x, &y);
            G[x].push_back(y);
        }
        //printf("%d\n",ans);
        for(int i = 1;i <= n;i++){
            if(vis[i] == 0){
                dfs(i);
            }
        }
        for(int i = 1;i <= n;i++){
            ans = max(ans, dp[i]);
        }
        printf("%d\n", ans);
    }    
    return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
#define int long long
using namespace std;


int K;
vector<int> cand;//すぬけ数候補
vector<int> ans;//全てのすぬけ数の集合


//問題文のS(n)
int S(int x){
    int res = 0;
    while(x > 0){
        res += x%10;
        x /= 10;
    }
    return res;
}


//問題文のn/S(n)
double g(int x){
    return (double)x/S(x);
}


signed main(){
    cin >> K;

    //候補の数を列挙
    int p10 = 1, n = 0;
    for(int i = 0;i <= 12;i++){
        for(int j = 1;j <= 999;j++) if(j*p10+n <= 1e15-1) cand.push_back(j*p10+n);
        n *= 10;
        n += 9;
        p10 *= 10;
    }

    //降順ソートしておく
    sort(begin(cand), end(cand), greater<int>());
    //複数存在している値を１つだけにする
    cand.erase(unique(begin(cand), end(cand)), end(cand));

    //cand[0]=999...999(9が15並ぶ)だからすぬけ数
    ans.push_back(cand[0]);
    double m = g(cand[0]);
    for(int i = 1;i < cand.size();i++)
        if(g(cand[i]) <= m) m = g(cand[i]), ans.push_back(cand[i]);

    //降順になっているので逆転させる
    reverse(begin(ans), end(ans));

    for(int i = 0;i < K;i++) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<vector<int>> li(m,vector<int>(n,0));
  rep(i,m){
    int k;cin >> k;
    rep(j,k){
      int x;cin >> x;x--;
      li[i][x] = 1;
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p[i];

  int res=0;
  rep(S,(1<<n)){
    bool f = true;
    rep(i,m){
      int cnt=0;
      rep(j,n){
	if(((S>>j)&1)&li[i][j]) cnt++;
      }
      if(cnt%2!=p[i]) f=false;
    }
    if(f) res++;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a,b,c,i,count=0;
	scanf("%d %d", &a, &b);
	for (i = 0;i < a;i++) {
		scanf("%d", &c);
		if (c >= b) {
			count++;
		}
	}
	printf("%d", count);
}

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

using namespace std;

#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__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

const ll MOD = 1e9 + 7;

void solve()
{
	ll n; cin >> n;
	ll res = 1;
	for (int i = 0; i < n; ++i)
	{
		res = ((res * (i + 1)) % MOD);
	}
	cout << res;
}

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

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

const int MAXN = 2e5 + 1;
ll N, K;
ll A[MAXN];

bool chk(ll l) {
    ll totalCut = 0;
    rep(i, N) {
        totalCut += (A[i] + l - 1) / l - 1;
    }
    return totalCut <= K;
}

int main() {
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    ll ans = -1;
    ll lo = 1, hi = 1e9;
    while(lo <= hi) {
        ll mid = (lo + hi) / 2;
        if(chk(mid)) {
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5040
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int arr[][] = new int[N+1][3];
		
		for(int i = 1;i<=N;i++) {
			for(int j =0;j<3;j++) {
				arr[i][j] = scan.nextInt();
			}
		}
		System.out.println(maxPoint(arr,N));
	}

	private static int maxPoint(int[][] arr, int n) {
		int dp[][] = new int[n+1][3];
		dp[1][0] = arr[1][0];
		dp[1][1] = arr[1][1];
		dp[1][2] = arr[1][2];
		
		for(int i=2;i<=n;i++) {
			dp[i][0] = arr[i][0] + Math.max(dp[i-1][1],dp[i-1][2]);
			dp[i][1] = arr[i][1] + Math.max(dp[i-1][0],dp[i-1][2]);
			dp[i][2] = arr[i][2] + Math.max(dp[i-1][0],dp[i-1][1]);
		}
		
		
		return Math.max(dp[n][0],Math.max(dp[n][1],dp[n][2]));
	}
	
}


Measured memory_bytes: 97556
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	bool jud=true;
	if(n%2) jud=false;
	else{
		REP(i,n/2){
			if(s[i]!=s[i+n/2]){
				jud=false;
				break;
			}
		}
	}
	
	cout<<((jud)?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];
    for(int i=0;i<n;i++){
      s[i] = sc.next();
    }
    int ans = 1;
    
    Arrays.sort(s);
    for(int i=1;i<n;i++){
      if(!s[i-1].equals(s[i]))
         ans += 1;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 69956
import java.util.Scanner;

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

        String contest = scanner.next().trim();

        if("ABC".equals(contest)){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 26952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        String word = in.next();
        StringBuilder x = new StringBuilder();
        for (int i = 0; i < word.length(); i++) x.append("x");
        out.println(x);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 22612
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int r = in.nextInt();

        List<Integer> rs = new ArrayList<>();
        ;
        for (int i = 0; i < r; i++) {
            rs.add(in.nextInt() - 1);
        }

        int[][] d = new int[n][n];
        int INF = 1 << 29;
        for (int i = 0; i < n; i++) {
            Arrays.fill(d[i], INF);
        }

        for (int i = 0; i < m; i++) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            int c = in.nextInt();

            d[a][b] = d[b][a] = c;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (d[j][k] > d[j][i] + d[i][k]) {
                        d[j][k] = d[j][i] + d[i][k];
                    }
                }
            }
        }

        Deque<Node> deque = new ArrayDeque<>();
        List<Integer> firstState = Collections.emptyList();
        deque.push(new Node(firstState, rs));
        int min = INF;
        while (!deque.isEmpty()) {
            Node node = deque.poll();

            if (node.state.size() == r) {
                int tmp = 0;
                for (int i = 0; i < r - 1; i++) {
                    int a = node.state.get(i);
                    int b = node.state.get(i + 1);
                    if (d[a][b] != INF) {
                        tmp += d[a][b];
                    }
                }
                min = (tmp != 0) ? Math.min(min, tmp) : min;
            }

            for (Integer element : node.candidate) {
                List<Integer> nextState = new ArrayList<>(node.state);
                nextState.add(element);

                List<Integer> candidate = new ArrayList<>(node.candidate);
                candidate.remove(element);

                deque.add(new Node(nextState, candidate));
            }
        }
        out.println(min);
    }
}

class Node {
    List<Integer> state;
    List<Integer> candidate;

    Node(List<Integer> state, List<Integer> candidate) {
        this.state = state;
        this.candidate = candidate;
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 52756
from sys import stdout

cs = {
    1: [None] + list("abcde"),
    2: [None] + list("fghij"),
    3: [None] + list("klmno"),
    4: [None] + list("pqrst"),
    5: [None] + list("uvwxy"),
    6: [None] + list("z.?! "),
}

while True:
    try:
        it = iter(raw_input().strip())
    except EOFError:
        break

    try:
        r = c = None
        s = []
        while True:
            r = int(it.next())
            c = int(it.next())
            s += [cs[r][c]]
            r = c = None
    except KeyError:
        stdout.write("NA\n")
    except IndexError:
        stdout.write("NA\n")
    except StopIteration:
        if not r and not c:
            stdout.write(''.join(s) + "\n")
        else:
            stdout.write("NA\n")
        continue

Measured memory_bytes: 4260
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<time.h>
#include<string>
#include<cmath>
#include<stack>
#include<map>
#include<set>
//ios::sync_with_stdio(false);
#define ull unsigned long long
#define endl "\n"
#define int long long
#define double long double
using namespace std;
#define PI  3.1415926535898
#define eqs 1e-17
const long long max_ = 5000 + 7;
//haxi = 137， haximod = 998244353;
const int mod = 998244353;
const int inf = 1e9 + 7;
const long long INF = 1e18;
int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') {
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * f;
}
inline void write(int x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}
inline int min(int a, int b) {
	return a < b ? a : b;
}
inline int max(int a, int b) {
	return a > b ? a : b;
}
int c[3][max_], n, m;
int low_bit(int x) {
	return (x&(-x));
}

void change(int x, int value,int ind) {
	while (x <= n) {
		c[ind][x] += value;
		x = x + low_bit(x);
	}
}

int sum_(int x,int ind) {
	if (x <= 0)return 0;
	//算1到x的总和
	int ans = 0;
	while (x != 0) {
		ans += c[ind][x];
		x = x - low_bit(x);
	}
	return ans;
}
char node[max_];
inline int getnum(char ch) {
	if (ch == 'R')return 0;
	if (ch == 'G')return 1;
	return 2;
}
inline int shengxia(int a, int b) {
	if (a != 0 && b != 0)return 0;
	if (a != 1 && b != 1)return 1;
	if (a != 2 && b != 2)return 2;
}
signed main() {
	cin >> n;
	cin >> node + 1;
	//R 0
	//G 1
	//B 2
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		change(i, 1, getnum(node[i]));
		for (int j = 1; j < i; j++) {
			if (node[i] != node[j]) {
				int t = shengxia(getnum(node[i]), getnum(node[j]));
				int v = sum_(j - 1, t);
				int v2 = sum_(j - i + j, t), v3 = sum_(j - i + j - 1, t);
				ans += v - (v2 - v3);
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3728
import math

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

A_max = max(A)

D = [i for i in range(1+A_max)]

for i in range(2,1+int(A_max**(1/2))):
    if D[i] == i:
        for j in range(2,1+A_max//i):
            D[i*j] = i

prime = {}

for i in range(2,1+A_max):
    if D[i] == i:
        prime[i] = 0

for a in A:
    X = []
    aa = a
    while aa > 1:
        X.append(D[aa])
        aa //= D[aa]
    
    X = set(X)

    for x in X:
        prime[x] += 1

if all([v<=1 for v in prime.values()]):
    print('pairwise coprime')

else:
    g = A[0]
    for i in range(1,N):
        g = math.gcd(g,A[i])
    if g == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Measured memory_bytes: 220136
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
 
int main()
{
    int num;
    int jump;
    cin >> num >> jump;
    vector<int> v;
    int tmp;
    for(int i=0;i<num;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    for(int i=0;i<=jump+10;i++){
        v.push_back(1000000);
    }
    array<int,110000> ans;
    for(int i=0;i<100010;i++){
        ans[i]=-1;
    }
    ans[0]=0;
    for(int i=0;i<num-1;i++){
        for(int j=1;j<=jump;j++){
            if(ans[i+j]==-1){
                ans[i+j]=ans[i]+abs(v[i+j]-v[i]);
            }else{
                ans[i+j]=min(ans[i+j],ans[i]+abs(v[i+j]-v[i]));
            }
        }
    }
    cout << ans[num-1] << endl;
    return 0;
}

Measured memory_bytes: 1144
#if 0



#endif // 0

#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = (int) 1e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;
int N,W;
int dp[MAXN];

void work(){
    while(~scanf("%d%d",&N,&W)){
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=N;i++){
            int v,w; scanf("%d%d",&v,&w);
            for(int j=w;j<=W;j++){
                dp[j]=max(dp[j],dp[j-w]+v);
            }
        }
        printf("%d\n",dp[W]);
    }
}

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



Measured memory_bytes: 3624
#include <stdio.h>


int main(){
	int k,a,b;
	
	scanf("%d",&k);
	scanf("%d%d",&a,&b);
	
	while(a<=b){
		if(a%k == 0){
			puts("OK");
			return 0;
		}
		a++;
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    long money = 1000;
    long stock = 0;
    for(int i = 0;i < n;i++){
          cin >> a[i];
    }
    
    for(int i = 0;i < n - 1;i++){
          if(a[i] < a[i + 1]){
                stock = money / a[i];
                money -= a[i] * stock;
                money += stock * a[i + 1];
          }
    }
    cout << money << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
 
 
void solve(int N) {
    vector<int> v(401);
    int max_len = 0;
    for (int i = 0; i < N * (N-1) / 2; i++) {
        int j; cin >> j; v[j]++;
        max_len = max(max_len, j);
    }
 
    set<vector<int>> ans;
    for (int i = 0; i < (1<<(N-1)); i++) {
        vector<int> s;
        auto count = v;
        bool flag = false;
 
        if (i % 2) s.push_back(max_len);
        else s.push_back(0);
 
        int t = max_len;
        int j = 0;
        while (t) {
            if (!count[t]) {
                t--;
                continue;
            }
 
            int position = (i & (1 << j)) ? max_len - t : t;
            for (auto k : s) {
                int dist = abs(k - position);
                if (count[dist]) count[dist]--;
                else {
                    flag = true;
                    break;
                }
            }
            if (flag) break;
            s.push_back(position);
            j++;
        }
        if (flag) continue;
        sort(s.begin(), s.end());
        vector<int> ad;
        for (int i = 0; i < N-1; i++) ad.push_back(s[i+1] - s[i]);
        ans.insert(ad);
    }
 
    for (auto avec: ans) {
        for (int i = 0; i < N-1; i++) {
            if (i < N-2) cout << avec[i] << " ";
            else cout << avec[i] << endl;
        }
    }
     
    cout << "-----" << endl;
}
 
int main() {
    int N;
    while (cin >> N, N) {
        solve(N);
    }
 
 
    return 0;
}

Measured memory_bytes: 3144
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = IntArray(n) { readLine()!!.toInt() }
  var ans = 0L
  var p = 1
  for (i in 0 until n) {
    val c = (a[i] - 1) / p
    ans += c
    if (p == 1 || p == a[i]) p++
  }
  println(ans)
}


Measured memory_bytes: 39356
#include <bits/stdc++.h>
using namespace std;
#define int long long
  queue<pair<int,int>> que;
signed main() {
  string s;
  cin>>s;
  int k[s.size()];
  k[s.size()-1]=1;
  for(int i=s.size()-2;i>=0;i--){
    k[i]=2*k[i+1];
  }
  int ans=0,a;
  for(int i=0;i<s.size();i++){
    a=1;
    for(int j=0;j<s.size()-i-1;j++){
      ans+=(s[i]-'0')*a*k[j]/2;
      a*=10;
    }
    ans+=(s[i]-'0')*a*k[s.size()-i-1];
  }
  cout<<ans;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<string> subs;
  string m;
  m=s.at(0);
  subs.push_back(m);
  string a;
  for(int i=1;i<s.size();){
      a += s.at(i);
      if(a!=m){
      subs.push_back(a);
      m = a;
      a = "";
      }
    i++;
  }
  cout << subs.size() << endl;
}

Measured memory_bytes: 10996
n = STDIN.gets.chomp.to_i
s = STDIN.gets.chomp
 
cs = s.chars.uniq
rs = cs.map {|c|
  if s.index(c) == s.rindex(c)
    nil
  else
    (s.index(c)..s.rindex(c))
  end
}.compact
 
puts n.times.map {|i|
  rs.select {|r| r.include?(i+1) }.count
}.max

Measured memory_bytes: 1788
import heapq

n, m = map(int, input().split())
dic = {}
for i in range(n):
    ai, bi = map(int, input().split())
    if ai in dic:
        dic[ai].append(bi)
    else:
        dic[ai] = [bi]

for key in dic.keys():
    dic[key] = sorted(dic[key])

ans = 0
hp = []
heapq.heapify(hp)
for i in range(1, m+1):
    if i in dic:
        heapq.heappush(hp, (-dic[i].pop(), i))
    if hp != []:
        maxi = heapq.heappop(hp)
        ans += -maxi[0]
        if dic[maxi[1]] != []:
            heapq.heappush(hp, (-dic[maxi[1]].pop(), maxi[1]))
print(ans)

Measured memory_bytes: 84696
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  cout << min({(A % 2) * (B * C), (B % 2) * (A * C), (C % 2) * (B * A)}) << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  intl X,Y;
  cin >>X>>Y;
  intl money = 0;
  if(X == 1){
    money +=300000;
  }
  if(X==2){money += 200000;}
  if(X==3){money += 100000;}
  if(Y == 1){
    money +=300000;
  }
  if(Y==2){money += 200000;}
  if(Y==3){money += 100000;}
  if(X==1 &&Y==1){money += 400000;}
  cout <<money;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int i,j;
    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
            cout<<i<<"x"<<j<<"="<<i*j<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 1112
n,m = list(map(int, input().split()))
parents = [-1] * (n + 1)
def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x, y = y, x

    parents[x] += parents[y]
    parents[y] = x

def same(x, y):
    return find(x) == find(y)

for _ in range(m):
    a,b = list(map(int, input().split()))    
    union(a,b)

print(-min(parents[1:]))

Measured memory_bytes: 80780
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define hash hash123s
#define index ind123
 
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepx(i, x, n) for (int i = (n) - 1; i >= x; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
#define rep(i, n) for (int i = 0; i < (n); i++)
 
template<class t>
void print(t x, int end = 1) {
	cout << x << (end == 1 ? "\n" : " ");
}
 
template<class T>
void print(const vector<T> &v, int end = 1) {
	rep(i, (int) v.size()) {
		print(v[ i ], 0);
	}
	cout << endl;
}

template<class T>
void print(const int *a, int sz, int end = 1) {
	rep(i, sz) {
		print(a[ i ], 0);
	}
	cout << endl;
}
 
template<class T>
void print(const set<T> &v, int end = 1) {
	for(auto to = v.begin(); to != v.end(); to++) {
		print(*to);
	}
	cout << endl;
}
 
template<class T>
void print(const map<T, T> &v, int end = 1) {
	for(auto to : v) {
		print(to.fi, 0);
		cout << ": ";
		print(to.se);
	}
}
 
template<class t>
void errprint(t x, int end = 1) {
	cerr << x << (end == 1 ? "\n" : " ");
}
 
#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif

bool solve();
 
clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
 
int main() {
	// freopen("substring.in", "r", stdin);
	// freopen("substring.out", "w", stdout);
 
	ios_base::sync_with_stdio(false);
	if(solve()) {
		print("Possible");
	} else {
		print("Impossible");
	}
}
 
/* ========== actual code starts here ========== */

bool solve() {
	int n, mx = 0, mn = 1e9;
	cin >> n;
	map<int, int> in;
	rep(i, n) {
		int x;
		cin >> x;

		in[ x ]++;
		mx = max(mx, x);
		mn = min(mn, x);
	}

	int possmn = (mx + 1) / 2;
	if(mx % 2 == 0) {
		if(in.find(possmn) == in.end()) re false;
		in[ possmn ]--;
		if(!in[ possmn ]) in.erase(possmn);
		++possmn;
	}

	repx(i, possmn, mx + 1) {
		rep(j, 2) {
			if(in.find(i) == in.end()) re false;
			in[ i ]--;
			if(!in[ i ]) in.erase(i);
		}
	}

	if(in.empty() || in.begin()->fi > (mx + 1) / 2) {
		re true;
	}
	re false;
}

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

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

int f[N];

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,x=0;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i],x^=a[i];
        for(int i=0;i<n;i++)cout<<(a[i]^x)<<" ";cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 5088