akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
ll N,M;
int main(){
	cin>>N>>M;
	if(N>M)swap(N,M);
	if(N==1){
		if(M==1)cout<<1<<endl;
		else cout<<M-2<<endl;
	}else{
		cout<<(N-2)*(M-2)<<endl;
	}
	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAX = 10000000;

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

    sort(x.begin(), x.end());//不可变成数组这样处理 

    int ans = MAX;
    for(int i = x[0]; i <= x[n - 1]; i++) {
        int sum = 0;
        for(int j = 0; j < n; j++) {
            int dist = pow(i - x[j], 2);
            sum += dist;
        }
        ans = min(ans, sum);
    }

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

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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair				
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;
 
#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

#ifndef LOCAL
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#else
#include</Users/dawid/algo/mac/ordered_set>
#endif

const int N = 307;

int n, m, cnt, k;

char g[N][N];
int pref[N][N];
int ans[N][N];

int ile(int x1, int x2, int y1, int y2)
{
	return pref[x2][y2] - pref[x2][y1-1] - pref[x1-1][y2] + pref[x1-1][y1-1];
}

void solve(int x1, int x2, int y1, int y2, int bit)
{
	if(ile(x1, x2, y1, y2)==1)
	{
		++cnt;

		for(int i = x1; i <= x2; ++i)
		{
			for(int j = y1; j <= y2; ++j)
			{
				ans[i][j] = cnt;
			}
		}

		return;
	}

	if(!bit)
	{
		for(int i = x1; i < x2; ++i)
		{
			if(ile(x1, i, y1, y2) && ile(i+1, x2, y1, y2))
			{
				solve(x1, i, y1, y2, 1);
				solve(i+1, x2, y1, y2, 1);
				return;
			}
		}

		solve(x1, x2, y1, y2, 1);
	}
	else
	{
		for(int i = y1; i < y2; ++i)
		{
			if(ile(x1, x2, y1, i) && ile(x1, x2, i+1, y2))
			{
				solve(x1, x2, y1, i, 0);
				solve(x1, x2, i+1, y2, 0);
				return;
			}
		}

		solve(x1, x2, y1, y2, 0);
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> m >> k;

	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			cin >> g[i][j];

			if(g[i][j]=='#')
				pref[i][j] = 1;

			pref[i][j] += pref[i-1][j];
		}
	}

	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			pref[i][j] += pref[i][j-1];
		}
	}

	solve(1, n, 1, m, 0);

	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			cout << ans[i][j] << " ";
		}

		cout << endl;
	}
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-

a, b, c, d = map(int,input().split())

flag =''


while c >= 0:
    c  -= b
    

    if c <= 0 and a > 0:
        flag ='yes'

    a -= d

if flag == 'yes':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61812
import itertools
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

# x1+x2+x3+...xN = X (x>=0) 
def nHk_list(N,X):
    if N == 0: return []
    elif N == 1: return [[X]]

    border = [i for i in range(X+1)]
    res = []
    for S in itertools.combinations_with_replacement(border, N-1):
        # print(S)
        pre = 0
        sub = []
        for s in S:
            sub.append(s-pre)
            pre = s
        sub.append(X-pre)
        res.append(sub)
    return res


INF=10**20
def main():
    N=ii()
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]

    ans = []
    for c in range(1,N+1):
        # print("___\nc",c)
        for X in nHk_list(c,N-c):
            # print("X:",X,"c:",c,"N-c:",N-c)
            V = []
            for i in range(len(X)):
                x = X[i]
                V.append(list(itertools.product(alphabet[:i+1],repeat=x)))

            # print("V",V)
            U = itertools.product(*V)
            base = alphabet[:c]
            for u in U:
                char = ""
                for i in range(c):
                    char += alphabet[i] + "".join(list(u[i]))
        
                ans.append(char)
        
    
    ans.sort()
    # ans.append("".join(alphabet[:N]))
    print(*ans,sep='\n')

            
            

        

if __name__ == "__main__":
    main()

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int) 2e7 + 17];
const ll inf = (ll) 1e9 + 7ll;

const int maxn = (int) 2e5 + 17;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;
string s;
deque<int> pos[maxn];
ordered_set st;

bool read() {
    if (scanf("%s", buff) != 1)
        return false;

    return true;
}

int f(int x) {
    return st.order_of_key(x);
}

int g(int x) {
    return sz(st) - 1 - st.order_of_key(x);
}

void solve() {
    s = buff;
    n = sz(s);

    for (int i = 0; i < n; ++i) {
        pos[s[i] - 'a'].push_back(i);
        st.insert(i);
    }

    ll ans = 0;

    for (int l = 0, r = n - 1; l < r; ++l, --r) {
        int c = -1, val = inf;

        for (int i = 0; i < 26; ++i)
            if (sz(pos[i]) > 1) {
                if (c == -1) {
                    c = i;
                    val = f(pos[i].front()) + g(pos[i].back());
                    continue;
                }

                int x = f(pos[i].front()) + g(pos[i].back());

                if (x < val)
                    val = x, c = i;
            }

        if (c == -1) {
            printf("-1\n");
            return ;
        }

        ans += val;
        st.erase(pos[c].front());
        st.erase(pos[c].back());
        pos[c].pop_front();
        pos[c].pop_back();
    }

    printf("%lld\n", ans);
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll r = n - 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      r = min(r, i + n / i - 2);
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A, B;
  scanf("%d%d", &A, &B);
  if(A%3==0 || B%3==0 || (A+B)%3==0){
    printf("Possible\n");
  }else{
    printf("Impossible\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int long n, v[MAXN], impar, mp, ok = 1;
int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        if(v[i] % 2) {
            impar++;
        }
        if(v[i] % 4 == 0) {
            mp++;
        }
        if(v[i] % 2 == 0 && v[i] % 4) {
            ok = 0;
        }
    }
    //cout << impar << " " << mp<< endl;
    if(impar > mp + ok) {
        cout << "No\n";
    }
    else
        cout << "Yes\n";

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    ll a, b, c, d; cin >> a >> b >> c >> d;

    ll ans = max({a*d, a*c, b * d, b * c});
    cout << ans;


    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
// " ", ' '
// std::string str;
// str = std::to_string(int i);
// bitset<3> s(N);

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

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

	int N, M; cin >> N >> M;
	vec A(N);
	rep(i, N) cin >> A.at(i);

	priority_queue<int> que;
	rep(i, N) {
		que.push(A.at(i));
	}

	rep(i, M) {
		int mx;
		mx = que.top(); que.pop();
		mx = mx / 2;
		que.push(mx);
	}

	int ans = 0;
	rep(i, N) {
		ans += que.top();
		que.pop();
	}

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


Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define lli long long int
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll c[101010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>N;
    ans=0;
    rep(i,0,N){
        cin>>a[i];
    }
    rep(i,0,N){
        cin>>b[i];
        ans+=b[i];
    }
    cerr<<ans<<endl;
    rep(i,0,N-1){
        cin>>c[i];
    }
    rep(i,0,N-1){
        if(a[i]+1==a[i+1]){
            ans+=c[a[i]-1];
            cerr<<c[a[i]-1]<<endl;;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6400
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int s;
	cin >> s;
	int x1=0, x2=1, x3=0, y1=0, y2=0, y3=0;
	x1 = 0, y1 = 0;
	for (int i = 1; i * i < s; i++) {
		x2++;
	}
	y3 = x2;
	int k = x2 * x2 - s;
	for (int i = 1; i * i <= k; i++) {
		if (k / i > 1000000000) continue;
		if (k % i == 0) {
			x3 = i, y2 = k / i;
		}
	}
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

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

using namespace std;
static const int MMAX = 20;
static const int NMAX = 50000;
static const int INF = ( 1 << 29 );
int main() {
	int n, m;
	int c[ MMAX ];
    int T[ NMAX + 1 ];

	cin >> n >> m;
	for( int i = 0; i < m; i++ ) cin >> c[i];
    
    for( int i = 1; i <= n; i++ ) T[i] =INF;

    T[0] = 0;
    
    for( int i = 0; i < m; i++ ) {
    	for(int j = c[i]; j <= n; j++)
    		T[j] = min( T[j], T[j-c[i]] + 1 );
    }

    cout << T[n] << endl;
	return 0;
}


Measured memory_bytes: 3260
def main():
    H, N = [int(x) for x in input().split()]
    magic = [list(map(int, input().split())) for _ in range(N)]
    # print(magic)
    max_a = max(a for a, _ in magic)
    dp = [10**18 for _ in range(H + max_a)]
    dp[0] = 0

    for i in range(1, H+max_a):
        dp[i] = min(dp[i-a] + b for a, b in magic)

    ans = min(dp[H:H+max_a])
    print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
    int n,m;
    std::cin>>n>>m;
    std::vector<int> p(m),y(m);
    for(int i=0;i<m;i++){std::cin>>p[i]>>y[i];p[i]--;}

    std::vector<std::vector<int>> vec(n); //県i
    for(int i=0;i<m;i++)vec[p[i]].push_back(y[i]);
    for(int i=0;i<n;i++)std::sort(vec[i].begin(),vec[i].end());

    for(int i=0;i<m;i++){
        std::cout<<std::setfill('0')<<std::right<<std::setw(6)<<p[i] + 1;
        std::cout<<std::setfill('0')<<std::right<<std::setw(6)<<1 + std::distance(vec[p[i]].begin(),std::lower_bound(vec[p[i]].begin(),vec[p[i]].end(),y[i]));
        std::cout<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean jg = false;

		for (int num = A; num <= B; num++) {
			if(num%K==0) {
				jg=true;
			}
		}
		if(jg) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}

	}
}


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

string cou(int n, string a, string b){
    string k;

    int t = n / 3;
    for(int i = 0; i < t; i++){
        if(a[0 + 3 * i] == b[0 + 3 * i]){
            if(a[1 + 3 * i] == b[1 + 3 * i]){
                k += "B";
            }else{
                k += "C";
            }
        }else{
            k += "A";
        }
    }

    return k;
}

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

    string a, b;
    cin >> a >> b;

    ll ans = 0;
    ll che = 10e8 + 7;

    if(n == 1){
        ans = 3;
    }else if(n == 2){
        ans = 6;
    }else{
        int flag = 0;
        for(int i = 0; i < n; i++){
            if(flag == 0){
                if(a[i] == b[i]){
                    ans += 3;
                    flag = 1;
                }else{
                    ans += 6;
                    i++;
                    flag = 2;
                }
            }else if(flag == 1){
                if(a[i] == b[i]){
                    ans *= 2;
                    flag = 1;
                }else{
                    ans *= 2;
                    i++;
                    flag = 2;
                }
            }else{
                if(a[i] == b[i]){
                    flag = 1;
                }else{
                    ans *= 3;
                    i++;
                    flag = 2;
                }
            }

            ans %= che;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <set>

#include <stdio.h>
#include <string.h>

using namespace std;

#define rep(i,n) for (int i=0; i < int(n); i++)

typedef pair<int, int> P;

// 素集合データ構造
struct UnionFind
{
	// par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
	vector<int> par;
	// sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		// 最初は全てのデータiがグループiに存在するものとして初期化
		rep(i, n) par[i] = i;
	}

	// データxが属する木の根を得る
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		// sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
	int a, b, cost;

	// コストの大小で順序定義
	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
	int n;  // 頂点数
	vector<Edge> es;  // 辺集合

					  // クラスカル法で無向最小全域木のコストの和を計算する
					  // グラフが非連結のときは最小全域森のコストの和となる
	int kruskal() {
		// コストが小さい順にソート
		sort(es.begin(), es.end());

		UnionFind uf(n);
		int min_cost = 0;

		rep(ei, es.size()) {
			Edge e = es[ei];
			if (!uf.same(e.a, e.b)) {
				// 辺を追加しても閉路ができないなら、その辺を採用する
				min_cost += e.cost;
				uf.unite(e.a, e.b);
			}
		}

		return min_cost;
	}
};

/*
// 標準入力からグラフを読み込む
Graph input_graph() {
Graph g;
int m;
cin >> g.n >> m;
rep(i, m) {
Edge e;
cin >> e.a >> e.b >> e.cost;
g.es.push_back(e);
}
return g;
}


int main()
{
Graph g = input_graph();
cout << "最小全域木のコスト: " << g.kruskal() << endl;
return 0;
}
*/


int main(int argc, char* argv[])
{
	int N;
	cin >> N;
	vector<P> x(N), y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i].first >> y[i].first;
		x[i].second = y[i].second = i;
	}

	// 最小全域木を求めるのに辺が多すぎるので、必要な辺だけを残す
	sort(x.begin(), x.end()); sort(y.begin(), y.end());

	Graph g;
	g.n = N;
	Edge e;
	for (int i = 0; i < N - 1; i++) {
		e.a = x[i].second; e.b = x[i + 1].second; e.cost = x[i + 1].first - x[i].first;
		g.es.push_back(e);
		e.a = y[i].second; e.b = y[i + 1].second; e.cost = y[i + 1].first - y[i].first;
		g.es.push_back(e);
	}

	cout << g.kruskal() << endl;

	return 0;
}

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

typedef pair<int, int> P;
#define INF (1<<31-1)
#define ll long long



int main(){

	string s;
	cin >> s;
	int n = s.length();

	map<int,int> m;
	for (int i = 0; i < n; i++)
		m[i + 1] = s[i] - '0';

	// 必要条件
	for (int i = 1; i <= n - 1; i++){
		if (m[i] != m[n - i]){
			cout << -1 << endl;
			return 0;
		}
	}
	if (m[1] != 1 | m[n]!=0){
		cout << -1 << endl;
		return 0;
	}


	int prev_root = 1;
	for (int i = 2; i <= n; i++){
		if (m[i] == 1){
			if (prev_root != i)
				cout << prev_root << " " << i << endl;
			for (int j = prev_root + 1; j < i; j++)
				cout << i << " " << j << endl;
			prev_root = i;
		}
	}
	if (prev_root != n)
		cout << prev_root << " " << n << endl;

	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define vii vector<int>
#define vip vector<pair<int,int> >
#define pb push_back

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //#endif
/*     int tc;
 *     cin>>tc;
 *     while(tc--)
 *     {
 *
 *     }
 */

    int a,b,c;bool f=0;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))
        f=1;
    cout<<(f?"Yes\n":"No\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
                if(a == b+c || b == c+a || c == a+b)
                        {printf("%s","Yes");}
                else{printf("%s","No");}
        return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

vector<int> G[100000];

const ll H = (1LL<<30);
const ll B = 100003;

ll ans=0;
map<ll,int> hs;

ll dfs(int cur,int bef,int depth){
    ll ret = 0;
    bool isLeaf=true;
    for(auto &e:G[cur]){
        if(e==bef)continue;
        isLeaf = false;
        ret += dfs(e,cur,depth+1);
    }
    
    if(isLeaf){
        if(hs.count(1)){
            ans+=hs[1];
        }
        hs[1]++;
        return 1;
    }
    
    if(hs.count((ret*B + 1)%H)){
        ans+=hs[(ret*B + 1)%H];
    }
    hs[(ret*B + 1)%H]++;
    return (ret*B + 1)%H;
}


int main(){
    int v;
    cin>>v;
    rep(i,v-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll res = dfs(0,-1,0);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 24260
#include <iostream>
#include <string>

int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	char rec[h+2][w+2] = {""};
	std::string inpt;
	int i, j;
	for (i = 0; i < h; i++) {
		std::cin >> inpt;
		for (j = 0; j < inpt.size(); j++) {
			rec[i+1][j+1] = inpt.at(j);
		}
	}
	for (i = 0; i < h + 2; i++) {
		for (j = 0; j < w + 2; j++) {
			if (i == 0 || j == 0 || i == h + 1 || j == w + 1) {
				rec[i][j] = '#';
			}
		}
	}
	for (i = 0; i < h + 2; i++) {
		for (j = 0; j < w + 2; j++) {
			printf("%c", rec[i][j]);
		}
		printf("\n");
	}
}

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

bool is_prime(int n){
  if(n==1) return false;

  int m = sqrt(n);
  for (int i = 2; i <= m; i++)
  {
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n ;
  vector<int> ans;

  for (int i = 2; i <= 55555; i++)
  {
    if(is_prime(i) && i%5==1) ans.push_back(i);
    if((int)ans.size()==n) break;
  }
  for (int i = 0; i < n-1; i++)
  {
    cout << ans[i] << " ";
  }
  cout << ans[n-1] << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split(' '))
S = input()

lens = {'L':[],'R':[]}

ps = S[0]
l = 1
ans = 0
for s in S[1:]:
	if ps == s:
		ans += 1
		l += 1
	else:
		lens[ps].append(l)
		l = 1
		ps = s
lens[ps].append(l)

nL = len(lens['L'])
nR = len(lens['R'])
if nL > nR:
	ans += 2 * min(K,nL-1)
elif nL == nR:
	ans += 2 * min(K,nL-1)
	if K > nL - 1:
		ans += 1
else:
	ans += 2 * min(K,nR-1)

print(ans)






Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr lint MOD = 1000000007;

int N, L;

int power(int x, int n)
{
    int ans = 1;
    while (n)
    {
        if (n & 1) ans = (lint)ans * x % MOD;
        x = (lint)x * x % MOD;
        n >>= 1;
    }
    return ans;
}

int main()
{
    {
        string s;
        cin >> N >> s;
        L = s.size();
    }
    vector<vector<lint> > dp(N+1, vector<lint>(N+2));
    dp[0][0] = 1;
    for (int i=1; i<=N; i++)
    {
        for (int j=0; j<=i; j++)
        {
            dp[i][j] = (dp[i-1][j+1] +  (j ? dp[i-1][j-1] * 2 : dp[i-1][0])) % MOD;
        }
    }
    cout << dp[N][L] * power(power(2, MOD-2), L) % MOD << endl;
}


Measured memory_bytes: 195968
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    cin >> n;
    int d[101] = {0};

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

    int sum = 0;
    for (int i = 0; i <= 100; i++){
        if (d[i] > 0){
            sum++;
        }
    }
    cout << sum << endl;




    return 0;
}


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




























int main () {
    string s, t;
    cin >> s >> t;
    int count = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3864
// https://atcoder.jp/contests/abc144/tasks/abc144_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: i32, b: i32
    };
    println!("{}", ifv!(a <= 9 && b <= 9, a * b, -1));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;



int main(){
    int n; cin >> n;
    string s;
    map<char,int> S;
    S['M'] = 0; S['A'] = 1; S['R'] = 2; S['C'] = 3; S['H'] = 4;
    map<int,int> m;
    REP(i,n){
        cin >> s;
        if(s[0] != 'M' && s[0] != 'A' && s[0] != 'R' && s[0] != 'C' && s[0] != 'H') continue;
        ++m[S[s[0]]];
    }

    ll ans = 0;

    REP(bit, 1<<5){
        if(__builtin_popcount(bit) == 3){
            ll tmp = 1;
            REP(i,5){
                if(bit & (1<<i)){
                    tmp *= m[i];
                }
            }
            ans += tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int n,pf[101],connect[101][101],numb[101],maxpath=1;
 
void search(int now,int path){
    int j;
    pf[now]=1;
    path++;
    if(maxpath<path) maxpath=path;
    for(j=0;connect[now][j]>0;j++){
        if(pf[connect[now][j]]==0){
                search(connect[now][j],path);
        }
    }
    pf[now]=0;
}
 
int main(){
    int i,a,b,j;
    scanf("%d",&n);
    while(n!=0){
    	memset(numb,0,sizeof(numb));
    	memset(connect,0,sizeof(connect));
    	memset(pf,0,sizeof(pf));
        for(i=0;i<n;i++){
            scanf("%d %d",&a,&b);
            connect[a][numb[a]]=b;
            connect[b][numb[b]]=a;
            numb[a]++;
            numb[b]++;
        }
        maxpath=1;
        for(i=1;i<=100;i++){
        	if(numb[i]>0) search(i,0);
        }
        printf("%d\n",maxpath);
        scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
using namespace std;

void swapCheck(int node, vector<vector<int>> &swapper, vector<bool> &checking) {
	if (checking[node]) {
		return;
	}
	checking[node] = true;
	for (int i = 0; i < swapper[node].size(); i++) {
		swapCheck(swapper[node][i], swapper, checking);
	}
}

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);

	vector<int> p = vector<int>(N, 0);
	int buf;
	for (int i = 0; i < N; i++) {
		scanf("%d", &buf);
		p[i] = buf - 1;
	}

	auto swapper = vector<vector<int>>(N, vector<int>());
	int x, y;
	for (int m = 0; m < M; m++) {
		scanf("%d %d", &x, &y);
		swapper[x - 1].push_back(y - 1);
		swapper[y - 1].push_back(x - 1);
	}

	auto enable = vector<bool>(N, false);
	auto checked = vector<bool>(N, false);
	for (int i = 0; i < N; i++) {
		if (checked[i]) {
			continue;
		}
		if (swapper[i].size() == 0) {
			checked[i] = true;
			if (i == p[i]) {
				enable[i] = true;
			}
			continue;
		}
		auto checking = vector<bool>(N, false);
		swapCheck(i, swapper, checking);
		for (int nd = 0; nd < N; nd++) {
			if (checking[nd] == false)continue;
			checked[nd] = true;
			if (checking[p[nd]]) {
				enable[nd] = true;
			}
		}
		checked[i] = true;
	}

	int count = 0;
	for (auto en : enable) {
		if (en)count++;
	}
	cout << count << endl;
	return 0;
}

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

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

    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++)
    {
        int Ai;
        cin >> Ai;
        A.at(i) = make_pair(Ai, i + 1);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++)
    {
        cout << A.at(i).second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;
const ll MOD = (ll)1e9 + 7;

int main(){
    int h,w,k; cin>>h>>w>>k;
    vector<vector<ll>> dp(h+1, vector<ll>(w,0));
    dp[0][0] = 1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            for(int bit=0; bit<(1<<w-1); bit++){
                bool check = true;
                for(int b=0; b<w-2; b++){
                    if(bit&(1<<b) && bit&(1<<b+1)){
                        check = false;
                        break;
                    }
                }
                if(check){
                    if(j!=0 && bit&(1<<j-1)){
                        dp[i+1][j-1] += dp[i][j];
                        dp[i+1][j-1] %= MOD;
                    } 
                    else if(j!=w-1 && bit&(1<<j)){
                        dp[i+1][j+1] += dp[i][j];
                        dp[i+1][j+1] %= MOD;
                    } 
                    else{
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= MOD;
                    }
                }
            }
        }
    }
    OUT(dp[h][k-1]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define N 100007
using namespace std;
const int T=1<<15;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rint s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
int n,t,d[N],sum[19],f[T+3],st,ans,p[T+3];
int main()
{
	rint i,j,x,y,val;n=read();
	for(i=1;i<n;i++)
		x=read()+1,y=read()+1,val=read(),d[x]^=val,d[y]^=val;
	for(i=1;i<=n;i++) ++sum[d[i]];
	for(i=1;i<16;i++) ans+=sum[i]>>1,st|=(sum[i]&1)<<(i-1);
	for(i=1;i<T;i++) f[i]=f[i>>1]+(i&1);
	for(i=1;i<T;i++) --f[i];
	for(i=0;i<T;i++)
		for(j=0;j<15;j++)
			if((i>>j)&1) p[i]^=(j+1);
	for(i=0;i<T;i++) {
		if(p[i]) continue;
		for(j=(i-1)&i;j;j=(j-1)&i)
			if(!p[j]) f[i]=min(f[i],f[j]+f[i^j]);
	}printf("%d",ans+f[st]);
	return 0;
}

Measured memory_bytes: 896
// 3B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<stdio.h>
#include<stack>
#include<algorithm>
#define MAX 1400

using namespace std;

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

struct Rectangle { int height; int pos; };
 
int getLargestRectangle(int size, int buffer[]) {
    stack<Rectangle> S;
    int maxv = 0;
    buffer[size] = 0;

    for (int i = 0; i <= size; i++) {
        Rectangle rect;
        rect.height = buffer[i];
        rect.pos = i;
        if (S.empty()) {
            S.push(rect);
        }
        else {
            if (S.top().height < rect.height) {
                S.push(rect);
            }
            else if (S.top().height > rect.height) {
                int target = i;
                while (!S.empty() && S.top().height >= rect.height) {
                    Rectangle pre = S.top(); S.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}
int getLargestRectangle() {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (buffer[i][j]) {
                T[i][j] = 0;
            }
            else {
                T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
            }
        }
    }

    int maxv = 0;
    for (int i = 0; i < H; i++) {
        maxv = max(maxv, getLargestRectangle(W, T[i]));
    }

    return maxv;
}
int main()
{
    
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> buffer[i][j];
        }
    }
    cout << getLargestRectangle() << endl;

    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 18404
import java.util.Scanner;

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

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
}

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

using namespace std;
using ll = long long;



class UnionFind{
  private:
    vector<int> data;

  public:
    UnionFind(int n) : data(n,-1) {}
    int root(int i) { return data[i] < 0 ? i : data[i] = root(data[i]); }
    int size(int i) { return -data[root(i)]; }
    bool same(int x, int y) {return root(x) == root(y); }
    bool connected() {return size(0) == (int)data.size(); }

    bool unit(int i,int j){
        i = root(i);
        j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
        return i != j;
    }
};

const int MAX = 1e5;

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

    vector<vector<int>> ver(MAX);
    for(int i = 0; i < n; i++) {
        int x, y; cin >> x >> y; x--;
        y--;
        ver[x].push_back(y);
    }

    UnionFind tree(MAX);

    for(int i = 0; i < MAX; i++) {
        int m = ver[i].size();
        for(int j = 1; j < m; j++) {
            tree.unit(ver[i][j - 1], ver[i][j]);
        }
    }

    ll sum = 0;
    
    for(int i = 0; i < MAX; i++) {
        if(!ver[i].size())continue;
        int cur = tree.size(ver[i].front()) - ver[i].size();
        sum += cur;
    }
    cout << sum << endl;

}

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

using namespace std;

long long f(long long x, long long y, long long z) {
	long long lcm = y * z / __gcd(y, z);
	return x - (x / y + x / z - x / lcm);
}

int main() {
	long long a, b, c, d, e;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		
	printf("%lld\n", f(b, c ,d) - f(a - 1, c, d));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll r,h; cin>>r>>h;
	if(r==1 || h==1){
		cout<<1<<endl;
		return 0;
	}
	ll aterm = r/2LL;
	ll bterm = h/2LL;
	ll tot = (ll)aterm*(ll)bterm;
	if(r%2){
		aterm++;
	}
	if(h%2){
		bterm++;
	}
	tot = tot + aterm*bterm;
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
h = []
c = []
d = []
for i in range(13):
    s.append(i+1)
    h.append(i+1)
    c.append(i+1)
    d.append(i+1)
for j in range(n):
    card, number = map(str, input().split())
    if card == 'S':
        s.remove(int(number))
    elif card == 'H':
        h.remove(int(number))
    elif card == 'C':
        c.remove(int(number))
    elif card == 'D':
        d.remove(int(number))
for k in range(len(s)):
    print('S ' + str(s[k]))
for l in range(len(h)):
    print('H ' + str(h[l]))
for m in range(len(c)):
    print('C ' + str(c[m]))
for n in range(len(d)):
    print('D ' + str(d[n]))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll mod = 998244353;



ll N,ans;
string s[10000];
int A, B, BA;

int main() {
	cin >> N;
	FOR(i, 0, N) {
		cin >> s[i];
		int L = s[i].length();
		char mae=s[i][0];
		FOR(k, 1, L) {
			if (mae == 'A'&&s[i][k] == 'B')ans++;
			mae = s[i][k];
		}
		if (s[i][0] == 'B') {
			if (s[i][L - 1] == 'A')BA++;
			else B++;
		}
		else if (s[i][L - 1] == 'A')A++;
	}
	if (BA > 0) {
		ans += BA - 1;
		if (A > 0)ans++;
		if (B > 0)ans++;
		ans += max(0,min(A - 1, B - 1));
	}
	else {
		ans += min(A, B);
	}

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

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] counts = new int[m];
		for(int i = 0; i < n; i++){
			int k = sc.nextInt();
			for(int i2 = 0; i2 < k; i2++){
				int a = sc.nextInt();
				counts[a - 1]++;
			}
		}
		int count = 0;
		for(int i = 0; i < m; i++){
			if(counts[i] == n){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 24404
import random
import time
import copy

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=list()
for i in range(d):
    tl.append(random.randint(1,26))
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]
last=list()
for i in range(26):
    last.append([a for a, x in enumerate(tl) if x==i+1])
dec=0
for i in range(26):
    if last[i]==list():
        dec+=(d*(d+1)/2)*cl[i]
    else:
        for v in range(len(last[i])):
            if v!=len(last[i])-1:    
                dec+=cl[i]*(last[i][v+1]-last[i][v]-1)*(last[i][v+1]-last[i][v])/2
            else:
                dec+=cl[i]*(d-last[i][v]-1)*(d-last[i][v])/2
        dec+=cl[i]*(last[i][0])*(last[i][0]+1)/2
        
def dechf(i,last):
    dech=0
    if last[i]==list():
        dech+=(d*(d+1)/2)*cl[i]
    else:
        for v in range(len(last[i])):
            if v!=len(last[i])-1:    
                dech+=cl[i]*(last[i][v+1]-last[i][v]-1)*(last[i][v+1]-last[i][v])/2
            else:
                dech+=cl[i]*(d-last[i][v]-1)*(d-last[i][v])/2
        dech+=cl[i]*(last[i][0])*(last[i][0]+1)/2
    return(int(dech))


oldlast=copy.deepcopy(last)
oldans=sat-int(dec)
oldtl=copy.copy(tl)
t2=time.time()
newans=0
while t2-t1<1.85:
    if round(t2)%2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        if d1==d2:
            continue
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        i=tl[d1-1]-1
        dech=dechf(i,last)
        i=tl[d2-1]-1
        dech+=dechf(i,last)
        last[tl[d2-1]-1].remove(d2-1)
        last[tl[d1-1]-1].remove(d1-1)
        last[tl[d1-1]-1].append(d2-1)
        last[tl[d1-1]-1].sort()
        last[tl[d2-1]-1].append(d1-1)
        last[tl[d2-1]-1].sort()
        tl[d2-1]=q2
        tl[d1-1]=q1
        i=tl[d1-1]-1
        dech-=dechf(i,last)
        i=tl[d2-1]-1
        dech-=dechf(i,last)
        newans=oldans+cha-dech
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        i=tl[da-1]-1
        dech=dechf(i,last)
        last[tl[da-1]-1].remove(da-1)
        last[q-1].append(da-1)
        last[q-1].sort()
        tl[da-1]=q
        i=tl[da-1]-1
        dech-=dechf(i,last)
        newans=oldans+cha-dech
    r=0
    if newans<oldans:
        if 2.7**((newans-oldans)/(1.85-(t2-t1)))<random.random():
            r=1
    if r==1:
        tl=copy.copy(oldtl)
        last=[i[:] for i in oldlast]
    else:
        oldans=newans
        oldtl=copy.copy(tl)
        oldlast=[i[:] for i in last]
    t2=time.time()
for i in range(d):
    print(tl[i])
        



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

int main() {
  int N; cin >> N;
  int a[100];
  for (  int i = 0; i < N; i++ ) {
    cin >> a[i];
  }
  sort(a,a+N,greater<int>());
  int A = 0,B = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( i % 2 == 0 ) A += a[i];
    else B+= a[i];
  }
  cout << A-B << endl;
  return 0;
}


Measured memory_bytes: 256