akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>
 
 
signed main(){
	
	int a,b;cin>>a>>b;
	
	int num = b-a;
	int len = 0;
	rep(i,num) len +=i+1;
	
	cout << len - b << endl;
	 
	
}

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

#define __STDC_FORMAT_MACROS

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

const string IMPOSSIBLE = "IMPOSSIBLE";
const string POSSIBLE = "POSSIBLE";

vector<int64_t> vt;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || '9' < c) break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int64_t gcd(int64_t a, int64_t b)
{
    int64_t result = a;
    int64_t k = 0;
    int64_t n = b;

    do
    {
        k = result % n;
        result = n;
        n = k;
    }
    while (k != 0);

    return result;
}

int64_t gcd_n(const vector<int64_t> &numbers)
{
    int64_t l;
    l = numbers[0];

    REP(i, (signed)numbers.size()) l = gcd(l, numbers[i]);

    return l;
}

int64_t lcm(int64_t a, int64_t b)
{
    int64_t g;

    g = gcd(a, b);

    return a * (b / g);
}

int64_t lcm_n(const vector<int64_t> &numbers)
{
    int64_t l;
    l = numbers[0];

    REP(i, (signed)numbers.size()) l = lcm(l, numbers[i]);

    return l;
}

int main()
{
    int64_t N, K;

    gc(N);
    gc(K);

    int64_t T;
    int64_t maxT = -1;

    REP(i, N)
    {
        gc(T);
        vt.push_back(T);
        maxT = max(maxT, T);
    }

    if (maxT < K) cout << IMPOSSIBLE << endl;
    else
    {
        int64_t l = gcd_n(vt);

        if (K % l == 0) cout << POSSIBLE << endl;
        else cout << IMPOSSIBLE << endl;
    }

    return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

  int r ,g ,b;
  int num;

  scanf("%d %d %d", &r, &g, &b);
  num = r*100+g*10+b;

  if(num%4 == 0) printf("YES\n");
  else printf("NO\n");

  return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N;
    cin >> N;
    int d[N];
    for(int i = 0; i < N; i++) cin >> d[i];

    map<int, int> mp;

    for(int i = 0; i < N; i++)
    {
        mp[d[i]]++;
    }

    cout << mp.size() <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

int main(){
	ll n;
	cin>>n;
	ll inp[n][3];
	ll dp[n][3];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++)
			cin>>dp[i][j];
		if(i>0){
			dp[i][0] += max(dp[i-1][1],dp[i-1][2]);
			dp[i][1] += max(dp[i-1][0],dp[i-1][2]);
			dp[i][2] += max(dp[i-1][0],dp[i-1][1]);
		}
	}

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

	return 0;
}

Measured memory_bytes: 2560
# import sys
# sys.setrecursionlimit(10000)

N, K = map(int, input().split())
mod = 10**9 + 7
# def cmb(n, r):
#     if n - r < r: r = n - r
#     if r == 0: return 1
#     if r == 1: return n

#     numerator = [n - r + k + 1 for k in range(r)]
#     denominator = [k + 1 for k in range(r)]

#     for p in range(2,r+1):
#         pivot = denominator[p - 1]
#         if pivot > 1:
#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot
#                 denominator[k] /= pivot

#     result = 1
#     for k in range(r):
#         if numerator[k] > 1:
#             result *= int(numerator[k])

#     return result


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1, K+1):
    # print(cmb(N-K+1, i) , cmb(K-1, i-1))
    ans = cmb(N-K+1, i, mod) * cmb(K-1, i-1, mod) % mod
    print(ans)



Measured memory_bytes: 3572
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ll n, q;
  string s;
  cin >> n >> s >> q;

  ll bs = sqrt(n);

  vll blst(n/bs+1);
  vll lst(n);

  rep(i, n) {
     lst[i] = 1LL << (s[i] - 'a');
     blst.at(i / bs) |= 1LL << (s[i] - 'a');
   }
  
  rep(i, q) {
    ll t;
    cin >> t;
    if (t == 1) {
      ll i;
      char c;
      cin >> i >> c;
      i--;
      lst[i] = 1LL << (c - 'a');
      ll ii = i / bs;
      blst[ii] = 0;
      for (ll j = ii * bs; j < (ii + 1) * bs; j++) {
        if (j >= n) break;
        blst[ii] |= lst[j];
      }  // j
    } else {
      ll s = 0;
      ll l, r;
      cin >> l >> r;
      l--;
      r--;
      ll iil = l / bs;
      ll iir = r / bs;
      if (iil == iir) {
        for (ll i = l; i <= r; i++) s |= lst[i];
      } else {
        for (ll i = l; i < (iil + 1) * bs; i++) s |= lst[i];
        for (ll ii = iil + 1; ii < iir; ii++) s |= blst[ii];
        for (ll i = (iir * bs); i <= r; i++) s |= lst[i];
      }
      cout << __builtin_popcount(s) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4868
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;
ll dp[100005];

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b;
	string s;
	
	cin >> n >> k;
	for(i=0;i<n;i++)
	{
		cin >> x;
		v.pb(x);
	}
	for(i=1;i<=k;i++)
		for(j=0;j<n && i-v[j]>=0;j++)
			if(!dp[i-v[j]])
			{
				dp[i]=1;
				break;
			}
	if(dp[k])
		cout << "First";
	else
		cout << "Second";

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vct vector<ll>
#define umap unordered_map<ll,ll>
#define mpp map<ll,ll>
#define stt set<ll>
#define pir pair<ll,ll>
#define vpp vector<pair<ll,ll> >

ll poww(ll x,ll y,ll m){   
    ll res=1;
    while(y){if(y%2==0){x=(x*x)%m;y=y/2;}else{res=(res*x)%m;y--;}}
    return res;
}
void prt(vct v)
{
    for(ll i=0;i<v.size();i++)cout<<v[i]<<"\n";
    // cout<<"\n";
}
vct siev(ll n)
{
    vct ans;ll ar[n+1];
    memset(ar,-1,sizeof(ar));ar[0]=0;ar[1]=0;
    for(ll i=2;i<=n;i++)
    {if(ar[i]==-1){ans.push_back(i);ar[i]=1;for(ll j=2*i;j<=n;j=j+i)ar[j]=0;}}
    return ans;
}
ll isprime(ll n)
{
    if(n==1||n==0)return 0;
    for(ll i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll etf(ll n) 
{
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)n /= i;
            result -= result / i;
        }
    }
    if(n > 1)result -= result / n;
    return result;
}
vct divsors(ll n)
{
    vct ans;//ans.push_back(1);
    for(ll i=1;i<=sqrt(n);i++)
    {if(n%i==0){ans.push_back(i);if(i!=(n/i))ans.push_back(n/i);}}
    // sort(ans.begin(),ans.end());
    return ans;
}
ll cnd(ll n){ll cnt=0;while(n){cnt++;n=n/10;}return cnt;}
ll t,m,n;
ll t1,t2,k;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    string s;
    cin>>s;
    char prv='#';
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        if(prv==s[i])
        {
            
        }
        else
        {
            cnt++;
            prv=s[i];
        }
    }
    cout<<cnt;
    
    
    
}

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

int main(void) {
    i64 n, s = 0, m = 1145141919, c = 0;
    cin >> n;
    vector<i64> a(n);
    for (i64 i = 0; i < n; i++) {
        cin >> a[i]; s += abs(a[i]); m = min(m, abs(a[i]));
        if (a[i] < 0) c++;
    }
    if (c % 2) cout << s - m * 2 << endl;
    else cout << s << endl;
}


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

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

typedef long long LL;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (max(a-x,x-a)>max(b-x,x-b)?"B":"A") << endl;
  return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

const int maxn = 2e5 + 228;

vector <int> g[maxn];

int ans[maxn];

void DFS(int v, int p = -1)
{
    for (auto it : g[v])
        if (it != p)
        {
            ans[it] += ans[v];
            DFS(it, v);
        }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, q;
    cin >> n >> q;
    for (int i = 0; i + 1 < n; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    for (int i = 0; i < q; i++)
    {
        int x, y;
        cin >> x >> y;
        ans[x] += y;
    }
    DFS(1);
    for (int i = 1; i <= n; i++)
        cout << ans[i] << " ";


    return 0;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint{
    int x;

    Mint() : x(0) {}
    Mint(int t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(int n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }

    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }

    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> v;
    for(int i = 1; i * i <= n; i++){
        v.emplace_back(i);
        if(i != n / i) v.emplace_back(n / i);
    }
    sort(ALL(v));
    int m = v.size();
    int cnt[m];
    cnt[0] = 1;
    for(int i = 1; i < m; i++){
        cnt[i] = v[i] - v[i - 1];
    }
    Mint<> dp[k + 1][m];
    dp[0][0] = 1;
    for(int i = 0; i < k; i++){
        Mint<> sum[m + 1];
        for(int j = 0; j < m; j++){
            sum[j + 1] = sum[j] + dp[i][j];
        }
        for(int j = 0; j < m; j++){
            dp[i + 1][j] += sum[m - j] * cnt[j];
        }
    }
    Mint<> ans = 0;
    for(int i = 0; i < m; i++){
        ans += dp[k][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26108
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    cin >> n;

    vl a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    double r = (a[0] + a[1]) / 2.0;
    for(int i = 2; i < n; i++) {
        r = (r + a[i]) / 2.0;
    }

    cout << r << endl;
}

Measured memory_bytes: 3852
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())

    pre = input()
    said = set([pre])
    for _ in range(N - 1):
        W = input()
        if W in said or pre[-1] != W[0]:
            print('No')
            exit()
        pre = W
        said.add(W)
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	int j=0;
	int k,max;
	cin>>k;
	for(int i=0;i<k;i++)
	{
		max=0;
		for(int p=1;p<3;p++)
		{
			if(a[max]<a[p])
				max=p;
		}
		a[max]=a[max]*2;
		
	}
	cout<<a[0]+a[1]+a[2]<<endl;
	
	return 0;
}

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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N,M);
    vi H(N);VCIN(H);
    Graph map(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        map[a].push_back(b);
        map[b].push_back(a);
    }
    int cnt=0;
    rep(i,N){
        flag=true;
        RepA(map[i])if(H[i]<=H[item])flag=false;
        if(flag)cnt++;
    }
    printf("%d\n",cnt);
    

    return 0;
}

Measured memory_bytes: 8736
N = int(input())
A = list(map(int, input().split()))
flg = True
n_node = 0.5
ans = 0
As = [0]*(N+2)
for i in range(N, -1, -1):
    As[i] = As[i+1] + A[i]
for i in range(N+1):
    if A[i] > n_node*2:
        flg = False
        break
    n_node = min(int(n_node*2)-A[i], As[i+1])
    ans += n_node + A[i]
print(ans if flg else -1)


Measured memory_bytes: 85476
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPLL(i, n) for(ll i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[100000]; cin >> n;
	REP(i, n) cin >> a[i];

	int gcd = a[0];
	for (int i = 1; i < n; i++) {
		gcd = GCD(gcd, a[i]);
	}
	cout << gcd << endl;

	return 0;
}

Measured memory_bytes: 640
io = STDIN
a=io.gets.to_i
b=io.gets.to_i
c=io.gets.to_i
x=io.gets.to_i
cnt=0
(0..a).each do |x500|
  (0..b).each do |x100|
    (0..c).each do |x50|
      cnt+=1 if x500*500+x100*100+x50*50==x
    end
  end
end
puts cnt


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

int main() {
  int n;
  cin >> n;
  
  if(n/100 == 1) cout << 9;
  else cout <<1;
  
  if((n/10)%10 == 1) cout << 9;
  else cout << 1;
  
  if(n%10 == 1) cout << 9 << endl;
  else cout << 1 << endl;
  
}

Measured memory_bytes: 3508
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<int> sth[600], stw[600];
    for(int i = 0; i < H; i++){
        for(int j  = 0; j < W; j++){
            char s;
            cin >> s;
            if(s == '#') {
                sth[i+j].push_back(i-j+299);
                stw[i-j+299].push_back(i+j);
            }
        }
    }
    long ans = 0;
    for(int i = 0; i < H+W; i++){
        for(auto iter = sth[i].begin(); iter != sth[i].end(); iter++){
            int j = *iter;
            for(auto iter2 = iter; iter2 != sth[i].end(); iter2++){
                int k = *iter2;
                if(j == k) continue;
                if(i+k-j >= 0 && i+k-j < 600) {
                    auto l = lower_bound(sth[i+k-j].begin(), sth[i+k-j].end(), min(j, k));
                    auto r = upper_bound(sth[i+k-j].begin(), sth[i+k-j].end(), max(j, k));
                    ans += r-l;
                }
                if(i+j-k >= 0 && i+j-k < 600) {
                    auto l = lower_bound(sth[i+j-k].begin(), sth[i+j-k].end(), min(j, k));
                    auto r = upper_bound(sth[i+j-k].begin(), sth[i+j-k].end(), max(j, k));
                    ans += r-l;
                }
            }
        }
    }
    for(int i = 0; i < 600; i++){
        for(auto iter = stw[i].begin(); iter != stw[i].end(); iter++){
            int j = *iter;
            for(auto iter2 = iter; iter2 != stw[i].end(); iter2++){
                int k = *iter2;
                if(j == k) continue;
                if(i+k-j >= 0 && i+k-j < 600) {
                    auto l = upper_bound(stw[i+k-j].begin(), stw[i+k-j].end(), min(j, k));
                    auto r = lower_bound(stw[i+k-j].begin(), stw[i+k-j].end(), max(j, k));
                    ans += r-l;
                }
                if(i+j-k >= 0 && i+j-k < 600) {
                    auto l = upper_bound(stw[i+j-k].begin(), stw[i+j-k].end(), min(j, k));
                    auto r = lower_bound(stw[i+j-k].begin(), stw[i+j-k].end(), max(j, k));
                    ans += r-l;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int k, s; cin >> k >> s;
  // [0, k]
  long long ans = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k; j++)
      if (0 <= s - i - j && s - i - j <= k)
        ans++;
  cout << ans << endl;
}

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

int main()
{
	string S;
	cin >> S;
	bool flag = false;
	if ((S[0]==S[1])&&(S[2]==S[3])&&(S[0]!=S[2]))
	{
		flag = true;
	}
	if ((S[0]==S[2])&&(S[1]==S[3])&&(S[0]!=S[1]))
	{
		flag = true;
	}
	if ((S[0]==S[3])&&(S[1]==S[2])&&(S[0]!=S[1]))
	{
		flag = true;
	}

	if (flag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;	
}

Measured memory_bytes: 760
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

typedef pair<int, int> P;
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h, w;
    cin>>n>>h>>w;
    print(((n-h)+1) * ((n-w) + 1));
    return 0;
}

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

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    string s, t;

    s = t = "";

    for (int i = 0; i < b; i++)
        s = s + (char)('0' + a);

    for (int i = 0; i < a; i++)
        t = t + (char)('0' + b);

    if (s < t)
        cout << s << "\n";
    else
        cout << t << "\n";
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

double dist(int x1,int x2,int y1,int y2){
	double d=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	return sqrt(d);
}

int main(){
	int n;
	cin >> n;
	vector<int> x(n,0);
	vector<int> y(n,0);
	int ptn=1;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		ptn*=(i+1);
	}
	double sum=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sum+=dist(x[i],x[j],y[i],y[j]);
		}
	}
	sum=sum*((n-1)*2*(ptn/(n*(n-1))));
	
	double ans=sum/ptn;
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n; cin >> n;
    int num = n / 15;

    int ans = (800 * n) - (200 * num);
    p(ans);
}


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

def judge(A):
  for i in range(len(A)):
    if A[i] == 0:
      print(0)
      return
  result = 1
  for i in range(N):
    result = result * A[i]
    if result > 1000000000000000000:
      print(-1)
      return
  if result <= 1000000000000000000:
    print(result)
    return
  
judge(A)

Measured memory_bytes: 21580
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e5+2;
int mp[MAX];
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    int a[n+1];
    lp(i,1,n+1)
        cin>>a[i],mp[a[i]]=i;
    lp(i,1,n+1)
        cout<<mp[i]<<" ";
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int s;
  cin >> s;
  if (s < 3) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> x(s + 1, 1);

  rep(i, 3, s + 1) {
    rep(j, 3, s - 2) {
      if (i - j >= 3) x[i] += x[j];
    }
    x[i] %= mod1;
  }
  cout << x[s] << '\n';
  return 0;
}

Measured memory_bytes: 3636
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var a = o.a();
  var b = o.a();

  if (a >= 13) {
    console.log(b);
  } else if (a <=5) {
    console.log(0);
  } else {
    console.log(b / 2);
  }
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define ll long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll n;
ll ans;
int main()
{
	cin>>n;
	forn(i,1,n)
	{
		ll m=n/i;
		ans+=m*(m+1)*i/2;
	}
	cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		
		 int b = N*(N-1)/2;
		 int c = M*(M-1)/2;
		 
		 int sum = b+ c;
		 System.out.println(sum);
	}
}

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

int dp_upper[1024][100001];
int par[1 << 18];

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

  int N; cin >> N;
  int NN = 1 << 18;
  int Lmax = 100000;
  vector<int> V(NN), W(NN);
  rep(i, N) {
    cin >> V[i+1] >> W[i+1];
  }
  vector<vector<int>> V_list(NN+1, vector<int>(0));
  vector<vector<int>> W_list(NN+1, vector<int>(0));
  rep(i_, NN) {
    int i; i = i_+1;
    int p; p = i / 2;
    rep(j, V_list[p].size()) {
      V_list[i].push_back(V_list[p][j]);
      W_list[i].push_back(W_list[p][j]);
    }
    V_list[i].push_back(V[i]);
    W_list[i].push_back(W[i]);
  }
  
  rep(i_, 1024-1) {
      int i; i = i_ + 1;
      int K; K = V_list[i].size();
      rep(j, 1<<K) {
        int vs = 0;
        int ws = 0;
        rep(k, K) {
          if ((j >> k) & 1) {
            vs += V_list[i][k];
            ws += W_list[i][k];
          }
        }
        if (ws <= Lmax) {
          dp_upper[i][ws] = max(dp_upper[i][ws], vs);
        }
      }
      rep(w_, Lmax) {
        int w; w = w_ +1;
        dp_upper[i][w] = max(dp_upper[i][w], dp_upper[i][w-1]);
      }
  }

  memset(par, 0, sizeof(par));
  rep(i_, NN - 1024) {
    int i; i = i_ + 1024;
    int p; p = i / 2;
    if (par[p] == 0) {
      par[i] = p;
    }
    else {
      par[i] = par[p];
    }
  }
  int Q; cin >> Q;
  rep(q, Q) {
    int v, L;cin >> v >> L;
    if (v < 1024) {
      cout << dp_upper[v][L] << "\n";
    }
    else {
      int ans = 0;
      int p; p = par[v];
      int K; K = V_list[v].size() - 10;
      rep(j, 1 << K) {
        int vs = 0;
        int ws = 0;
        rep(k, K) {
          if ((j >> k) & 1) {
            vs += V_list[v][k+10];
            ws += W_list[v][k+10];
          }
        if (ws <= L) {
          ans = max(ans, vs + dp_upper[p][L - ws]);
        }
        }
      }
      cout << ans << "\n";
      
    }
  }
  return 0;
}


Measured memory_bytes: 483756
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
v1 = [None]*n
v2 = [None]*n
v = 0
for i in range(n):
    if s[i]=="#":
        v += 1
    v1[i] = v
v1.insert(0,0)
v = 0
for i in range(n-1, -1, -1):
    if s[i]==".":
        v += 1
    v2[i] = v
v2.append(0)
ans = min((v1[i]+v2[i]) for i in range(n+1))
print(ans)

Measured memory_bytes: 86392
// Copyright 2017 Parallelc
#include <bits/stdc++.h>
using namespace std;  // NOLINT

using LL = int64_t;
const int INF = 0x3f3f3f3f;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(void)
{
  ll a;
  cin>>a;
  ll i=1;
  while(4)
  {
    if(a==4||a==2||a==1)
    {
      break;
    }
    if(a%2)
    {
      a=3*a+1;
    }
    else
    {
      a=a/2;
    }
    ++i;
  }
  cout<<i+3;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    int a=0,b=0;
    int answer=0;
    int op;
    
    while(1){
        scanf("%d %c %d", &a, &op, &b);//読み込み
        
        if(op == '+'){
            answer = a + b;//＋のとき和
        }else if(op == '-'){
            answer = a - b;//ーのとき差
        }else if(op == '*'){
            answer = a * b;//＊のとき積
        }else if(op == '/'){
            answer = a / b;// /のとき商
        }else{
            break;
        }
        
        printf("%d\n",answer);

    }

    return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;

signed main()
{
   char s[1205];
   fgets( s, sizeof(s), stdin );
   for(int i=0; s[i] != 0; ++i)
      if( (s[i] >= 'a' && s[i] <= 'z') ||( s[i] >= 'A' && s[i] <= 'Z') )
         s[i] ^= 32;
   printf("%s", s);
}




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

int main(){
    double a, b, h, m, ans;
    cin >> a >> b >> h >> m;


    // 角度を定義して弧度法に変換
    double angle = 30*h - 5.5*m;
    if(angle>180) angle=360-angle;
    // 円周率はM_PI
    angle = (angle *M_PI) / 180;

    ans = sqrt(a*a + b*b - 2*a*b*cos(angle));
    

    cout << fixed << setprecision(20) << ans << endl;

    
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> l(n);
    vector<pair<ll, ll>> xr(n);
    rep(i, n) {
        cin >> x[i] >> l[i];
        xr[i] = make_pair(x[i] + l[i], i);
    }
    sort(xr.begin(), xr.end());
    vector<ll> ans(1);
    ans[0] = xr[0].second;
    int num = 0;
    rep(i, n) {
        if ( xr[num].first <= x[xr[i+1].second] - l[xr[i+1].second] ) {
            ans.push_back(xr[i+1].second);
            num = i + 1;
        }
    }
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 4472
#include<stdio.h>
 
 int main(){
   int a[110],n,temp;
   int i,j,count=0; 
   int minj;
   
   scanf("%d",&n);
   for(i=0;i<n;i++) scanf("%d",&a[i]);

   for(i=0;i<n;i++){
     minj =i;
     for(j=i;j<n;j++){
       if(a[j]<a[minj]) minj = j;
     }
     if(minj != i){
       temp = a[i];
       a[i] = a[minj];
       a[minj] = temp;
       count++;
     }
   }
   
   for(i=0;i<n;i++){
     printf("%d",a[i]);
     if(i!=n-1) printf(" ");
     else printf("\n");
   }
   printf("%d\n",count);
   
   return 0;
 }



Measured memory_bytes: 2136
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

// ------ Required ------ //
#include <vector>

// ------ Class ------ //
class RankUnionFind {
private:
	std::size_t size_; std::vector<std::size_t> par, rank;
public:
	RankUnionFind() : size_(0), par(std::vector<std::size_t>()), rank(std::vector<std::size_t>()) {};
	RankUnionFind(std::size_t size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (std::size_t i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	std::size_t size() { return size_; }
	std::size_t root(std::size_t x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(std::size_t x, std::size_t y) { return root(x) == root(y); }
	void unite(std::size_t x, std::size_t y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const RankUnionFind &u) { return par == u.par; }
	bool operator!=(const RankUnionFind &u) { return par != u.par; }
};

#endif

#include <iostream>
#include <algorithm>
using namespace std;
struct Edge { int a, b, w; };
bool operator<(const Edge& e1, const Edge& e2) { return e1.w < e2.w; }
int N, M, a, b, w; Edge G[5000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> N >> M, N | M) {
		for (int i = 0; i < M; i++) cin >> G[i].a >> G[i].b >> G[i].w, G[i].a--, G[i].b--;
		sort(G, G + M);
		int ret = 999999999;
		for (int i = 0; i < M; i++) {
			int r = 0, c = 0;
			RankUnionFind uf(N);
			for (int j = i; j < M; j++) {
				if (!uf.same(G[j].a, G[j].b)) {
					uf.unite(G[j].a, G[j].b);
					r = G[j].w; c++;
					if (c == N - 1) break;
				}
			}
			if (c == N - 1) ret = min(ret, r - G[i].w);
		}
		if (ret == 999999999) cout << -1 << endl;
		else cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <map>

using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  multimap<long, long> AB;
  for (int i = 0; i < N; i++) {
    long Ai, Bi;
    cin >> Ai >> Bi;
    AB.insert(make_pair(Ai, Bi));
  }
  long result = 0;
  for (auto it = AB.begin(); it != AB.end(); it++) {
    if (M > it->second) {
      result += it->first * it->second;
      M -= it->second;
    } else {
      result += it->first * M;
      M = 0;
      break;
    }
  }
  cout << result << endl;
}

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

int main(void)
{
	int a,i,j,ret;
	while(scanf("%d",&a), a){
		ret = 0;
		for(i = 2;i <= 500;i++){
			if ((a << 1) <= i * i)
				break;
			if (!((a << 1) % i) && (((a << 1) / i + i) & 1))
				ret++;
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, m;
    cin >> n >> m;
    std::vector<int> a(n);
    std::vector<int> count(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]]++;
    }
    int sum = 0;
    std::vector<int> check(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        int left = max((int)0, i + 1 - count[i]);
        check[left]++;
        check[i + 1]--;
    }
    for (int i = 1; i <= n; i++) {
        check[i] += check[i - 1];
        if (check[i] == 0) {
            sum++;
        }
    }
    std::vector<int> out;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        int left = max((int)0, a[x] + 1 - count[a[x]]);
        check[left]--;
        count[a[x]]--;
        if (check[left] == 0 && left > 0) {
            sum++;
        }
        count[y]++;
        int newleft = max((int)0, y + 1 - count[y]);
        check[newleft]++;
        if (check[newleft] == 1 && newleft > 0) {
            sum--;
        }
        a[x] = y;
        out.pb(sum);
    }
    for (int i = 0; i < m; i++) {
        cout << out[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 7920
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;

using ll = long long;

ll grid[3000][3000];
int R, C, K;

int dr[2] = {0, 1};
int dc[2] = {1, 0};
ll dp[3001][3001][4];

void solve() {
  dp[0][0][1] = grid[0][0];
  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      for (int k = 3; k >=0; --k) {
        // cerr << r << " " << c << " " << k << " " << dp[r][c][k] << endl;
        for (int i = 0; i < 2; ++i) {
          int nr = r+dr[i];
          int nc = c+dc[i];
          if (nr >= R || nc >= C) continue;
          int nk = k;
          if (nr > r) nk = 0;
          dp[nr][nc][nk] = max(dp[nr][nc][nk], dp[r][c][k]);
          if (grid[nr][nc] > 0) {
            int nk = k+1;
            if (nr > r) nk = 1;
            if (nk <= 3) {
              dp[nr][nc][nk] = max(dp[nr][nc][nk], dp[r][c][k]+grid[nr][nc]);
            }
          }
        }
      }
    }
  }
  ll ans = 0;
  for (int k = 0; k < 4; ++k) {
    ans = max(ans, dp[R-1][C-1][k]);
  }
  cout << ans << endl;
}

int main() {
  cin >> R >> C >> K;
  for (int i = 0; i < K; ++i) {
    int r, c, k; cin >> r >> c >> k;
    --r; --c;
    grid[r][c] = k;
  }
  // for (int i = 0; i < R; ++i) {
  //   for (int j = 0; j < C; ++j) {
  //     cout << grid[i][j];
  //   }
  //   cout << endl;
  // }
  solve();
}



Measured memory_bytes: 355280
A, B, C, X, Y = gets.split.map(&:to_i)

price = 0
if X == Y
  price += if C * 2 <= A || C * 2 <= B
             C * 2 * X
           else
             A * X + B * Y
           end
else
  if C * 2 <= A && C * 2 <= B
    price += C * 2 * [X, Y].max
  elsif C * 2 <= A
    price += C * 2 * X
    diff = Y - X
    price += B * diff if diff.positive?
  elsif C * 2 <= B
    price += C * 2 * Y
    diff = X - Y
    price += A * diff if diff.positive?
  elsif C * 2 <= A + B
    price += C * 2 * [X, Y].min
    price += (X < Y ? B : A) * (X - Y).abs
  else
    price += A * X + B * Y
  end
end

puts price


Measured memory_bytes: 1916
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
	int i, j;

	for (i = 1;i < 10;i++) {
		for (j = 1;j < 10;j++) {
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 2496
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int a[110000]={0};
	for(int i=0;i<n;i++) cin>>a[i];

	sort(a, a+n, greater<int>());
	int edge=0,edge2=0;
	bool exist = false, exist2 = false;
	for(int i=0;i<n-3;i++){
		if(a[i] == a[i+1] && exist == false){
			exist = true;
			edge = a[i+1];
		}
		if(a[i+2] == a[i+3] && exist == true && exist2 == false){
			exist2 = true;
			edge2 = a[i+3];
		}
	}

	//for(int i=0;i<n;i++) cout<<a[i]<<endl;
	//cout<<endl;

	//cout<<edge<<" "<<edge2<<endl;
	//ll ans = edge * edge2;
	ll ans = edge;
	ans *= edge2;
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 640
import std.stdio;
import std.conv;
import std.string;
import std.file;
import std.math;

int main() {
	string l;
	while((l = readln().chomp, l.length)){
		for(int x=0; x<26; x++){
			string l2;
			for(int i=0; i<l.length; i++){
				char c = l[i];
				if(c >= 'a' && c + x <= 'z') l2 ~= c + x;
				else if(c + x > 'z' && c <= 'z') l2 ~= c - 26 + x;
				else l2 ~= c;
				}
			if(l2.indexOf("the") >= 0 || l2.indexOf("this") >= 0 || l2.indexOf("that") >= 0) write(l2 ~ "\n");
			}
		}
	return 0;
	}

Measured memory_bytes: 1100