akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
multiset <int> slimes;
vector <long long int> repro;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, s;
    cin >> n;
    for (long long int i = 0; i < (long long int)1<<n; i++) {
        cin >> s;
        slimes.insert(s);
    }
    slimes.insert(0);
    auto it = --slimes.end();
    repro.push_back(*it);
    slimes.erase(it);
    while (slimes.size() > 1){
        int size_ = repro.size();
        for (int i = 0; i < size_; i++) {
            auto it2 = slimes.lower_bound(repro[i]);
            it2--;
            if (!(*it2)){
                cout << "No\n";
                return 0;
            }
            slimes.erase(it2);
            repro.push_back(*it2);
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 14708
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, e = 0;
  string s;
  cin >> n >> s;
  int a[2][n + 1];
  a[0][0] = 0;
  a[1][0] = 0;
  rep(i,n)
  {
    if (s[i] == 'W') {
      a[0][i + 1] = a[0][i] + 1;
      a[1][i] = a[1][i > 0 ? i - 1 : 0];
    } else {
      a[0][i + 1] = a[0][i];
      a[1][i] = a[1][i > 0 ? i - 1 : 0] - 1;
      e++;
    }
  }
  int ans = n;
  rep(i,n)
  {
    ans = min(ans, a[0][i] + a[1][i] + e);
  }
  cout <<ans;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve()
{
    int x,y;
    cin>>x>>y;
    if(y>=2*x && (y-2*x)%2==0 && 4*x-y>=0 && (4*x-y)%2==0)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
}
int32_t main()
{
    
    //_READ
    
    int t;
    t=1;
    while(t--)
        solve();

    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll func(ll n) {
  ll ans = 0;
  /* cout << "now start search " << n << endl; */ 
  for (ll i = 1; i * i <= n; i++) {
    for (ll j = 1; j * j <= n; j++) {
      /* cout << "i and j " << i << " " << j << endl; */
      ll left = 0, right = 101;
      ll a = i + j, b = n - i * i - j * j - i * j;
      /* cout << "a is " << a << " b is " << b << endl; */
      while(left + 1 != right) {
        ll mid = (left + right) / 2;
        ll tmp = mid * mid + a * mid - b;
        /* cout << left << " " << right << " " << mid << " " << tmp << endl; */
        /* cout << mid << " " << tmp << endl; */
        if (tmp > 0) right = mid;
        else if (tmp < 0) left = mid;
        else if (tmp == 0) {
          ans++;
          break;
        }
      } 
    }
  }
  return ans;
}


int main(int argc, char const *argv[]) {
  int n; cin >> n;
  /* init(); */
  FOR(i,1,n) {
    ll tmp = func(i);
    printf("%lld\n",tmp);
  }

  return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>

int main(void)
{
        int a,b,c,i;
        scanf("%d%d%d",&a,&b,&c);
        for(i=a;i<a*b;i+=a){
                if(i%b==c){
                        printf("YES\n");
                        return 0;
                }
        }
        printf("NO\n");
        return 0;
}


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

int main(){
    ll h;
    scanf("%lld",&h);
    ll a = 1;
    int cnt = 0;
    while(h){
    	h /= 2;
    	cnt++;
	}
	cnt--;
	ll ans = 0;
	while(cnt){
		ans += pow(2,cnt);
		cnt--;
	}
	ans++;
	cout << ans <<endl;
    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 20;
const int mod = 1e9 + 7;

long long a[maxn];
long long b[maxn];

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, s1 = 0, s2 = 0, t1 = 0, t2 = 0;
    cin >> n;
    for (int i = 0; i < n; i++){cin >> a[i]; b[i] = a[i];}
    for (int i = 0; i < n; i++)
    {
        if (i & 1)
        {
            s1 += a[i];
            if (s1 <= 0)
            {

                t1 += 0 - s1 + 1;
                s1 = 1;
            }
            s2 += a[i];
            if (s2 >= 0)
            {

                t2 += s2 + 1;
                s2 = -1;
            }
        }
        else
        {
            s2 += a[i];
            if (s2 <= 0)
            {

                t2 += 0 - s2 + 1;
                s2 = 1;
            }
            s1 += a[i];
            if (s1 >= 0)
            {

                t1 += s1 + 1;
                s1 = -1;
            }
        }
    }
    //cout << t1 << ' ' << t2;
    cout << min (t1, t2) << endl;

    return 0;
}











Measured memory_bytes: 1792
using System;
using System.Linq;

namespace AGC026_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var cnt = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (a[i] == a[i+1])
                {
                    cnt++;
                    i++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13268
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

bool is_ok(const string &s) {
    rep(i, (int)s.size() / 2) if (s[i] != s[(int)s.size() - i - 1]) return false;
    return true;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string t = "";
    rep(i, (n - 1) / 2) t += s[i];
    string u = "";
    repr(i, (n + 3) / 2 - 1, n) u += s[i];

    if (is_ok(s) && is_ok(t) && is_ok(u)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
const int N=1e5+10;
const ll mod=1e9+7;
ll dp1[N],dp2[N];
void dfs(int v,int par,vector<int>adj[])
{
    ll sum1=1;
    ll sum2=1;
    int ch=0;
    for(auto node:adj[v])
    {
        if(node==par) continue;
        ch=1;
        dfs(node,v,adj);
        sum1=(sum1*(dp1[node]+dp2[node]))%mod;
        sum2=(sum2*(dp1[node]))%mod;
    }
    if(!ch)
    {
        dp1[v]=dp2[v]=1;
    }
    else 
    {
        dp1[v]=sum1;
        dp2[v]=sum2;
    }
}
int main()
{
    int n;
    cin>>n;
    vector<int>adj[n+1];
    forl(i,0,n-1)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1,-1,adj);
    cout<<(dp1[1]+dp2[1])%mod<<endl;
}















Measured memory_bytes: 15616
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int calc(int a) {
    if (a % 2 == 0) return 1 + calc(a / 2);
    else return 0;
}

int main() {

    int N;
    scanf("%d", &N);

    int a[N];
    for (int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
    }

    vector<int> v;
    for (int i = 0; i < N; ++i) {
        v.push_back(calc(a[i]));
    }

    int m = *min_element(v.begin(), v.end());

    printf("%d\n", m);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    const ll mod = 1e9 + 7;
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    set<ll> sa, sb;
    rep(i, n) {
        if (sa.count(a[i]) > 0) {
            cout << 0 << endl;
            return 0;
        }
        sa.insert(a[i]);
    }
    rep(i, m) {
        if (sb.count(b[i]) > 0) {
            cout << 0 << endl;
            return 0;
        }
        sb.insert(b[i]);
    }
    ll ans = 1;
    rreps(i, 1, n * m + 1) {
        if ((sa.count(i) > 0) && (sb.count(i) > 0)) {
            continue;
        }
        else if (sa.count(i) > 0) {
            auto itb = lower_bound(all(b), i);
            ll cntb = m - (itb - b.begin());
            if (itb == b.end()) cntb = 0;
            ans = ans * cntb % mod;
        }
        else if (sb.count(i) > 0) {
            auto ita = lower_bound(all(a), i);
            ll cnta = n - (ita - a.begin());
            if (ita == a.end()) cnta = 0;
            ans = ans * cnta % mod;
        }
        else {
            auto ita = lower_bound(all(a), i);
            ll cnta = n - (ita - a.begin());
            if (ita == a.end()) cnta = 0;
            auto itb = lower_bound(all(b), i);
            ll cntb = m - (itb - b.begin());
            if (itb == b.end()) cntb = 0;
            ll tmp = max(0LL, cnta * cntb - (n * m - i));
            ans = ans * tmp % mod;
            // printf("i=%lld, cnta=%lld, cntb=%lld\n", i, cnta, cntb);
        }
        // printf("i=%lld, ans=%lld\n", i, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
// 11232019.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
using namespace std;

long long a[200005] = { 0 };

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if(i>=1) a[i] += a[i - 1];
	}
	long long ans = 999999999999999999;
	for (int i = 0; i < n; i++) {
		if ((a[n - 1] - a[i]) == a[i]) ans = 0;
		else if ((a[n - 1] - a[i]) < a[i]) {
			ans = min(ans, a[i] - (a[n - 1] - a[i]));
		}
		else {
			ans = min(ans, (a[n - 1] - a[i]) - a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	int n, k;
	string s;
	cin >> n >> k >> s;
	k--;
	s[k] += 32;
	
	cout << s << endl;
	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main(){
  int n;
  int alice = 0, bob = 0;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  sort(a, a+n);
  for(int i = 0; i < n; i++){
    if(i%2) alice += a[i];
    else    bob += a[i];
  }

  cout << abs(alice-bob) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sum_up(x)  (x*(x+1))/2
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define mp(a,b)   make_pair(a,b)
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define BSv(v,a) binary_search(v.begin(),v.end(), a)
#define BSa(v,n,a) binary_search(v,v+n, a)

using namespace std;

void base()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

bool prime[100001];
void sieve(int n)
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int power(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x*x;
    }
    return res;
}

double float_sq(double n)
{
    double x = n;
    double y = 1;
    double e = 0.000001;
    while (x - y > e)
    {
        x = (x + y) / 2;
        y = n / x;
    }
    return x;
}

int int_sq(int x)
{
    if (x == 0 || x == 1)
        return x;
    int start = 1, end = x, ans;
    while (start <= end)
    {
        int mid = (start + end) / 2;
        if (mid*mid == x)
            return mid;
        if (mid*mid < x)
        {
            start = mid + 1;
            ans = mid;
        }
        else
            end = mid-1;
    }
    return ans;
}

int nxt()
{
    int x;
    cin >> x;
    return x;
}

set<int>s;
void printArray(vector<int> arr, int n)
{
    int cnt=0;
    for (int i = 0; i < n; i++)
        cnt+=arr[i] ;
    if(cnt%2==0)
        s.insert(cnt);
}
void printSubsequences(vector<int> arr, int index,
                       vector<int> subarr)
{
    if (index == arr.size())
    {
        int l = subarr.size();
        if (l != 0)
            printArray(subarr, l);
    }
    else
    {
        printSubsequences(arr, index + 1, subarr);
        subarr.push_back(arr[index]);
        printSubsequences(arr, index + 1, subarr);
    }
    return;
}

int32_t main()
{
    base();
    int a=nxt(),b=nxt();
    int even=2,odd=1;
    vector<int>v;
    int arr[a+b];
    for(int i=0;i<a;i++){
            arr[i]=even;
            even+=2;
    }
    for(int i=a;i<a+b;i++){
            arr[i]=odd;
            odd+=2;
    }
    int cnt=0;
    for(int i=0;i<(a+b)-1;i++)
        for(int j=i+1;j<a+b;j++)
            cnt+=((arr[i]+arr[j])%2==0?1:0);
    cout<<cnt;
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  unordered_map<int, int> m;
  REP(i, N) {
    int K;
    cin >> K;
    REP(j, K) {
      int A;
      cin >> A;
      m[A]++;
    }
  }
  const auto count =
      count_if(ALL(m), [N](const pair<int, int> &p) { return p.second == N; });
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <tuple>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using node_t = tuple<int,int,int>;
using tree_t = vector<node_t>;

void preorder(tree_t tree,int id) {
	cout << " " << id;
	if (get<1>(tree[id]) != -1) {
		preorder(tree,get<1>(tree[id]));
	}
	if (get<2>(tree[id]) != -1) {
		preorder(tree,get<2>(tree[id]));
	}
}

void inorder(tree_t tree,int id) {
	if (get<1>(tree[id]) != -1) {
		inorder(tree,get<1>(tree[id]));
	}
	cout << " " << id;
	if (get<2>(tree[id]) != -1) {
		inorder(tree,get<2>(tree[id]));
	}
}

void postorder(tree_t tree,int id) {
	if (get<1>(tree[id]) != -1) {
		postorder(tree,get<1>(tree[id]));
	}
	if (get<2>(tree[id]) != -1) {
		postorder(tree,get<2>(tree[id]));
	}
	cout << " " << id;
}

int main() {
	int n; // number of nodes
	cin >> n;
	tree_t tree(n);
	for (int i = 0;i != n;++i) {
		int id,left,right;
		cin >> id >> left >> right;
		tree[i] = make_tuple(id,left,right);
	}
	// sort by id
	sort(tree.begin(),tree.end(),[](node_t n1,node_t n2) { return get<0>(n1) < get<0>(n2); });
	// mark root
	bool *is_root = new bool[n];
	for (int i = 0;i != n;++i) {
		is_root[i] = true; // default to all are roots
	}
	for (int i = 0;i != n;++i) {
		if (get<1>(tree[i]) != -1 && is_root[get<1>(tree[i])]) {
			is_root[get<1>(tree[i])] = false;
		}
		if (get<2>(tree[i]) != -1 && is_root[get<2>(tree[i])]) {
			is_root[get<2>(tree[i])] = false;
		}
	}
	// find root
	int root;
	for (int i = 0;i != n;++i) {
		if (is_root[i]) {
			root = i;
			break;
		}
	}
	delete [] is_root;
	cout << "Preorder" << endl;
	preorder(tree,root);
	cout << endl;
	cout << "Inorder" << endl;
	inorder(tree,root);
	cout << endl;
	cout << "Postorder" << endl;
	postorder(tree,root);
	cout << endl;
}

Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var HA = ReadInts();
            var H = HA[0];
            var A = HA[1];
            var ans = 0;
            while (H > 0)
            {
                H = H - A;
                ans++;
            }
            WriteLine(ans);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
#include<utility>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n, vector<int>());
  for (int i=0; i<m; ++i) {
    int a, b;
    cin >> a >> b;
    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }
  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));
  vector<bool> visited(n, false);
  vector<int> distanceVec(n, INT_MAX);
  while (!q.empty()) {
    auto current = q.front().first;
    auto currentDistance = q.front().second;
    q.pop();
    if(visited[current]) continue;
    visited[current] = true;
    if (currentDistance > 3) {
      break;
    }
    distanceVec[current] = currentDistance;
    //cout << "cu" << current << endl;
    //cout << "di" << currentDistance << endl;
    for(auto& e : graph[current]) {
      //cout << "ta " << e << ", ";
      q.push(make_pair(e, currentDistance+1));
    }
    //cout << endl;
  }
  //cout << distanceVec[n-1] << endl;
  if (distanceVec[n-1] <= 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> vt(n,0);
    for(int i=0;i<n;i++)
    cin>>vt[i];
    vector<int> rg(n,0);
    rg[0]=0;
    rg[1]=rg[0]+abs(vt[0]-vt[1]);
    for(int i=2;i<n;i++)
    {
        int a=INT_MAX;
        for(int j=1;j<=k && i-j >=0;j++)
        {
            a=min(a,rg[i-j]+abs(vt[i]-vt[i-j]));
            if(i-j == 0) break;
        }
        
        rg[i]=a;
    }
    cout<<rg[n-1];
    

    return 0;
}


Measured memory_bytes: 1024
N = int(input())

c0 = 0
c1 = 0
c2 = 0
c3 = 0

for i in range(N):
    s = input()
    if s == 'AC':
        c0 += 1
    elif s == 'WA':
        c1 += 1
    elif s == 'TLE':
        c2 += 1
    elif s == 'RE':
        c3 += 1

print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(c0, c1, c2, c3))

Measured memory_bytes: 9124
using System;
using System.Linq;
 
namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = "";
            var ball = new[]{true, false, false};
            while((s = Console.ReadLine()) != null)
            {
            	var arr = s.Split(',').ToArray();
            	var a = (int)(Char.Parse(arr[0]) - 'A');
            	var b = (int)(Char.Parse(arr[1]) - 'A');
            	var t = ball[b];
            	ball[b] = ball[a];
            	ball[a] = t;
            }
            Console.WriteLine(ball[0] ? "A" : ball[1] ? "B" : "C");
        }
        
    }
}

Measured memory_bytes: 5488
#include <iostream>
using namespace std;
int a[9];
int main() {
	int i;
	for(i=0; i<9; i++) cin>>a[i];
	for(i=8; i>2; i--) a[i] -= a[i-3];
	cout<<(a[3]==a[4] && a[4]==a[5] && a[6]==a[7] && a[7]==a[8] ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
/** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define mod 1000000007
using namespace std;
const int maxN=100005;
void Onigiri()
{
 int n;
 cin>>n;
 int a[3*n];
 rep(i,0,3*n)
 cin>>a[i];

 multiset<int> ms; 
 int dpl[3*n]={0},dpr[3*n]={0};
 int sum=0;
 rep(i,0,3*n)
 {
   if(ms.size()<n){
      ms.insert(a[i]);
      sum+=a[i];
      dpl[i]=sum;
   }
   else{
      ms.insert(a[i]);
      sum+=a[i];
      sum-=*ms.begin();
      ms.erase(ms.begin());
      dpl[i]=sum;
   }
 }

 multiset<int,greater<int>>ms2;
 sum=0;
 repr(i,3*n-1,0)
 {
   if(ms2.size()<n){
      ms2.insert(a[i]);
      sum+=a[i];
      dpr[i]=sum;
   }
   else{
      ms2.insert(a[i]);
      sum+=a[i];
      sum-=*ms2.begin();
      ms2.erase(ms2.begin());
      dpr[i]=sum;
   }
 }

 int ans=INT64_MIN;
 rep(i,n-1,3*n-n)
 { 
   //if(dpl[i]==-1||dpr[i+1]==-1)continue;
   //cout<<dpl[i]<<" : "<<dpr[i+1]<<endl;
   ans=max(ans,dpl[i]-dpr[i+1]);
 }
 cout<<ans;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("/home/pritish/Competitive/in", "r", stdin);
   freopen("/home/pritish/Competitive/out", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

Measured memory_bytes: 20256
matrixlst = []
vectorlst = []
vector2lst = []
tempresult = 0
count = 0
count2 = 0
i = 0
j = 0
finalA = 0
finalB = 0
testnumber = 0
n, m = input().split()
for b in range(int(n)):
    testinput = [int(x) for x in input().split()]
    for c in range(int(m)):
        matrixlst.append(testinput[count])
        count += 1
    count = 0
    testinput.clear()
for d in range(int(m)):
    testinput = int(input())
    vectorlst.append(testinput)
for e in range(int(n)):
    for f in range(int(m)):
        finalA = int(matrixlst[testnumber])
        finalB = int(vectorlst[j])
        tempresult += int(finalA * finalB)
        j += 1
        testnumber += 1
    vector2lst.append(tempresult)
    j = 0
    tempresult = 0
for g in range(int(n)):
    print(vector2lst[count2])
    count2 += 1


Measured memory_bytes: 5952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    FAST;
    ll n,k,i;
    cin>>n>>k;
    vector<ll> v;
    ll x;
    v.push_back(-1);
    for(i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    ll d[n+7]={0};
    bool vs[n+7];
    memset(vs,false,sizeof(vs));
    ll c=1;
    ll cnt=0;
    i=1;
    ll count=0;
    ll sm=0;
    vs[1]=true;
    while(1)
    {
        if(vs[v[i]]==false)
        {
            d[v[i]]=c;
            c++;
            vs[v[i]]=true;
            i=v[i];
          //  cout<<i<<" ";
            cnt++;
            if(cnt==k)
            {
                cout<<i;
                return 0;
            }
        }
        else
        {
            count=c-d[v[i]];
            break;
        }
    }
    // cout<<endl;
    // cout<<count<<" "<<i<<" "<<d[v[v[i]]]<<endl;
    ll k1=k;
    k1-=d[v[i]];
    cnt=0;
    ll r=k1%count;
    i=v[i];
    for(ll p=0;p<r;p++)
    {
        i=v[i];
    }
    cout<<i;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int H, W, K, count = 1;
    cin >> H >> W >> K;
    vector<vector<char>> s(H, vector<char> (W));
    vector<vector<int>> A(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> s.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++) {
        int fin = 0;
        bool T = false;
        for (int j = 0; j < W; j++) {
            if (s.at(i).at(j) == '#'){
                int k = fin, a = j;
                while(!(s.at(i).at(k) == '#' && a != k)) {
                    A.at(i).at(k) = count;
                    k++;
                    if (k > W - 1) {
                        count++;
                        T = true;
                        break;
                    }
                }
                if (T) {
                    break;
                }
                count++;
                fin = k;
            }

        }
    }
    for (int i = 1; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A.at(i).at(j) == 0) {
                A.at(i).at(j) = A.at(i - 1).at(j);
            }
        }
    }
    for (int i = H - 2; i >= 0; i--) {
        for (int j = 0; j < W; j++) {
            if (A.at(i).at(j) == 0) {
                A.at(i).at(j) = A.at(i + 1).at(j);
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << A.at(i).at(j);
            if (j != W - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 1280
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"



int main() {
	long double A, B;
	cin >> A >> B;
	printf("%lld\r\n", (long long)((A * (100 * B)) / 100 + 0.001));

	return 0;
}




Measured memory_bytes: 3772
#include <stdio.h>

int main(void)
{
	int num;
	int i;
	int ans;
	
	for(i = 1; i < 10; i++){
		for(num = 1; num < 10; num++){
			ans = i * num;
			printf("%dx%d=%d\n", i, num, ans);
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=998244353;
int dp[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,s;
	cin>>n>>s;
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		for(int j=s;j>=0;j--)
		{
			dp[j+x]+=dp[j];
			dp[j+x]%=mod;
			dp[j]*=2;
			dp[j]%=mod;
		}
	}
	cout<<dp[s]<<endl;
	return 0;
}




Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
const ll mod = 998244353 ;
const double pi = acos(-1);
ll fastpow(ll b, ll e) {
    if (!e)
        return 1;
    ll ret = fastpow(b, e / 2);
    ret = (ret * ret) % mod;
    if (e % 2)
        ret = (ret * b) % mod;
    return ret;
}
ll modinv(ll x) {
    return fastpow(x, mod - 2);
}
double torad(double ang) {
    return ang * pi / 180.0;
}
int prime[N];
void sieve() {
    prime[0] = prime[1] = 1;
    for (int i = 2; i < N; i++) {
        if (!prime[i]) {
            for (int j = i; j < N; j += i)
                prime[j] = i;
        }
    }
}


int w[N], v[N];
ll dp[N][int(1e5 + 5)];
int main()
{
    ///smallest/largest case
    ///initialize
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &w[i], &v[i]);

    for (int j = 0; j <= m; j++) {
        if (w[n - 1] <= j)
            dp[n - 1][j] = v[n - 1];
        else
            dp[n - 1][j] = 0;
    }
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j - w[i] >= 0) {
                //cout << dp[i][j] << " * " << dp[i + 1][j - w[i]] + v[i] << '\n';
                dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
                //cout << j - w[i] << ' ' << dp[i + 1][j - w[i]] << ' ' << v[i] << '\n';
            }
        }
    }
    /*
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++)
            cout << dp[i][j] << ' ';
        cout << '\n';
    }
    */
    printf("%lld", dp[0][m]);
    return 0;
}


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

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x))

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> S[M];
    vector<int> P;
    rep(i, M){
        int k;
        cin >> k;
        rep(j, k){
            int s;
            cin >> s;
            S[i].push_back(s);
        }
    }
    rep(i, M){
        int p;
        cin >> p;
        P.push_back(p);
    }

    int ans = 0;
    rep(pattern, 1 << N){
        bool ok = true;
        rep(j, M){
            int cnt = 0;
            rep(k, S[j].size()){
                // cout << pattern << " " << (1 << S[j][k]-1) << endl;
                if( pattern & (1 << S[j][k]-1) ) cnt++;
            }
            if( cnt % 2 != P[j] ) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>

using namespace std;

int main()
{
	int n;
	stack<int> t;

	while(cin >> n){
		if(n==0){
			cout << t.top() << endl;
			t.pop();
		}
		else{t.push(n);}
	}

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); 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 INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    vi memo(N + 1);
    REP(i, N) {
        memo[a[i]]++;
    }
    REP(i, N + 1) {
        ll tmp = memo[i];
        ans += tmp * (tmp - 1) / 2;
    }
    REP(i, N) {
        if (memo[a[i]] == 1) {
            cout << ans << endl;
        } else {
            cout << ans - (memo[a[i]] - 1) << endl;
        }
    }
}

Measured memory_bytes: 4096
#include <stdio.h>
int main(){
  int N,D,X;
  scanf("%d",&N);
  int A[N],ans=0;
  scanf("%d %d",&D,&X);
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
    ans+=1;
    for(int j=1;j<D;j++){
      int aa=j*A[i]+1;
      if(aa>D)break;
      ans+=1;
    }
  }
  printf("%d\n",ans+X);
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

double a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0, startp = 0, endp = 0, checker = 0;
std::vector <std::string> vec{}, vecsec{}, vecth{};
int iremono[100001];
std::vector<double>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{

	cin >> a;
	rep(i, a) {
	
		cin >> b;
		ans.push_back(b);
		cin >> input;
		vec.push_back(input);
	}
	rep(i, a) {
		if (vec[i] == "BTC")
		{
		
			counter += ans[i] * 380000.0;
		}
		if(vec[i]=="JPY") {
	
			counter += ans[i];
		}

	}
	cout << counter << endl;
}

Measured memory_bytes: 256
/*
ID: rajiv
TASK: test
LANG: C++14
*/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>
#include<iterator>
#include<random>
#include<chrono>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ONLINE_JUDGE

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
int rnd(int a, int b){ // including a and b
	return a+(rng()%(b-a+1));
}
#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sortr(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb push_back
#define endl '\n'

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

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

void solve(){
	int x,y; cin>>x>>y;
	rep(i,101){
		rep(j,101){
			if(i+j==x and 2*i+4*j==y){
				cout<<"Yes\n";
				return;
			}		
		}
	}
	cout<<"No\n";
	
}

int main(){
	fast_io
	#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
	#endif 
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 3076
#include<iostream>

using namespace std;

int main()
{
	int n,x,i;
	cin >> n >> x;

	int m[n];

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

	int count=0;

	x -= Ado;
	count += n;

	int min=m[0];
	for(i=1; i<n; i++){
		if(m[i] < min) min=m[i];
	}

	count += x/min;

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>

using namespace std;

int main()
{
    int k;
    cin >> k;
    cout << ((k/2) * (((k-1)/2)+1)) << '\n';
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a;
	long long ans = 0;

	int num_minus = 0;	// 0 : マイナスが偶数個
	int minx = 1000000000;
	for( int i = 0; i < n; ++i )
	{
		cin >> a;
		if( a < 0 )
		{
			num_minus ^= 1;
			minx = min( -a, minx );
			ans -= a;
		}
		else
		{
			minx = min( a, minx );
			ans += a;
		}
	}
	if( num_minus )	// マイナスが奇数個
		ans -= 2*minx;

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

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

using namespace std;

struct UnionFind
{
  vector<int> data;
  UnionFind(int n):data(n, -1){}
  int size(int x){ return -data[find(x)]; }
  int find(int x){ return data[x] < 0 ? x : data[x] = find(data[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  int unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] < data[y]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return -data[x];
  }
};

struct edge {
  int u, v, cost;
  edge(){}
  edge(int u, int v, int cost):u(u), v(v), cost(cost){}
  bool operator < (const edge& e) const {
    return cost < e.cost;
  }
};

vector<edge> E;
int n, m;

int Kruskal()
{
  sort(E.begin(), E.end());
  UnionFind uf(n);
  int cnt = 0;
  for(int i = 0; i < E.size(); i++) {
    edge& e = E[i];
    if(!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      if(++cnt == n/2) return e.cost;
    }
  }
}

int main()
{
  while(cin >> n >> m, n || m) {
    E.clear();
    for(int i = 0; i < m; i++) {
      int s, t, c;
      cin >> s >> t >> c;
      --s, --t;
      E.push_back(edge(s, t, c));
    }
    cout << Kruskal() << endl;
  }
  return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin>>k;
    int a[13]={1,2,3,5,7,11,13,15,17,19,23,29,31};
    int b[9]={4,6,9,10,14,21,22,25,26};
    int c[2]={28,30};
    int d[5]={8,12,18,20,27};
    int e[1]={16};
    int f[1]={24};
    int h[1]={32};
    for(int i : a){
        if(i==k){
            cout<<"1\n";
            break;
        }
    }
    for(int i : b){
        if(i==k){
            cout<<"2\n";
            break;
        }
    }
    for(int i : c){
        if(i==k){
            cout<<"4\n";
            break;
        }
    }
    for(int i : d){
        if(i==k){
            cout<<"5\n";
            break;
        }
    }
    for(int i:e){
        if(i==k){
            cout<<"14\n";
            break;
        }
    }
    for(int i: f){
        if(i==k){
            cout<<"15\n";
            break;
        }
    }
    for(int i : h){
        if(i==k){
            cout<<"51\n";
            break;
        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"YES":"NO");
}
int main() {
  ll a,v;cin>>a>>v;
  ll b,w;cin>>b>>w;
  ll t;cin>>t;
  bool ans=false;
  if(a<b){
    if(a+v*t>=b+w*t){
      ans=true;
    }
  }else{
    if(a-v*t<=b-w*t){
      ans=true;
    }
  }
  cout<<yesno(ans)<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int b, c;
	string a;
	cin >> c >> b >> a;
	b -= 1;
	if (a[b] == 'A') {
		a[b] = 'a';
	}
	else if (a[b] == 'B') {
		a[b] = 'b';
	}
	else {
		a[b] = 'c';
	}
	cout << a << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    ans = 0
    flag = True
    for rep in discount:
        pay = a[rep[0]-1] + b[rep[1]-1] - rep[2]
        if flag:
            ans = pay
            flag = False
        else:
            ans = min(ans,pay)
    
    ans = min(ans,min(a)+min(b))
    print(ans)
    return

if __name__=='__main__':
    A,B,M = IL()
    a = list(IL())
    b = list(IL())
    discount = [list(IL()) for _ in range(M)]
    solve()

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

ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int f(int x) {
    int res = 0;
    while (x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

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

    // a -> a'
    rep(i,n) {
        if (a[i] % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    // a' -> a''
    int t = f(a[0]);
    rep(i,n) {
        if (f(a[i]) != t) {
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    rep(i,n) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m+1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

    int n=5;
    int w=4;
    int t=1;
    int tmp;

int go_r()
{ 
    tmp = n;
    n = w;
    w = 7-tmp;
    return t;
}
int go_l()
{
    tmp = w;
    w = n;
    n = 7-tmp;
    return t;
}
int go_n()
{
    tmp = n;
    n = t;
    t = 7-tmp;
    return t;
}
int go_e()
{
    tmp = t;
    t = w;
    w = 7-tmp;
    return t;
}
int go_w()
{
    tmp = w;
    w = t;
    t = 7-tmp;
    return t;
}
int go_s()
{
    tmp = t;
    t = n;
    n = 7-tmp;
    return t;
}

int main(int argc, char const* argv[])
{
    int row;
    while (cin >> row) 
    {
        int sum=1;
        n=5;
        w=4;
        t=1;
        //終端判断
        if (row==0){break;}
        string s;
        for (int i = 0; i < row; i++) 
        {
            cin >> s;
            if(s == "North"){ sum += go_n();}
            if(s == "South"){ sum += go_s();}
            if(s == "West") { sum += go_w();}
            if(s == "East") { sum += go_e();}
            if(s == "Right"){ sum += go_r();}
            if(s == "Left") { sum += go_l();}
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
def linearSearch(as, bs)
  n = 0
  for i in bs
    for j in as
      if i == j
        n = n + 1
        break;
      end
    end
  end
  puts n
end


a_size = STDIN.gets.to_i
as = STDIN.gets.split(' ')

b_size = STDIN.gets.to_i
bs = STDIN.gets.split(' ')

linearSearch(as, bs)

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

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

  string ans = "Yes";

  for (int i = 0; i < A + B + 1; i++) {
    if (i != A && S.at(i) == '-') ans = "No";
    if (i == A && S.at(i) != '-') ans = "No";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
d = dict()

maxi = 0
for _ in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    maxi = max(maxi, d[s])
    
max_k_list = [kv[0] for kv in d.items() if kv[1] == maxi]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)

Measured memory_bytes: 32148