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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

const int MAX_N = 100005;
int par[MAX_N], tree_rank[MAX_N];
void init_union_find(int n){
	for(int i=0; i<n; i++){
		par[i] = i;
		tree_rank[i] = 0;
	}
}

int root(int x){
	return par[x] == x ? x : par[x] = root(par[x]);
}

bool same(int x, int y){
	return root(x) == root(y);
}

void unite(int x, int y){
	x = root(x);
	y = root(y);
	if(x == y) return;

	if(tree_rank[x] < tree_rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(tree_rank[x] == tree_rank[y]) tree_rank[x]++;
	}
}

const int MAX_E = 1000000;
struct edge{int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

edge es[MAX_E];
int n, E;

int kruskal(){
	sort(es, es + E, comp);
	init_union_find(n);
	int res = 0;
	for(int i=0; i<E; i++){
		edge e = es[i];
		if(!same(e.u, e.v)){
			//printf("%d %d %d connect\n", e.u, e.v, e.cost);
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

typedef pair<int, int> P;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	cin >> n;
	vector< P >  p1, p2;
	for(int i=0; i<n; i++){
		int x, y;
		cin >> x >> y;
		p1.pb(make_pair(x, i));
		p2.pb(make_pair(y, i));
	}

	sort(p1.begin(), p1.end());
	sort(p2.begin(), p2.end());

	E = 0;
	for(int i=0; i<n-1; i++){
		int x1 = p1[i].first;
		int x2 = p1[i+1].first;
		int i1 = p1[i].second;
		int i2 = p1[i+1].second;

		//printf("%d : %d %d %d\n", E, x1, x2, x2 - x1);
		es[E] = edge{i1, i2, x2 - x1};
		E++;
	}

	for(int i=0; i<n-1; i++){
		int x1 = p2[i].first;
		int x2 = p2[i+1].first;
		int i1 = p2[i].second;
		int i2 = p2[i+1].second;

		//printf("%d : %d %d %d\n", E, x1, x2, x2 - x1);
		es[E] = edge{i1, i2, x2 - x1};
		E++;
	}

	cout << kruskal() << endl;
	
	return 0;
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> t, s;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    t.push_back(x+y);
    s.push_back(x-y);
  }
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  cout << max(s[n-1]-s[0],t[n-1]-t[0]) << endl;
  return 0;
}


Measured memory_bytes: 6636
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-1000000001,min=1000000001,ans=0,sum=0;
    string s,t;
    cin >> s;
    //VL a(n);
    if(s=="MON")
        cout << 6 << endl;
    else if(s=="TUE")
        cout << 5 << endl;
    else if(s=="WED")
        cout << 4 << endl;
    else if(s=="THU")
        cout << 3 << endl;
    else if(s=="FRI")
        cout << 2 << endl;
    else if(s=="SAT")
        cout << 1 << endl;
    else if(s=="SUN")
        cout << 7 << 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 < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  map<string,ll> m;
  rep(i,N){
    string s;cin>>s;
    m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
  cout<<"WA x "<<m["WA"]<<endl;
  cout<<"TLE x "<<m["TLE"]<<endl;
  cout<<"RE x "<<m["RE"]<<endl;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<int> A(n*n,0);

    for(int i=0; i<n; ++i){
        int u,k;
        cin >> u >> k;
        for(int j=0; j<k; j++){
            int v;
            cin >> v;
            A[n*(u-1) + (v-1)] = 1;
        }
    }

    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            cout << A[i*n+j];
            if(j<n-1){
                cout << " ";
            } else {cout << endl;}
        }
    }
    return 0;
}


Measured memory_bytes: 3128
from collections import Counter
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(1, N):
	A[i] += A[i-1]
c=Counter([a%M for a in A])
ans = c[0] if 0 in c else 0
for v in [x for x in c.values() if x > 1]:
	ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 63384
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,h,a,b,c,d;
vector<int>g[444];
int in[444],out[444];
void addedge(int u,int v)
{
	in[v]++;out[u]++;
	g[u].pb(v);
	g[v].pb(u);
}
bool vis[444],ok;
void dfs(int x)
{
	vis[x]=1;
	for(int i=0;i<(int)g[x].size();i++)
		if(!vis[g[x][i]])
			dfs(g[x][i]);
	if(in[x]!=out[x])ok=1;
}
int main()
{
	get2(n,h);
	for(int i=1;i<=n;i++)
	{
		get2(a,b);
		get2(c,d);
		int l,r;
		if(c==0)l=a;else l=-c;
		if(d==0)r=-b;else r=d;
		addedge(l+h,r+h);
	}
	for(int i=1;i<=h;i++)
	{
		if(out[h-i]>in[h-i]||in[h+i]>out[h+i])
		{
			puts("NO");
			return 0;
		}
	}
	for(int i=0;i<h+h;i++)
	{
		if(g[i].size()&&!vis[i])
		{
			ok=0;
			dfs(i);
			if(!ok)
			{
				puts("NO");
				return 0;
			}
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if ((a <= b && a+w >= b) || (b <= a && b+w >= a))cout << 0 << endl;
	else if(a+w <= b) cout << abs(b-a-w) << endl;
	else if (b + w <= a) cout << abs(a - b - w) << endl;
	return 0;
}

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

int main(){
    int n,m;
    int result = 0;
    scanf("%d %d",&n,&m);
    result = (n*(n - 1) / 2) + (m*(m - 1) / 2);
    printf("%d",result);
    return 0;
}


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

using namespace std;
int main(){
    string s;
    cin>>s;
    int K;
    cin>>K;
    vector<string>ss;
    for(int i=0; i<s.size(); i++){
        int j=1;
        while(j<=5 && i+j<s.size()+1){
            ss.push_back(s.substr(i,j));
            j++;
        }
    }
    sort(ss.begin(),ss.end());
    ss.erase(unique(ss.begin(),ss.end()),ss.end());
    cout<<ss[K-1];

    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int ans=0;int flag=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++){
        flag=0;
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(arr[i]+arr[j]<=arr[k]){
                    flag=1;
                    break;
                }else ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char s[200001];

int main(void) {
	size_t N, M;
	char A[50][51], B[50][51];

	scanf("%zu %zu\n", &N, &M);
	for (size_t i = 0; i < N; i++) {
		scanf("%s\n", A[i]);
	}
	for (size_t i = 0; i < M; i++) {
		scanf("%s", B[i]);
		if (i < M - 1) {
			scanf("\n");
		}
	}

	bool found = false;

	for (size_t rowOffset = 0; rowOffset <= N - M; rowOffset++) {
		for (size_t colOffset = 0; colOffset <= N - M; colOffset++) {
			bool matched = true;
			for (size_t row = 0; row < M; row++) {
				for (size_t col = 0; col < M; col++) {
					if (A[rowOffset + row][colOffset + col] != B[row][col]) {
						matched = false;
						break;
					}
				}
			}

			if (matched) {
				found = true;
				break;
			}
		}
	}

	puts(found ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long,long long>;

ll gcd(ll a,ll b,ll c){
	while(true){
		if(a < b)swap(a,b);
		if(!b)break;
		a %= b;
	}
	ll d = a;
	while(true){
		if(c < d)swap(c,d);
		if(!d)break;
		c %= d;
	}
	return c;
}

int main(){
	ll k; cin >> k;
	ll ans = 0;
	rep(i,k){
		rep(j,k){
			rep(l,k)ans += gcd(i+1,j+1,l+1);
		}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

struct coor {
	int x, y, h;
	coor() {}
	coor(int x, int y, int h = -1) :x(x), y(y), h(h) {}
	const bool operator<(coor l) const { return h > l.h; } // 先頭にh!=0が来るように
};

int main() {

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

	int N;
	cin >> N;

	vector<coor> data(N);
	for (int i = 0; i < N; i++) cin >> data[i].x >> data[i].y >> data[i].h;
	sort(data.begin(), data.end());

	vector<coor> tmp;
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {

			int H = data[0].h + abs(data[0].x - X) + abs(data[0].y - Y);
			bool flag = true;
			for (int i = 0; i < N; i++) {

				if (max(H - abs(data[i].x - X) - abs(data[i].y - Y), 0) != data[i].h) {
					flag = false;
					break;
				}

			}

			if (flag) {
				cout << X << " " << Y << " " << H << "\n";
				return 0;
			}

		}
	}
}

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define delete

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

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

    int x;
    cin >> x;

    if (x == 0) cout << 1 << endl;
    else cout << 0 << endl;


    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}

signed main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3656
def median_low(A):
    A.sort()
    b=A
    n = len(A)
    if n%2==1:
        med =b[n//2]
    else:
        x=b[n//2-1]
        y=b[n//2]
        med=(x+y)/2
        if med!=int(med):
            med=x
        else:
            med=int(med)
    return med


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

A = [v-i-1 for i,v in enumerate(A)]
x = median_low(A)

print(sum(abs(v - x) for v in A))



Measured memory_bytes: 25200
import sys
import itertools
#import resource
#xrange = lambda stop: iter(itertools.count().next, stop)
#sys.setrecursionlimit(1000000)
#sys.setrecursionlimit(10 ** 13)
n = int(input())

chars ={1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}

if n <= 26:
    print(chars[n])
    sys.exit()


ans = []
while True:
    n -= 1
    ans.append(chr(ord("a") + n % 26))
    n //= 26
    if n <= 0:
        break
for i in range(len(ans)):
    print(ans[-i-1], end="")

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n,q;
	cin>>n>>q;
	vector<vector<long long>> kankei(n+1);
	vector<long long> point(n+1,0);
	vector<long long> button(n+1,0);

	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		kankei.at(a).push_back(b);
		kankei.at(b).push_back(a);
	}

	for(int i=0;i<q;i++){
		int p,x;
		cin>>p>>x;
		button.at(p)+=x;
	}

	map<long long,bool> seen;
	queue<long long> que;
	seen[1]=true;
	que.push(1);

	while(!que.empty()){
		long long now=que.front();
		que.pop();
		point.at(now)+=button.at(now);

		for(auto next:kankei.at(now)){
			if(seen.count(next)) continue;

			point.at(next)+=point.at(now);
			seen[next]=true;
			que.push(next);
		}
	}

	for(int i=1;i<=n;i++){
		cout<<point.at(i);
		if(i==n) cout<<endl;
		else cout<<" ";
	}

	return 0;
}


Measured memory_bytes: 31984
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;
    cin>>n;
    int h[n];
    for(int i = 0;i<n;i++) cin >> h[i];
    int sai = h[0];
    //cout<<sai;
    int soko;
    int ido=0;
    int saido = 0;
    for(int i = 1;i<n;i++){
      //if(i == 0) continue;
      if(sai >= h[i]){
        ido += 1;
        sai = h[i];
        if(ido >= saido){
          saido = ido;
        }
      }
      else {
        sai = h[i];
        ido = 0;
      }
    }
    cout<< saido;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int len = s.length();
    for (int i = 0; i < len; i++) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 512
N = int(input())
S = input()

single_flag = [False]*10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()

for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(s)
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True

tmp = 0
for v in ans.values():
    tmp += len(v)
print(tmp)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll ans = 0;
    ans += min(k,a);
    k -= min(k,a);
    k -= min(k,b);
    ans -= max(0ll, k);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3536
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

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

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

from collections import deque
        
n = int(input())
uf = UnionFind(n)
g = [[] for i in range(n)]
cnt = [0] * n
ans = [0] * (n - 1)

for i in range(n - 1):
    a, b = map(lambda x:int(x) - 1, input().split())
    uf.union(a, b)
    g[a].append((b, i))
    g[b].append((a, i))
    cnt[a] += 1
    cnt[b] += 1
    

for i in uf.roots():
    visited = [0] * n
    visited[i] = 1
    que = deque()
    que.append([i, 0])
    while que:
        s = que.popleft()
        k = 0
        for j in g[s[0]]:
            if not visited[j[0]]:
                while True:
                    k += 1
                    if k != s[1]:
                        que.append([j[0], k])
                        visited[j[0]] = 1
                        ans[j[1]] = k
                        break

print(max(cnt))
print(*ans, sep = "\n")
    
        

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

int main() {
    string S;
    cin >> S;
    string ans = "Yes";
    for(int i = 0; i < S.length(); i++) {
        if(i % 2 == 0) {
            if(S[i] == 'L') {
                ans = "No";
                break;
            }
        }else{
            if(S[i] == 'R') {
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n], c = new int[n];
		for(int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		int ans = 0;
		for(int j = 0; j < n; j++) {
			if(v[j] > c[j]) {
				ans += v[j]-c[j];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23508
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] p = nextIntArray(sc, N);

		sc.close();

		int c = 0;
		for (int i = 0; i < N; i++) {
			if (p[i] != i + 1) {
				c++;
			}
		}

		if (c <= 2) {
			out.println("YES");
		} else {
			out.println("NO");
		}

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;

int main() {
    int M;
    cin >> M;
    vector<ll> d(M), c(M);
    REP(i, M) cin >> d[i] >> c[i];

    ll c_sum = accumulate(all(c), 0ll);
    ll digit_sum = 0;
    REP(i, M) digit_sum += d[i] * c[i];
    ll result = c_sum - 1 + (digit_sum - 1) / 9;
    cout << result << endl;

    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

bool ac[100100];
lli waCnt[100100];

signed main(){

	lli n,m;
	cin>>n>>m;

	REP(i,0,m){
		lli a;
		string b;
		cin>>a>>b;
		a--;
		if(b=="AC")ac[a]=true;
		else{
			if(ac[a]==false)waCnt[a]++;
			else{}
		}
	}

	lli waSum=0;
	lli acSum=0;
	REP(i,0,n){
		if(ac[i]){
			acSum++;
			waSum += waCnt[i];
		}
	}

	cout<<acSum<<" "<<waSum<<endl;

	return 0;
}

Measured memory_bytes: 1152
from collections import deque

def idx(h,w):
    return h*W + w

def main():
    adj=[(-1,0), (0,1), (1,0), (0,-1)]
    graph=[set() for _ in range(N)]
    for h in range(H):
        for w in range(W):
            idx_from=idx(h,w)
            if Ss[h][w]=='#':
                continue
            for dh in range(-2,3):
                for dw in range(-2,3):
                    if dh==0 and dw==0:
                        continue
                    h_dst=h+dh
                    w_dst=w+dw
                    
                    if (0<=h_dst<H) and (0<=w_dst<W) and (Ss[h_dst][w_dst]=='.'):
                        idx_to=idx(h_dst,w_dst)
                        if (dh,dw) in adj:
                            graph[idx_from].add((idx_to,0))
                            #graph[idx_to].add((idx_from,0))
                        else:
                            graph[idx_from].add((idx_to,1))
                            #graph[idx_to].add((idx_from,1))
    s=idx(Ch,Cw)
    dist=[10**9]*N
    dist[s]=0
    que=deque()
    que.append(s)

    while len(que)>0:
        i = que.popleft() # 先頭取り出し
        for j,c in graph[i]:
            d = dist[i] + c
            if d < dist[j]:
                dist[j] = d
                if c == 1:
                    que.append(j) # 末尾へ
                else:
                    que.appendleft(j) #先頭へ
    #print(graph,dist)
    ans = dist[idx(Dh,Dw)]
    print(-1 if ans == 10**9 else ans)

H,W=map(int,input().split())
N=H*W
Ch,Cw=[int(e)-1 for e in input().split()]
Dh,Dw=[int(e)-1 for e in input().split()]
Ss=[]
for _ in range(H):
    #Ss.append([(1 if c=='.'else 0) for c in input()])
    Ss.append(input())
main()

Measured memory_bytes: 485000
import sys
import string
input=sys.stdin.readline

n=int(input())
l=[list(input().rstrip()) for i in range(n)]
if len(set(map(tuple,l)))!=len(l):
        print('No')
else:
    for i in range(n-1):
        if l[i][-1]!=l[i+1][0]:
            print('No')
            break
    else:
        print('Yes')

Measured memory_bytes: 3768
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn make_compress_dict(xs: &Vec<usize>) -> HashMap<usize, usize> {
    let mut x_compress_dict = HashMap::new();
    for &x in xs.iter() {
        if !x_compress_dict.contains_key(&x) {
            let next = x_compress_dict.len();
            x_compress_dict.insert(x, next);
        }
    }
    x_compress_dict
}

fn main() {
    let n = read::<usize>();

    let mut points = vec![];
    for _ in 0..n {
        let v = read_vec::<usize>();
        let (x, y) = (v[0], v[1]);
        points.push((x, y));
    }
    points.sort();

    let mut xs = points.iter().map(|x| x.0).collect::<Vec<_>>();
    let mut ys = points.iter().map(|x| x.1).collect::<Vec<_>>();
    let x_compress_dict = make_compress_dict(&xs);
    let y_compress_dict = make_compress_dict(&ys);

    let length = x_compress_dict.len() + y_compress_dict.len();
    let mut edges = vec![vec![]; length];
    for &(x, y) in points.iter() {
        edges[x_compress_dict[&x]].push(x_compress_dict.len() + y_compress_dict[&y]);
        edges[x_compress_dict.len() + y_compress_dict[&y]].push(x_compress_dict[&x]);
    }

    let mut checked = vec![false; length];
    let mut ans = 0;
    for &(x, y) in points.iter() {
        let x = x_compress_dict[&x];
        if checked[x] {
            continue;
        }
        let (ret, x_size, y_size) = dfs(x, x_compress_dict.len(), &edges, &mut checked);
        ans += x_size * y_size - ret / 2;
    }
    println!("{}", ans);
}

fn dfs(
    current_idx: usize,
    x_length: usize,
    edges: &Vec<Vec<usize>>,
    checked: &mut Vec<bool>,
) -> (i64, i64, i64) {
    checked[current_idx] = true;
    let mut ret = 0i64;
    let mut x_size = 0i64;
    let mut y_size = 0i64;
    if current_idx < x_length {
        x_size = 1;
    } else {
        y_size = 1;
    }
    ret += edges[current_idx].len() as i64;
    for &to in edges[current_idx].iter() {
        if checked[to] {
            continue;
        }
        let result = dfs(to, x_length, edges, checked);
        ret += result.0;
        x_size += result.1;
        y_size += result.2;
    }
    (ret, x_size, y_size)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 25536
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

int main() {
  int n; cin >> n;
	map<string, vector<pair<int,int>>> mp;
	rep1(i, n) {
	  string s;
		int p;
		cin >> s >> p;
		mp[s].push_back({p,i});
	}
	for (auto v : mp) {
		sort(all(v.second), greater<pair<int,int>>());
		for(auto pi : v.second) cout << pi.second << endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
class Program
{
    static List<int> s = new List<int>();
static long result;
static string[] S;
  static int A,B;
    static void Main()
    {
        S=Console.ReadLine().Split(' ');
A=int.Parse(S[0]);
      B=int.Parse(S[1]);
      int i;
for(i=0;i<1000000;i++){if(B<=1+(A-1)*i){break;}}
                    Console.WriteLine(i.ToString());

    }

}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = 1000000007;
ll num[100005];
ll sum = 0;
int main()
{
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                scanf("%lld", num + i);
                sum += 1LL * abs(num[i] - num[i - 1]);
        }
        sum += abs(num[n]);
        for (int i = 1; i <= n; i++)
        {
                cout << sum - abs(num[i] - num[i - 1]) - abs(num[i] - num[i + 1]) + abs(num[i - 1] - num[i + 1]) << endl;
        }
        //cout << sum - abs(num[n] - num[n - 1]) - abs(num[n]) + abs(num[n - 1]) << endl;
        return 0;
}


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

#define MOD 998244353

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
int compare_int(const void *a,const void *b){
    return *(int*)a - *(int*)b;
}


typedef long long int64;

int main(void){
  int N;
  scanf("%d",&N);
  int A[N];
  int mi=0;
  int min;
  int64 ans=0;
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]<0) mi++;
    A[i]=fabs(A[i]);
    ans+=A[i];
  }
  qsort(A,N,sizeof(int),compare_int);
  if(mi%2) ans-=A[0]*2;
  printf("%lld",ans);

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define MOD 1000000007
int cnt=0;
bool P[11];
int N,M;
vector<int> s[11];
bool curr[11];
void dfs(int i)
{
    if(i==N+1)
    { //cout<<"GFHJK";
        int flag=1;
        for(int i=1;i<=M;i++)
        {
            if(curr[i]!=P[i])
            {
                flag=0;
                break;
            }
        }
        if(flag)
        {
           
           // cout<<endl;
            cnt++;
            
        }
        
        return;
    }
    //CASE1 Si=0
    
    dfs(i+1);
    
    for(int j=0;j<s[i].size();j++)
    {
        curr[s[i][j]]=!curr[s[i][j]];
    }
    dfs(i+1);
    //cout<<"SUYASH";
    for(int j=0;j<s[i].size();j++)
    {
        curr[s[i][j]]=!curr[s[i][j]];
    }
    return;
}
int main()
{
    
    cin>>N>>M;
    
    for(int i=1;i<=M;i++)
    {
        int k;
        cin>>k;
        while(k--)
        {
            int s0;
            cin>>s0;
            s[s0].push_back(i);
        }
    }
    
    for(int i=1;i<=M;i++)
    cin>>P[i];
    
    
    for(int i=1;i<=M;i++)
    curr[i]=false;
    //cout<<N<<M<<endl;
    dfs(1);
    cout<<cnt;
    return 0;

}

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

int main () {
  int A, B, C;
  cin >> A >> B >> C;
  
  if( A == B && B != C || B == C && C != A || A == C && B != C)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans = 0
arr.each.with_index do |num,id|
  if id + 1 == num
    ans += 1
    arr[id],arr[id+1] = arr[id+1],arr[id]
  end
end
puts ans

Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 998244353
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,s;
ll arr[30001];
ll dp[3001][3001];
ll func(ll i,ll j)
{
	if(i==n)
		return j==s;
	if(j>s)
		return 0;
	ll &ret = dp[i][j];
	if(ret!=-1)
		return ret;
	ret = func(i+1,j)*2+func(i+1,j+arr[i]);
	ret%=mod;
	return ret;
}
signed main()
{
    fast;
    cin>>n>>s;
    fr(i,n)cin>>arr[i];
    mem(dp,-1);
    cout<<func(0,0);
}


Measured memory_bytes: 74184
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	ret := make([]rune, len(s))
	for i, r := range s {
		r2 := int(r)
		if r2+n <= 'Z' {
			ret[i] = rune(r2 + n)
		} else {
			ret[i] = 'A' + rune(r2+n-'Z'-1)
		}
	}
	fmt.Println(string(ret))
}


Measured memory_bytes: 768
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

#define lim 200005

pii a[lim];

bool comp(pii U,pii V){
    return U.f2 < V.f2;
}

bool comp1(pii U,pii V){
    return U.f1 < V.f1;
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,ans;
    sfl(n);
    FOR(i,n){
        sfl(a[i].f1),sfl(a[i].f2);
    }
    if(n&1){
        sort(a+1,a+n+1,comp);
        ans = a[(n+1)/2].f2;
        sort(a+1,a+n+1,comp1);
        ans -= a[(n+1)/2].f1;
        ans++;
        ans = max(ans,0ll);
        pfl(ans);
    }
    else{
        sort(a+1,a+n+1,comp);
        ans = a[n/2].f2+a[(n/2)+1].f2;
        sort(a+1,a+n+1,comp1);
        ans -= a[n/2].f1+a[(n/2)+1].f1;
        ans++;
        ans = max(ans,0ll);
        pfl(ans);
    }
    return 0;
}

Measured memory_bytes: 6848
#include <stdio.h>
#define N 102
#define WHITE 0
#define GRAY 1
#define BLACK 2

struct info{
  int ver;
  int color;
  int dis_time;
  int fin_time;
} typedef Info;

void Dfs(int);
void Visit(int, int);

int gin[N][N];
Info x[N];
int vtime = 0;

int main(){
  int n, i, j;

  scanf("%d", &n);
  for(i = 1; i < n + 1; i++){
    scanf("%d%d", &gin[i][0], &gin[i][1]);
    for(j = 2; j < 2 + gin[i][1]; j++){
      scanf("%d", &gin[i][j]);
    }
  }
 
  Dfs(n);

  for(i = 1; i < n + 1; i++){
    printf("%d %d %d\n", gin[i][0], x[i].dis_time, x[i].fin_time);
  }

  return 0;
}

void Dfs(int n){
  int i, j;

  for(i = 1; i < n + 1; i++){
      x[i].ver = gin[i][0];
      x[i].color = WHITE;
      x[i].dis_time = 0;
      x[i].fin_time = 0;
  }

  for(i = 1; i < n; i++){
    if (x[i].color == WHITE) Visit(i, n);
  }
  
}

void Visit(int k, int n){
  int i;

  x[k].color = GRAY;
  x[k].dis_time = ++vtime;
    for(i = 2; i < 2 + gin[k][1]; i++){
     if(x[ gin[k][i] ].color == WHITE) Visit(gin[k][i], n) ;
  }
  x[k].color = BLACK;
  x[k].fin_time = ++vtime;

}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi r(n,0), w(n,0);
    rep(i,n){
        if(s[i] == 'R')r[i]++;
        else w[i]++;
    }
    rep(i,n-1)w[i+1] += w[i];
    for(int i = n-2; i >= 0; i--)r[i] += r[i+1];
    int ans = INF;
    rep(i,n+1){
        //[0,i)がR、[i,n)がWにする
        int cnt1 = 0, cnt2 = 0;
        if(i)cnt1 = w[i-1];
        if(i<n)cnt2 = r[i];
        int cnt = max(cnt1, cnt2);
        //cout << cnt1 << " " << cnt2 << " " << cnt << endl;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6824
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  double a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  double noudo = e / (e+100);
//  cout << noudo <<endl;
  int num =0;
  int num2 = 0;
  double ndcheck=0;
  double stcheck=0;
  double hanteinoudo = 0;
  for(int i=0;i<f/100;i++){
    for(int j=0;j<f/100;j++){
      if(i == 0 && j == 0);
      else if(i*a*100 + j*b*100 >=f);
      else{
        for(int k=0;k>-1;k++){
          for(int m=0;m>-1;m++){
            ndcheck = (k*c + m*d)/(i*a*100 + j*b*100 + k*c + m*d);
            stcheck = i*a*100 + j*b*100 + k*c + m*d;
            if(ndcheck <= noudo && stcheck <= f){
              if(ndcheck >= hanteinoudo){
                hanteinoudo = ndcheck;
                num = stcheck;
                num2 =  k*c + m*d;
              }
            }
            else break;
          }
          ndcheck = (k*c )/(i*a*100 + j*b*100 + k*c );
          stcheck = i*a*100 + j*b*100 + k*c ;
          if(ndcheck <= noudo && stcheck <= f);
          else break;
        }
      }
    }
  }
    cout << num << " " << num2 << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))

Ts = list(accumulate([0] + ts))

# 横向きにカットするイメージ
def solve(begin, end, v):
    # print(' ' * v, begin, end, v, vs[bisect_right(Ts, begin) - 1:bisect_left(Ts, end)])
    if begin >= end:
        return 0
    if begin + 1 == end:
        if v < vs[bisect_right(Ts, begin) - 1]:
            return 0.25
        else:
            return 0
    min_v = min(vs[bisect_right(Ts, begin) - 1:bisect_left(Ts, end)])
    if min_v == v:
        ret = 0
        last = begin
        for i in range(bisect_right(Ts, begin) - 1, bisect_left(Ts, end)):
            if v == vs[i]:
                ret += solve(last, Ts[i], v)
                last = Ts[i + 1]
        ret += solve(last, end, v)
        return ret
    else:
        return end - begin - 1 + solve(begin + 1, end - 1, v + 1)

print(solve(0, Ts[-1], 0))


Measured memory_bytes: 67712
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	a := make([]int, n)
	xs := make([]int, 1000001)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
		if xs[a[i]] == 0 {
			for j := a[i]; j < len(xs); j += a[i] {
				xs[j]++
			}
			continue
		}
		xs[a[i]]++
	}

	ans := 0
	for _, v := range a {
		if xs[v] == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int N,M,Q;
int ans = 0;
int a[50], b[50], c[50], d[50];
void dfs(int n, int x, vector<int> &A) {
    if (n==N-1) {
        int val = 0;
        rep(i,Q) {
            if (A[b[i]] - A[a[i]]==c[i]) val += d[i];
        }
        chmax(ans,val);
        return;
    }
    for (int i = 0; i <= x; i++) {
        A[n+1] = A[n]+i;
        dfs(n+1,x-i,A);
    }
    return;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> M >> Q;
    rep(i,Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    vector<int> A(N);
    dfs(0,M-1,A);
    cout << ans << ln;
}

Measured memory_bytes: 3616