akhauriyash/Code-Regression huggingface dataset:
def submit():
    n = int(input())
    a = list(map(int, input().split()))
    
    a_max = max(a) # -> n
    a.remove(a_max)

    r_best = a_max / 2
    a_diff = [(i, abs(e - r_best)) for i, e in enumerate(a)]
    a_diff.sort(key=lambda x: x[1])
    print(a_max, a[a_diff[0][0]])


submit()
    

    

Measured memory_bytes: 21600
N = int(input())
A = tuple(map(int,input().split()))
B = tuple(map(int,input().split()))

x = 0
y = 0
for a,b in zip(A,B):
  if a > b:
    x += a-b
  else:
    y += (b-a)//2

print('Yes' if y >= x else 'No')

Measured memory_bytes: 4600
s = input()
l = len(s)
S =[]
for i in range(l):
    S.append(int(s[i]))
m = [1]
n = [0]
for i in range(1,l):
    if i % 2 == 1:
        m.append(0)
        n.append(1)
    else:
        m.append(1)
        n.append(0)
ans1 = 0
ans2 = 0
for i in range(l):
    if m[i] != S[i]:
        ans1 += 1
    if n[i] != S[i]:
        ans2 += 1
print(min(ans1,ans2))

Measured memory_bytes: 5612
#include<bits/stdc++.h>
using ll = long long;
const ll INF = 1000000000000;
#define fir first
#define sec second

class Union_Find{
private:
    std::vector<long long> data; //data[i] : 頂点iの親
public:
    Union_Find(int n){
        data.resize(n,-1);
    }
    //頂点iの親を返す
    int root(int i){
        if(data[i] < 0)return i;
        else return data[i] = root(data[i]);
    }
    //連結
    void unit(int i,int j){
        i = root(i);j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
    }

    //頂点iの属する集合の頂点数
    int size(int i){
        i = root(i);
        return data[i];
    }
};

int main()
{
    int n,m;
    std::cin >> n >> m;
    std::vector<int> p(n);
    for(int i = 0; i < n; i++){std::cin >> p[i];p[i]--;}
    Union_Find uni(n);
    for(int i = 0; i < m; i++){
        int t,k; std::cin >> t >> k;
        t--;
        k--;
        uni.unit(t,k);
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(uni.root(p[i]) == uni.root(i))cnt++;
    }
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 1408
N, X = map(int,input().split())
A = tuple(map(int,input().split()))

def it():
    memo = [float('inf')]*N
    for offset,n in zip(range(-N,0),range(N)):
        for i,v in enumerate(memo):
            memo[i] = min(v, A[i+offset])
        yield sum(memo) + n*X

print(min(it()))

Measured memory_bytes: 42972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX = 4e5 + 50 ;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m  , a , b , k , Q  , ind  , x , y, ans , p , T , G; string s;
vector < ll > v ;
map < ll , ll > occ;
ll solve(ll a , ll b , ll L , ll R){
    if(a > b)
        return L;
    return R;
}

ll sum_left[MAX],sum_right[MAX];
vector < ll > org;
ll calc(ll b){
    ll ans = 0 ;
    for(int i = 0 ; i < n ; ++i)
        ans += abs(org[i] - (b + i + 1));
    return ans;
}
int main(){

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


    cin >> n ;
     if(n == 1)
        return cout << 0 << '\n' , 0;
     for(int i = 0 ; i < n ; ++i)
        cin >> x , v.pb(x - i - 1) ;

    sort(all(v));

    ans = 1e18;



    for(int i = n - 2 ; i >=0 ; --i)
        sum_right[i] = sum_right[i + 1] + (n - i - 1) * 1LL * (v[i + 1] - v[i]) ;
    for(int i = 1 ; i < n ; ++i)
        sum_left[i] = sum_left[i - 1] + i * 1LL * (v[i] - v[i - 1]);


    for(int i = 0 ; i < n - 1 ; ++i){
       ll b = solve(i + 1 , n - i - 1 , v[i],v[i + 1]);
    ans = min(ans , (sum_left[i] + sum_right[i + 1] + (b - v[i])* 1LL * (i + 1) + (v[i + 1] - b) * 1LL * (n - i - 1)));


    }



    cout << ans << '\n';

     return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1<<21
#define N 100

int n, A[N][N];

int ans() {
	int color[N], p[N], d[N];
	int u, minv;

	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		d[i] = INFTY;
		p[i] = -1;
	}
	d[0] = 0;

	while (1) {
		u = -1;
		minv = INFTY;
		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK && d[i] < minv) {
				minv = d[i];
				u = i;
			}
		}

		if (u == -1) break;
		color[u] = BLACK;

		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK && A[u][i] != INFTY) {
				if (A[u][i] < d[i]) {
					d[i] = A[u][i];
					p[i] = u;
					color[i] = GRAY;
				}
			}
		}
	}

	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1) sum += A[i][p[i]];
	}
	return sum;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int e;
			cin >> e;
			A[i][j] = (e != -1) ? e : INFTY;
		}
	}
	cout << ans() << endl;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
  int a, b;
  scanf("%d%d", &a, &b);
  int i;
  int count = 0;
  for(i = a; i <= b; i++){
    if(((i / 10000) % 10) == i % 10){
      if((i / 1000) % 10 == (i / 10) % 10){
        count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size()) if (s[i] == '1') ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

int n, k;
vector<vector<int>> g;
mint res;
vector<ll> cnt;
vector<bool> used;
vector<int> dep;
void dfs(int cur, int pre) {
	if (pre == -1) dep[cur] = 0;
	else dep[cur] = dep[pre] + 1;
	int t = 1;
	if (dep[cur] >= 2) cnt[cur] -= 1;
	res *= cnt[cur];
	for (auto nxt : g[cur]) {
		if (nxt == pre)continue;
		cnt[nxt] -= t;
		dfs(nxt, cur);
		t++;
	}
}
int main()
{

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

	cin >> n >> k;
	g.resize(n); dep.resize(n);
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	cnt.resize(n, k);
	res = 1;
	dfs(0, -1);
	cout << res.x << "\n";
	return 0;
}


Measured memory_bytes: 13372
a, b, c = list(map(int, input().split()))
k = int(input())

count = 0
while True:
    if b > a:
        break
    b *= 2
    count += 1
while True:
    if c > b:
        break
    c *= 2
    count += 1
if count <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8880
#include <stdio.h>

int main(){
  int N,M,S=0,V=0;
  int A[102];
  scanf("%d %d",&N,&M);
  for(int i=1;i<=N;i++){
    scanf("%d",A+i);
    V+=A[i];
    A[i]*=4*M;
  }
  for(int i=1;i<=N;i++){
    if(A[i]>=V) S++;
  }
  if(S>=M) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    for(int i = 0; i<N; ++i) cin >> a[i];
    // a1 > a2 < a3 > a4 < a5 > a6 < a7 (> a8)
    // sum = a1-a2 + a3-a2 + a3-a4 + a5-a4 + a5-a6 + a7-a6 + (a7-a8)
    // sum = a1 - 2*a2 + 2*a3 - 2*a4 + 2*a5 - 2*a6 + a7(*2 - a8)
    sort(a, a + N);

    ll ans = 0;
    if(N % 2 == 0){ // a1 > a2 < a3 ... > aN
        ans -= a[N/2-1]; // most large num of subtracted
        ans += a[N/2]; // most small num of added
        for(int i=0    ; i < N/2-1; ++i) ans -= a[i] * 2;
        for(int i=N/2+1; i < N    ; ++i) ans += a[i] * 2;
    } else {
        // 1, a1 > a2 < a3 ... < aN
        ll ans1 = 0;
        for(int i=0    ; i < N/2; ++i) ans1 -= a[i] * 2;
        ans1 += a[N/2  ];
        ans1 += a[N/2+1];
        for(int i=N/2+2; i < N  ; ++i) ans1 += a[i] * 2;

        // 2, a1 < a2 > a3 ... > aN
        ll ans2 = 0;
        for(int i=0    ; i < N/2-1; ++i) ans2 -= a[i] * 2;
        ans2 -= a[N/2-1];
        ans2 -= a[N/2  ];
        for(int i=N/2+1; i < N    ; ++i) ans2 += a[i] * 2;

        ans = max(ans1, ans2);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main()
{
  int n, m, S[10000], T[500], i, j, count;
  count = 0;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
  
  scanf("%d", &m);
  for(i = 0; i < m; i++){
    scanf("%d", &T[i]);
  }
  
  for(i = 0; i < n; i++){
    for(j = i+1; j < n; j++){
      if(S[i] == S[j]){
        S[j] = -1;
      }
    }
  }
  
  for(i = 0; i < m; i++){
    for(j = 0; j < n; j++){
      if(T[i] == S[j]){
        count++;
      }
    }
  }
  
  printf("%d\n", count);
}

Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
#define N 3010
int dp[N][N];
int main ()
{
    string s, t, sol;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= m; j ++) {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }
    while (n > 0 && m > 0) {
        if (s[n - 1] == t[m - 1] && dp[n][m] == dp[n - 1][m - 1] + 1) {
            sol = s[n - 1] + sol;
            n --;
            m --;
        } else if (dp[n - 1][m] > dp[n][m - 1]) {
            n --;
        } else {
            m --;
        }
    }
    cout << sol;
    return 0;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

ll N, K;

int main(void) {
    cin >> N >> K;

    vector<ll> nums(100001);

    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        nums[a] += b;
    }

    ll ans = 0;
    for(int i = 1; i <= 100000; ++i) {
        if (nums[i] >= K) {
            ans = i;
            break;
        }
        K -= nums[i];
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

unsigned long gcd(unsigned long x, unsigned long y)
{
 
  if(y == 0)
      return x;
  else
    return gcd(y, x%y);
}

int main()
{
  unsigned long A, B;

  cin >> A >> B;
  
  unsigned long elm =  gcd(A, B);

  cout << A*B/elm << endl; 
  
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
int a,b[10],j=0;
for(int i=0;i<10;i++) b[i]=0;
scanf("%d",&a);
for(int i=1;i<10;i++) {
	if(a%i==0) b[0]=i;}
for(int i=1;i<10;i++){
	if((a/b[0])%i==0) b[1]=i;}
if(b[0]*b[1]==a) printf("Yes\n");
else printf("No\n");
return 0;
}


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

#define mp make_pair
#define pb push_back
#define MOD 1000000007LL
#define INF 1000000000000000018LL
#define F first
#define S second
#define ll long long
#define ld long double
#define eps 1e-9

ll gcd(ll a, ll b)
{
	if(a == 0LL)
		return b;
	if(b == 0LL)
		return a;
	return gcd(b, a%b);
}

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 200005;

void solve()
{
	ll n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	ll g = gcd(n, m);
	bool flag = true;
	ll p1 = n/g;
	ll p2 = m/g;
	int pt1 = 0, pt2 = 0;
	while(pt1 < n)
	{
		flag = flag&(s[pt1] == t[pt2]);
		pt1 += p1;
		pt2 += p2;
	}

	if(flag)
	{
		n = n/g;
		cout << n*m << "\n";
		return;
	}
	cout << "-1\n";

	return;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	// freopen("in.in", "r", stdin);
	// freopen("out.out", "w", stdout);

	clock_t clk = clock();
	
	int t = 1;
	// cin >> t;
	for(int tests = 1; tests <= t; tests++)
	{
		// cout << "Case #" << tests << ": ";
		solve();
	}

	clk = clock() - clk;
	cerr << "Time Elapsed: " << fixed << setprecision(10) << ((long double)clk)/CLOCKS_PER_SEC << "\n";

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    ll a,b,c,x,y;
    ll ans=0;
	cin >> a>> b>> c>>x>>y;
    if(a+b>2*c){
      ans+=min(x,y)*2*c;
      if(x>y){
        ans+=min(a,2*c)*(x-y);
      }
      else if(y>x){
        ans+=min(b,2*c)*(y-x);
      }
    }
    else ans+=a*x+b*y;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "string.h"
using namespace std;
 
int main(){
 
  int K,len;
  string S;
  
  cin >> K;
  cin >> S;
 
  if(K>=S.size()) len=S.size();
  else len=K;
  
 for(int i=0; i<len; i++){
  cout << S[i]; 
 }
  
  if(S.size()>K) cout <<"...";
  
  return 0;
  
}

Measured memory_bytes: 3624
uses crt;
var n,d,i,j:longint;
    a:array[1..200000]of longint;
begin
        clrscr;
        readln(n);
        for i:=1 to n do
        read(a[i]);
        d:=1;
        for i:=1 to n do
        if (a[i]=d)then inc(d);
        if (d=1)then write(-1) else write(n-d+1);
        readln;
        readln
end.



Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n + 1), b(n);
  for(int i = 0; i <= n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  ll sum = 0;
  for(int i = n - 1; i >= 0; i--) {
    if(b[i] <= a[i + 1]){
      sum += b[i];
    }else{
      sum += a[i + 1];
      b[i] -= a[i + 1];
      if(b[i] <= a[i]){
        sum += b[i];
        a[i] -= b[i];
      }else{
        sum += a[i];
        a[i] = 0;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	int N, K;
	char *S;
	cin >> N >> K;
	S = (char *)malloc(sizeof(char) * N);
	cin >> S;
	S[K - 1] = S[K - 1] - 'A' + 'a';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [""] * N
T = [0] * N
for i in range(N):
    s, t = input().split()
    S[i] = s
    T[i] = int(t)
X = input()

t = 0
for i in range(N):
    t += T[i]
    if S[i] == X:
        break
print(sum(T) - t)


Measured memory_bytes: 38484
#include<stdio.h>
#define M 500000
 
int a[M],b[M],count=0;
 
void ms(int *a,int l,int r)
{
  int i,j,k,m;
  if(r>l){
    m=(r+l)/2;
    ms(a, l, m);
    ms(a, m+1, r);
 
    for(i=m+1; i>l; i--){
      b[i-1]=a[i-1];
    }
  
    for(j=m; j<r; j++){
      b[r+m-j]=a[j+1];
    }
 
    for(k=l; k<=r; k++){
      a[k]=(b[i]<b[j])?b[i++]:b[j--];
      count++;
    }
  }
}

int main()
{
  int i, n;
 
  scanf("%d", &n);
  for(i=0; i<n; i++)
    scanf("%d", &a[i]);
  ms(a, 0, n-1);
  for(i=0; i<n-1; i++){
 printf("%d ", a[i]); 
  }
 
  printf("%d\n%d\n", a[n-1], count);
  return 0;
} 


Measured memory_bytes: 5688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

int main() {
    int h, w, n;
    cin >> h;
    cin >> w;
    cin >> n;
    int ans;
    if(h>w) {
        if(n%h==0) {
            ans = n/h;
        } else {
            ans = n/h+1;
        }
    } else {
        if(n%w==0) {
            ans = n/w;
        } else {
            ans = n/w+1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define p pair<int,int>
#define ll long long
ll N, M;
vector<p> E;
vector<ll> ans;
int par[100010];
int ran[100010];
ll siz[100010];
ll res;


void init(int n){
    for(int i = 1; i <= N; i++){
        par[i] = i;
        ran[i] = 0;
        siz[i] = 1;
    }
}

int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
}

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

    res -= siz[x] * siz[y];
    if(ran[x] > ran[y]){
        par[y] = x;
        siz[x] += siz[y];
    }else{
        par[x] = y;
        siz[y] += siz[x];
        if(ran[x] == ran[y]) ran[y]++;
    }
}

int main(){
    cin >> N >> M;

    res = N * (N - 1) / 2;
    init(N);

    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        E.push_back({A, B});
    }
    for(int i = M - 1; i >= 0; i--){
        ans.push_back(res);
        unite(E[i].first, E[i].second);
    }
    for(int i= M - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

int v[20],c[20],sub[20],n,res;

void bubblesort(int *a,int n)
{

    for (int i = 0 ; i < n ; i ++)
        for (int j = 0 ; j < n - i - 1 ; j ++)
            if (a[j] > a[j+1]) swap(a[j],a[j+1]);

}

int main()
{
    cin >> n;
    for (int i = 0 ; i < n ; i ++) cin >> v[i];
    for (int i = 0 ; i < n ; i ++) cin >> c[i];
    for (int i = 0 ; i < n ; i ++) sub[i] = v[i] - c[i];
    bubblesort(sub,n);
    for (int i = n - 1; i >= 0 ; i --) if (sub[i] > 0) res += sub[i];
    cout << res;
}


Measured memory_bytes: 256
i=list(map(int,input().split()))
j=list(map(int,input().split()))
h=i[0]
a=True
c=0
j.sort(reverse=True)
for b in j:
  c+=b
  if c>=h:
    print("Yes")
    a=False
    break
if a:
  print("No")


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ope;
    bool ok = true;
    for (int i = n - 1; i >= 0; i--) {
        bool found = false;
        for (int j = i; j >= 0; j--) {
            if (a[j] == j + 1) {
                found = true;
                a.erase(a.begin() + j);
                ope.push_back(j);
                break;
            }
        }
        if (!found) {
            ok = false;
            break;
        }
    }
    reverse(ope.begin(), ope.end());
    if (ok) for (auto x:ope)cout << x + 1 << endl;
    else cout << -1 << endl;
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll h, n; cin >> h >> n;
  vll a(n);
  ll su = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    su += a[i];
  }
  cout << (su >= h ? "Yes" : "No") << endl;



}


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

ans = []

x = 0
for i, ai in enumerate(A):
    if i % 2 == 0:
        x += ai
    else:
        x -= ai

ans.append(x)

for ai in A:
    x = 2 * ai - x
    ans.append(x)

ans = [str(i) for i in ans[:-1]]
print(" ".join(ans))

Measured memory_bytes: 19276
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b)cout<<"delicious"<<endl;
  else if(a<b&&b-a<=x)cout<<"safe"<<endl;
  else if(a<b&&b-a>x)cout<<"dangerous"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l[105],n,ans=0;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>l[i];
	}
	sort(l+1,l+1+n);
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			for (int k=j+1;k<=n;k++)
			{
				if (l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]&&l[i]+l[j]>l[k])   ans++;
			}
		}
	}
	cout<<ans;
	return 0;
} 

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

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int ans = r * 100 + g * 10 + b;
    if (ans % 4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>

using namespace std;

int main() {

	int N;

	cin >> N;

	int* X = new int[N];
	float u = 0;
	int x = 0;

	for (int i = 0; i < N; ++i)
	{
		cin >> X[i];
	}

	for (int i = 0; i < N; ++i)
	{
		u += X[i];
	}

	u = round(u / N);

	for (int i = 0; i < N; ++i)
	{
		x += (X[i] - u) * (X[i] - u);
	}

	cout << x;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  int A[N],ans = 0,min_val = 0;
  rep(i,N){
    cin >> A[i];
    //ひく数は10の倍数でない数のうち最小？
    if(A[i] % 10 != 0){
      if(min_val == 0 || min_val > A[i]) min_val = A[i];  
    }
    ans += A[i];
  }
  if(ans % 10 == 0){
    ans -= min_val;
    if(ans % 10 == 0) ans = 0;
  }
  cout << ans << endl;
  return 0;
}


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

#define M 1e9+7
#define ll long long int
#define vii vector<int>
#define pii pair<int,int>

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

    int n;
    cin>>n;

    int a[n][3];

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }

    int dp[n][3]={0};

    for(int i=0;i<3;i++){
        dp[0][i]=a[0][i];
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=a[i][j]+max(dp[(i-1)][(j+1)%(3)],dp[(i-1)][(j+2)%(3)]);
        }
    }

    int ans=max(dp[n-1][0],max(dp[n-1][2],dp[n-1][1]));
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main() {
  int i, j, n, t, k, id, G[101][101];

  scanf("%d", &n);
  for(i = 0;i < n;i++)
    for(j = 0;j < n;j++)
      G[i][j] = 0;

  for(i = 0;i < n;i++) {
    scanf("%d", &id);
    scanf("%d", &k);
    for(j = 0;j < k;j++) {
      scanf("%d", &t);
      G[id - 1][t - 1] = 1;
    }
  }

  for(i = 0;i < n;i++) {
    for(j = 0;j < n - 1;j++)
      G[i][j] ? printf("1 ") : printf("0 ");
    G[i][j] ? printf("1\n") : printf("0\n");
  }

  return 0;
}



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

int main(){
    int a[4];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7){
        puts("YES");
    }else{
    
        puts("NO");
    }
    return 0;
}
 

Measured memory_bytes: 256
m = []
N = gets.to_i
(N-1).times{|i|
  m[i] = gets.split[0].to_i
}
m.concat gets.split.map &:to_i
cost = Array.new(N){Array.new(N, 0x7fffffff)}
N.times{|i| cost[i][i] = 0}
(1...N).each{|d|
  (0...N-d).each{|first|
    last = first + d
    a = []
    (first...last).each{|s|
      a << cost[first][s] + cost[s+1][last] + m[first] * m[s+1] * m[last+1]
    }
    cost[first][last] = a.min
  }
}
puts cost[0][N-1]

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

int main ()
{
  int n, m, l;
  int a[100][100];
  int b[100][100];
  long c;

  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++) cin >> b[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      c = 0;
      for (int k = 0; k < m; k++) c += a[i][k] * b[k][j];
      cout << c; if (j < l-1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}


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

#define LL long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    LL a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    LL xr = a[0];
    for(int i=1;i<n;i++){
        xr ^= a[i];
    }
    for(int i=0;i<n;i++){
        LL tmp = xr^a[i];
        cout << tmp << ' ';
    }cout << '\n';
    
    return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, p;
    string s;
    cin >> n >> p >> s;

    if (p == 2) {
        ll a = 0;
        REP(i, n) {
            if ((int)(s[i] - '0') % 2 == 0) {
                a += i + 1;
            }
        }
        cout << a << endl;
        return;
    }

    if (p == 5) {
        ll a = 0;
        REP(i, n) {
            if ((int)(s[i] - '0') % 5 == 0) {
                a += i + 1;
            }
        }
        cout << a << endl;
        return;
    }
    map<int, ll> m;
    m[0]++;
    int md = 0;
    int ex = 1;
    REPR(i, n) {
        md = (md + (int)(s[i] - '0') * ex) % p;
        ex = (ex * 10) % p;
        m[md]++;
    }

    ll ans = 0;
    for (auto x : m) {
        if (x.second > 1) {
            ans += x.second * (x.second - 1) / 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1044
#include <bits/stdc++.h>
#include <boost/math/common_factor.hpp>
using namespace std;

int main() {
   long	int a,b,c;
	scanf("%ld %ld",&a,&b);
	c = boost::math::lcm(a,b);
	printf("%ld\n",c);
	
	
	
	
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 7;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

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

    ll tot = 0LL;
    for (int i = 1; i < n; i++) {
        if (v[i] >= v[i-1]) continue;
        tot += (v[i-1]-v[i]);
        v[i] = v[i-1];
    }

    out(tot);
    
    
    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;

    int ans[] = {1, 2, 3};
    rep(i, 3) {
        if (ans[i] != A and ans[i] != B) {
            cout << ans[i] << endl;
        }
    }
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

x,y=map(int,input().split())

for i in range(x+1):
    kame=i
    tsuru=x-i
    # print(kame,tsuru)
    if kame*4+tsuru*2==y:
        print("Yes")
        quit()
print("No")

Measured memory_bytes: 68216
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;

constexpr int MOD = 10000007;

vector<long> divisor(long &_n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

long kadanes(vector<long> &_ls) {
  long highestMax=0,currentMax=0,length=_ls.size();
  for(long i=0;i<length;i++){
    currentMax=max(_ls[i],currentMax+_ls[i]);
    highestMax=max(highestMax,currentMax);
  }
  return highestMax;
}

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // cout<<fixed<<setprecision(20);
  }
} init;

/*----------------------------*/

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  REP(i,n)cin>>a[i];

  unsigned long ans,ed;ans=ed=0;

  for(int i=1;i<n;i++){
    if(a[i-1]+ed>a[i]){
      ed=(a[i-1]+ed)-a[i];
      ans+=ed;
    }else{
      ed=0;
    }
  }

  cout<<ans<<"\n";

}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int l=a.size();
	for(int i=0;i<l;i++)
		if(a[i]=='C')
			for(int j=i+1;j<l;j++)
				if(a[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
				
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
a[51],i,j;main(n){for(;scanf("%d",&n)*n;){for(i=n;i;)scanf("%d",a+i--);for(i=n;i;i-j&&printf("%d-",a[i]),printf("%d%c",a[j],j-1?32:10),i=j-1)for(j=i;a[j-1]==a[j]+1;j--);}}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

// powのll番
ll pow(ll a,ll b) {
    ll k = 1;
    REP(_,b) k*=a;
    return b;
}

void solve() {
    ll N;
    cin >> N;
    string s;
    while(N > 26) {
        --N;
        auto c = 'a'+(N%26);
        N/=26;
        s.insert(s.begin(),c);
    }
    N--;
    s.insert(s.begin(),char('a'+(N%26)));
    cout << s << endl;
}

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

Measured memory_bytes: 3624
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	fmt.Printf("%d", lcm(a, b))
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}

	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}


Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    c = collections.Counter(s)
    d = collections.defaultdict(int)
    r = n - 1
    for i in range(n):
        c[s[i]] -= 1
        t = c['E'] + d['W']
        if r > t:
            r = t
        d[s[i]] += 1

    return r




print(main())



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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
const int zqc = 1e9+7;
const int maxn = 100050;
typedef long long ll;

int n, a[maxn], pos;
ll fac[maxn];
int las, t[maxn];

ll qpow(ll a, ll b)
{
    ll ans = 1ll;
    while(b)
    {
        if(b&1) ans = ans*a%zqc;
        b >>= 1; a = a*a%zqc;
    }
    return ans;
}

ll inv(ll a)
{
	return qpow(a,zqc-2);
}

ll Comb(int a, int b)
{
	if(b == 0) return 1;
	if(a < b) return 0;
	return ((fac[a]*inv(fac[b])%zqc)*inv(fac[a-b]))%zqc;
}

int main()
{
	scanf("%d",&n);
	++ n;
	fo(i,1,n) 
	{
		scanf("%d",&a[i]);
		if(t[a[i]]) pos = i, las = t[a[i]];
		t[a[i]] = i;
	}
	fac[0] = 1; fo(i,1,n) fac[i] = fac[i-1]*i%zqc;
	fo(i,1,n) printf("%lld\n",((Comb(n,i)-Comb(n-pos+las-1,i-1))%zqc+zqc)%zqc);
	return 0;
}

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

vector<string> A;

int main() {
    string s;
    int K;
    cin >> s >> K;
    for (int i = 0; i < K; i++) {
        for (int j = 0; j + i < s.size(); j++) {
            string t = s.substr(j, i+1);
            A.push_back(t);
        }
    }
    sort(A.begin(), A.end());
    int cnt = 1, idx = 1;
    string u = A[0];
    while (cnt < K) {
        if (u != A[idx]) {
            u = A[idx];
            cnt++;
        }
        idx++;
    }
    cout << u << endl;
    return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<string>
using namespace std;
char str[110];
struct wolf{
	int type;
	int num;
	int at;
	wolf(int a,int b,int c){
		type=a;num=b;at=c;
	}
	wolf(){type=num=at=0;}
};
int sz;
vector<wolf>v;
int t[210];
int main(){
	int a;scanf("%d",&a);
	while(a--){
		scanf("%s",str);
		int m=0;
		int b=0;
		int n=strlen(str);
		for(int i=0;str[i];i++){
			if(str[i]=='o')m++;
			else b++;
		}
		if(m<b){
			printf("-1\n");continue;
		}
		if(m==b){
			int now=0;
			bool ok=true;
			for(int i=0;str[i];i++){
				if(str[i]=='o')now++;
				else now--;
				if(now==2||now==-2)ok=false;
			}
			if(!ok){
				printf("-1\n");
			}else{
				printf("%d\n",n/2-1);
				for(int i=0;i<n/2-1;i++){
					printf("split %d %d\n",i*2,1);
				}
			}
			continue;
		}
		sz=1;
		v.clear();
		string now=str;
		int s=0;
		while(now.size()>2){
		//	printf("%s ",now.c_str());fflush(stdout);
			bool ow=true;
			for(int i=0;i<now.size();i++){
				if(now[i]=='x')ow=false;
			}
			if(ow){
				v.push_back(wolf(1,s,0));
				s=sz;
				sz++;
				now=now.substr(1);
				continue;
			}
			for(int i=0;i<now.size()-1;i++){
				if(now[i]=='o'&&now[i+1]=='o')continue;
				if(now[i]=='x'&&now[i+1]=='x')continue;
				int V=0;
				for(int j=0;j<i;j++){
					if(now[j]=='o')V++;
					else V--;
				}
				if(i==0){
					v.push_back(wolf(1,s,1));
					s=sz+1;
					sz+=2;
					now=now.substr(2);
					break;
				}
				if(i==now.size()-2){
					v.push_back(wolf(1,s,now.size()-3));
					s=sz;
					sz+=2;
					now=now.substr(0,now.size()-2);
					break;
				}
			//	printf("%d %d\n",i,V);fflush(stdout);
				if(V>=0){
					for(int j=0;j<110;j++)t[j]=-1;
					int dep=0;
					for(int j=0;j<i;j++){
						if(now[j]=='o')dep++;
						else dep--;
						if(dep>=0)t[dep]=j;
					}
					int rot=0;
					for(int j=0;j<=V;j++){
						if(t[j]==-1)continue;							
						v.push_back(wolf(1,s,t[j]-rot));
						v.push_back(wolf(2,sz+1,sz));
						s=sz+2;
						sz+=3;
						now=now.substr(t[j]-rot+1)+now.substr(0,t[j]-rot+1);
						rot=t[j]+1;
					}
					v.push_back(wolf(1,s,1));
					now=now.substr(2);
					s=sz+1;
					sz+=2;
				}else{
					V=0;
					for(int j=i+2;j<now.size();j++){
						if(now[j]=='o')V++;
						else V--;
					}
					for(int j=0;j<110;j++)t[j]=-1;
					int dep=0;
					for(int j=now.size()-1;j>i+1;j--){
						if(now[j]=='o')dep++;
						else dep--;
						if(dep>=0)t[dep]=j;
					}
					int rot=0;
					for(int j=0;j<=V;j++){
						if(t[j]==-1)continue;
					//	printf("%d %d %d\n",s,t[j],t[j]+rot);fflush(stdout);
						v.push_back(wolf(1,s,t[j]-1+rot));
						v.push_back(wolf(2,sz+1,sz));
						s=sz+2;
						sz+=3;
						now=now.substr(t[j]+rot)+now.substr(0,t[j]+rot);
						rot=now.size()-t[j];
					}
					v.push_back(wolf(1,s,now.size()-3));
					now=now.substr(0,now.size()-2);
					s=sz;
					sz+=2;
				}
				break;
			}
		}
		printf("%d\n",v.size());
		for(int i=0;i<v.size();i++){
			if(v[i].type==1)printf("split ");
			else printf("join ");
			printf("%d %d\n",v[i].num,v[i].at);
		}
	}
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

bool ismonth(ll n) {
  if(1<=n and n<=12) return 1;
  else return 0;
}

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

  ll s;
  cin >> s;
  ll m=s/100, n=s%100;
  if(ismonth(m) and ismonth(n)) cout << "AMBIGUOUS" << newl;
  if(ismonth(m) and !ismonth(n)) cout << "MMYY" << newl;
  if(!ismonth(m) and ismonth(n)) cout << "YYMM" << newl;
  if(!ismonth(m) and !ismonth(n)) cout << "NA" << newl;
  return 0;
}


Measured memory_bytes: 3620
//five antenna
//
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	int antenna[5],k;
	cin>>antenna[0]>>antenna[1]>>antenna[2]>>antenna[3]>>antenna[4]>>k;
	sort(antenna,antenna+5);
	if(antenna[4]-antenna[0] > k){
		cout << ":(" << endl;
	}else{
		cout << "Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,t,ma=0,mi=1000000000,i;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> t;
    if(t>ma) ma=t;
    if(t<mi) mi=t;
  }
  cout << ma-mi << endl;
  return 0;
}

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

int main(){
  int m,n;
  cin >>m >>n;
  vector<int> vec1(n);
  vector<int> vec2(n);
  for (int i=0;i<n;i++){
    cin >>vec1.at(i) >>vec2.at(i);
  }
  for (int i=1;i<=m;i++){
    int sum= 0;
    for (int x=0;x<n;x++){
      if (vec1.at(x)==i){
        sum ++;
      }
      if (vec2.at(x)==i){
        sum++;
      }
    }
    cout <<sum<<endl;
  }
}

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

class UnionFind {
public:
	vector<int> par;

	void init(int sz) {
		par.resize(sz, -1);
	}
	int root(int pos) {
		if (par[pos] == -1) return pos;
		par[pos] = root(par[pos]);
		return par[pos];
	}
	void unite(int u, int v) {
		u = root(u); v = root(v);
		if (u == v) return;
		par[u] = v;
	}
	bool same(int u, int v) {
		if (root(u) == root(v)) return true;
		return false;
	}
};

int N, M, A[1 << 17], B[1 << 17], deg[1 << 17], pars[1 << 17]; bool used[1 << 17];
vector<int> X[1 << 17]; vector<pair<int, int>>G;
UnionFind UF;

void dfs(int pos) {
	used[pos] = true;

	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == true) continue;
		pars[X[pos][i]] = pos;
		dfs(X[pos][i]);
	}
	if (pos != 1) {
		if (deg[pos] % 2 == 1) {
			G.push_back(make_pair(pos, pars[pos]));
			deg[pos] ^= 1;
		}
		else {
			G.push_back(make_pair(pars[pos], pos));
			deg[pars[pos]] ^= 1;
		}
	}
}

int main() {
	cin >> N >> M; UF.init(N + 2);
	if (M % 2 == 1) {
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		if (UF.same(A[i], B[i]) == false) {
			UF.unite(A[i], B[i]);
			X[A[i]].push_back(B[i]);
			X[B[i]].push_back(A[i]);
		}
		else {
			G.push_back(make_pair(A[i], B[i]));
			deg[A[i]] ^= 1;
		}
	}
	dfs(1);

	for (int i = 0; i < G.size(); i++) cout << G[i].first << " " << G[i].second << endl;
	return 0;
}

Measured memory_bytes: 15988
#include<iostream>
#include <cstdio>
#include <string>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>  

using namespace std;


int main()
{
	int n, t, a;
	scanf("%d%d%d", &n, &t, &a);
	double sa = 1000000000;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		double k = t - a - x * 0.006;
		if (k < 0)k = -k;
		if (sa > k) {
			sa = k;
			ans = i + 1;
		}
	}
	printf("%d", ans);
}

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

int A[3][3],B[10];
int N;
bool bingo[3][3];

int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>A[i][j];
        }
    }
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            bingo[i][j]=false;
            for(int k=0;k<N;k++){
                if(A[i][j]==B[k]){bingo[i][j]=true;}
            }
        }
    }

    string ans="No";
    for(int i=0;i<3;i++){
        if(bingo[0][i] and bingo[1][i] and bingo[2][i])ans="Yes";
    }
    for(int i=0;i<3;i++){
        if(bingo[i][0] and bingo[i][1] and bingo[i][2])ans="Yes";
        if(bingo[0][0] and bingo[1][1] and bingo[2][2])ans="Yes";
        if(bingo[2][0] and bingo[1][1] and bingo[0][2])ans="Yes";
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

bool hoge(int cur, vector< vector<int> >& g, vector<int>& color) {
    for (int i : g[cur]) {
        if (color[i] == color[cur]) return false;
        if (color[i] == -1) {
            color[i] = !color[cur];
            if (!hoge(i, g, color)) return false;
        }
    }
    return true;
}

bool link[705][705];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        link[a][b] = true;
        link[b][a] = true;
    }

    vector< vector<int> > g(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (!link[i][j]) {
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    vector<int> color(n, -1);
    vector<int> dp(n + 1, false);
    dp[0] = true;
    for (int i = 0; i < n; i++) {
        if (color[i] == -1) {
            color[i] = 0;
            if (!hoge(i, g, color)) {
                cout << -1 << endl;
                return 0;
            }

            vector<int> cnt(2, 0);
            for (int j = 0; j < n; j++) {
                if (color[j] <= -1) continue;
                cnt[color[j]]++;
                color[j] = -2;
            }

            for (int j = n; j >= 0; j--) {
                dp[j] = ((j - cnt[0] >= 0 && dp[j - cnt[0]]) || (j - cnt[1] >= 0 && dp[j - cnt[1]]));
            }
        }
    }

    int ans = m;
    for (int i = 1; i <= n; i++) {
        if (!dp[i]) continue;
        ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2 );
    }

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

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    long long a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    
    long long ab = a * b;
    long long cab = c - a - b;
    if (cab < 0) {
        printf("No\n");
        return 0;
    }
    printf(4 * ab < cab * cab ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256