akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;

    cin >> n;

    vector<int> data(n);
    for(int i = 0 ; i < n ; i++){
        cin >> data.at(i);
    }

    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());

    int alice = 0;

    for(int i = 0 ; i < n ; i++){
        if(i % 2 == 0){
            alice += data.at(i);
        }else{
            alice -= data.at(i);
        }
    }

    cout << alice << endl;
}


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

int main(){

  int64_t a;
  string str;

  cin>>a>>str;
  int b1,b2,b3;
  b1 = str[0] - 48;
  b2 = str[2] - 48;
  b3 = str[3] - 48;


  int64_t b4 = b1*100+b2*10 + b3*1;
  int64_t mul = (a*(b4))/100;
  cout<<mul;
  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).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 chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n;
	cin>>n;
	ll p, q;
	cin>>p>>q;
	rep(i, n-1){
		ll a, b;
		cin>>a>>b;
		ll d = max((p+a-1)/a, (q+b-1)/b);
		p = a*d;
		q = b*d;
	}
	cout<<p+q<<endl;
	return 0;
}


Measured memory_bytes: 256
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n, m, rt[maxn], ce[maxn], cv[maxn];
pip es[maxn];

ll root(ll x) {
    return rt[x] == x ? x : rt[x] = root(rt[x]);
}

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

    cin >> n >> m;
    fori (i, n) cin >> cv[i];
    iota(rt, rt + n, 0);
    fori (i, m) {
        ll a, b, c;
        cin >> a >> b >> c; --a, --b;
        es[i] = {c, {a, b}};
    }
    sort(es, es + m);
    fori (i, m) {
        ll a = root(es[i].S.F), b = root(es[i].S.S), c = es[i].F;
        if (a == b) {
            if (c > cv[a]) ++ce[a];
        } else {
            rt[a] = b;
            cv[b] += cv[a];
            ce[b] += ce[a];
            if (c > cv[b]) ++ce[b];
            else ce[b] = 0;
        }
    }
    ll ans = 0;
    fori (i, n) if (root(i) == i) ans += ce[i];
    cout << ans << '\n';

}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
      if(i%k==0){
        cout<<"OK"<<endl;
        return 0;
      }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
using namespace std;
int g[15][15];
void floyd()
{
    for(int k=0;k<=9;k++)
    {
        for(int i=0;i<=9;i++)
        {
            for(int j=0;j<=9;j++)
            {
                g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
            }
        }
    }
    return;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=9;i++)
    {
        for(int j=0;j<=9;j++)
        {
            if(i==j) g[i][j]=0;
            else g[i][j]=100005;
        }
    }
    for(int i=0;i<=9;i++)
    {
        for(int j=0;j<=9;j++)
        {
            scanf("%d",&g[i][j]);
        }
    }
    floyd();
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int k;
            cin>>k;
            if(k==-1) continue;
            if(k==1) continue;
            else sum+=g[k][1];
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    int r, g, b;
    cin >> r >> g >> b;

    if ((10 * g + b) % 4 == 0) { cout << "YES" << endl; }
    else { cout << "NO" << endl; }

}

Measured memory_bytes: 256
use std::io;

fn read() -> i32 {
    let mut x = String::new();
    io::stdin().read_line(&mut x).unwrap();
    let x: i32 = x.trim().parse().unwrap();
    x
}

fn main(){
    let a = read();
    let b = read();
    let c = read();
    let x = read();
    let mut result = 0;
    let mut sum = 0;

    for i in 0..a+1{
        for j in 0..b+1{
            for k in 0..c+1{
                sum = 500*i + 100*j + 50*k;
                if sum==x{
                    result += 1;
                }
                if sum>x{
                    break;
                }
            }
            
        }
    }
    println!("{}", result); 
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;

    ll start = min(n, b - 1);
    ll ans = (a * start) / b;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, N);

	int sum1 = 0, sum2 = 0;
	rep(i, N) sum2 += a[i];
	sum1 = a[0];
	sum2 -= a[0];

	int ret = LLONG_MAX;
	REP(i, 1, N - 1) {
		ret = min(ret, abs(sum1 - sum2));
		sum1 += a[i];
		sum2 -= a[i];
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin >> s;
    int K;
    cin >> K;

    const int M = 5'000'000'000'000'000LL;
    REP(i, SZ(s)) {
        if (s[i] == '1') {
            K--;
        } else {
            K = 0;
        }
        if (K == 0) {
            cout << s[i] << endl;
            return 0;
        }
    }
    return 0;
}



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

int cnt[30];

int main(){
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++){
		memset(cnt, 0, sizeof(cnt));
		cnt[a[i] - 'a']++, cnt[b[i] - 'a']++, cnt[c[i] - 'a']++;
		if (cnt[a[i] - 'a'] == 3) ans += 0;
		else if (cnt[a[i] - 'a'] == 2 || cnt[b[i] - 'a'] == 2 || cnt[c[i] - 'a'] == 2) ans++;
		else ans += 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  double a,b,x,x2,theta,deg;
  cin >> a >> b >> x;
  x2=x/a;
  if(x2<a*b/2){
    theta= atan((b*b)/(2*x2));
  }else{
    theta= atan(2*(a*b-x2)/(a*a));
  }
  deg= theta*180/M_PI;
  cout << fixed << setprecision(10) << deg << endl;
  
  return 0;
}


Measured memory_bytes: 384
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

/*
定数 k のある山での grundy 数を考えます。
まず n < k なら 0 です。
n = k*q + r として、r = 0 なら q で、そうでなければ q + 1 減らしたものと同じです。
*/

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;

  auto cal = [&] (auto&& cal, int n, int k) {
    if (n < k) return 0;
    int q = n / k, r = n % k;
    if (r == 0) return q;
    return cal(cal, n - q - 1, k);
  };

  int g = 0;
  loop(n) {
    int a, k; std::cin >> a >> k;
    int now = cal(cal, a,k);
    debug(a,k,now);
    g ^= now;
  }
  bool ans = g != 0;
  std::cout << (ans ? "Takahashi" : "Aoki") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int N,B;
vector<pair<pair<int,int>,short> >item;//<value,weight>,i
vector<int>bag;

int main(){
	int i,j,r,m;
	scanf("%d%d",&N,&B);
	item.resize(N);
	bag.resize(B+1);bag[0]=1;
	for(i=0;i<N;i++)scanf("%d%d",&item[i].first.first,&item[i].first.second),item[i].second=i;
	for(i=0;i<N;i++){
		for(j=B;j>=item[i].first.second;j--){
			if(bag[j-item[i].first.second]&&bag[j]<bag[j-item[i].first.second]+item[i].first.first){
				bag[j]=bag[j-item[i].first.second]+item[i].first.first;
			}
		}
	}
	for(r=i=0;i<=B;i++){
		if(r<bag[i]){
			r=bag[i];
			m=i;
		}
	}
	printf("%d\n",r-1);
}

Measured memory_bytes: 1072
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion

signed main() {
	int A=0,B=0,C=0,D=0,x;
	rep(i, 4) {
		cin >> x;
		if (x == 1)
			A++;
		if (x == 9)
			B++;
		if (x == 7)
			C++;
		if (x == 4)
			D++;
	}
	if (A=1 && B==1 && C==1 && D==1)
		cout << "YES";
	else
		cout << "NO";
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> d(n);
  for (i64 i = 0; i < n; i++)
    cin >> d[i];
  sort(d.begin(), d.end());
  cout << d[n / 2] - d[n / 2 - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import math

n, k = list(map(int, input().split(" ")))


sum_v = 0

if n >= k :
    j = k
    s = [0]*(k-1)
else:
    j = n + 1
    s = [0]*n
    
for i in range(1, j):
    s[i-1] = math.ceil(math.log2(k/i))
    sum_v += (1/2)**s[i-1]
    #print(i,s[i-1],sum_v)
    
if n - k >= 0: 
    p1 = (n-k+1)/n
else:
    p1 = 0
    
p2 = sum_v/n
print(p1 + p2)

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int liner_search(vector<int> a) {
    int ret;
    for (int i = a.size()-1; i >= 0; --i) {
        if (i+1 == a[i]) {
            return i;
        }
    } 
    return -1;
}

int main(){
    int N;
    cin >> N;
    vector<int> b(N);
    for (auto& x : b) {
        cin >> x;
    }

    vector<int> ans;
    int i;
    for (i = 0; i < N; ++i) {
        int d = liner_search(b);
        if (d != -1) {
            ans.push_back(b[d]);
            b.erase(b.begin() + d);
        } else {
            break;
        }
    }
    if (i == N) {
        reverse(all(ans));
        for (auto& x: ans) {
            cout << x << endl;
        }
    } else {
        cout << -1 << endl;
    }

    /*for (auto& x: ans) {
        cout << x << endl;
    }
    */




        

    return 0;
}


Measured memory_bytes: 256
L,R=map(int,input().split())
if R-L>2017:
    mod=[i for i in range(2019)]
else:
    l=L%2019
    r=R%2019
    mod=[i for i in range(2019)]*2
    mod=mod[mod.index(l):]
    mod=mod[:mod.index(r)+1]
ans=3000
for i in range(len(mod)-1):
    for k in range(len(mod)-i-1):
        min=mod[i]*mod[i+k+1]%2019
        if min<ans:
            ans=min
print(ans)

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

template<typename T>
struct WeightedUnionFind {
    const int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
    // w[x] := xのrootに対する重み
    vector<T> w;
    WeightedUnionFind(const int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1)),
		w(vector<T>(V))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
    // w[y] - w[x] = z
    bool unite(int x, int y, T z) {
        z = z + weight(x) - weight(y);
        x = root(x), y = root(y);
        if(same(x, y)) return false;
        if(y < x) {
            swap(x, y);
            z = -z;
        }
        par[y] = x;
        sz[x] += sz[y];
        w[y] = z;
        return true;
    }
    int root(int x) {
    	if(par[x] == x) return x;
        root(par[x]); // rootから累積和
        w[x] += w[par[x]]; // 親の重みを加算する
    	return (par[x] = root(par[x])); // xの親のroot
    }
    bool same(int x, int y) {
    	return (root(x) == root(y));
    }
    int size(int x) {
        return sz[root(x)];
    }
    T weight(int x) {
        root(x); // 経路圧縮用
        return w[x];
    }
    T diff(int x, int y) {
        assert(same(x, y));
        return weight(y) - weight(x);
    }
};

int main() {
    int n, q; cin >> n >> q;
    WeightedUnionFind<int64_t> uf(n);
    while(q--) {
        int info, x, y, z; cin >> info >> x >> y;
        if(info == 0) {
            cin >> z;
            uf.unite(x, y, z);
        } else {
            if(uf.same(x, y)) {
                cout << uf.diff(x, y) << '\n';
            } else {
                cout << '?' << '\n';
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4440
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  int a,b;
  cin>>a>>b;
  cout<<a*b<<"\n";
}


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

int main(){
    string s;
    vector<string> w;
    w.push_back("SUN");
    w.push_back("MON");
    w.push_back("TUE");
    w.push_back("WED");
    w.push_back("THU");
    w.push_back("FRI");
    w.push_back("SAT");
    
    cin >> s;

    cout << 7 - (int)(find(w.begin(), w.end(), s) - w.begin()) << endl;
    
    return 0;
}


Measured memory_bytes: 256
def bubble_sort(A, n):
	flag = 1
	i = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if int(A[j][1]) < int(A[j-1][1]):
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1

		i += 1
	
	return A

def selection_sort(A, n):
	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if int(A[j][1]) < int(A[minj][1]):
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	return A

def is_stable(A, B, n):
	for i in range(0, n):
		for j in range(i+1, n):
			for a in range(0, n):
				for b in range(a+1, n):
					if int(A[i][1]) == int(A[j][1]) and A[i] == B[b] and A[j] == B[a]:
						return False

	return True

def print_stable(flag):
	if flag:
		print('Stable')
	else:
		print('Not stable')

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	A2 = A[:]

	B = bubble_sort(A, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))

	B = selection_sort(A2, n)
	print(' '.join(B))
	print_stable(is_stable(A, B, n))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   vector<int>x(n);
   vector<int>y(n);
    for (int i = 0; i < n; ++i) {
        cin >>x[i]>>y[i];
    }
    map<P,int>mp;
    for (int i = 0; i < n; ++i) {
        for (int j =i+1;j < n; ++j) {
            mp[{x[i]-x[j],y[i]-y[j]}]++;
            mp[{x[j]-x[i],y[j]-y[i]}]++;
        }
    }
    ll mx=0;
    for (int i = 0; i < n; ++i) {
        for (int j =i+1;j < n; ++j) {
            mx=max(mx,(ll)mp[{x[i]-x[j],y[i]-y[j]}]);
            mx=max(mx,(ll)mp[{x[j]-x[i],y[j]-y[i]}]);
        }
    }
    cout <<n-mx<<endl;
}


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

int main() {
    ll a,b,k;
    cin>>a>>b>>k;
    if(b-a+1 < 2*k) {
        for(int i=a; i<=b; i++) {
            cout<<i<<"\n";
        }
    }
    else {
        for(int i=a; i<a+k; i++) {
            cout<<i<<"\n";
        }
        for(int i=b-k+1; i<=b; i++) {
            cout<<i<<"\n";
        }
    }
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;


#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
// #define PI 3.1415926535897932384626433832795
#define PI acos(-1.0)
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

// map<char, int> m;
// bool cmp(const pair< pair<int,int> , int>& a, const pair < pair<int,int> , int>& b) {
// 	return a.ff.ss < b.ff.ss;
// }
int mod=1e9+7;

int32_t main(void) {
	IOS;
	int r,c,a,b; cin>>r>>c>>a>>b;
	// if(a > 0) {
	// 	if(b==0) {
	// 		for(int i = 0; i < r; i++) {
	// 			int cnt=0;
	// 			for(int j = 0; j < c; j++) {
	// 				if(cnt < a) cout<<0;
	// 				else cout<<1<<endl;
	// 				cnt++;
	// 			}
	// 			cout<<endl;
	// 		}
	// 	} else {
			int cnt = 0;
			vector<int> col(c);
			int tmp=0;
			for(int i = 0; i < c; i++) {
				if(tmp < a) col[i]=0;
				else col[i]=1;
				tmp++;
			}
			// for(int i: col) cout<<i;
			// 	cout<<endl;
			for(int i = 0; i < r; i++) {
				// for(int j = 0; j < c; j++) {
				if(cnt < b) {
					for(int i: col) cout<<i;
				} else {
					for(int i: col) cout<<(i^1);
				}
				// }
				cout<<endl;
				cnt++;
			}
	// 	}
	// } else {
	// 	if(b==0) {
	// 		for(int i = 0; i < r; i++) {
	// 			for(int j = 0; j < c; j++)
	// 				cout<<0<<;
	// 			cout<<endl;
	// 		}
	// 	} else {
	// 		int cnt=0;
	// 		for(int i = 0; i < r; i++) {
	// 			for(int j = 0; j < c; j++) {
	// 				if(cnt < b) cout<<0;
	// 				else cout<<1<<endl;
	// 			}
	// 			cout<<endl;
	// 			cnt++;
	// 		}	
	// 	}
	// }
	time();
	return 0;
}

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

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int ans;
  if (n%x>0)
    ans = (n/x+1)*t;
  else
    ans = (n/x)*t;

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

Measured memory_bytes: 3632
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
        int k = sc.nextInt(); long ans = 0;
        if (k >= 0) {
            ans += 1 * Math.min(a, k);
            k -= Math.min(a, k);
        }
        if (k >= 0) {
            ans += 0 * Math.min(b, k);
            k -= Math.min(b, k);
        }
        if (k >= 0) {
            ans += -1 * Math.min(c, k);
            k -= Math.min(c, k);
        }
        System.out.println(ans);
    }


}

Measured memory_bytes: 35844
#include<stdio.h>

int main(void)
{
	int i, N;
	long long power;


	while(scanf("%d", &N)==1)
	{
		if(N<1 || 100000<N) break;

		power=1;
		for(i=1;i<=N;i++)
		{
			power=(power*i)%1000000007;
		}
		printf("%d\n", (int)power);
	}

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		boolean[] moji=new boolean[10];
		for(int i=0; i<10; i++) {
			moji[i]=true;
		}
		int N=sc.nextInt();
		int K=sc.nextInt();
		for(int i=0; i<K; i++) {
			moji[sc.nextInt()]=false;
		}
		int[] ss=new int[10-K];
		int a=0;
		for(int i=0; i<10; i++) {
			if(moji[i]) {
				ss[a]=i;
				a++;
			}
		}
		int min=114514;
		int tmp=0;

		for(int i=0; i<a; i++) {
			for(int j=0; j<a; j++) {
				for(int k=0; k<a; k++) {
					for(int l=0; l<a; l++) {
						for(int m=0; m<a; m++) {
							tmp=10000*ss[i]+1000*ss[j]+100*ss[k]+10*ss[l]+ss[m];
							if(tmp<min && tmp>=N) {
								min=tmp;
							}
						}
					}
				}
			}
		}

		for(int i=0; i<a; i++) {
			for(int j=0; j<a; j++) {
				for(int k=0; k<a; k++) {
					for(int l=0; l<a; l++) {
						tmp=1000*ss[i]+100*ss[j]+10*ss[k]+ss[l];
						if(tmp<min && tmp>=N) {
							min=tmp;
						}
					}
				}
			}
		}
		for(int i=0; i<a; i++) {
			for(int j=0; j<a; j++) {
				for(int k=0; k<a; k++) {
					tmp=100*ss[i]+10*ss[j]+ss[k];
					if(tmp<min && tmp>=N) {
						min=tmp;
					}
				}
			}
		}
		for(int i=0; i<a; i++) {
			for(int j=0; j<a; j++) {
				tmp=10*ss[i]+ss[j];
				if(tmp<min && tmp>=N) {
					min=tmp;
				}
			}
		}
		for(int i=0; i<a; i++) {
			tmp=ss[i];
			if(tmp<min && tmp>=N) {
				min=tmp;
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 21844
n = int(input())

a_list = list(map(int,input().split()))
for i in range(n):
  a_list[i] *= -1
import heapq  # heapqライブラリのimport
heapq.heapify(a_list)
n = n-1
result = 0
target = heapq.heappop(a_list)
result += -(target)
n = n-1

while True:
  if n == 0:
    break
  target = heapq.heappop(a_list)
  result += -(target)
  n = n-1
  if n == 0:
    break
  result += -(target)
  n = n-1
  if n == 0:
    break
print(result)  

Measured memory_bytes: 31528
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll K, N;
    ll A;
    ll Afirst;
    ll P = 0;
    ll D = 0;
    ll Dmax = 0;

    cin >> K >> N;

    for(ll i = 0; i < N; i++){
        cin >> A;
        if(i == 0){
            Afirst = A;
        }
        D = A - P;
        if(Dmax < D){
            Dmax = D;
        }
        P = A;
    }
    D = K - A + Afirst;
    if(Dmax < D){
        Dmax = D;
    }

    cout << K - Dmax << endl;

    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, k;
const int MAX = 402020, MOD = INF;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
	inv[0] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(i64 n, i64 k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
void solve(){
	cin >> n >> k;
	
	COMinit();
	i64 ans = 0;
	for(int i = 0; i <= min(n,k); i++){
		ans += (C(n,i) * C(n-1,i))%INF;
		ans %= INF;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 9728
// AOJ 0604: Take the 'IOI' train
// 2017.12.5 bal4u@uu

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

char s[2002], t[2002];
int dp[2][2002][2002];

int main()
{
	int n, m, i, j, ans;
	char *p;

	fgets(s, 20, stdin);
	sscanf(s, "%d%d", &m, &n);
	fgets(s, 2002, stdin);
	fgets(t, 2002, stdin);

	for (p = s; *p > ' '; p++) *p = (*p >> 1) & 1;
	for (p = t; *p > ' '; p++) *p = (*p >> 1) & 1;

	ans = 0;
	memset(dp[0], -1, sizeof(dp[0]));

	for (i = 0; i <= m; i++) for (j = 0; j <= n; j++) {
		if (i < m) {
			if (dp[s[i]][i+1][j] < dp[1-s[i]][i][j] + 1)
				dp[s[i]][i+1][j] = dp[1-s[i]][i][j] + 1;
		}
		if (j < n) {
			if (dp[t[j]][i][j+1] < dp[1-t[j]][i][j] + 1)
				dp[t[j]][i][j+1] = dp[1-t[j]][i][j] + 1;
		}
		if (ans < dp[0][i][j]) ans = dp[0][i][j];
	}

	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
using ll = long long int;

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

    ll n;
    cin >> n;
    ll s = 0;
    for(ll i=1; i<=n; i++) {
        if(i%3 > 0 && i%5 > 0)
            s += i;
    }
    cout << s << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
int rd()
{
	int num = 0;char c = getchar();bool flag = true;
	while(c < '0'||c > '9') {if(c == '-') flag = false;c = getchar();}
	while(c >= '0' && c <= '9') num = num*10+c-48,c = getchar();
	if(flag) return num;else return -num;
}
int main()
{
	int x = rd();
	if(x == 25)printf("Christmas\n");
	else if(x == 24) printf("Christmas Eve\n");
	else if(x == 23) printf("Christmas Eve Eve\n");
	else printf("Christmas Eve Eve Eve\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  string ori[n+1];
  for(int i=0;i<n;i++){
    cin>>ori[i];
  }
  string temp[m+1];
  for(int i=0;i<m;i++)	
    cin>>temp[i];
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      bool hoge=true;
      for(int ii=i;ii<i+m;ii++){
        for(int jj=j;jj<j+m;jj++){
          	if(ori[ii][jj]!=temp[ii-i][jj-j])hoge=false;
        }
      }
      if(hoge){cout<<"Yes"<<endl;return 0;}
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
x = list(map(int, input().split()))
mc = 0
m = 1000000001

for v in range(n):
    t = x[v]
    if t < 0:
        mc += 1
    
    m = min(m, abs(t))

if mc % 2 == 0:
    s = 0
    for v in range(n):
        s += abs(x[v])
    print(s)
else:
    s = 0
    for v in range(n):
        t = abs(x[v])
        if t == m:
            s -= t
        else:
            s += t
            
    print(s)

Measured memory_bytes: 15180
input_line = input().split(" ")
X = int(input_line[0])
Y = int(input_line[1])
Pat = 0
for i in range(X + 1):
  C = i
  T = X - i
  Cf = C * 2
  Tf = T * 4
  F = Cf + Tf
  if Y == F:
      Pat = Pat + 1
if Pat > 0:
  print("Yes")
else:
  print("No")


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    int ans = 1e+8, tmp;
    rep(i, n) cin >> x[i];
    rep(i, 100) {
        tmp = 0;
        rep(j, n) {
            tmp += (i - x[j]) * (i - x[j]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n, m;
  cin >> n >> m;
  if(n >= m / 2){
    cout << min(n, m / 2) << endl;
  }
  else{
    m -= n * 2;
    cout << n + m / 4 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n, ans = 0; cin >> n;
	for (int i = 1; i <= n; i++) {
		if (1 <= i && i <= 9)ans++;
		else if (100 <= i && i <= 999)ans++;
		else if (10000 <= i && i <= 99999)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 0; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 

int dp[205][205];

int main(){
    
    string s;
    cin >> s;
    int n = s.size();
    char a = s[n-1];



    if(a == '2' || a == '4' || a == '5' || a == '7' || a == '9'){
        cout << "hon" << endl;
    }else if (a == '3'){
        cout << "bon" << endl;
    }else{
        cout << "pon" << endl;
    }



}

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

struct node {
  array<int, 26> to, memo;
  node() {
    for (int i = 0; i < 26; ++i) to[i] = -1, memo[i] = 0;
  }
};

int n;
vector<string> s;
vector<node> trie;

long long solve();

int main() {
  cin >> n;
  s.resize(n);
  for (auto &p : s) {
    cin >> p;
    reverse(p.begin(), p.end());
  }
  sort(s.begin(), s.end(),
       [](string &l, string &r) { return l.size() < r.size(); });
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  node uni;
  trie.push_back(uni);
  for (int i = 0; i < n; ++i) {
    int len = s[i].size(), id = 0;
    vector<int> memo(len + 1, 0);
    for (int j = len - 1; j >= 0; --j)
      memo[j] = memo[j + 1] | (1LL << (s[i][j] - 'a'));
    for (int j = 0; j < len; ++j) {
      int c = s[i][j] - 'a';
      for (int k = 0; k < 26; ++k)
        if (memo[j] >> k & 1) res += trie[id].memo[k];
      if (trie[id].to[c] < 0) {
        trie[id].to[c] = trie.size();
        trie.push_back(uni);
      }
      if (j == len - 1) ++trie[id].memo[c];
      id = trie[id].to[c];
    }
  }
  return res;
}

Measured memory_bytes: 222044
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e18;
	const ll mod = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	
	signed main(){
		IOS;
		ll n;
		cin >> n;
		ll x;
		map<ll,ll> mp;
		REP(i,n){
			cin >> x;
			mp[x]++;
		}
		ll sum = 0;
		ll cnt = 0;
		for(auto it = mp.begin();it != mp.end();it++){
			cnt++;
			sum += it ->second - 1;
		}
		if(sum % 2 == 1)dump(cnt - 1);
		else dump(cnt);
	}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    int maxi = -1;
    int ind = -1;
    for (int i=0; i<n; i++) {
        if (chmax(maxi, abs(a.at(i)))) ind = i;
    }
    maxi = a.at(ind);
    cout << 2*n-1 << endl;
    for (int i=1; i<n+1; i++) {
        cout << ind+1 << " " << i << "\n";
    }
    if (maxi > 0) {
        for (int i=2; i<n+1; i++) {
            cout << i-1 << " " << i << "\n";
        }
    } else {
        for (int i=n; i>1; i--) {
            cout << i << " " << i-1 << "\n";
        }
    }
}

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

    solve();

    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;


int main(){
    vector<vector<int>>c(3,vector<int>(3));
    bool flg=false;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin>>c[i][j];
        }
    }
    for (int a1 = 0; a1 <=100; ++a1) {
        for (int a2 = 0; a2 <=100; ++a2) {
            for (int a3 = 0; a3 <=100; ++a3) {
                vector<int>b(3);
                b[0]=c[0][0]-a1;
                b[1]=c[0][1]-a1;
                b[2]=c[0][2]-a1;
                bool ch=true;
                vector<int>a(3);
                a[0]=a1;
                a[1]=a2;
                a[2]=a3;
                for (int i = 0; i < 3; ++i) {
                    for (int j = 0; j < 3; ++j) {
                        if(c[i][j]!=a[i]+b[j])ch=false;
                    }
                }
                if(ch)flg=true;
            }
        }
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3596
#import<iostream>
#import<cstdio>
#import<vector>
#define N 1005
using namespace std;

typedef long long ll;
ll n, mx = -1e9, c, s[2], a[N];
vector<int> b;
main(){
	ll i, j;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]), s[i % 2] += a[i] * (a[i] > 0), mx = max(mx, a[i]);
	cout << (mx < 0 ? mx : max(s[0], s[1])) << endl;
	if (mx >= 0) mx = -2e9;
	for (i = 0; i < n; i++) if (i % 2 == (s[0] < s[1]) && a[i] > 0 || a[i] == mx) mx = -2e9, b.push_back(i);
	for (i = 1; i < b.size(); i++) c += (b[i] - b[i - 1]) / 2;
	c += b[0] + n - b[b.size() - 1] - 1;
	cout << c << endl;
	for (i = n; i > b[b.size() - 1] + 1; i--) printf("%lld\n", i);
	for (i = 0; i < b[0]; i++) printf("1\n");
	for (i = 1; i < b.size(); i++)
		for (j = (b[i] - b[i - 1]) / 2 + 1; j > 1; j--) printf("%lld\n", j);
}

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

int cnt[3][50];

int main(){
    int n,m;
    cin>>n>>m;
    int d[m][m];
    for(int i=0;i<m;i++) for(int j=0;j<m;j++){
        cin>>d[i][j];
    }

    int c[n][n];
    

    for(int i=0;i<n;i++) for(int j=0;j<n;j++){
        cin>>c[i][j];
        c[i][j]--;
        int s=(i+j)%3;
        cnt[s][c[i][j]]++;
    }

    int ans=1e9,ret=0;
    for(int c1=0;c1<m;c1++)for(int c2=0;c2<m;c2++)for(int c3=0;c3<m;c3++){
        if(c1==c2 || c2==c3 || c3==c1) continue;
        ret=0;
        for(int i=0;i<m;i++){
            ret+=cnt[0][i]*d[i][c1];
        }
        for(int i=0;i<m;i++){
            ret+=cnt[1][i]*d[i][c2];
        }
        for(int i=0;i<m;i++){
            ret+=cnt[2][i]*d[i][c3];
        }
        cerr<<ret<<" "<<c1<<" "<<c2<<" "<<c3<<endl;
        ans=min(ans,ret);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;


void fff(long long N,vector<int> &bit) {
    int L = bit.size();

    bit[0] = ((N + 1) / 2) % 2;
    long long p_two = 2;
    for (int i = 1; i < L; i++) {
        if (((N + 1) % (p_two*2) - p_two) % 2==1)
            bit[i] = 1;
        p_two *= 2;
    }

}

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

    long long ans = 0;
    if (A == 0)
        ans = B;
      
    else {
        vector<int> bit_A(log2(A) + 1), bit_B(log2(B) + 1);

        fff(B, bit_B);
        fff(A - 1, bit_A);

        for (int i = 0; i < (int)bit_A.size(); i++) {
            bit_B[i] = (bit_A[i] + bit_B[i]) % 2;
        }

        
        long long temp = 1;
        for (int i = 0; i < (int)bit_B.size(); i++) {
            ans += bit_B[i] * temp;
            temp *= 2;
        }
    }
    cout << ans << endl;
}


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

int main(){
      int n;cin >> n;
      set<int> s;
      for(int i = 1;i <= 9;i++){
            for(int j = 1;j <= 9;j++){
                  s.insert(i * j);
            }
      }
      if(s.count(n) != 0)cout << "Yes";
      else cout << "No";
}

Measured memory_bytes: 256
/*
* author: pavveu
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int,int>;
using graph = vector<vi>;

#define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__)
#define all(x) begin(x), end(x)
#define mp make_pair
#define mt make_tuple

template<class T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T value) {
	assert(matrix.empty());
	FOR (row, rows) 
		matrix.emplace_back(cols, value);
}

void go() {
	int x; cin >> x;
	cout << (x == 1 ? 0 : 1) << "\n";

}

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

	go();

	return 0;
}


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

signed main(){

  int d;
  vector<int> c(26);
  cin>>d;
  for(auto& ci:c)cin>>ci;
  vector<vector<int>> s(d,vector<int>(26));
  for(auto& si:s)for(auto& sij:si)cin>>sij;

  vector<int> last(26,0);

  auto calc_satisfaction_level = [&](int d,int i){
    int res = s[d][i];
    for(int j=0;j<26;++j){
      if(i==j)continue;
      res -= c[j]*(d-last[j]+1);
    }
    return res;
  };

  vector<int> ans(d);

  //-----------------------------------------------------

  auto test_all_get_max = [&](int di)->pair<int,int>{
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    int k = 5;
    int val_max = -(1<<28),type_max = -1;
    vector<pair<int,int>> valtype_max(26);
    auto chmax = [](auto& a,auto b){if(a<b){a=b;return true;}return false;};
    for(int type=0;type<26;++type){
      if(chmax(val_max,calc_satisfaction_level(di,type)))type_max=type;
    }
    return {val_max,type_max};
  };

  for(int di=0;di<d;++di){
    auto [vi,type] = test_all_get_max(di);
    if(type==-1)type=0;
    ans[di] = type;
    last[type] = di+1;
  }

  //-----------------------------------------------------

  for(auto x:ans){
    assert(1<=x+1 && x+1<=26);
    cout<< x+1 <<endl;
  }


}

Measured memory_bytes: 3676