akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

int N;
char sq[510][510];
bool rfull[510]; // det if a row is all '#'
bool cfull[510]; // det if a column is all '#'

int solve(int r, int r2) {
	/*bool has = false;
	for(int i=0; i<N; i++) {
		if(sq[r][i]) {
			has = true;
			break;
		}
	}
	if(!has) return N*3; // impossible*/
	int now = 0;
	if(sq[r][r2] == '.') {
		for(int i=0; i<N; i++) {
			if(sq[i][r] == '#') {
				// step 0: need 1 more step
				// perform move (i,r2) to fill sq[i][r] to sq[r][r2]
				now = 1;
				break;
			}
		}
		if(now == 0) {
			return N*3; // impossible
		}
	}
	// step1: copy row r to fill row r2 with all '#'
	// step2: then copy row r2 to fill all '#'
	for(int i=0; i<N; i++) {
		if(sq[r2][i] == '.') {
			// need step1 fill (r,i)
			now ++;
			if(!rfull[r]) {
				// need step2 fill (r2,i)
				now ++;
			}
		}
		else if(!cfull[i]) {
			// need step2 fill (r2,i)
			now ++;
		}
	}
	return now;
}


int main() {
	scanf("%d", &N);
	for(int i=0; i<N; i++) {
		scanf("%s", sq[i]);
	}
	int ans = N*3;
	// prepare
	for(int i=0; i<N; i++) {
		rfull[i] = true;
		cfull[i] = true;
	}
	for(int r=0; r<N; r++) {
		for(int c=0; c<N; c++) {
			rfull[r] = rfull[r] && (sq[r][c] == '#');
			cfull[c] = cfull[c] && (sq[r][c] == '#');
		}
	}
	// check all r=i, r2=j
	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) {
			int now = solve(i, j);
			//printf("%d/%d : %d\n", i, j, now);
			if(now < ans) ans = now;
		}
	}
	printf("%d\n", ans==N*3 ? -1 : ans);
	return 0;
}

/*

fail on

3
.##
...
...

*/

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int a,b;
int main()
{
    cin >> a >> b;
    if(a + b <= 9)
    {
        cout << a + b << endl;
    }
    else
    {
        cout << "error" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int n;
	while(cin >>n){
		if(n == -1){break;}
		double x = n/2;
		for(;;){
			if(fabs(x*x*x-n)<0.00001*n){break;}
			x = x-(x*x*x-n)/(3*x*x);
		}
		printf("%.6lf\n",x);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    // sort(a.rbegin(), a.rend());
    sort(a.begin(), a.end(), greater<int>());
    ll ans = 0;
    int t = n-1;
    rep(i,n) {
        int lim = 2;
        if (i==0) lim = 1;
        rep(j,lim) {
            if (t>0) {
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 4000
use std::io::*;
use std::str::FromStr;

fn main() {
	let x: u64 = read();
	if x == 2 {
		println!("2");
	} else {
		println!("{}", ans(x));
	}
}

fn ans(n: u64) -> u64 {
	let mut k = n-1;
	let m = (n as f64).sqrt().ceil() as u64;
	let p = primes(m);
	'outer: loop {
		k += 1;
		for i in &p {
			if k % i == 0 { continue 'outer; }
		}
		break;
	}
	k
}

fn primes(n: u64) -> Vec<u64> {
	let mut v = Vec::new();
	let mut k = 1;
	if n >= 2 { v.push(2); }
	'outer: while k+2 <= n {
		k += 2;
		'inner: for i in &v {
			if (*i)*(*i) > k {
				break 'inner;
			} else if k % *i == 0 {
				continue 'outer;
			}
		}
		v.push(k);
	}
	v
}

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


Measured memory_bytes: 4352
n=int(input())
a=list(map(int, input().split()))
temp=0
nummin=0
minabs=10**9
ans=0

for i in range(n):
    if a[i]==0:
        ans+=temp
        temp=0
        nummin=0
        minabs=0
    else:
        if a[i]<0:
            temp+=-a[i]
            nummin+=1
        else:
            temp+=a[i]
        if abs(a[i])<abs(minabs):
            minabs=a[i]
if nummin%2==1:
    temp-=abs(minabs)*2
ans+=temp
print(ans)

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		ll cnt=0;
		int b[10][10];
		memset(b,0,sizeof(b));
		string z;
		for(int i=1;i<=n;i++){
			z=to_string(i);
			b[z[0]-'0'][z[z.size()-1]-'0']++;
		}
		ll count=0;
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				count+=b[i][j]*b[j][i];
			}
		}
		cout<<count;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll n,a,b;cin>>n>>a>>b;
    ll mn=min(n*a,b);
    cout<<mn;
	
	
	
 return 0;
}

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

using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
         int n;
         cin>>n;
         map<string,int> m;
         rep(i,0,n){
            string s;
            cin>>s;
            sort(all(s));
            m[s]++;
         }
         int ans=0;
         for(auto j:m) ans+=((j.sc)*(j.sc-1))/2;
        cout<<ans;
    }   
}     

Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
 
using namespace std;
 
int main()
{
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      printf("%dx%d=%d\n",i,j,i*j);
    }
  }
  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	vector<int> dp(n, 1000000001);
	dp[0] = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j >= n) break;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc050/tasks/arc066_a
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))
    al.sort()

    if len(al) % 2 == 1:  # odd
        if al[0] != 0:
            print(0)
            return
        al = al[1:]

    for i in range(0, len(al), 2):
        if al[i] != al[i+1]:
            print(0)
            return

    mod = 10**9 + 7
    print(2 ** (len(al) // 2) % mod)


if __name__ == '__main__':
    main()


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

int main()
{
    int a, b,c;
    cin >> a>> b>>c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

i = a.index(1)

s = n

for j in range(i-k+1, i+k):
    if j < 0:
        continue
    elif j >= n:
        continue
    else:
        l = j
        u = (n-1-j)
        t = (l+k-2) // (k-1) + (u+k-2) // (k-1)
        #print(t)
        s = min(s, t)

print(s)

Measured memory_bytes: 20436
s = input()
ans = 0
for bit in range(2 ** (len(s) - 1)):
    i = 0
    tmp = []
    for j in range(1, len(s) + 1):
        if j != len(s) and bit >> (j - 1) & 1 == 0: continue
        tmp.append(int(s[i:j]))
        i = j
    ans += sum(tmp)
print(ans)

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  VLL p(m);
  vector<string> s(m);
  VLL ng(n, 0);
  VLL ok(n, 0);
  rep(i, m) {
    cin >> p[i] >> s[i];
    p[i]--;
  }

  rep(i,m){
    if (ok[p[i]] == -1) continue;
    if (s[i] == "WA") ng[p[i]]++;
    else
      ok[p[i]] = -1;
  }
  ll ans = 0;
  ll cnt = 0;
  rep(i, n) {
    if (ok[i] == -1){
      ans += ng[i];
      cnt++;
    }
  }
  cout << cnt << ' ' << ans << endl;
  return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

#define MAX_LEN 1010

template<size_t N>
const bitset<N> operator+(const bitset<N>& lhs, const bitset<N>& rhs)
{
    bitset<N> a(lhs), b(rhs), ret(lhs ^ rhs);

    for (b = (a & b) << 1, a = ret; b.any(); b = (a & b) << 1, a = ret) ret ^= b;

    return ret;
}

template<size_t N>
int edit_distance_bitset(const string& s1, const string& s2)
{
    int m = s1.size();
    int n = s2.size();

    const bitset<N> ONE(1);
    bitset<N> Peq[0x100];
    bitset<N> Pv, Mv, Eq, Xv, Xh, Ph, Mh;
    int Score = m;

    for (int i = 0; i < m; i++) {
        Peq[s1[i]] |= ONE << i;
        Pv |= (ONE << i);
    }
    for (int j = 0; j < n; j++) {
        Eq = Peq[s2[j]];
        Xv = Eq | Mv;
        Xh = (((Eq & Pv) + Pv) ^ Pv) | Eq;
        Ph = Mv | ~(Xh | Pv);
        Mh = Pv & Xh;
        if ((Ph & (ONE << (m - 1))).any()) Score++;
        else if ((Mh & (ONE << (m - 1))).any()) Score--;
        Ph = Ph << 1 | ONE;
        Pv = (Mh << 1) | ~(Xv | Ph);
        Mv = Ph & Xv;
    }

    return Score;
}

int main(){
  
    string a,b; 
    cin>>a>>b;
    cout<<edit_distance_bitset<MAX_LEN>(a,b)<<endl;
  return 0;
}

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

void solve(){
    string S, T;
    cin >> S;
    cin >> T;

    int dp[1001][1001];
    dp[0][0] = 0;

    for (int i = 0; i < S.size(); i++){
        for (int j = 0; j < T.size(); j++){
            if (S[i] == T[j])
                dp[i+1][j+1] = dp[i][j] + 1;
            else
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }
    cout << dp[S.size()][T.size()] << endl;
}

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

    for (int i = 0; i < q; i++)
        solve();
}


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

using namespace std;

int main() {
	string S;
	int Year, Month, Day;
	cin >> S;
	Year  = stoi(S.substr(0, 4));
	Month = stoi(S.substr(5, 2));
	Day   = stoi(S.substr(8, 2));
	if (Year < 2019) {
		cout << "Heisei" << endl;
	} else if (Year > 2019) {
		cout << "TBD" << endl;
	} else {
		if (Month < 4) {
			cout << "Heisei" << endl;
		} else if (Month > 4) {
			cout << "TBD" << endl;
		} else {
			cout << "Heisei" << endl;
		}
	}
}


Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var com = Console.ReadLine();
		var c = com.ToArray();
		var N = c.Length;
		var I = G();
		var dx = new List<int>();
		var dy = new List<int>();
		Action<int,int> f = (d, l) => {
			if (d % 2 == 0) dx.Add(l);
			else dy.Add(l);
		};
		var dir = 0;
		var i = 0;
		while (i < N && c[i] == 'F') i++;
		I[0] -= i;
		while (i < N)
		{
			var l = 0;
			while (i < N && c[i] == 'F') { i++; l++; }
			if (l > 0) f(dir, l);
			while (i < N && c[i] == 'T') { i++; dir++; }
		}
		Console.WriteLine(Calc(dx, I[0]) && Calc(dy, I[1]) ? "Yes" : "No");
	}
	bool Calc(List<int> dx, int sum)
	{
		var s = new HashSet<int>{ 0 };
		foreach (var d in dx)
		{
			var t = new HashSet<int>();
			foreach (var x in s)
			{
				t.Add(x + d);
				t.Add(x - d);
			}
			s = t;
		}
		return s.Contains(sum);
	}
}


Measured memory_bytes: 35264
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
#H,N = LI()
_XY = [LI() for _ in range(N)]
# X,Y = zip(*XY)
XY = np.array(_XY)
#C = np.zeros(N + 1)
# print(XY)

# print(np.linalg.norm(XY[1]-XY[0]))

def calcdis(p1,p2):
    return np.linalg.norm(p2-p1)

ans = []
for i in range(N):
    tmp = 0
    for j in range(N):
        if not i==j:
            # print(i,j)
            tmp += calcdis(XY[i],XY[j])
    ans.append(tmp)
print(np.average(ans))

# if ans:
#     print('Yes')
# else:
#     print('No')

Measured memory_bytes: 27284
N = int(input())
if N == 0:
        print("0")
else:
        ans = []
        while N != 0:
                if N%2 == 1:
                        ans.append(1)
                        N -= 1
                        N = N//(-2)
                else:
                        ans.append(0)
                        N = N//(-2)
        ans_str = ""
        for i in ans:
                ans_str = str(i) + ans_str
        print(ans_str)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
    cin>>N>>M;
    vec h(N);
    rep(i,N) cin>>h[i];
    vector<bool> good(N, true);
    rep(i,M){
        cin>>A>>B;
        --A;
        --B;
        if(h[A] >= h[B]) good[B] = false;
        if(h[B] >= h[A]) good[A] = false;
    }
    ll ans = accumulate(ALL(good), 0LL);
    cout<<ans<<endl;
}

Measured memory_bytes: 3996
#include <iostream>
using namespace std;
int main(void){
int H,W;
cin>>H>>W;
string S[50]={};
for(int i=0;i<H;i++)
    cin>>S[i];
const int dx[8]={1,-1,0,0,1,1,-1,-1};
const int dy[8]={0,0,1,-1,1,-1,1,-1};
for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        if(S[i][j]=='#')
            continue;  
        int number=0;
        for(int d=0;d<8;d++){
            int nj=j+dx[d];
            int ni=i+dy[d];
            if(nj<0 or W<=nj)
                continue;
            if(ni<0 or H<=ni)
                continue;
            if(S[ni][nj]=='#')
                number++;
        }
    S[i][j]=char(number+'0');
    }
}
for(int i=0;i<H;i++){
    cout<<S[i]<<endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }

struct UnionFind {
    vector<int> par;
    vector<int> sz;
 
    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }
 
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
 
    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};


int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  rep(i, m) { 
    int a, b;
    cin >> a >> b;
    a--, b--;
    UF.unite(a, b);
  }
  int ans = -1;
  rep(i, n) chmax(ans, UF.size(i));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4772
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define SIZE 222
#define INF 1000000
typedef pair<int, int>pii;
class maxflow
{
public:
	vector<int>pat[SIZE];
	vector<int>cap[SIZE];
	vector<int>rev[SIZE];
	bool flag[SIZE];
	int dist[SIZE];
	int now[SIZE], ind[SIZE];
	int idx[SIZE];
	int flow;
	int gd;
	void adde(int s, int t, int cp)//多重辺は消してから s->tの容量cpの辺をはる
	{
		pat[s].push_back(t);
		pat[t].push_back(s);
		cap[s].push_back(cp);
		cap[t].push_back(0);
		rev[s].push_back(pat[t].size() - 1);
		rev[t].push_back(pat[s].size() - 1);
	}
	void blockflow(int node, int len, int go, int pt)//ブロックフローを求めて流す
	{
		if (pt == len)
		{
			if (node != go)return;
			int mini = INF, rr = -1;
			for (int i = 0; i < pt; i++)if (cap[now[i]][ind[i]] < mini)mini = cap[now[i]][ind[i]], rr = i;
			for (int i = 0; i < pt; i++)cap[now[i]][ind[i]] -= mini, cap[pat[now[i]][ind[i]]][rev[now[i]][ind[i]]] += mini;
			flow += mini;//mini==INFになったら非有界
			gd = rr;
			return;
		}
		now[pt] = node;
		for (int i = idx[node]; i < pat[node].size(); i++)
		{
			if (dist[pat[node][i]] == dist[node] + 1 && cap[node][i]>0)
			{
				ind[pt] = i;
				blockflow(pat[node][i], len, go, pt + 1);
				if (gd < pt)break;
				else gd = INF;
			}
			idx[node]++;
		}
	}
	void dinic(int st, int go, int num)//dinicのアルゴリズムで最大流を求める 変数flowにmaxflowの値が入る
	{
		flow = 0;
		for (;;)
		{
			queue<pii>que;
			fill(dist, dist + num, INF);
			fill(flag, flag + num, false);
			que.push(make_pair(st, 0));
			for (;;)
			{
				if (que.empty())break;
				pii z = que.front();
				que.pop();
				if (flag[z.first])continue;
				flag[z.first] = true;
				dist[z.first] = z.second;
				for (int i = 0; i < pat[z.first].size(); i++)
				{
					if (dist[pat[z.first][i]]>z.second + 1 && cap[z.first][i] > 0)
					{
						dist[pat[z.first][i]] = z.second + 1;
						que.push(make_pair(pat[z.first][i], z.second + 1));
					}
				}
			}
			if (dist[go] == INF)return;
			gd = INF;
			fill(idx, idx + SIZE, 0);
			blockflow(st, dist[go], go, 0);
		}
	}
	vector<int>getcut(int st, int go, int num)//頂点iがmincutのst側なら1 そうでなければ0
	{
		dinic(st, go, num);
		vector<int>ret;
		for (int i = 0; i < num; i++)ret.push_back(flag[i]);
		return ret;
	}
};
maxflow gr;
char m[200][200];
int main()
{
	int mx, my;
	scanf("%d%d", &mx, &my);
	for (int i = 0; i < mx; i++)scanf("%s", m[i]);
	int sx, sy, gx, gy;
	for (int i = 0; i < mx; i++)
	{
		for (int j = 0; j < my; j++)
		{
			if (m[i][j] != '.')gr.adde(i, j + 100, 1), gr.adde(j + 100, i, 1);
			if (m[i][j] == 'S')sx = i, sy = j + 100;
			if (m[i][j] == 'T')gx = i, gy = j + 100;
		}
	}
	gr.adde(200, sx, INF);
	gr.adde(200, sy, INF);
	gr.adde(gx, 201, INF);
	gr.adde(gy, 201, INF);
	gr.dinic(200, 201, 202);
	if (gr.flow >= INF)printf("-1\n");
	else printf("%d\n", gr.flow);
}

Measured memory_bytes: 896
#include<stdio.h>
#define N 20
#define TRUE 1
#define FALSE 0

int solve(int, int);

int a;
int A[N];

int main(){
  int b,i,k,j,B[200];

  scanf("%d",&a);
  for(i=0;i<a;i++)
    scanf("%d",&A[i]);

  scanf("%d",&b);
  for(j=0;j<b;j++)
    scanf("%d",&B[j]);

  for(k=0;k<b;k++){
    
    if( solve(0,B[k]) ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }

  return 0;
}


int solve(int i,int b){
  int res;
  if (b == 0){
    //printf("yes\n");
    return TRUE;
  }
	     
  if (i >= a){
    //printf("no\n");
    return FALSE;
  }
  
  res = solve(i + 1, b) || solve(i + 1, b - A[i]);
  return res;
}



Measured memory_bytes: 2104
'use strict';
const main = (input) => {
const inputData = input.split(' ');
const a = parseInt(inputData[0], 10);
  const b = parseInt(inputData[1], 10);
  const c = parseInt(inputData[2], 10);
  if((a == b || b == c || c == a) && (a !== b || b !== c || c !== a)){
  console.log('Yes');
  } else {
  console.log('No');
  }
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll a, b, c; cin >> a >> b >> c;
	ll d = c - a - b;
	if (d <= 0)cout << "No" << endl;
	else if (4 * a*b < d*d)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long 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 pair<long, long> PLL;
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 SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;



int cnt[123457*2];
int main(){
	int N;
	cnt[0]=cnt[1]=0;
	FOR(i,2,123457*2){
		bool flag=true;
		for(int j=2;j*j<=i;j++)if(i%j==0)flag=false;
		if(flag)cnt[i]=cnt[i-1]+1;
		else cnt[i]=cnt[i-1];
	}
	
	while(cin>>N){
		if(N==0)break;
		cout<<cnt[2*N]-cnt[N]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2124
arr = gets.chomp.split.map(&:to_i)
result = [0, 0, 0, 0, 0]
prev = arr[1]
pd1 = pd2 = nil
arr[2..-1].each{|x|
    d = (x == prev) ? 0 : (x > prev) ? 1 : -1
    prev = x
    
    if d != pd1
        case pd1
        when 0
            case d
            when +1
                case pd2
                when +1 then result[2] += 1
                when -1 then result[1] += 1
                end
            when -1
                case pd2
                when -1 then result[2] += 1
                when +1 then result[0] += 1
                end
            end
        when +1, -1
            case d
            when +1 then result[4] += 1
            when -1 then result[3] += 1
            end
        end
        pd2 = pd1
        pd1 = d
    end
}
puts result.join(" ")


Measured memory_bytes: 12320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=505,di[4][2]={1,0,0,1,-1,0,0,-1};

int n,dis[MAXN][MAXN],a[MAXN][MAXN];
pii q[MAXN*MAXN];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int x,y;
	readint(n);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			dis[i][j]=min(min(i,n-i+1),min(j,n-j+1)),a[i][j]=1;
	int ans=0;
	for(int t=1;t<=n*n;++t)
	{
		readint(x);y=(x-1)%n+1,x=(x-1)/n+1;
		--dis[x][y];a[x][y]=0;
		ans+=dis[x][y];
		int front=1,rear=0;
		q[++rear]=mp(x,y);
		while(front<=rear)
		{
			pii p=q[front++];
			int x=p.x,y=p.y;
			for(int d=0;d<4;++d)
			{
				int tx=x+di[d][0],ty=y+di[d][1];
				if(!tx || !ty || tx>n || ty>n || dis[tx][ty]<=dis[x][y]+a[tx][ty])continue;
				dis[tx][ty]=dis[x][y]+a[tx][ty];
				q[++rear]=mp(tx,ty);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7508
#include <iostream>

#define SIZE 2010
int ans[SIZE];

int main() {
    int n, x, y; std::cin >> n >> x >> y; --x; --y;

    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            int dist = std::min(abs(y-i)+1+abs(x-j), abs(x-i)+1+abs(y-j));
            dist = std::min(dist, j-i);
            ++ans[dist];
        }
    }
    for (int i=1; i<n; ++i)
        std::cout << ans[i] << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <math.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const int inf = 1000000000;
const double eps = 1e-7;

const int mod = 1000000007;

ll sum(ll a) {
	return a * (a + 1) / 2;
}

ll sum(ll l, ll r) {
	return sum(r) - sum(l - 1);
}

void solve() {
	int n, k;
	cin >> n >> k;
	
	ll ans = 0;
	for (int i = k; i <= n + 1; ++i) {
		ll l = sum(i - 1);
		ll r = sum(n - i + 1, n);
		ans = (ans + r - l + 1) % mod;
	}
	
	cout << ans << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; ++i)
		solve();
	return 0;
}

Measured memory_bytes: 3632
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
ll N;
ll dp[1145141]={0};
ll MOD = 1000000007;
ll bik[1145141];
ll bikinv[1145141];
ll gcd(ll a, ll b) {
	return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
ll extgcd(ll a, ll b, ll &x, ll &y) {
	ll g = a; x = 1; y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
ll invMod(ll a, ll m) {
	ll x, y;
	if (extgcd(a, m, x, y) == 1) return (x + m) % m;
	else                         return 0; // unsolvable
}
void bikcal(int NN){
	ll hoge=(ll)1;
	bik[0]=(ll)1;
	bikinv[0]=(ll)1;
	for(int i=1;i<NN;i++){
		hoge=(hoge*(ll)i)%MOD;
		bik[i]=hoge;
		bikinv[i]=invMod(bik[i],MOD);
	}
}


ll Comb(int a,int b){
	ll ret;
	ret=(((bik[a]*bikinv[b])%MOD)*bikinv[a-b])%MOD;
	return ret;
}
int main(){
	cin>>N;
	int now=0;
	bikcal(N+1);
	//cout<<bikinv[0]<<endl;
	//cout<<Comb(4,0)<<endl;
	ll ans=0;
	for(int i=(N+1)/2;i<=N-1;i++){
		dp[i]=(((bik[i]*bik[N-i-1])%MOD)*Comb(i-1,2*i-N))%MOD;
		//if(i!=(N-1)&&(N%2==1))dp[i]=(2*dp[i])%MOD;
		//cout<<dp[i]<<endl;
		ans=(ans+(((dp[i]-dp[i-1]+MOD)%MOD)*(ll)i)%MOD)%MOD;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 24832
#include "bits/stdc++.h"
#define ll long long
#define ld long double 
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define ee 1000000007
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

void solve() {
	ll n, k;
	cin >> n >> k;
	ll a[n];
	For(i, 0, n) {
		cin >> a[i];
	}
	ll dp[n];
	For(i, 0, n)
		dp[i] = ee;
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	For(i, 2, n) {
		For(j, max((ll)0, i - k), i) {
			dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
			//cout << dp[i] << "\n";
		}
	}
	cout << dp[n - 1] << "\n";
}

int main() {
    fio;
    ll t = 1;
    //cin >> t;
    while(t--) {
    	solve();
    }
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
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(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int x,y,z;
  cin>>x>>y>>z;

  int ct=1;

  int now=2*z+y;

  rep(i,100000){
    now+=y+z;
    if(now>x) break;
    ct++;
  }

  cout<< ct<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s, t := r.nextString(), r.nextString()

	fmt.Fprintln(stdout, t+s)
}


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

int main(){
  long long h,w,ans=1e18,yoko,tate;
  cin>>h>>w;
  yoko=w/2;
  tate=h/2;
  if(h==3||w==3){
    cout<<0<<endl;
    return 0;
  }
  for(int i=1;i<h-1;i++){
    long long tate1=(h-i)/2;
    ans=min(ans,max({i*w,tate1*w,(h-tate1-i)*w})-min({i*w,tate1*w,(h-tate1-i)*w}));
  }
  for(int i=1;i<w-1;i++){
    long long yoko1=(w-i)/2;
    ans=min(ans,max({i*h,yoko1*h,(w-yoko1-i)*h})-min({i*h,yoko1*h,(w-yoko1-i)*h}));
  }
  for(int i=1;i<h;i++){
    ans=min(ans,max({i*w,(h-i)*yoko,(h-i)*(w-yoko)})-min({i*w,(h-i)*yoko,(h-i)*(w-yoko)}));
  }
  for(int i=1;i<w;i++){
    ans=min(ans,max({i*h,(w-i)*tate,(w-i)*(h-tate)})-min({i*h,(w-i)*tate,(w-i)*(h-tate)}));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
vector<int> G[10010];
vector<int> c;
bool flag[10010];
int ans[10010];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int sum = 0;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        sum += x;
        c.push_back(x);
    }
    sort(c.rbegin(), c.rend());
    queue<int> q;
    q.push(1);
    flag[1] = true;
    int idx = 0;
    while(!q.empty()){
        int a = q.front();
        ans[a] = c[idx++];
        q.pop();
        for(int i = 0; i < G[a].size(); i++){
            int g = G[a][i];
            if(!flag[g]){
                flag[g] = true;
                q.push(g);
            }
        }
    }
    cout << sum - c[0] << endl;
    for(int i = 1; i <= N; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

struct node{int key; node *p, *l, *r;};

node *nil, *root;

void preparse(node *root){
    if(root == nil) return;
    cout << " " << root->key;
    preparse(root->l);
    preparse(root->r);
}

void inparse(node *root){
    if(root == nil) return;
    inparse(root->l);
    cout << " " << root->key;
    inparse(root->r);
}

void insert(int k){
    node *y = nil;
    node *x = root;
    node *z;
    z = (node *)malloc(sizeof(node));
    z->key = k;
    z->l = nil;
    z->r = nil;
    while(x != nil){
        y = x;
        if(z->key < x->key) x = x->l;
        else x = x->r;
    }
    z->p = y;
    if(y == nil) root = z;
    else if(z->key < y->key) y->l = z;
    else y->r = z;
}

int main(){
    int n, d;
    string com;
    cin >> n;
    rep(i, n){
        cin >> com;
        if(com == "insert"){
            cin >> d;
            insert(d);
        }else if(com == "print"){
            inparse(root);
            cout << endl;
            preparse(root);
            cout << endl;
        }
    }
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> c(10, vector<int>(10));
  rep(i, 10) rep(j, 10) cin >> c[i][j];
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (a[i][j] == -1) continue;
    ans += c[a[i][j]][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  int a,b;
  cin >> a >> b;
  if(a<b)swap(a,b);
  rep(i,a)cout << b;
  cout << endl;
}


Measured memory_bytes: 256
sub f{$_-$u[$_]?(map$_=&f,$u[$_])[0]:$_}map{@u=0..$`;($==f$_=<>=~$"*$')-($%=f$_=$`)and$u[$%]=$=for 1..$_;@{$|--}=map f,@u}<>=~/ \d+/g;print$$_,$/for map{++${$t=\${$0[$_]}{$1[$_]}};$t}1..$`

Measured memory_bytes: 164608
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    ll h, a;
    cin >> h >> a;
    auto ans = h / a;
    if (h % a != 0) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		ll ans = 0;
		FOR(x, 1, 100) FOR(y, 1, 100) {
			ll b = x + y, c = x*x + y*y + x*y - i;
			if (c > 0) continue;
			if (b*b - 4*c < 0) continue;
			//cout << i << " " << x << " " << y << "\n";
			ll disc = sqrt(b*b - 4*c);
			if (disc * disc != b * b - 4*c) continue;
			ll num = -b + disc;
			if (num >= 2 and num % 2 == 0) ans++;
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 3540
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

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

int main(void) {
    int num = get_int();
    int arr[NUM_MAX];
    fget_array(arr, num);

    int ans = arr[0];
    int i;
    for(i = 1; i < num; i++) {
        int val = arr[i];
        if(ans > val) swap(&ans, &val);
        ans = gcd(ans, val);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<numeric>
using namespace std;
long long gcd(long long m,long long n){
  if(n==0)return abs(m);
  else return gcd(n,m%n);
}
long long lcm(long long m,long long n){
  return m/gcd(m,n)*n;
}
int main(){
  long long n,temp,gc,temp2;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> temp;
    if(i==0){
      gc=temp;
    }else{
      if(temp>gc) gc=lcm(temp,gc);
      else gc=lcm(gc,temp);
    }
  }
  cout << gc <<endl;
}


  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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



Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  scanf("%d", &n);
  map<int, int> mp;
  for (int i = 0; i < (1 << n); ++i) {
    int x;
    scanf("%d", &x);
    ++mp[-x];
  }
  vector<int> tr(1 << (n + 1));
  auto it = mp.begin();
  tr[1] = it->first;
  if (--(it->second) == 0)
    mp.erase(it);
  bool ok = true;
  for (int i = 1; i < (1 << n); ++i) {
    tr[i << 1] = tr[i];
    it = mp.upper_bound(tr[i]);
    if (it == mp.end()) {
      ok = false;
      break;
    }
    tr[i << 1 | 1] = it->first;
    if (--(it->second) == 0)
      mp.erase(it);
  }
  puts(ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 14592