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

int main(){
  int n,y;
  scanf("%d%d",&n,&y);
  int x1=y/10000;
  int x2=y/5000;
  
  
  
  for(int j=0;j<=x2;j++){
    for(int k=0;k<=x1;k++){
      int i=n-j-k;
      if(1000*i+5000*j+10000*k==y&&i>=0){
	printf("%d %d %d\n",k,j,i);
	return 0;
      }
    }
  }

  printf("-1 -1 -1\n");
  
  return 0;
}

Measured memory_bytes: 128
from fractions import gcd

n,x=map(int,input().split())
l=list(map(int,input().split()))+[x]
l.sort()

ans=l[1]-l[0]
for i in range(2,n+1):
  sa=l[i]-l[i-1]
  ans=gcd(ans,sa)

print(ans)

Measured memory_bytes: 16280
#include <iostream>
using namespace std;
int main(void){
int a,b,c,d,e,f,i,g;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
for (i=1;i<=10;i++){
    cin>>g;
    if(a<=g){
        c=b;
        b=a;
        a=g;
    }else if(b<=g){
        c=b;
        b=g;
    }else if(c<=g){
        c=g;
    }
}
for (i=1;i<=10;i++){
    cin>>g;
    if(d<=g){
        f=e;
        e=d;
        d=g;
    }else if(e<=g){
        f=e;
        e=g;
    }else if(f<=g){
        f=g;
    }
}
cout<<a+b+c<<" "<<d+e+f<<endl;
}



Measured memory_bytes: 3080
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;
typedef vector<P> VP;
typedef greater<P> GP;

#define MOD 1000000007
#define INF 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

VP G[100000];
int dist[100000];

void dijkstra(int start) {
  priority_queue<P, VP, GP> que;  // firstの小さい順に取り出す
  REP(i, 100000) dist[i] = INF;
  dist[start] = 0;
  que.push(P(0, start));
  while (que.size()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first) continue;
    REP(i, G[v].size()) {
      int to = G[v][i].first;
      int cost = G[v][i].second;
      if (dist[v] + cost < dist[to]) {
        dist[to] = dist[v] + cost;
        que.push(P(dist[to], to));
      }
    }
  }
}

int main() {
  int V, E, r;
  cin >> V >> E >> r;
  REP(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    G[s].push_back(P(t, d));  // s -> t
  }
  dijkstra(r);
  REP(i, V) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 13092
#include<stdio.h>

int main(){
    long long LMT=1000000000000000000;
    long long A, B, C, K;
    long long tmp;

    scanf("%lld %lld %lld %lld", &A, &B, &C, &K);
    tmp = K%2;

    if(tmp==0){
        printf("%d", A-B);
    }else{
        printf("%d", B-A);
    }

    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m, s = 0;
	cin >> n >> m;
	for(int i = 0; i < m;i ++){	
		int a;
		cin >> a;
		s += a;
	}
	if(s > n){	
		cout << "-1" << "\n";
	}else{	
		cout << n - s;
	}
	return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	string s; cin >> s;
	string t; cin >> t;
	int a = t.length();
	if(s.length() + 1 == t.length() and s == t.substr(0, a-1)) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   string str;
   cin>>str;
   if(str[0]==str[1] && str[1]==str[2])
    cout<<str;
   else if(str[1]<=str[0] && str[2]<=str[0])
    cout<<str[0]<<str[0]<<str[0];
   else 
   {
    for(int i=1;i<=3;i++)
        cout<<(int)(str[0]-48+1);
   }




 return 0;
}








Measured memory_bytes: 3644
import sys
input = sys.stdin.readline
def main():
    n = int(input())
    a = []
    b = []
    for _ in range(n):
        A,B = map(int,input().split())
        a.append(A)
        b.append(B)
    a.sort()
    b.sort()
    if n%2:
        print(b[n//2]-a[n//2]+1)
    else:
        print((b[n//2]+b[n//2-1]) - (a[n//2]+a[n//2-1])+1)
    
if __name__ == "__main__":
    main()

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int H, W, K; cin >> H >> W >> K;
	vector<string> B(H);
	for (int i = 0; i < H; i++) {
		cin >> B[i];
	}

	int ans = H*W;
	for (int m = 0; m < (1 << (H-1)); m++) {
		int cost = 0;

		vector<int> cutoffs;
		cutoffs.push_back(0);
		for (int i = 1; i < H; i++) {
			if (m & (1 << (i-1))) {
				cutoffs.push_back(i);
				cost++;
			}
		}
		cutoffs.push_back(H);

		vector<int> tots(cutoffs.size()-1);
		for (int j = 0; j < W; j++) {
			bool doCut = false;
			for (int i = 0; i+1 < int(cutoffs.size()); i++) {
				int cur = 0;
				for (int l = cutoffs[i]; l < cutoffs[i+1]; l++) {
					cur += (B[l][j] == '1');
				}
				if (cur > K) {
					cost = H*W;
					goto done;
				}
				if (tots[i] + cur > K) {
					doCut = true;
					break;
				}
			}
			if (doCut) cost++;
			for (int i = 0; i+1 < int(cutoffs.size()); i++) {
				int cur = 0;
				for (int l = cutoffs[i]; l < cutoffs[i+1]; l++) {
					cur += (B[l][j] == '1');
				}
				if (doCut) {
					tots[i] = cur;
				} else {
					tots[i] += cur;
				}
			}
		}

done:
		ans = min(ans, cost);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
#define MAXN   1000000
int spf[MAXN];
void sieve()
{
	spf[1] = 1;
	for (int i = 2; i < MAXN; i++)
		spf[i] = i;
	for (int i = 4; i < MAXN; i += 2)
		spf[i] = 2;
	for (int i = 3; i * i < MAXN; i++)
	{
		if (spf[i] == i)
		{
			for (int j = i * i; j < MAXN; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

int getFactorization(int x)
{
	vector<int> ret;
	while (x != 1)
	{
		ret.push_back(spf[x]);
		x = x / spf[x];
	}
	unordered_map<int, int> m;
	rep(i, 0, ret.size()) {
		m[ret[i]]++;
	}
	int ans = 1;
	for (auto i : m) {
		ans *= (i.S + 1);
	}
	return ans;
}
void solve() {
	sieve();
	int n, ans = 0;
	cin >> n;
	rep(i, 1, n) {
		int k = getFactorization(i);
		// trace(i, k)
		ans += k ;
	}
	cout << ans;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int h = ty - sy;
  int w = tx - sx;

  string ans = string(h, 'U');
  ans += string(w, 'R');
  ans += string(h, 'D');
  ans += string(w, 'L');
  ans += string(1, 'L');
  ans += string(h+1, 'U');
  ans += string(w+1, 'R');
  ans += string(1, 'D');
  ans += string(1, 'R');
  ans += string(h+1, 'D');
  ans += string(w+1, 'L');
  ans += string(1, 'U');

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int a,b,c,d;

int main() {
	//freopen("test.in","r",stdin);
	cin >> a >> b >> c >> d;
	int64 r=-1e18;
	for (int64 x : {a,b}) {
		for (int64 y : {c,d}) {
			int64 p=x*y;
			r=max(r,p);
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 3632
n = int(input())
a = [int(i) for i in input().split()]

c = [0] * 8
over = 0

for i in a:
    if i < 400:
        c[0] = 1
    elif i < 800:
        c[1] = 1
    elif i < 1200:
        c[2] = 1
    elif i < 1600:
        c[3] = 1
    elif i < 2000:
        c[4] = 1
    elif i < 2400:
        c[5] = 1
    elif i < 2800:
        c[6] = 1
    elif i < 3200:
        c[7] = 1
    else:
        over += 1

print(max(1, sum(c)), sum(c) + over)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string s;
  cin >> s;
  
  int N;
  N = s.size();
  
  int f,e;
  int ans=0;
  
  for(int i=0; i<N; i++){
    if(s.at(i) == 'A'){
      f = i;
      break;
    }  
  }
  
  for(int i=0; i<N; i++){
    if(s.at(i) == 'Z'){
      e = i;
    }
  }

  ans = e - f + 1;
    
  cout << ans << endl;
}

Measured memory_bytes: 3716
n,w=map(int,input().split())
dp=[0]*(n*10**3+1)
c,p=map(int,input().split())
dp[p]=c
mpos=p
for _ in range(n-1):
  c,p=map(int,input().split())
  for i in range(mpos+p,0,-1):
    if dp[i-p]!=0:
      if dp[i]==0:
        dp[i]=dp[i-p]+c
      else:
        dp[i]=min(dp[i-p]+c,dp[i])
  if dp[p]==0:
    dp[p]=c
  else:
    dp[p]=min(dp[p],c)
  mpos=mpos+p
ans=0
for i in range(len(dp)):
  if dp[i]<=w and dp[i]!=0:
    ans=i
print(ans)

Measured memory_bytes: 5748
#include <iostream>
using namespace std;
int main ()
{
	int a,b,c,d,n;
	cin>>a>>b>>c;
	n=a;	
	int x[100],y[100] ;
	while (a--) cin>>x[a];
	int i , j, k,m ;
	for(i=0,m=0;i<n ;i++)
	{
		 k=0;
		for(j=0;;)
		{
			y[i] =j*x[i]+1;
			if(y[i]>b)  break ;	
			j++ ;
			k++ ;
		}  
	m+=k;	
	
	}
	cout<<c+m<<endl;
	
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string S; 
    cin >> S;

    reverse(S.begin(),S.end());
    for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
    bool can = true;
    for(int i=0;i<S.size();){
        bool can2 =false;
        for(int j =0;j<4;j++){
            string d =divide[j];
            if(S.substr(i,d.size())==d){
                can2=true;
                i += d.size();
            }
        }
        if(!can2){
            can=false;
            break;
        }
    }
    if(can){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int dp[1100][5500];
int p[11],c[11];
signed main(){
    int d,g;cin >> d >> g;
    rep(i,d)cin >> p[i] >> c[i];
    int ans = 1001001001001ll;
    rep(perf,1<<d){
        int score = 0;
        int solve = 0;
        rep(i,d){
            if(perf>>i&1){
                score += (p[i]*100*(i+1))+ c[i];
                solve += p[i];
            }

        }
        //cout << solve <<" " <<  score << endl;
        for(int i = d-1;i >= 0 ; i--){
            if(perf>>i&1)continue;
            if(score + (p[i]-1)*100*(i+1) >= g){
                int rest = max(0ll,g-score);
                int onep = 100*(i+1);
                solve += (rest+onep-1)/onep;
                score += solve*100*(i+1);
                break;

            }
          
            else {
                solve += p[i]-1;
                score += (p[i]-1)*100*(i+1);    

            }
            
        }
        if(score >= g)ans = min(ans,solve);
        //cout << solve << " " << score << endl;
    }
    
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(){
    int a;
    //string s,t;

    cin>>a;
    cout<<2.0*a*PI<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <vector>

using namespace std;

class PriorityQueue {
    vector<int> heap;
    int sz;

public:
    PriorityQueue(int n) { sz = 0; heap.resize(n); }
    void Push(int x);
    int Pop();
};

void PriorityQueue::Push(int x)
{
    // 自分のノード番号
    int i = sz++;

    while (i > 0) {
        // 親のノード番号
        int p = (i - 1) / 2;

        // もう逆転していないなら抜ける
        if (heap[p] >= x)
            break;
        // 親のノードの数字を下ろして，自分は上に
        heap[i] = heap[p];
        i = p;
    }

    heap[i] = x;
}

int PriorityQueue::Pop()
{
    // 最小値
    int ret = heap[0];

    // 根に持ってくる値
    int x = heap[--sz];

    // 根からおろしていく
    int i = 0;
    while (i * 2 + 1 < sz) {
        // 小同士を比較
        int a = i * 2 + 1, b = i * 2 + 2;
        if (b < sz && heap[b] > heap[a])
            a = b;

        // もう逆転してないなら終わり
        if (heap[a] <= x)
            break;

        // 個の数字を持ち上げる
        heap[i] = heap[a];
        i = a;
    }

    heap[i] = x;

    return ret;
}

int main()
{
    string s;
    int k;
    PriorityQueue pq(2000000);

    while (cin >> s) {
        if (s == "end")
            break;
        else if (s == "insert") {
            cin >> k;
            pq.Push(k);
        }
        else if (s == "extract") {
            cout << pq.Pop() << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 8980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));
bool flg[26];

void solve(string S){
	int n = S.length();
	
	if (n < 26) {
		rep(i, n) {
			flg[S[i]-'a'] = true;
		}
		char c = 'A';
		rep(i, 26) {
			if (!flg[i]) {
				c = i+'a';
				break;
			}
		}
		cout << S+c << endl;
	} else if (S == "zyxwvutsrqponmlkjihgfedcba") {
		cout << "-1" << endl;
	} else {
		int i;
		bool se = false;
		for (i = n-2; i >= 0; i--) {
			if (S[i] < S[i+1]) {
				// cout << i << " " << endl;
				se = true;
				break;
			}
		}
		if (se) {
			char last = 'z';
			for (int j = i; j < n; j++) if (S[j] > S[i]) last = min(last, S[j]); 
			rep(j, i) cout << S[j];
			cout << last << endl;
		} else {
			char c = S[0]+1;
			cout << c << endl;
		}
	}
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0]; var K = NK[1];
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            for (int i = K + 1; i <= N; i++)
            {
                Console.WriteLine(A[i - K - 1] < A[i - 1] ? "Yes" : "No");
            }
        }
    }
}


Measured memory_bytes: 45744
n = int(input())
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[n-1])

Measured memory_bytes: 3060
#include<stdio.h>
void swap(int *x, int *y)
{
	int t;
	t = *x, *x = *y, *y = t;
}
int main()
{
	int w, x[30], n, h1, h2, i;
	scanf("%d%d", &w, &n);
	for (i = 0; i < w; i ++)
		x[i] = 1+i;
	for (i = 0; i < n; i ++) {
		scanf("%d,%d", &h1, &h2);
		swap (&x[h1-1], &x[h2-1]);
	}
	for (i = 0; i < w; i ++)
		printf("%d\n", x[i]);
	return 0;
}

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


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

    if(k%2==0) cout << k/2 * k/2;
    if(k%2==1) cout << k/2 * (k/2 + 1);

    return 0;
}

Measured memory_bytes: 256
r , c = [int(x) for x in input().split()]
s_row = [0 for x in range(c+1)]
for i in range(r):
    row = [int(x) for x in input().split()]
    row.append(sum(row))
    print(" ".join([str(x) for x in row]))
    s_row = [x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))


Measured memory_bytes: 5624
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
char a[10];
int used[10];

void solve(int u) {
    if (u == n) {
        FOR(i,0,n-1) cout << a[i];
        cout << "\n";
        return;
    }
    FOR(i,0,u) {
        bool co = true;
        FOR(j,0,i-1)
            if (used[j] == 0) co = false;
        if (!co) break;
        a[u] = char(i + 'a');
        used[i]++;
        solve(u+1);
        used[i]--;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    solve(0);
    return 0;

}


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

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<int> A(N + 1), B(N + 1);
    for(int i = 0; i < N; ++i) if(S[i] == '<') A[i + 1] = A[i] + 1;
    for(int i = N - 1; i >= 0; --i) if(S[i] == '>') B[i] = B[i + 1] + 1;
    int64_t ans = 0;
    for(int i = 0; i <= N; ++i) ans += max(A[i], B[i]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4740
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
cnt=0
x=int(input())
sgn=[[1,1],[-1,-1],[-1,1],[1,-1]]
for i in range(0,201):
    for j in range(0,201):
        for k in range(4):
            if sgn[k][0]*i**5-sgn[k][1]*j**5==x:
                print(sgn[k][0]*i, sgn[k][1]*j)
                sys.exit()


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b;
	cin>>a>>b;
	for(ll i=0;i<=inf;i++){
		if(abs(a-i)==abs(b-i)){
			cout << i;
			return 0;
		}
	}
	cout <<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<char,char> p2;
#define sz(a) ll(a.size())
ll n,k,a[1005],res;
vector<ll> v;
void func(ll bit){
	if(!bit){
		cout<<res;
		exit(0);
	}
	vector<ll> temp;
	ll val=pow(2,bit-1);
	for(ll i=0;i<sz(v);i++){
		if(!(v[i]&val))
		continue;
		temp.push_back(v[i]);
	}
	if(sz(temp)>=k){
		res+=val;
		v=temp;
	}
	func(bit-1);
}
void solve(){
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	cin>>a[i];
	for(ll i=1;i<=n;i++){
		ll sum=0;
		for(ll j=i;j<=n;j++){
			sum+=a[j];
			v.push_back(sum);
		}
	}
	func(50);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 14576
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int A, B, C;
	cin >> A >> B >> C;
	swap(A, B);
	swap(A, C);
	cout << A << " " << B << " " << C << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
N = int(input())
W = [input() for i in range(N)]
S = set([W[0]])
ans = "Yes"
for i in range(1,N):
  if W[i] in S:
    ans = "No"
  if W[i][0] != W[i-1][-1]:
    ans = "No"
  S.add(W[i])
print(ans)


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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL p[5];

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

	string s;
	for (int i = 0; i < n; i++) {
		cin >> s;

		if (s[0] == 'M')p[0]++;
		if (s[0] == 'A')p[1]++;
		if (s[0] == 'R')p[2]++;
		if (s[0] == 'C')p[3]++;
		if (s[0] == 'H')p[4]++;
	}

	LL ans = 0;

	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += p[i] * p[j] * p[k];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long K = sc.nextLong() + 1;
    long[] k = new long[40];
    for(int j = 0; j < 40; j++) {
      k[j] = (K % 2);
      K /= 2; 
    }  
    long[][] a = new long[n][40];
    long[][] b = new long[40][2];
    for(int i = 0; i < n; i++) {
      long A = sc.nextLong();
      for(int j = 0; j < 40; j++) {
        a[i][j] = (A % 2);
        if(a[i][j] == 0) {
          b[j][0]++;
        } else {
          b[j][1]++;
        }
        A /= 2; 
      }
    }
    long[] ansh = new long[40];
    for(int i = 39; i >= 0; i--) {
      long t = 0;
      if(k[i] == 1) {
        for(int j = 39; j >= 0; j--) {
          if(j > i) {
            int d = (int)(1 - k[j]);
            t += (b[j][d] * (long)Math.pow(2, j));
          } else if(j == i) {										                t += (b[j][1] * (long)Math.pow(2, j));						
          } else {
            t += (Math.max(b[j][0] * (long)Math.pow(2, j), b[j][1] * (long)Math.pow(2, j)));
          }
        }
      }
      ansh[i] = t;
    }
    long ans = 0;
    for(int i = 0; i < 40; i++) {
      ans = Math.max(ans, ansh[i]);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 105800
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,C;
    cin>>N>>M>>C;
    vector<int> B(M);
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    int problemsSolved = 0;
    vector<int> A(M);
    for(int i=0;i<N;i++){
        int sum = 0;
        for(int i=0;i<M;i++){
            cin>>A[i];
            sum += A[i] * B[i];
        }
        if (sum > -C){
            problemsSolved++;
        }
    }
    cout<<problemsSolved<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}

int main() {
	int m, d;
	int ans = 0;
	cin >> m >> d;
	rep(i, 4, m + 1) {
		rep(j, 22, d + 1) {
			if (j % 10 < 2)continue;
			if (i == (j % 10) * (j / 10)) {
				ans++;
				
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
int calc(int y,int m,int d){
    y--;
    int res=y/3*20*10+(y-y/3)*39*5;
    m--;
    if((y+1)%3==0){
        res+=m*20;
    }else{
        res+=m/2*19;
        res+=(m+1)/2*20;
    }
    return res+d;
}
void solve(){
    int N;
    cin>>N;
    int y=calc(1000,1,1);
    rep(_,N){
        int Y,M,D;
        cin>>Y>>M>>D;
        cout<<y-calc(Y,M,D)<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double p = Math.PI;
        System.out.printf("%f %f", r*r*p, 2*r*p);
    }
}




Measured memory_bytes: 28024
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
const int ms = 1e5+9;
int dist[ms];
vector<ii> g[ms];
int n;

void dfs(int v){
	memset(dist,0x3f,sizeof(dist));
	priority_queue<ii,vector<ii>,greater<ii>> pq;
	pq.push({0,v});
	dist[v] = 0;
	
	while(pq.size()){
		int u = pq.top().second;
		int d = pq.top().first;
		pq.pop();
		if(d > dist[u])
			continue;
		for(auto &it:g[u]){
			if(dist[it.first] > d + it.second){
				dist[it.first]  = d + it.second;
				pq.push({dist[it.first],it.first});
			}
		}
	}

}

main(){
	int a,b,c;
	cin >> n;
	for(int i =0;i<n-1;i++){
		cin >> a >> b >> c;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	dfs(1);
	for(int i = 1;i<=n;i++)	{
		dist[i] = labs(dist[i]-dist[1]);
		cout<<(dist[i]&1)<<"\n";
	}
	
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    string s,t;
    cin >> s >> t;
    int n = s.length();

    int tugi[n][26];
    REP(i,n) REP(j,26) tugi[i][j] = -1;
    int before[26] = {};
    REP(i,n){
        int tmp = int(s[i]) - int('a');
        FOR(j,before[tmp],i){
            tugi[j][tmp] = i;
        }
        before[tmp] = i;
    }

    REP(i,n){
        int tmp = int(s[i]) - int('a');
        if(before[tmp] != -1){
            FOR(j,before[tmp],n){
                tugi[j][tmp] = i;
            }
            before[tmp] = -1;
        }
    }



    int ans = 1;
    int ind = 0;
    if(s[0] != t[0]){
        int tmp = int(t[0]) - int('a');
        ind = tugi[0][ tmp];
        if(tugi[0][tmp]== -1){
            cout << -1 << endl;
            return 0;
        }
        ans += ind;
    }


    FOR(i,1,t.length()){
        int tmp = int(t[i]) - int('a');

        if(tugi[ind][tmp] == -1){
            cout << -1 << endl;
            return 0;
        }
        if(ind >= tugi[ind][tmp]){
            ans += n - (ind - tugi[ind][tmp]);
        }
        else{
            ans += tugi[ind][tmp] - ind;
        }
        ind = tugi[ind][tmp];
    }

    cout << ans << endl;

}

Measured memory_bytes: 20864
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	long long int x;
	cin >> x;
	long long int ans = 0;
	ans = ans + x / 500 * 1000;
	x = x % 500;
	ans = ans + x / 5 * 5;
	cout << ans;
}


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

ll gcd(ll x, ll y){
      return (y==0)? x: gcd(y,x%y);
   }

int main(){ 
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);
    vector<ll> v;
    ll num = c;
    for(ll i = 2; i*i<=c;i++) {
         ll cnt=0;
        while(num%i ==0){
               num /= i;
               cnt++;
             }
        if( cnt >=1) v.push_back(i);
         }
        if(num!=1) v.push_back(num);
   cout << v.size()+1 << endl;
   return 0;
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
S=list(str(input()))
lst=[[0,0] for _ in range(Q)]
for i in range(Q):
  lst[i]=list(map(int,input().split()))
tmp=[0]*N
for i in range(1,N):
  if S[i-1]=='A' and S[i]=='C':
    tmp[i]=1+tmp[i-1]
  else:
    tmp[i]=tmp[i-1]
for i in range(Q):
  a,b=lst[i][0],lst[i][1]
  print(tmp[b-1]-tmp[a-1])

Measured memory_bytes: 31368
N, M, X = map(int, input().split())
alist = [ list(map(int,input().split())) for _ in range(N)]
ans = float('inf')
for i in range(2**N):
  current = [0]*(M+1)
  for j in range(N):
    if (i>>j)&1:
      for k in range(M+1):
        current[k]+=alist[j][k]
  if X<= min(current[1:]) and current[0]<ans:
    ans = current[0]
print(-1 if ans==float('inf') else ans)

Measured memory_bytes: 9176
import java.util.Arrays;
import java.util.Scanner;

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

		boolean a[] = new boolean [1000001];
		Arrays.fill(a, true);
		a[0]=a[1]=false;
		for(int i=0; i*i<=1000000;i++)
		{
			if(!a[i])
				continue;
			for(int j=i*2; j<=1000000; j+=i)
				a[j]=false;
		}

		while(sc.hasNext())
		{
			int n=sc.nextInt();
			if(n==0)
				return;
			int ans=0;

			for(int i=1; i<=n/2; i++)
			{
				if(!a[i])
					continue;
				if(a[n-i])
				{
					//System.out.println(i+" "+(n-i));
					ans++;
				}
			}
			System.out.println(ans);

		}
	}

}

Measured memory_bytes: 13000
# 参考：
# https://note.nkmk.me/python-union-find/

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())


N, M = map(int, input().split())

union = UnionFind(N)

for _ in range(M):
    A, B = map(int, input().split())
    union.union(A - 1, B - 1)

ans = 0

for children_minus in union.parents:
    if children_minus < 0:
        ans = max(children_minus * -1, ans)

print(ans)


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

int main()
{
    valarray<int> bld(0,120);
    int n, b, f, r, v;
    cin >> n;
    REP(i,n) {
        cin >> b >> f >> r >> v;
        int id = 30 * (b - 1) + 10 * (f - 1) + (r - 1);
        bld[id] += v;
    }
    REP(i,bld.size()){
        cout << " " << bld[i];
        if ((i+1)%10 == 0) cout << endl;
        if ((i+1)%30 == 0 && i != bld.size()-1) cout << "####################" << endl;
    }

    return 0;
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        String s = sc.next();
        String t = sc.next();
        sc.close();

        long tn = n;
        long tm = m;
        long gcf;

        while((gcf = tn % tm) != 0){
            tn = tm;
            tm = gcf;
        }

        gcf = tm;
        long min = n*m / gcf;

        boolean ans = true;

        for(int i=0; i<gcf; i++){
            if(s.charAt((int)(i * (n/gcf))) != t.charAt((int)(i * (m/gcf)))){
                ans = false;
            }
        }

        if(ans){
            System.out.println(min);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 28596
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

// cout pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  s << p.first << " " << p.second << "\n"; return s;
}

// cout vector<pair>
template<typename T1, typename T2> ostream& operator<<(ostream& s, const vector<pair<T1, T2> >& vp) {
  int len = vp.size(); s << "\n";
  for (int i = 0; i < len; ++i) { s << vp[i]; }
    s << "\n"; return s;
}

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout deque
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

// cout 2-dimentional deque
template<typename T> ostream& operator<<(ostream& s, const deque< deque<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int main() {
  string x;
  cin >> x;
  int len = x.length();
  int ans = len;
  /*
  rep (i, len) {
    if (x[i] =='S') {
      tmp = i;
      break;
    }
  }
  x = x.substr(tmp, len - tmp);
  len = x.length();
  */
  deque<pii> st;
  int current = 'S';
  map<char, int> stlen;
  rep (i, len) {
    if (current == 'T' && x[i] == 'S') {
      st.push_back(mp(stlen['S'], stlen['T']));
      stlen['S'] = stlen['T'] = 0;
    }
    stlen[x[i]] += 1;
    current = x[i];
  }
  st.push_back(mp(stlen['S'], stlen['T']));
  int stsize = st.size();
  rep (i, stsize) {
    ans -= 2 * min(st[i].fst, st[i].snd);
    if (i < stsize && st[i].fst > st[i].snd) {
      st[i+1].fst += (st[i].fst - st[i].snd);
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
#define MAXN 100005
#define pi pair<int,int>
#define pl pair<ll,ll>
int n;
char a[MAXN];
int main() {
string k;
cin>>n;
cout<<0<<'\n';
cout.flush();
cin>>k;
if (k[0]=='V') return 0;
a[0]=k[0];
int st=0,dr=n;
int precedent=0;
while (dr-st>=1){
    string x;
    int mijloc=(st+dr)/2;
    cout<<mijloc<<'\n';
    cout.flush();
    cin>>x;
    if (x[0]=='V') return 0;
    a[mijloc]=x[0];
    if (a[mijloc]==a[st]){
        if (!((mijloc-st)%2)) st=mijloc;
        else dr=mijloc;
    }
    else {
        if ((mijloc-st)%2) st=mijloc;
        else dr=mijloc;
    }
}
cout<<st<<'\n';
cout.flush();
cin>>k;
if (k[0]=='V') return 0;
cout<<dr<<'\n';
cout.flush();
cin>>k;
return 0;
}



Measured memory_bytes: 852
N,T = map(int,input().split())
ans = 1001
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))
for i in ls:
    if i[1] <= T:
        ans = min(ans,i[0])
    else:
        continue
if ans == 1001:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 9136
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include <cmath>

using namespace std;

long long int gcd(long long int a, long long int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}


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

    int x;
    cin >> x;
    int b = 1;
    int p = 2;
    int ma = 1;
    for(int i = 2; ; i++) {
        bool end = false;
        for(int j = 2; ; j++) {
            if(j == 2 && pow(i,j) > x) {
                end = true;
                break;
            }
            if(j != 2 && pow(i,j) > x) {
                break;
            }
            ma = max(ma,(int)pow(i,j));
        }
        if(end) break;
    }
    cout << ma << endl;

}





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

int main() {
    string S;
    cin >> S;
    int n = S.size();
    vector<int> ans(n);
    for (int i=0; i<2; i++) {
        int cnt = 0;
        for (int i=0; i <n; i++) {
            if (S[i]=='R') {
                cnt++;
            } else {
                ans[i] += cnt/2;
                ans[i-1] += (cnt+1)/2;
                cnt = 0;
            }
        }
        reverse(ans.begin(), ans.end());
        reverse(S.begin(), S.end());
        for(int i=0; i<n; i++) {
            if (S[i]=='L') {
                S[i] = 'R';
            } else {
                S[i] = 'L';
            }
        }
    }
    for (int i=0; i<n; i++) {
        if (i==n-1) {
            cout << ans[i] << endl;
        } else {
            cout << ans[i] << " "; 
        }
    } 
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a = c - a;
    b = d - b;
    for(int i=0;i<b;i++) cout << 'U';
    for(int i=0;i<a;i++) cout << 'R';
    for(int i=0;i<b;i++) cout << 'D';
    for(int i=0;i<a+1;i++) cout << 'L';
    for(int i=0;i<b+1;i++) cout << 'U';
    for(int i=0;i<a+1;i++) cout << 'R';
    cout << "DR";
    for(int i=0;i<b+1;i++) cout << 'D';
    for(int i=0;i<a+1;i++) cout << 'L';
    cout << 'U' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
    int h,n,a=0;
    cin>>h>>n;
    int arr[n];
    for (int i=0;i<n;i++){
        cin>>arr[i];
        a=a+arr[i];
        }
        if (a>=h)
            cout<<"Yes";
        else
            cout<<"No";
            }











Measured memory_bytes: 768