akhauriyash/Code-Regression huggingface dataset:
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

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

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

int main(){
int N;
cin>>N;
vector<pair<ll,int>> xlist,ylist;
rep3(i,N){
    ll x,y;
    cin>>x>>y;
    xlist.push_back(make_pair(x,i));
    ylist.push_back(make_pair(y,i));

}
sort(all(xlist));
sort(all(ylist));
vector<tuple<ll,int,int>> roadl;
rep(i,xlist.size()-1){
    roadl.push_back(make_tuple(xlist[i+1].first-xlist[i].first,xlist[i+1].second,xlist[i].second));
    roadl.push_back(make_tuple(ylist[i+1].first-ylist[i].first,ylist[i+1].second,ylist[i].second));
}
sort(all(roadl));



ll costsum=0;
UnionFind U(N+1);//橋となるもの以外は辺に加えなくてよいのでその判定用。
rep(i,roadl.size()){
    tuple<ll,int,int> e=roadl[i];
    ll cost;
    int s,t;
    cost=get<0>(e),s=get<1>(e),t=get<2>(e);
    if(U.root(s)!=U.root(t)){
        U.unite(s,t);
        costsum+=cost;

    }
}
cout<<costsum<<endl;

return 0;

}

Measured memory_bytes: 10576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int R,C,K;
    cin >> R >> C >> K;
    vvl item(R,vl(C,0));
    rep(i,K){
        int r,c,v;
        cin >> r >> c >> v;
        r--,c--;
        item[r][c] = v;
    }
    
    ve<vvl> dp(R+1,vvl(C+1,vl(4,-infl)));
    
    dp[0][0][0] = 0;
    
    reps(i,1,R+1){
        rep(k,4) dp[i][0][k] = dp[i-1][0][k];
        reps(j,1,C+1){
            
            rep(k,4) dp[i][j][k] = dp[i][j-1][k];
            if(item[i-1][j-1] > 0) reps(k,1,4) chmax(dp[i][j][k],dp[i][j-1][k-1]+item[i-1][j-1]);
            rep(k,4) chmax(dp[i][j][0],dp[i-1][j][k]);
            if(item[i-1][j-1] > 0) rep(k,4) chmax(dp[i][j][1],dp[i-1][j][k]+item[i-1][j-1]);
            
        }
    }

    ll ans = 0;
    rep(i,4) chmax(ans,dp[R][C][i]);
    
    cout << ans << endl;
    
    //rep(i,R+1) {{rep(j,C+1) cout << dp[i][j][0] << " ";}cout  << endl;}
    

    return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, p;
	cin >> a >> p;
	p += a*3;
	p /= 2;
	cout << p << endl;
	return 0;
}

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

int main() {
    
    int  n; cin >> n;
    vector<ll> l(n + 1);
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; i++) {
        l[i] = l[i - 1] + l[i - 2];
    }
    cout << l[n] << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A <= 5){
    cout << 0 << endl;
  }
  else if( A>=6 && A<=12){
    cout << B/2 << endl;
  }
  else cout << B << endl;
}

    

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;


#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 100001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);


ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
    ll res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= MOD;
        res %= MOD;
    }

    return res % MOD;
}

const ll mod = 1e9 + 7;

int T = 1;
int n, m, k;
ll ans = 0;
vector<int> a, b, c, d;


void check(int p, int num, vector<int>& arr)
{
    if(p == n)
    {
        ll cur = 0;
        for(int i = 0; i < k; i++)
        {
            if(arr[b[i]] - arr[a[i]] == c[i]) cur += d[i];
        }
        ans = max(ans, cur);
        return;
    }

    for(int i = num; i <= m; i++)
    {
        arr[p] = i;
        check(p + 1, i, arr);
    }


}


void solve()
{
    cin >> n >> m >> k;
    a.resize(k);
    b.resize(k);
    c.resize(k);
    d.resize(k);
    for(int i = 0; i < k; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }



    vector<int> arr(n, 0);

    check(0, 1, arr);
    cout << ans << "\n";

    return;
}


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

//    cin >> T;

    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;
const lli mod = 998244353;
 
vector<lli> solve(int b, int e, lli s, vector<lli> &a){
    vector<lli> res(s+1, 0);
    if(e-b == 1){
        res[0] = 2;
        if(a[b] <= s){
            res[a[b]] = 1;
        }
        return res;
    }

    int mid = (b+e)/2;
    auto ret1 = solve(b, mid, s, a);
    auto ret2 = solve(mid, e, s, a);
    for(int i=0; i<=s; i++){
        for(int j=0; j<=i; j++){
            res[i] += (ret1[j] * ret2[i-j]) %mod;
            res[i] %= mod;
        }
    }
    /*
    cerr << b << "," << e << endl;
    for(int i=0; i<=s; i++){
        cerr << res[i] << " ";
    }
    cerr << endl;
    */
    return res;
}

int main(){
    lli n,s;
    cin >> n >> s;
    vector<lli> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    vector<lli> dp(s+1, 0);
    dp[0] = 1;
    for(int i=0; i<n; i++){
        vector<lli> ndp(s+1, 0);
        for(int j=0; j<=s; j++){
            ndp[j] += (2*dp[j])%mod;
            ndp[j] %= mod;
        }
        for(int j=0; j+a[i]<=s; j++){
            ndp[j+a[i]] += dp[j];
            ndp[j+a[i]] %= mod; 
        }
        swap(dp, ndp);
    }
    cout << dp[s] << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, p);
    int ans = 0;
    for(int i = 1; i+1 < n; i ++){
        if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) ans ++;
    }
    Cout(ans);
}




Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

vector<int> path2[200005];
vector<int> path[200005];
bool used[200005];
int t[200005];
int s=0;

void create_path(int a){
	if(used[a])return;
	used[a]=true;
	int b;
	for(int i=0;i<path2[a].size();i++){
		b=path2[a][i];
		if(used[b])continue;
		path[a].push_back(b);
		create_path(b);
	}
}

void check(int a){
	if(path[a].size()==0)return;
	int i,j;
	int b,c;
	for(i=0;i<path[a].size();i++){
		check(path[a][i]);
		c=t[path[a][i]]+1;
		if(t[a]<=c){
			b=t[a],t[a]=c;
		}else b=max(b,c);
	}
	if(path[a].size()>1){
		b+=t[a];
		s=max(s,b);
	}
	s=max(s,t[a]);
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=0;i<n-1;i++){
		cin>>a>>b;
		a--,b--;
		path2[a].push_back(b);
		path2[b].push_back(a);
	}
	create_path(0);
	check(0);
	if(s%3!=1)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}


Measured memory_bytes: 35072
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
ans += a[0]//2
a[0] %= 2
for i in range(1,n):
    if a[i-1] == 1 and a[i] > 0:
        ans += 1
        a[i] -= 1
    ans += a[i]//2
    a[i] %= 2
print(ans)

Measured memory_bytes: 7072
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 1e12
#define MAXN 100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t; cin>>s>>t;
    ll N = s.length();
    ll M = t.length();
    
    ll dp[N + 1][M + 1];
    memset(dp,0,sizeof(dp));
    
    for(ll i=1;i<=N;++i)
    {
        for(ll j=1;j<=M;++j)
        {
            if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
        }
    }
    
    //backtrack
    ll c = dp[N][M];
    ll L = N;
    ll R = M;
    string ans;
    
    while(c)
    {
        for(ll j=R;j>0;--j)
        {
            if(s[L - 1] == t[j - 1] && dp[L][j] == c)
            {
                ans = t[j - 1] + ans;
                R = j - 1;
                c--;
                break;
            }
        }
        
        L--; 
    }
    
    cout<<ans<<endl;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<vector<ll>> v(N, vector<ll>(N, 0));
  vector<vector<ll>> w(N, vector<ll>(N, 0));

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

  bool flg = true;
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(v[i][j] > v[i][k] + v[k][j]){
          flg = false;
          break;
        }
        if(w[i][j] == 0 && v[i][j] == v[i][k] + v[k][j] && k != j && k != i){
          w[i][j] = 1; // ijの辺はなくてもいい
        }
      }
      if(!flg) break;
    }
    if(!flg) break;
  }

  if(flg){
    ll ans = 0;
    // todo
    for(int i = 0; i < N-1; i++){
      for(int j = i+1; j < N; j++){
        // cerr << i << " " << j << " " << w[i][j] << " " << v[i][j] << endl;
        if(w[i][j] == 0){
          ans += v[i][j];
        }
      }
    }
    cout << ans << endl;
  } else { 
    cout << -1 << endl;
  }
}


Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
int n,k,t,a[4010],vis[4010][2];
long long fac[4010],g[4010],ans,f[4010][4010][2],p=924844033;
int main() {
//    freopen("permutation.in","r",stdin);
//    freopen("permutation.out","w",stdout);
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        for(int j=0; j<=1; j++)
            if(!vis[i][j]) {
                int x=i,y=j,len=0;
                while(x<=n) {
                    vis[x][y]=1;
                    len++;
                    x+=k;
                    y^=1;
                }t+=len;
                a[t]=1;
            }
    f[1][0][0]=1;
    for(int i=1; i<=t; i++)
        for(int j=0; j<=n; j++) {
            f[i+1][j][0]=(f[i][j][0]%p+f[i][j][1]%p)%p;
            if(!a[i]) f[i+1][j+1][1]=f[i][j][0];
        }
    for(int i=1; i<=n; i++) g[i]=(f[t][i][0]%p+f[t][i][1]%p)%p;
    fac[0]=1;
    for(int i=1; i<=n; i++) fac[i]=fac[i-1]%p*i%p;
    ans=fac[n]%p;
    for(int i=1,j=-1; i<=n; i++,j=-j) ans=(ans%p+p+j%p*g[i]%p*fac[n-i]%p)%p;
    printf("%lld\n",ans%p);
    return 0;
}



Measured memory_bytes: 249728
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> a){
    bool allEven = true;
    rep(i, N){
        if(a[i]%2) 
            allEven = false;
    }
    if(!allEven)
        cout << "first" << endl;
    else
        cout << "second" << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d %d", $a, $b);
$s1 = $a+$b;
$s2 = $a+$a-1;
$s3 = $b+$b-1;
if($s1 > $s2 && $s1 > $s3){
    echo $s1;
}else if($s2 > $s3){
    echo $s2;
}else{
    echo $s3;
}
?>

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
using namespace std;
#define lli long long int

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vector<lli> a;
	a.resize(n);
	int i;
	lli sum = 0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum += a[i];
	}
	sum = sum/2;
	lli even_sum=0;
	for(i=0;i<(n-1);i=i+2)
	{
		even_sum += a[i];
	}
	vector<lli> ans;
	ans.resize(n);
	ans[n-1] = sum - even_sum ;
	for(i=n-2;i>=0;i--)
		ans[i] = a[i] - ans[i+1];
	for(i=0;i<n;i++)
		cout<<2*ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
sumx=0
i=0
while(i<n):
    if(sumx+arr[i]<=k):
        sumx+=arr[i]
        i+=1
    else:
        break
if(i<n):
    print(i)
elif(i==n and sumx==k):
    print(i)
else:
    print(i-1)

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

char c[3][3];

void solve() 
{
    string s;
    s += c[0][0];
    s += c[1][1];
    s += c[2][2];

    cout << s << endl;
}

int main()
{
    for (int i = 0; i < 3; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 3; j++) {
            c[i][j] = s[j];
        }
    }

    solve();

    return 0;
}

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

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

int main() {
    int N;
    long long X;
    cin >> N >> X;
    vector<long long> x(N);
    for (int i = 0; i < N; ++i) cin >> x[i], x[i] -= X;
    long long g = abs(x[0]);
  
    for (int i = 0; i < N; ++i){
      g = GCD(g, abs(x[i]));
    }
    cout << g << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int x11,x12,x13,x21,x22,x23,x31,x32,x33;
	cin>>x11>>x12>>x22;
	int i=x22*3;
	x13=i-x11-x12;
	x33=i-x22-x11;
	x31=i-x22-x13;
	x32=i-x22-x12;
	x21=i-x11-x31;
	x23=i-x22-x21;
	cout<<x11<<" "<<x12<<" "<<x13<<endl;
	cout<<x21<<" "<<x22<<" "<<x23<<endl;
	cout<<x31<<" "<<x32<<" "<<x33<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1LL<<32
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll n, m, i, j;
    ll x[3][1000];
    cin >> n >> m;
    for(i=0; i<n; i++) {
        cin >> x[0][i] >> x[1][i] >> x[2][i];
    }
    ll ans=0, tmp;
    ll sum[1000];
    ll s[3];
    for(i=0; i<8; i++) {
        tmp=0;
        s[0]=0; s[1]=0; s[2]=0;
        for(j=0; j<n; j++)
            sum[j]=0;
        
        for(j=0; j<3; j++) {
            if(1&i>>j)
                s[j]=1;
            else
                s[j]=-1;
        }
        
        for(j=0; j<n; j++)
            sum[j]=s[0]*x[0][j]+s[1]*x[1][j]+s[2]*x[2][j];
        
        sort(sum, sum+n);
        for(j=n-1; j>=n-m; j--)
            tmp+=sum[j];
        
        ans=max(ans, tmp);
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Team{
	int id;
	int result;
	bool operator<(const Team &t)const{return result<t.result;}
};
void Input(Team &t){
	int c,m1,s1,m2,s2,m3,s3,m4,s4;
	scanf("%d%d%d%d%d%d%d%d%d",&c,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
	t.id = c;
	t.result = m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
}
int main(){
	while(true){
		int n;
		vector<Team> vteams;
		scanf("%d", &n);
		if(n==0)break;
		vteams.resize(n);
		for(int i = 0; i < n; ++i){Input(vteams[i]);}
		sort(vteams.begin(),vteams.end());
		printf("%d\n%d\n%d\n",vteams[0].id,vteams[1].id,vteams[n-2].id);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
const int MAX_N = 2e5+5;
int par[MAX_N]; //親
int tree_rank[MAX_N]; //木の深さ
int siz[MAX_N]; //木の深さ

// n要素で初期化
void init(int n){
  rep(i, n){
    par[i] = i;
    tree_rank[i] = 0;
    siz[i] = 1;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (tree_rank[x] < tree_rank[y]) {
    par[x] = y;
    int tmp = siz[x];
    siz[x] += siz[y];
    siz[y] = siz[x];
  }
  else{
    par[y] = x;
    int tmp = siz[x];
    siz[x] += siz[y];
    siz[y] = siz[x];
    if (tree_rank[x] == tree_rank[y]) tree_rank[x]++;
  }
}

// xとyが同じ要素に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

int size(int x) { // 素集合のサイズ
  return siz[find(x)];
}

int main() {
  INCANT;
  cin >> N >> M;
  init(N);
  int a,b;
  rep(i, M) {
    cin >> a >> b;
    a--;b--;
    unite(a,b);
  }
  int mx=0;
  rep(i, N) {
    mx=max(mx, size(i));
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 5972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 100000000

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n] = {0};
    int tmp1, tmp2;
    for (int i = 0; i < m; i++)
    {
        cin >> tmp1 >> tmp2;
        a[tmp1 - 1]++;
        a[tmp2 - 1]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	vector<int> ans;
	while (n != 0) {
		n--;
		ans.emplace_back(n % 26);
		n /= 26;
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << (char)(ans[i] + 'a');
	}
	cout << endl;

	return 0;
}

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

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

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}
 
template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}
 
template<class T>
void write(const T &x){ cout << x << endl; }


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

set<ll> DecomposePrime(ll n)
{
    set<ll> ret;
    // 割る数の初期値
    ll a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            ret.insert(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    ret.insert(n);
    return ret;
}

int main(){
    auto A = read<ll>();
    auto B = read<ll>();
    
    auto GCD = gcd(A, B);
    if(GCD == 1){ write(1); }
    else{
        auto s = DecomposePrime(GCD);
        write(s.size() + 1);
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x:usize = read();
    let a:usize = read();
    let b:usize = read();
    let mut ans = "delicious";
    if b > x + a {
        ans = "dangerous";
    } else if a < b {
        ans = "safe";
    }
    println!("{}", ans);
}


Measured memory_bytes: 2088
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final long Mod = 1000_000_007;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();
		int[] a = new int[n+1];
		Arrays.fill(a, 1);
		long res = 1;

		for(int i = 2;i<=n;i++) {
			int t=i;
			for(int j=2;j<=t;j++) {
				while(t%j==0) {
					t/=j;
					a[j]++;
				}
			}
		}
		for(int i=1;i<=n;i++) {
			res = res*a[i];
			for(;res>Mod;)res-=Mod;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 22740
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] cs = sc.next().toCharArray();
		
		Arrays.sort(cs);
		if(cs[0]==cs[1] && cs[0]!=cs[2] && cs[2]==cs[3]) {
			System.out.println("Yes");
		}
		else System.out.println("No");
	}
}


Measured memory_bytes: 23380
#include<iostream>

using namespace std;

int main()
{
  int t, h, m, s;

  cin >> t;

  h = t / 3600;
  m = (t % 3600) / 60;
  s = (t % 3600 ) % 60;

  cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int i,j,n,p,q,temp;
    int t=0;
    int flag=0;
    int count=0;
    int maxl=0;
    cin>>n>>q;
    int kotae[q];
    string s;
    cin>>s;
    int hidari[n];
    int migi[n];
    int lr[q][2];
    for(i=0; i<q; ++i){
        cin>>lr[i][0]>>lr[i][1];
    }
    for(i=0; i<n; ++i){
        if(flag==1&&s[i]=='C'){++count;flag=0;}
        if(s[i]=='A'){flag=1;}
        else{flag=0;}
        hidari[i]=count;
    }
    flag=0;
    count=0;
    for(i=n-1; i>=0; --i){
        if(flag==1&&s[i]=='A'){++count;flag=0;}
        if(s[i]=='C'){flag=1;}
        else{flag=0;}
        migi[t]=count;
        ++t;
    }
    for(i=0; i<q; ++i){
        if(lr[i][0]==1&&lr[i][1]==n){kotae[i]=hidari[n-1];}
        else if(lr[i][0]==1){kotae[i]=hidari[lr[i][1]-1];}
        else if(lr[i][1]==n){kotae[i]=migi[n-lr[i][0]];}
        else {
            kotae[i] = hidari[n - 1] - hidari[lr[i][0] - 2] - migi[n - lr[i][1] - 1];
        
        if(lr[i][0]!=1){if(s[lr[i][0]-1]=='C'&&s[lr[i][0]-2]=='A'){--kotae[i];}}
        if(lr[i][1]!=n){if(s[lr[i][1]-1]=='A'&&s[lr[i][1]]=='C'){--kotae[i];}}
        }
        if(i!=q-1){cout<<kotae[i]<<endl;}
        else{cout<<kotae[i];}
    }
    return 0;
}

Measured memory_bytes: 2944
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x, y = map(int, readline().split())

    a = {1, 3, 5, 7, 8, 10, 12}
    b = {4, 6, 9, 11}
    c = {2}

    if x in a and y in a:
        print("Yes")
    elif x in b and y in b:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61944
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))

def dfs(i: int, j: int) -> int:
    if i == 1 and j == n-1:
        return a[i][j]

    if i == 1:
        return dfs(i, j+1) + a[i][j]
    elif j == n-1:
        return dfs(i+1, j) + a[i][j]

    return max(dfs(i+1, j) + a[i][j], dfs(i, j+1) + a[i][j])

print(dfs(0, 0))


Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    h,w = map(int, input().split())
    a = [list(input().rstrip()) for _ in range(h)]
    tate = []
    yoko = []
    for i in range(h):
        if '#' not in a[i]:
            yoko.append(i)
    for i in range(w):
        for j in range(h):
            if a[j][i] == '#':
                break
        else:
            tate.append(i)
    res = []
    for i in range(h):
        temp = []
        if i in yoko:
            continue
        for j in range(w):
            if j in tate:
                continue
            temp.append(a[i][j])
        res.append(temp)
    for i in res:
        print(''.join(i))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll cal(ll a){
	ll cnt = 0 ;
	while(a % 2 == 0){
		a/=2;
		cnt ++;
	}
	return cnt;
}

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

	ll N;
	cin >> N;
	ll ans = 0;
	rep(i,N){
		ll inp;
		cin >> inp;
		ans += cal(inp);
	}

	cout << ans << endl;


	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


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

cnt = {}

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

cnt = sorted(cnt.items(), key=lambda x: x[1])
ans = 0

for i in range(len(cnt)):
    if len(cnt) - i <= K:
        break
    ans += cnt[i][1]

print(ans)


Measured memory_bytes: 107728
open Num

type btree = Node of node | Nil and
     node = {k : num; l : btree; r : btree}

let preorder f tr =
  let rec iter = function
      Nil -> ()
    | Node {k = k; l = l; r = r} -> f k; iter l; iter r
  in iter tr; print_newline ()
  
let inorder f tr =
  let rec iter = function
      Nil -> ()
    | Node {k = k; l = l; r = r} -> iter l; f k; iter r
  in iter tr; print_newline ()

let insert k tr =
  let rec iter = function
      Nil -> Node {k = k; l = Nil; r = Nil}
    | Node {k = v; l = l; r = r} -> if k = v then Node {k = v; l = l; r = r}
                                    else if v < k then Node {k = v; l = l; r = iter r}
                                    else Node {k = v; l = iter l; r = r}
  in iter tr
          
let () =
  let n = read_int () in
  let rec read tr x =
    if x = 0 then ()
    else let com = read_line () in
         if com = "print" then
           begin
             inorder (fun i -> print_string @@ " " ^ (string_of_num i)) tr;
             preorder (fun i -> print_string @@ " " ^ (string_of_num i)) tr;
             read tr (x-1)
           end
         else let y =
                let l = String.length com in
                num_of_string (String.sub com 7 (l-7)) in
              read (insert y tr) (x-1)
  in
  read Nil n

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
  int k,n;
  int p[1000];
  int sum=0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&p[i]);
  }

  qsort(p, n, sizeof(int), compare_int);

  for(int i=0;i<k;i++)
  {
    sum += p[i];
  }

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

  return 0;
}

Measured memory_bytes: 1736
n = int(input())
x = list(map(int, input().split()))
min = min(x)
max = max(x)

ans = 1000000000000
for p in range(min, max + 1):
  now = 0
  for q in x:
    if now < abs(p - q):
      now = abs(p - q)
  if ans > now:
    ans = now
print(ans)



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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>

using namespace std;

int get(int pos, set<int> s) {
  for (int x : s) {
    if (!pos) return x;
    pos--;
  }
  return -1;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vi h(n), dp(n, 1e9);
  for (int i = 0; i < n; i++) {
      cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
      for (int j = i + 1; j <= i + k; j++) {
          if (j < n) {
              dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
          }
      }
  }
  cout << dp[n - 1] << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  srand (time(NULL));
  int t = 1;
  // cin >> t;
  while (t--) solve();
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,j,x[8],y[8];
	cin >> n;
	for(i=0;i<n;i++){
    	cin >> x[i] >> y[i];
    }
  	double sum=0;
  	for(i=0;i<n;i++){
    	for(j=i+1;j<n;j++){
        	sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }

	double r=2;
	for(i=1;i<n;i++){
    	r*=i;
		r/=i+1;
    }

	cout<<setprecision(16)<<sum*r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
template<typename T,typename _T>inline bool chk_min(T &x,const _T y){return y<x?x=y,1:0;}
template<typename T,typename _T>inline bool chk_max(T &x,const _T y){return x<y?x=y,1:0;}
typedef long long ll;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",std::min(a*b,c));
	return 0;
}


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

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

const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll N, M;
vector<vector<int>> s;
vector<int> p;

bool check(int bit)
{
    for (int i = 0; i < M; ++i)
    {
        int count = 0;
        for (int sw : s[i])
        {
            count += (bit >> sw) & 1;
        }

        if ((count % 2) != p[i])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    cin >> N >> M;
    s.resize(M);
    p.resize(M);
    for (int i = 0; i < M; ++i)
    {
        int k;
        cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; ++j)
        {
            cin >> s[i][j];
            --s[i][j];
        }
    }

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

    ll res = 0;
    for (ll bit = 0; bit < (1 << N); ++bit)
    {
        if (check(bit))
            ++res;
    }
    cout << res << endl;
}


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

int main(){
  long long n,b,ans=1e9;
  cin>>n;
  for(long long a=1;a<=sqrt(n);a++){
    if(n%a==0){
      long long keta=0;
      b=n/a;
      while(b){
        b/=10;
        keta++;
      }
      ans=min(ans,keta);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
signed main() {
	int n, a, b, sum = 0, ans = 0; cin >> n >> a >> b;
	sum = n / gcd(n, a) * a / gcd(n, a);
	cout << sum * b << endl;
}


Measured memory_bytes: 3116
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	r := nextInt()

	if n >= 10 {
		fmt.Println(r)
	} else {

		fmt.Println(r + 100*(10-n))
	}

}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

struct modint {
    static constexpr int MOD = 998244353;
    ll v;

    bool operator==(const modint& other) const {
        return v == other.v;
    }

    modint& operator+=(const modint& other) {
        v += other.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }

    modint& operator-=(const modint& other) {
        v -= other.v;
        if (v < 0)
            v += MOD;
        return *this;
    }

    modint& operator*=(const modint& other) {
        v = v * other.v % MOD;
        return *this;
    }

    modint& operator/=(const modint& other) {
        *this *= other.inv();
        return *this;
    }

    modint operator+(const modint& other) const {
        return modint { v } += other;
    }

    modint operator-(const modint& other) const {
        return modint { v } -= other;
    }

    modint operator*(const modint& other) const {
        return modint { v } *= other;
    }

    modint operator/(const modint& other) const {
        return modint { v } /= other;
    }

    static modint pow(modint b, ll e) {
        modint res { 1 };
        for (ll p = 1; p <= e; p <<= 1) {
            if (p & e)
                res *= b;
            b *= b;
        }

        return res;
    }

    modint pow(ll e) const {
        return pow(*this, e);
    }

    modint inv() const {
        return pow(MOD - 2);
    }

    friend ostream& operator<<(ostream& os, modint m) {
        return os << m.v;
    }
};

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

    int n;
    cin >> n;

    modint ans = modint::pow(modint { 3 }, n);
    modint cur = { 0 };
    modint term = { 1 };
    modint p = { 2 };
    // n choose k * 2^k for k in range()
    for (int k = n; k > n / 2; --k) {
        cur += term * p;
        // going from n!/k!(n-k)! to n!/(k-1)!(n-k+1)!
        // multiply by k/(n-k+1)
        term /= modint { n - k + 1 };
        term *= modint { k };
        p += p;
    }

    cout << ans - cur << '\n';
 
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#define MOD 100000
#define NMAX 7
#define SMAX 3000

int main(void){
  int n, m, s;
  while(scanf("%d %d %d", &n, &m, &s), n){
    int i, j, dp[NMAX*NMAX+1][SMAX+1] = {0};
    dp[0][0] = 1;
    for(i = 1; i <= n * n; i++){
      for(j = 0; j <= s; j++){
	if(j - i >= 0) dp[i][j] += dp[i-1][j-i];
	if(j - i >= 0) dp[i][j] += dp[i][j-i];
	if(j - m - 1 >= 0) dp[i][j] += (MOD - dp[i-1][j-m-1]);
	dp[i][j] %= MOD;
      }
    }
    printf("%d\n", dp[n*n][s]);
  }
  return 0;
}


Measured memory_bytes: 2280
#include <bits/stdc++.h>
using namespace std;
main() {
 int A, B, C, D;
 cin >> A >> B >> C >> D;
  
 if (D <= A || B <= C )
   cout << 0 << endl;
 else 
   cout << min(B, D) - max(A, C) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<climits>
#include<cassert>
#include<iomanip>
#include<map>
#include<set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

typedef long double ld;

// Library - template - begin

class Point
{
  public:
  double x,y;

  Point(double x = -IINF,double y = -IINF): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const
  {
    return !equals(x,p.x)?x<p.x:y<p.y;
  }

  bool operator == (const Point& p)const
  {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }

};

typedef Point Vector;

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

//rad は角度をラジアンで持たせること
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

// 度をラジアンに変換
double toRad(double agl){ return agl*M_PI/180.0; }

// Library - template - end

double R;

Point getMP(Point a,Point b,Point c)
{
  double nm[3] = {norm(a),norm(b),norm(c)};
  double u = 0.5/(a.x*b.y-b.x*a.y+b.x*c.y-c.x*b.y+c.x*a.y-a.x*c.y);
  double x = u * (nm[0]*b.y-nm[1]*a.y+nm[1]*c.y-nm[2]*b.y+nm[2]*a.y-nm[0]*c.y);
  double y = u * (a.x*nm[1]-b.x*nm[0]+b.x*nm[2]-c.x*nm[1]+c.x*nm[0]-a.x*nm[2]);
  R = sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y)); //半径
  return Point(x,y);
}

int n,V;

int main(){

  while(cin >> n,n){

    if( n == 1 )
      {
	cout << "0.433013" << endl;
	continue;
      }

    if(n % 3)V = 3 * n;
    else     V = n;

    double theta = 360.0 / V;
    double theta2 = ( ( 180.0 - theta ) * 0.5 ) - 30.0;
    assert( theta2 >= 0.0 );  

    Point sp = Point(1,0);
    Point np = rotate(sp,toRad(60.0));
    Point mp = getMP(Point(0,0),sp,np);

    /* solution - 1 
    double h = R  / ( sqrt(3.0) + ( 1.0 / tan( toRad(theta*0.5) ) ) );
    double area2 = ( h * R / 2 ) * V * 2;
    cout << setiosflags(ios::fixed) << setprecision(7) << area2  << endl;  
    continue;
    */


    // solution - 2 
    np = np - mp;
    Point np2 = rotate(np,toRad(theta));

    double len = abs(np-np2);
    double L = len * 0.5;
    double theta3 = 180.0 - ( 90.0 + theta2 );
    assert( theta3 >= 0 );
    double L2 = L * sin(toRad(theta2)) / sin(toRad(theta3));

    double sub = L * L2;

    double area = ( V * len * len ) / ( 4 * tan( M_PI / V ) );

    cout << setiosflags(ios::fixed) << setprecision(7) << area - sub * V << endl;

  }
  return 0;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int n;
int sum=0;
vector<vector<int>> g(10);

void solve(int u,vector<bool>&m){
  bool f=0;
  m[u]=1;
  rep(i,n){
    if(!(m[i])) f=1;
  }
  if(f){
    rep(i,g[u].size()){
      int v=g[u][i];
      if(!(m[v])){
        vector<bool> k(n,0);
        rep(i,n){
          if(m[i]) k[i]=1;
        }
        solve(v,k);
      }
    }
  }else sum++;
}

int main(){
  int m; cin>>n>>m;
  rep(i,m){
    int a,b; cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  vector<bool> k(n,0);
  solve(0,k);
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s,int v,vector<int>&d,whei(edge)&G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size();i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

int main() {
	string s;
	cin >> s;
	for (int i = 1;;i++) {
		s.erase(s.size() - 1);
		if ((s.size() % 2) == 1)continue;
		string t = s.substr(0, s.size()/2);
		string z = s.substr((s.size() / 2), s.size() / 2);
		if (t == z) {
			cout << s.size() << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int d[] = new int[n];

        for (int i=0; i<n; i++){
            d[i] = sc.nextInt();
        }


        Arrays.sort(d);

        if (n%2!=0){
            System.out.println(0);
        }else if(d[(n/2)-1]==d[n/2]){
            System.out.println(0);
        }else{
            System.out.println(d[n/2]-d[(n/2)-1]);
        }


        }
    }


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

using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, k; cin >> n >> k;
  vector<bool> snack(n, false);
  while(k--) {
    int dk; cin >> dk;
    while(dk--) {
      int x; cin >> x;
      snack[x-1] = true;
    }
  }

  int ret = 0;
  for(int i = 0; i<n; ++i) {
    if(!snack[i]) ret++;
  }
  cout << ret << endl;
}


Measured memory_bytes: 3652
n = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)

hash = array.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h

ng = {}

new_arr = []
hash.each do |k,v|
  if v == 1
    new_arr.push(k)
  else
    ng[k] = true
    new_arr.push(k)
  end
end

new_arr.sort!

new_n = new_arr.size

ans = 0

reached = Array.new(10**6+1, false)

new_arr.each do |a|
  if !reached[a]
    ans += 1 unless ng[a]
    1.upto(10**6) do |i|
      break if a*i > 10**6+1
      reached[a*i] = true
    end
  end
end

p ans


Measured memory_bytes: 73012