akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a,k) distance((v).begin(),(k)+upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a,k) distance((v).begin(),(k)+lower_bound((v).begin(),(v).end(),(a)))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vp;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define M 1000000007
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)

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

void Main(){
  int n;
  cin>>n;
  vl a(n);
  cin>>a;
  int a0=0; 
  int a1=0; 
  int a2=0;
  rep(i,n){
    if(a[i]%2==0){
      a[i]/=2;
      if(a[i]%2==0){
        a2++;
      }else{
        a1++;
      }
    }else{
      a0++;
    }
  }
  if(a2>=a0){
    cout<<"Yes"<<endl;
  }else{
    if(a1==0){
      if(a2==a0-1){
        cout<<"Yes"<<endl;
        return;
      }
    }
    cout<<"No"<<endl;
  }

} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int p(double x1, double x2, double x3, double x4) {
  return x1 * x4 - x2 * x3;
}

int main() {
  double x[4], y[4];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != EOF) {
    double dt[4];
    for (int i = 0; i < 4; i++) {
      dt[i] = p(x[(i+1)%4]-x[i], y[(i+1)%4]-y[i], x[(i+2)%4]-x[i], y[(i+2)%4]-y[i]);
    }
    if ((dt[0] > 0 && dt[1] > 0 && dt[2] > 0 && dt[3] > 0) ||
        (dt[0] < 0 && dt[1] < 0 && dt[2] < 0 && dt[3] < 0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long n,k;
long long a[1000009];
long long dp[1000090];
int main()
{
    cin>>n>>k;
    for(long long i=0; i<n; i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(long long i=2; i<n; i++)
    { dp[i]=10000000009;
        for(long long j=1;j<=k && i-j>=0;j++)
        dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
    }
    cout<<dp[n-1];
return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <iomanip>

using namespace std;

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

	double L2 = (double)L;
	long double ans = L2 * L2 * L2;

	ans /= 27;

	cout << fixed;
	cout << setprecision(8) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string> solve(int cur, int mask){
    //printf("%d %d\n",cur,mask);
    vector<string> s;
    if (cur ==0){
        s.push_back("");
        return s;
    }
    vector<string> S = solve(cur-1,mask);
    for (int i = 0; i < 10; i++){
        char OK = i+'a';
        if ((mask&(1<<i)) == 0){
            vector<string> T = solve(cur-1,mask|(1<<i));
            for (auto x : T){
                s.push_back(OK + x);
            }
            break;
        }
        else{
            for (auto x : S){
                s.push_back(OK + x);
            }
        }
    }
    return s;
}
int main(){
    int n;
    scanf("%d",&n);
    vector<string> ans = solve(n,0);
    for (auto x : ans){
        cout << x << endl;
    }
}


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

using namespace std;
using int64 = long long;

int main() {
    int n;
    int64 sum = 0;
    cin >> n;

    for (int i=1; i<=n; i++) {
        if (i%3!=0 && i%5!=0)
            sum += i;
    }

    cout << sum << endl;
}


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

int main()
{
    int n,x;
    cin>>n>>x;
    int a[n];
    int min=100000,s=0,d;
    for(int i=0; i<n; i++) {
        cin>>a[i];
        if(min>a[i]) {
            min=a[i];
        }
        s=s+a[i];
    }
    x=x-s;
    d=x/min;
    cout<<(d+n);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 30
int a[maxn],c[maxn];
int main(){
	int n,x,ans=0;scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",a+i);if(a[i]==a[i-1]+1)c[a[i-1]]=1;}
	for(int i=1;i<=n;i++)scanf("%d",&x),ans+=x;
	for(int i=1;i<n;i++)scanf("%d",&x),ans+=x*c[i];
	printf("%d",ans);
	return 0;
}

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

using namespace std;
int a[15];
int dfs(int x, int y, int step)
{
    if( step == 11)
       return 1;
    if(x < a[step]) dfs(a[step], y, step+1);
    else if(y < a[step]) dfs(x, a[step], step+1);
  else
    return 0;
}
int main ()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        for(i = 1;i <= 10;i++)
            scanf("%d", &a[i]);
        if(dfs(0, 0, 1))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

class Point {
  public:
  int x, y;

  Point(int x = 0, int y = 0): x(x), y(y) {}
};

struct Segment {
  Point p1, p2;
};

#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3

class EndPoint {
  public:
    Point p;
    int seg, st; // 入力線分のID, 端点の種類
    EndPoint() {}
    EndPoint(Point p, int seg, int st): p(p), seg(seg), st(st) {}

    bool operator < (const EndPoint &ep) const {
      // y 座標が小さい順に整列
      if (p.y == ep.p.y) {
        return st < ep.st; // y同一の場合下、左、右、上端点の順に調べる
      } else return p.y < ep.p.y;
    }
};

EndPoint EP[2 * 100000]; // 端点(EP)のリスト

int manhattanIntersection(vector<Segment> S) {
  int n = S.size();

  for (int i = 0, k = 0; i < n; i++) {
    // 端点p1, p2が左下を基準に並ぶように調整
    if (S[i].p1.y == S[i].p2.y) { // 平行線
      if (S[i].p1.x > S[i].p2.x) swap(S[i].p1, S[i].p2);
    } else if (S[i].p1.y > S[i].p2.y) swap(S[i].p1, S[i].p2); // 垂直線

    if (S[i].p1.y == S[i].p2.y) { // 水平線分を端点リストに追加
      EP[k++] = EndPoint(S[i].p1, i, LEFT);
      EP[k++] = EndPoint(S[i].p2, i, RIGHT);
    } else {
      EP[k++] = EndPoint(S[i].p1, i, BOTTOM);
      EP[k++] = EndPoint(S[i].p2, i, TOP);
    }
  }

  sort(EP, EP + (2*n));

  set<int> BT; // 二分探索木
  BT.insert(1000000001); // 番兵追加 (1)参照
  int cnt = 0;

  rep(i, 0, 2 * n) {
    if (EP[i].st == TOP) {
      BT.erase(EP[i].p.x);
    } else if (EP[i].st == BOTTOM) {
      BT.insert(EP[i].p.x);
    } else if (EP[i].st == LEFT) {
      auto b = BT.lower_bound(S[EP[i].seg].p1.x); // O(log n)
      auto e = BT.upper_bound(S[EP[i].seg].p2.x); // O(log n) - (1)このために番兵を追加している
      cnt += distance(b, e); // bとeの距離（点の数）を加算, O(k)
    }
  }

  return cnt;
};

int main() {
  int n;
  cin >> n;
  int x1, y1, x2, y2;
  vector<Segment> S(n);
  rep(i, 0, n) {
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    Point p1 = Point(x1, y1);
    Point p2 = Point(x2, y2);
    Segment seg = { p1, p2 };
    S[i] = seg;
  }

  int ans = manhattanIntersection(S);

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



Measured memory_bytes: 11756
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

//最大流
struct MaxFlow {
    struct Edge {
        int to, cap, rev;
        Edge() {};
        Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {};
    };
    int V;
    vector<vector<Edge>> G;
    vector<int> used;

    MaxFlow(int V) : V(V), G(V, vector<Edge>()), used(V){}

    void add_edge(int from, int to, int cap) {
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, 0, (int)G[from].size() - 1});
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            // memset(used, 0, sizeof(used));
            used = vector<int>(V, 0);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};


int main(){
    int n;
    cin >> n;
    vi a(n), b(n), c(n), d(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(j, n) cin >> c[j] >> d[j];
    MaxFlow flow(n*2+2);
    int sink = n*2+1, source = n*2;
    rep(i, n) rep(j, n) {
        if(a[i] < c[j] && b[i] < d[j]) {
            flow.add_edge(i, j+n, 1);
        }
    }
    rep(i, n) {
        flow.add_edge(source, i, 1);
    }
    rep(j, n) {
        flow.add_edge(j+n, sink, 1);
    }
    cout << flow.max_flow(source, sink) << endl;;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b - 1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

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

    cout << (N * (N - 1))/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        long long N,K;
        cin >> N >> K;
        long long count=0;
        if(K != 0)
                for(long long i=K+1; i<=N; i++){
                        count+=(N/i)*(i-K);
                        if(N%i>=K)
                                count+=(N%i)-K+1;
        }
        else
                count=N*N;
        cout << count << endl;
        return 0;
}

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

int n;

int dfs(long long x, int f) {
    if (x > n) return 0;

    int ret = f == 7;
    ret += dfs(10 * x + 3, f | 1);
    ret += dfs(10 * x + 5, f | 2);
    ret += dfs(10 * x + 7, f | 4);

    return ret;
}
int main()
{
    cin >> n;

    cout << dfs(0, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;

typedef long long ll;



ll calc(ll tag,vector<ll> a,int n)
{
    ll sum=tag;
    ll res=0;
    for(int i=1;i<n;i++)
    {
        if(sum<0&&sum+a[i]<=0)
        {
            res+=abs(a[i]-(1-sum));
            a[i]=1-sum;
        }
        else if(sum>0&&sum+a[i]>=0)
        {
            res+=abs(a[i]-(-1-sum));
            a[i]=-1-sum;
            
        }
        sum+=a[i];
    }
    
    return res;
}

int main()
{
    //freopen("/Users/qianjay/Documents/apac/in", "r", stdin);
    int n;
    ll a[100010];
    scanf("%d",&n);
    vector<ll> v;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        v.push_back(a[i]);
    }
    ll res=0;
    if(a[0]==0)
    {
        
        res=calc(1,v,n)+1;
        res=min(calc(-1,v,n)+1,res);
    }
    else
    {
        res=calc(a[0],v,n);
        
        if(a[0]>0) {
            ll tp=abs(-1-a[0]);
            
            res=min(res,tp+calc(-1,v,n));
        }
        else
        {
            ll tp=abs(1-a[0]);
            
            res=min(res,tp+calc(1,v,n));
            
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 2676
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
	
	int r, g, b;
	
	cin >> r >> g >> b;
	
	int hoge = r * 100 + g * 10 + b;
	
	if(hoge % 4 == 0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
from math import sqrt
n = int(input())
cnt = 0
for i in range(2, int(sqrt(n))):
    if n % i == 0:
        div = i
        while n % div == 0:
            n /= div
            div *= i
            cnt += 1
        while n % i == 0:
            n /= i
if n > 1:
    cnt += 1
print(cnt)

Measured memory_bytes: 9256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

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

  int n; cin >> n;
  vector<pair<int, int> > a(n);

  rep(i, n) {
    int t; cin >> t;
    a[i] = make_pair(t, i+1);
  }
  sort(a.begin(), a.end());

  rep(i, n) {
    cout << a[i].second;
    cout << (i == n-1 ? "\n" : " ");
  }
    
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int array[3];
for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
for(int i = 2; i > 0; i--){
for(int j = 0; j < i; j++){
if(array[j] > array[j+1])swap(array[j],array[j+1]);
}
}
printf("%d %d %d\n",array[0],array[1],array[2]);
}


Measured memory_bytes: 2708
x, k, d = map(int,input().split())

if x > x - k*d >= 0:
  print(x-k*d)
  exit()
if x < x + k*d <= 0:
  print(-x-k*d)
  exit()

x = abs(x)
if (x//d)%2 == k%2:
  print(x % d)
  exit()

else:
  print(-(x % d - d))
  exit()

Measured memory_bytes: 9072
#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>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int n,x; cin>>n>>x;
  int mi = 1000000000;
  int k;
  int ans = 0;
  rep(i,n) {
    cin>>k;
    if (mi > k) mi = k;
    x -= k;
  }
  cout << n + (x/mi) << endl;

}


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

using namespace std;
typedef long long ll;

// #define DEBUG

void shave(vector<int> &v, int n)
{
    vector<int> x, y;
    int n_sq = sqrt(n) + 1;
    for (int i = 3; i < n + 1; i += 2)
    {
        x.push_back(i);
    }
    for (int i = 3; i < n_sq; i += 2)
    {
        for (auto itr = x.begin(); itr != x.end(); itr++)
        {
            if (*itr == i || *itr % i != 0)
                y.push_back(*itr);
        }
        x.clear();
        x = y;
        y.clear();
    }
    if (n >= 2)
        x.insert(x.begin(), 2);

    for (auto itr = x.begin(); itr != x.end(); itr++)
    {
        v.push_back(*itr);
    }
}

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, p, q, end_time, ans;
    cin >> n;
    pair<int, int> a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> p >> q;
        a[i] = make_pair(q, p);
    }
    sort(a, a + n);

    ans = 0, end_time = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i].second > end_time)
        {
            ans++;
            end_time = a[i].first;
        }
    }
    cout << ans << endl;
}


// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


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

    using namespace std;

    typedef long long int ll;
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()

    void __print(int x) {cerr << x;}
    void __print(long x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(unsigned x) {cerr << x;}
    void __print(unsigned long x) {cerr << x;}
    void __print(unsigned long long x) {cerr << x;}
    void __print(float x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const char *x) {cerr << '\"' << x << '\"';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }

  
  

    /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
    int main()
    {
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      vector<ll> a(n);
      ll sum = 0;
      ll ans = 0;
      forn(i,0,n){
        cin>>a[i];
        ans += sum*a[i];
        ans %= MOD;
        sum += a[i];
        sum %= MOD;
      }
      cout<<ans<<endl;
      

  } 


Measured memory_bytes: 4744
#include <algorithm>
#include <string>
#include <iostream>

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

using namespace std;

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

    long long A,B,K;
    cin >> A >> B >> K;


    int counter = 0;
    while( counter <K){
        if(A % 2 != 0){
            A--;
        }
        A /= 2;
        B += A;
        counter++;

if(counter >= K)
    break;
        if(B % 2 != 0){
            B--;
        }
        B /= 2;
        A += B;
counter++;

    }
    cout << A << " " << B;
}


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

int main() {
	int a, b, A, B;
	int LCM = 0;	//最小公倍数
	int GCD = 0;	//最大公約数
	while (cin >> a >> b) {
		if (a < b) {
			int temp = a;
			a = b;
			b = temp;
		}
		A = a, B = b;
		while (a%b != 0) {
			int r = a % b;
			a = b;
			b = r;
		}
		GCD = b;
		LCM = A * (B / GCD);
		cout << GCD << " " << LCM << endl;
	}
	return 0;
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


typedef int Flow;
struct Edge{
  int src;int dst;int rev;
  Flow cap;
  Edge(int s=0,int d=0,Flow c=0,int r=0):
  src(s),dst(d),cap(c),rev(r){}
};

using Graph = vector<vector<Edge>>;
Graph g;
bool used[101];

void add(int src,int dst,int cap){
  g[src].emplace_back(src,dst,cap,g[dst].size());
  g[dst].emplace_back(dst,src,0,g[src].size()-1);
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  REP(i,g[v].size()){
    Edge &e=g[v][i];
    if(!used[e.dst]&&e.cap>0){
      int d=dfs(e.dst,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        g[e.dst][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int maximum_flow(int s,int t){
  int flow=0;
  for(;;){
    fill(used,used+101,0);
    int f=dfs(s,t,INF);
    if(!f) return flow;
    flow+=f;
  }
}

signed main(){
  int n;
  cin>>n;
  g=Graph(n+2);
  int sum=0;
  LOOP(i,1,n+1){
    int a;
    cin>>a;
    if(a>0)sum+=a;
    if(a>0){
      add(0,i,a);
      add(i,n+1,0);
    }else{
      add(0,i,0);
      add(i,n+1,abs(a));
    }
    for(int j=2*i;j<=n;j+=i){
      add(j,i,INF);
    }
  }
  int loss=maximum_flow(0,n+1);
  cout<<sum-loss<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int i,j,dif;
int max=-1;
int arr[101];
int N;
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&arr[i]);
}
for(i=0;i<N;i++){
for(j=i+1;j<N;j++){
dif=arr[i]-arr[j];
if(dif<0) dif*=-1;

if(dif>max) max=dif;

}
}
printf("%d",max);
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

Measured memory_bytes: 256
def PrintSquare( board,n )
	n.times{ |i|
		n.times{ |j|
			printf( "%4d",board[ j ][ i ])
		}
		puts
	}
end

def PutNext( board, n, x, y, num )
	next_x = x + 1
	next_y = y + 1
	while true
		next_x = 0     	if next_x >= n
		next_x = n - 1 	if next_x < 0
		next_y = 0 		if next_y >= n
		next_y = n - 1	if next_y < 0
		break if board[ next_x ][ next_y ] == 0
		next_x -= 1
		next_y += 1
	end

	board[ next_x ][ next_y ] = num
	return board, next_x, next_y
end

def MagicSquare( n )
	next_num = 1
	board = Array.new( n ){ Array.new( n, 0) }

	mid = n / 2
	x = mid
	y = mid + 1

	board[ x ][ y ] = next_num
	2.upto( n * n ){ |count|
		board, x, y = PutNext( board, n, x, y, count )
	}
	PrintSquare( board, n )	
end

def main
	questions = Array.new
	while line = $stdin.gets 
		n = line.chomp.to_i
		break if n == 0
		questions << n
	end
	questions.each{ |n|
		MagicSquare( n )
	}
end
main


Measured memory_bytes: 6116
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int a, b, c;
int N;
string s;

int main() {
	cin >> s;

	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int get(vector<int> v) {
	return (*max_element(all(v))) - (*min_element(all(v)));
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n), d(n);
	rep(i, n) {
		cin >> a[i] >> b[i];
		c[i] = a[i] + b[i];
		d[i] = a[i] - b[i];
	}
	cout << max(get(c), get(d)) << '\n';
}

Measured memory_bytes: 7952
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int h = sc.nextInt(), w = sc.nextInt();
        int[][] a = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        List<Ans> ans = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (a[i][j] % 2 != 0) {
                    if (j + 1 < w) {
                        a[i][j]--;
                        a[i][j + 1]++;
                        Ans aa = new Ans();
                        aa.y = i + 1;
                        aa.x = j + 1;
                        aa.yy = i + 1;
                        aa.xx = j + 2;
                        ans.add(aa);
                    } else if (i + 1 < h) {
                        a[i][j]--;
                        a[i + 1][j]++;
                        Ans aa = new Ans();
                        aa.y = i + 1;
                        aa.x = j + 1;
                        aa.yy = i + 2;
                        aa.xx = j + 1;
                        ans.add(aa);
                    }
                }
            }
        }
        System.out.println(ans.size());
        for (Ans aa : ans) {
            System.out.println(aa.toString());
        }
    }

    class Ans {

        int y, x, yy, xx;

        public String toString() {
            return y + " " + x + " " + yy + " " + xx;
        }
    }
}

Measured memory_bytes: 106120
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int H, A;

void solve() {
	cin >> H >> A;
	cout << (H + A - 1) / A << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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


int main() {
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
        string s;
        cin>>s;
        int y=s.length();
        if(s[y-1]=='s')
        	cout<<s<<"es\n";
        else
        	cout<<s<<"s\n";
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

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

  vi a(m);
  int b;
  Graph c(m);
  int tmp;
  Graph unlock(n);

  rep(i,m) {
    cin >> a[i] >> b;
    rep(j,b) {
      cin >> tmp; --tmp;
      c[i].push_back(tmp);
      unlock[tmp].push_back(i);
    }
  }

  rep(i,n) {
    if (unlock[i].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  vi dp((1<<n), 2e6);
  priority_queue<P, vector<P>, greater<P>> pq;
  bitset<12> s;
  vector<P> key;
  rep(i,m) {
    s.reset();
    for (auto v : c[i]) s.set(v);
    int x = s.to_ullong();
    dp[x] = min(dp[x], a[i]);
    pq.push(P(a[i], x));
    key.push_back(P(a[i], x));
  }
  sort(all(key));

  int price, treasure;
  int np, nt;
  while (!pq.empty()) {
    tie(price, treasure) = pq.top(); pq.pop();
    for (auto p : key) {
      tie(np, nt) = p;
      int v = (treasure | nt);
      if (dp[v] > price + np) {
        dp[v] = price + np;
        pq.push(P(dp[v], v));
      }
    }
  }
  cout << dp.back() << endl;
  return 0;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n;
  cin >> n;
  int ost = 0;
  int res = 0;
  R(i,n){
    int pom;
    cin >> pom;
    bool p2 = (pom & -pom) == pom;
    int il = 0;
    while(pom > 1){
      pom /= 2;
      il++;
    }
    debug(il,p2);
    if(p2){
      if(ost < il){
        res += il - ost;
      }
      ost = il;
    }else{
      if(ost <= il){
        res += il + 1 - ost;
        ost = il + 1;
      }else{
        ost = il;
      }
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

using namespace std;

int main(){
    int n;
    cin >> n;
    set<int> st;
    rep(i, n){
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size() % 2 == 0){
        cout << st.size() - 1 << endl;
    }else{
        cout << st.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
const int INF = 1001001001;

int main(){
  ll a;
  double b;
  cin >> a >> b;
  ll B = b*100+0.1;
  cout << (a*B)/100 << endl;
  return 0;
}


Measured memory_bytes: 3692
main :: IO ()
main = do
  abcd <- getLine
  putStrLn . head . filter (not . null) . map (solve . tail . concat . zipWith (\x y -> [y,x]) abcd . ('@':)) . foldr (<*>) [[]] . replicate (length abcd -1 ) $ [('+':),('-':)]


solve :: String -> String
solve xs = go xs 0
  where go :: String -> Int -> String
        go [] acc = if acc == 7 then xs ++ "=7" else []
        go [_] _ = []
        go (a:b:as) acc
          | a == '+' = go as (acc + readInt [b])
          | a == '-' = go as (acc - readInt [b])
          | otherwise = go (b:as) (readInt [a])

readInt :: String -> Int
readInt = read


Measured memory_bytes: 636
/*
power code taken from geeks for geeks
*/

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 100001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}

bool _check(ll a[],ll b[], ll n){
    for(ll i=0;i<n;i++){
        if(a[i]!=b[i]){
            return false;
        }
    }
    return true;
}

int main(){


    // #ifndef ONLINE_JUDGE 

    // // For getting input from input.txt file 
    // freopen("input.txt", "r", stdin); 

    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout); 
    // #endif 


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll x;
    cin>>x;
    ll ans=(x/500)*1000;
    x=x%500;
    ans+=(x/5)*5;
    cout<<ans<<endl;
    
    return 0;
}


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

int main(){
 string s;
  cin>>s;
  if(s=="SUN") cout<<7<<endl;
  else if(s=="MON") cout<<6<<endl;
  else if(s=="TUE") cout<<5<<endl;
  else if(s=="WED") cout<<4<<endl;
  else if (s=="THU") cout<<3<<endl;
  else if(s=="FRI") cout<<2<<endl;
  else cout<<1<<endl;
  
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

class UnionFind:
    def __init__(self, N):
        # negative value: represents the root of a tree; its absolute value is the size of the tree
        # positive value: the parent's index
        self.vertices = [-1 for _ in range(N)]
        self.rank = [0] * N
        
    def find(self, v):
        if self.vertices[v] < 0: # v is a root
            return v
        else:
            # path compression: reconnect v to the root
            self.vertices[v] = self.find(self.vertices[v])
            return self.vertices[v]
        
    def union(self, u, v):
        s1 = self.find(u) # the root of the tree including vertex u
        s2 = self.find(v) # the root of the tree including vertex v
        
        if s1 == s2: # u and v is in the same tree
            return False
        
        if self.rank[s1] > self.rank[s2]: # the tree including u is taller
            self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree
            self.vertices[s2] = s1
        else: # the tree including v is taller
            self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree
            self.vertices[s1] = s2
            if self.rank[s1] == self.rank[s2]:
                self.rank[s2] += 1
        return True
        
    def is_connected(self, u, v):
        return self.find(u) == self.find(v)
    
    def size(self, v):
        return -self.vertices[self.find(v)]
    
N, K, L = map(int, input().split())
uf_road = UnionFind(N)
uf_rail = UnionFind(N)
for _ in range(K):
    p, q = map(int, input().split())
    uf_road.union(p-1, q-1)
for _ in range(L):
    r, s = map(int, input().split())
    uf_rail.union(r-1, s-1)
    
d = defaultdict(int)
comp = [(uf_road.find(i), uf_rail.find(i)) for i in range(N)]
for c in comp:
    d[c] += 1
    
print(*[d[c] for c in comp], sep=' ')

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(b-a<=k&& c-a<=k&& d-a<=k&& e-a<=k&& c-b<=k&& d-b<=k&& e-b<=k&& d-c<=k&& e-c<=k&& e-d<=k) cout << "Yay!" << endl;
  else cout<< ":(" << endl;
  }

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<int> a_row(W, 0);//0初期化
	vector<vector<int> > a(H, a_row); 
	for (int i=0; i<H; ++i) {
		for (int j=0; j<W; ++j) {
			char c;
			cin >> c;
			// whiteを1とする
			if (c=='.') a[i][j] = 1;
		}
	}
	vector<int> row_index(H,0);
	for (int i=0; i<H; ++i) {
		int is_white = 1;
		for (int j=0; j<W; ++j) {
			is_white *= a[i][j];
		}
		if (is_white == 1) row_index[i] = 1;
	}
	vector<int> col_index(W,0);
	for (int j=0; j<W; ++j) {
		int is_white = 1;
		for (int i=0; i<H; ++i) {
			is_white *= a[i][j];
		}
		if (is_white == 1) col_index[j] = 1;
	}
	for (int i=0; i<H; ++i) {
		if (row_index[i] == 1) continue;
		for (int j=0; j<W; ++j) {
			if (col_index[j] == 1) continue;
			cout << (a[i][j] == 1 ? '.' : '#');
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 256
<?php
# A - Security

$array = str_split((fgets(STDIN)));
$key = $array[0];
for ($i = 1; $i < 4; $i++) {
    if ($array[$i] == $key) {
        echo 'Bad' . PHP_EOL;
        exit;
    } else {
        $key = $array[$i];
    }
}
echo 'Good' . PHP_EOL;



Measured memory_bytes: 4728
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<int,int>
#define pb push_back
#define M 103
#define inf (ll)1e9+11
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;  
int dp[M][M][2], K; 
  
int countInRangeUtil(int pos, int cnt, int tight,               string num) 
{ 
    if (pos == num.size()) 
    { 
        if (cnt == K) 
            return 1; 
        return 0; 
    } 
  
    if (dp[pos][cnt][tight] != -1) 
        return dp[pos][cnt][tight]; 
  
    int ans = 0; 
  
    int limit = (tight ? 9 : num[pos]-'0'); 
  
    for (int dig = 0; dig <= limit; dig++) 
    { 
        int currCnt = cnt; 
  
        if (dig != 0) 
            currCnt++; 
  
        int currTight = tight; 
  
        if (dig < num[pos]-'0') 
            currTight = 1; 
  
        ans += countInRangeUtil(pos + 1, currCnt,                              currTight, num); 
    } 
    return dp[pos][cnt][tight] = ans; 
} 
  
int countInRange(string num) 
{   
    memset(dp, -1, sizeof(dp)); 
    return countInRangeUtil(0, 0, 0, num); 
} 
  
int main() 
{ 
    string n;
    cin>>n>>K;
    cout<<countInRange(n);
    
    return 0; 
} 

Measured memory_bytes: 384
#include <stdio.h>
#define NIL -1
#define N 10000

typedef struct data
{
    int p, l, r;
} DATA;
DATA T[N];

void Preorder(int);
void Inorder(int);
void Postorder(int);

int main()
{
    int i;
    int n;
    int id, left, right, root;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d", &id, &left, &right);
        T[id].l = left;
        T[id].r = right;
        if (left != NIL)
            T[left].p = id;
        if (right != NIL)
            T[right].p = id;
    }

    for (i = 0; i < n; i++)
    {
        if (T[i].p == NIL)
            root = i;
    }

    printf("Preorder\n");
    Preorder(root);
    printf("\n");

    printf("Inorder\n");
    Inorder(root);
    printf("\n");

    printf("Postorder\n");
    Postorder(root);
    printf("\n");

    return 0;
}

void Preorder(int u)
{
    if (u == NIL)
        return;

    printf(" %d", u);
    Preorder(T[u].l);
    Preorder(T[u].r);
}

void Inorder(int u)
{
    if (u == NIL)
        return;

    Inorder(T[u].l);
    printf(" %d", u);
    Inorder(T[u].r);
}
void Postorder(int u)
{
    if (u == NIL)
        return;

    Postorder(T[u].l);
    Postorder(T[u].r);
    printf(" %d", u);
}



Measured memory_bytes: 2056
import numpy as np
import copy
h,w,k=map(int,input().split())
c=np.empty((h,w), dtype=int)
for i in range(h):
    s=np.array(list(input()))
    c[i,:]=np.where(s=="#", 1, 0)

ans=0
loop=0
for i in range(2**h):
    tmp=copy.deepcopy(c)
    for j in range(h):
        if (i>>j)&1:
            tmp[j,:]=0
    
    for p in range(2**w):
        tmp1=copy.deepcopy(tmp)
        for q in range(w):
            if (p>>q)&1:
                tmp1[:,q]=0
        if tmp1.sum()==k:
            ans+=1
print(ans)

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

int main()
{
    int n;
    pair<string, pair<int, int> > res[105];

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> res[i].first >> res[i].second.first;
        res[i].second.first *= -1;
        res[i].second.second = i + 1;
    }

    sort(res, res + n);

    for (int i = 0; i < n; i++) {
        cout << res[i].second.second << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
void print_vector(std::vector<int> v){
    for(int i=0;i<v.size();i++){
        std::cout<<v[i]<<" ";
    }
    std::cout<<"\n";
}
int main(){
    int a,b;
    std::vector<int> s;
    std::vector<int> t;
    std::cin>>a;
    for(int i=0;i<a;i++){
        int x;
        std::cin>>x;
        s.push_back(x);
    }
    // print_vector(s);
    std::cin>>b;
    for(int i=0;i<b;i++){
        int x;
        std::cin>>x;
        t.push_back(x);
    }
    // print_vector(t);
    std::sort(s.begin(),s.end());
    std::sort(t.begin(),t.end());
    // print_vector(s);
    // print_vector(t);
    int cnt=0;
    for(int i=0;i<b;i++){
        for(int j=0;j<a;j++){
            if(t[i]==s[j]){
                cnt++;
                break;
            }
        }
    }   
   std::cout<<cnt<<"\n";

}


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

void intsertionSort(int N,vector<int> &A){
  int v;
  int j;

  for(int i=1;i<=N-1;++i){
    v = A.at(i);
    j = i - 1;
    while(j >= 0 && A.at(j) > v){
      A.at(j+1) = A.at(j);
      j--;
    }
    A.at(j+1) = v;
    for(int k=0;k<N-1;++k){
      cout << A.at(k) << " ";
    }
      cout << A.at(N-1) << endl;
    }
}
int main(){
  int N;

  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;++i){
    cin >> vec.at(i);
  }
  for(int i=0;i<N-1;++i){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(N-1) << endl;
  intsertionSort(N,vec);


}



Measured memory_bytes: 3084
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]

def modcmb(n, r, mod):
    if n < 0 or r < 0 or r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def main():
    H,W,A,B = map(int, readline().split())

    n = H+W+1
    for i in range(2,n):
        fac.append((fac[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD//i)) % MOD)
        f_inv.append((f_inv[-1] * inv[-1]) % MOD)

    ans = 0
    for i in range(H-A):
        ans += modcmb(B-1+i, B-1, MOD) * modcmb(H+W-B-2-i, W-1-B, MOD) % MOD
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int n;
  int k;
  cin >> n >> k;
  char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string ans;
  while (n >= k) {
    ans += table[n % k];
    n /= k;
  }
  ans += table[n];
  cout << ans.size() << endl;
  return 0;
}


Measured memory_bytes: 256