akhauriyash/Code-Regression huggingface dataset:
#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<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<llint> vllint;
typedef vector<vllint> vvllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#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 YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define coutans rep(i, ans.size())cout << ans[i] << endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	vector<double> ans;
	while (1) {
		double n;
		cin >> n;
		if (n == 0)break;
		vint a(n);
		double av = 0, aa = 0;
		rep(i, n) {
			cin >> a[i];
			av += a[i];
			aa += a[i] * a[i];
		}
		av /= n;
		aa /= n;
		aa -= av * av;
		ans.push_back(sqrt(aa));
	}
	rep(i, ans.size())printf("%.15f\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int dp[1001][10001];
int m,n; cin >> m >> n;
int h[n]; int mp[n];
for (int i=0; i<n; i++){cin >> h[i] >> mp[i];}
dp[0][0]=0;
for (int i=0; i<n; i++){
  for (int j=0; j<=m;j++){
    if(j<=h[i]){if(i!=0){dp[i][j]=min(dp[i-1][j],mp[i]);}
               else{dp[i][j]=mp[i];}}
    else{
      if(i==0){dp[0][j]=dp[0][j-h[0]]+mp[0];}
      else{dp[i][j]=min(dp[i-1][j],dp[i][j-h[i]]+mp[i]);}
    }
  }
}
cout << dp[n-1][m] << endl;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
    int A, B, C;
    cin >> A >> B >> C;
    
    int ans = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        if (A == B && B == C) {
            cout << -1 << endl;
            return;
        }
        int nA = (B + C) / 2, nB = (A + C) / 2, nC = (A + B) / 2;
        A = nA;
        B = nB;
        C = nC;
        ans++;
    }
    cout << ans << endl;
    
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

b = []
c = []
for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

for x in abc:
    count[x] += 1

print(max(count))

Measured memory_bytes: 20452
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll h(n+1, 0); REP(i, n) cin >> h.at(i+1);
  rep(i, 1, n+1) {
    cout << "node " << i << ": key = " << h.at(i) << ", ";
    if (i / 2 >= 1) cout << "parent key = " << h.at(i/2) << ", ";
    if (i*2 <= n) cout << "left key = " << h.at(i*2) << ", ";
    if (i*2+1 <= n) cout << "right key = " << h.at(i*2+1) << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3048
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;


int main () {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    
    int x, y, z;
    int result = 0;
    
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        x = b / 2 + c / 2;
        y = a / 2 + c / 2;
        z = a / 2 + b / 2;
        result++;
        if (x == y && y == z) {
            printf("-1");
            return 0;
        }
        a = x;
        b = y;
        c = z;
    }
    printf("%d", result);
}


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

using namespace std;

typedef long long ll;

const string T = "AKIHABARA";
const int n = (int) T.size();

int main() {
    string s;
    cin >> s;
    vector<int> index;
    for (int i = 0; i < n; ++i) {
        if (T[i] == 'A') index.emplace_back(i);
    }

    vector<bool> use(n, true);

    int m = (int)index.size();
    for (int bit = 0; bit < 1 << m; ++bit) {
        for (int i = 0; i < m; ++i) {
            if (bit >> i & 1) use[index[i]] = true;
            else use[index[i]] = false;
        }

        string t;
        for (int j = 0; j < n; ++j) {
            if (use[j]) t.push_back(T[j]);
        }
        if (t == s){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define n_size 100000

int main(){
    bool isPrime[n_size];
    isPrime[0] = false;
    isPrime[1] = false;

    for (unsigned i = 2; i < n_size; i++)
        isPrime[i] = true;

    for (unsigned i = 2; i * i < n_size; i++){
        if (isPrime[i]){
            for (unsigned j = (i * i); j < n_size; j += i)
                isPrime[j] = false;
        }
    }

    unsigned n;
    while(cin >> n){
        unsigned a = n-1;
        unsigned b = n+1;
        while(!isPrime[a])
            a--;
        while(!isPrime[b])
            b++;
        cout << a << " " << b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
days_to_stay = int(input())
special_days = int(input())
normal_price = int(input())
special_price = int(input())
payment = 0 

if days_to_stay <= special_days:
    payment = days_to_stay * normal_price
else:
    payment = (days_to_stay - special_days) * special_price + special_days * normal_price
    
print(payment)

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

int cal(int x, int y, char z){
    if (z == '+'){
        return x + y;
    }
    else{
        return x - y;
    }
}

int main(){
    int A, B, C, D, X;
    cin >> X;
    A = X/1000;
    B = (X-A*1000)/100;
    C = (X-A*1000-B*100)/10;
    D = (X-A*1000-B*100-C*10);
    vector<char> ii = {'+', '-'};
    vector<char> jj = {'+', '-'};
    vector<char> kk = {'+', '-'};
    vector<char> ans(3);
    for (int i = 0; i < 2; i ++){
        for (int j = 0; j < 2; j ++){
            for (int k = 0; k < 2; k ++){
                if (cal(cal(cal(A, B, kk.at(k)), C, jj.at(j)), D, ii.at(i)) == 7){
                    ans = {kk.at(k), jj.at(j), ii.at(i)};
                }
            }
        }
    }
    
    cout << A << ans.at(0) << B << ans.at(1) << C << ans.at(2) << D << "=7" << endl;
}


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

int	main()
{
	double	a, b, C;
	cin >> a >> b >> C;
	double	theta = C / 180. * M_PI;
	double	h = b * sin(theta);
	double	L = a + b + sqrt(a * a + b * b - 2. * a * b * cos(theta));
	double	S = a * h / 2.;
	cout << fixed << setprecision(8) << S << "\n" << L << "\n" << h << endl;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

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

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

signed main(){
	int n=read();
	string s=readString(),t=readString();
	if(s==t){
		cout<<0<<endl;
		return 0;
	}
	int k=n-1,ans=0,bias=0,last=n;
	queue<int> q;
	for(int i=n-1;i>=0;i--){
		chmin(k,i);
		while(k>=0&&s[k]!=t[i])
			k--;
		if(k==-1){
			cout<<-1<<endl;
			return 0;
		}
		while(!q.empty()&&q.front()+bias>i)
			q.pop();
		if(k!=last){
			chmax(ans,int(q.size())+1);
			bias--;
			q.push(k-bias);
		}
		last=k;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11408
#pragma GCC optimize("Ofast")

#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>         //可変長配列
#include <list>           //双方向連結リスト

using namespace std;

int allocate(const vector<int>& w, int k, int p){
    int track = 0;
    int cap = p;
    int i;
    for(i = 0; i < w.size();){
        if(cap >= w[i]){
            cap -= w[i];
            ++i;
        }else{
            cap = p;
            ++track;
        }
        if(track == k){
            return i;
        }
    }
    return i;
}

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

    int n, k;
    cin >> n >> k;
    vector<int> w(n);
    for(int i = 0; i < n; ++i){
        cin >> w[i];
    }

    int min = 1, max = 10000 * 100000, middle;
    while(min < max){
        middle = (min + max) / 2;
        int v = allocate(w, k, middle);
        if(v == n){
            max = middle;
        }else{
            min = middle + 1;
        }
    }
    middle = (min + max) / 2;
    cout << middle << "\n";

	return 0;
}


Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 1e5+5,mod = 1e9+7;
int n,k,ans,val[N],sum[N],fac[N],ifac[N];
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
it C(int n,int m){return mul(fac[n],mul(ifac[m],ifac[n-m]));}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(k);
	for(ri i=1;i<=n;++i)
		read(val[i]);
	sort(val+1,val+1+n);
	for(ri i=1;i<=n;++i) val[i]=val[i]<0?val[i]+mod:val[i];
	for(ri i=1;i<=n;++i) sum[i]=add(sum[i-1],val[i]);
	fac[0]=1;
	for(ri i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
	ifac[n]=qpow(fac[n],mod-2,mod);
	for(ri i=n-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	for(ri len=k;len<=n;++len){
		int res=add(add(sum[n],mod-sum[len-1]),mod-sum[n-len+1]);
		res=mul(res,C(len-2,k-2)),inc(ans,res);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int

using namespace std;



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    ll R;
    cin>>R;
    cout<<3*(R*R)<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long int n,k,a[200010],ans=0,i;
cin >> n >> k;
for(i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n,greater<long long int>());
for(i=k;i<n;i++){
ans=ans+a[i];
}
cout << ans << endl;
  return 0;
  }

Measured memory_bytes: 1792
def main():
     AlfaToNum={'a':2,'b':3,'c':5,'d':7,'e':11,'f':13,'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
     n=int(input())
     s=[]
     ans=0
     for i in range(n):
          si=input()
          cnt=1
          for j in si:
               cnt*=AlfaToNum[j]
          s.append(cnt)
     #print(s)
     s.sort()
     cnt=1
     for i in range(n-1):
          if s[i]==s[i+1]:
               cnt+=1
          else:
               ans+=cnt*(cnt-1)//2
               cnt=1
     ans+=cnt*(cnt-1)//2
     print(ans)
if __name__ == '__main__':
     main()

Measured memory_bytes: 59736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005;
int n,R[N],G[N],B[N];
char s[N];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=n;i>=1;i--)
    {
        R[i]=R[i+1]+(s[i]=='R');
        G[i]=G[i+1]+(s[i]=='G');
        B[i]=B[i+1]+(s[i]=='B');
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
    {
        if(s[i]==s[j]) continue;
        if(s[i]!='R'&&s[j]!='R') ans+=R[j+1];
        if(s[i]!='G'&&s[j]!='G') ans+=G[j+1];
        if(s[i]!='B'&&s[j]!='B') ans+=B[j+1];
        if(j+j-i<=n&&s[j+j-i]!=s[i]&&s[j+j-i]!=s[j])
            ans--;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3840
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
var nab=arr.shift();
   if(nab=="0 0 0")break;
   nab=nab.split(" ").map(Number);
   var n=nab[0];
   var ab=[nab[1],nab[2]];
   var dp=[];
   for(var i=0;i<=n;i++)dp[i]=false;
   dp[0]=true;
   for(var i=0;i<ab.length;i++){
      for(var j=0;j<=n;j++){
         if(dp[j])dp[j+ab[i]]=true;
      }
   }
   var cnt=0;
   dp.forEach(function(v){
      if(v==false)cnt++;
   });
   console.log(cnt);
}

Measured memory_bytes: 40460
N, K = map(int, input().split())
X = [int(i) for i in input().split()]

X_n = sorted([-x for x in X if x < 0])
X_p = sorted([x for x in X if x >= 0])

ans = 10**20
for k in range(K+1):
    if len(X_n) >= k and len(X_p) >= K-k:
        if k == 0:
            ans = min(ans, X_p[K-1])
        elif k == K:
            ans = min(ans, X_n[K-1])
        else:
            ans = min(ans, 2*X_n[k-1] + X_p[K-k-1], X_n[k-1] + 2*X_p[K-k-1])
print(ans)


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

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ar = new int[M];
        for (int i = 0; i < M; i++) {
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        int[] dis = new int[M-1];
        for (int i = 0; i < dis.length; i++) {
            dis[i] = Math.abs(ar[i] - ar[i+1]);
        }
        Arrays.sort(dis);
        long count = 0;
        for (int i = 0; i < dis.length-N+1; i++) {
            count += dis[i];
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 59656
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1;
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

ll sum(ll mi, ll ma) {
	ll res = (ma + 1)*ma / 2 - mi * (mi - 1) / 2;
	return res;
}

int main(){
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, 0, n)cin >> a[i];
	
	rep(i, 0, n) {
		if (a[i] % 2 != 0) {
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cmath>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
#define downint greater<int>()
#define downchar greater<char>()
#define downstring greater<string>()
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,a,v,b,w,t;
  
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  
  result = 1;
  if(v-w<0) result=0;
  else{
    if(abs(a-b)>(v-w)*t) result=0;
  }
  cout << (result==1 ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
void dfs(int v, int p, vector<int> &ans, vector<vector<int> > &G)
{
	for (int u : G[v]) {
		if (u == p)
			continue;
		ans[u] += ans[v];
		dfs(u, v, ans, G);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, q;
	cin >> n >> q;
	vector<vector<int> > G(n + 1);
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a); 
	}
		
	vector<int> ans(n + 1, 0);
	while (q--) {
		int p, x;
		cin >> p >> x;
		ans[p] += x;
	}
	dfs(1, 0, ans, G);
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 29696
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

NUM = 20005

table = [""]*NUM


while True:

    T = str(input())
    if T == '-':
        break

    left = 0
    right = 0
    #長い配列にパターン文字列を転記
    for i in range(len(T)):
        # print(T[right])
        table[left+right] = T[right]
        right += 1

    num_suffle = int(input())

    for loop in range(num_suffle):
        pick_num = int(input())
        #先頭からpick_num文字を末尾に転記し、論理削除
        for i in range(pick_num):
            table[right+i] = table[left+i]
        left += pick_num
        right += pick_num

    for i in range(left,right):
        print("%s"%(table[i]),end = "")
    print()


Measured memory_bytes: 5740
#include<bits/stdc++.h>
#define ll long long

int take()
{
    int n;
    scanf("%d",&n);
    return n;

}

ll takes()
{
    ll n;
    scanf("%lld",&n);
    return n;

}
#define M 200005
#define Int take()
#define LL takes()

#define fr(n) for(int i=1;i<=n;i++)
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)
using namespace std;

int main(){
        int n=Int,v;

        vi a,b,c;
        fr(3){
                for(int k=1;k<=n;k++){
                        v=Int;
                        if(i==1) a.pb(v);
                        else if(i==2) b.pb(v);
                        else c.pb(v);
                }
        }

        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        ll ans=0;

        for(int i=1;i<=n;i++){
              ll d=lower_bound(a.begin(),a.end(),b[i-1])-a.begin();
              ll e=c.end()-upper_bound(c.begin(),c.end(),b[i-1]);
              ans+=(d*e);
        }

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

        return 0;
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		int B = sc.nextInt();

		if (B % A == 0) {
			System.out.println(A + B);
		} else {
			System.out.println(B - A);
		}
	}

}

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

int main() {
  int X;
  cin >> X;
  for (int i = 1; i <= X / 100; ++i) {
    if (100 * i <= X && X <= 105 * i) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
s = input()
t = input()
slen = len(s)
tlen = len(t)
dp = [[0] * (tlen+1) for i in range(slen+1)]
for i in range(slen):
    for j in range(tlen):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
stlen = dp[slen][tlen]
ans = [0]*stlen
i = slen
j = tlen
while stlen > 0:
    if s[i-1] == t[j-1]:
        ans[stlen-1] = s[i-1]
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        j -= 1
    stlen = dp[i][j]
print(''.join(ans))

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	ll x, y, ans;
	cin >> x >> y;
	if (x == 0){
		if (y >= 0){
			ans = y;
		} else {
			ans = -y + 1;
		}
	} else if (y == 0){
		if (x < 0){
			ans = -x;
		} else {
			ans = x + 1;
		}
	}
	else if (x * y < 0){
		ans = abs(abs(x) - abs(y)) + 1;
	} else {
		if (x <= y){
			ans = y - x;
		} else {
			ans = x - y + 2;
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

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

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  cin >> s;
  int white = 0;
  i64 ans = 0;
  rrep(i, s.size()) {
    if (s[i] == 'W') white++;
    if (s[i] == 'B') ans += white;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
#include "stdio.h"
#include "iostream"
#include "string"
using namespace std;
int main(){
  long int a,b,c,m,t;
  cin>>a>>b>>c;
  m=a;
  if(m<b)m=b;
  if(m<c)m=c;
  t=3*m-a-b-c;
  if(t%2){cout<<(t+3)/2<<endl;}
  else{cout<<t/2<<endl;}
  return 0;
}

Measured memory_bytes: 256
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 500005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

/* Factorial modulo MOD */
LL fact[MAX];
void factorial() {
	fact[0] = 1;
	for(int i=1;i<MAX;i++) {
		fact[i] = (i * fact[i-1]) % MOD;
	}
}

/* Modulo exponentiation */
LL power(LL base, LL exp, LL ans) {
	if(!exp) return ans % MOD;
	if(exp&1) ans = (ans * base) % MOD;
	return power((base * base) % MOD, exp>>1, ans);
}

/* nCr modulo MOD */
LL nCr(LL n, LL r) {
	if(n < r) return 0;
	LL numerator = fact[n];
	LL denominator = (fact[n-r] * fact[r]) % MOD;
	return (numerator * power(denominator, MOD-2, 1)) % MOD;
}

void pre() {
	factorial();
}

void solve() {
	LL n, m;
	inl2(n, m);
	
	LL npr = (nCr(m, n) * fact[n]) % MOD;
	
	LL derr = 0;
	for(int i=0;i<=n;i++) {
		LL temp = (nCr(n, i) * nCr(m-i, n-i)) % MOD;
		temp = (temp * fact[n-i]) % MOD;
		
		if(i & 1) derr = (derr - temp + MOD) % MOD;
		else derr = (derr + temp) % MOD;
	}
	
	LL ans = (npr * derr) % MOD;
	cout<<ans<<en;
}

int main() {
	int t = 1;
	pre();
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 7548
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

#define debug(x) cout << #x << " = " << x << endl
#define lowbit(x) (x & (-x))

typedef long long LL;
typedef pair<int, int>PII;
const int maxn = 1e5 + 10;
const int inf = 1e9 + 10;

struct point {
	LL x, c, i;
	LL pos;
}num[maxn];
LL n, ans;
LL G;
int vis[105];
bool cmp(point a, point b){
	if(a.pos == b.pos) return a.x < b.x;
	return a.pos > b.pos;
}
void Dfs(LL x){
	if(G <= 0){
		if(x) ans = min(ans, x);
		return ;
	}
	for(int i = 1; i <= n ; i ++){
		if(!vis[num[i].i] /*&& num[i].pos >= G*/){
			LL ind = G / (num[i].i * 100);
			if(G % num[i].i) ind++;
			vis[num[i].i] = 1;
			G -= num[i].pos;
			Dfs(x + min(ind, num[i].x));
			vis[num[i].i] = 0;
			G += num[i].pos;
		}
//		else if(!vis[num[i].i] && num[i].pos < G){
//			G -= num[i].pos;
//			vis[num[i].i] = 1;
//			Dfs(x + num[i].x);
//			vis[num[i].i] = 0;
//			G += num[i].pos;
//		}
	}
}
int main(){
	scanf("%lld %lld", &n, &G);
	for(int i = 1; i <= n; i ++){
		scanf("%lld %lld", &num[i].x, &num[i].c);
		num[i].pos = num[i].x * 100 * i + num[i].c;
		num[i].i = i;
	}
	ans = inf;
	memset(vis, 0, sizeof(vis));
	Dfs(0);
	printf("%lld\n", ans);
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long

void solve(){
	int ans = 0;
	string a, b;
	cin >> a >> b;
	for(int i=0; i<(int) a.size(); i++) {
		ans += (a[i] != b[i]);
	}
	cout << ans;
}

int main(){
	IOS;
	int t = 1; 
	// cin >> t;
	while(t--) solve();
	return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  if(s == t) puts("=");
  if(s < t) puts("<");
  if(s > t) puts(">");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using ll = long long;
using ull = unsigned long long;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ull> vul;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<ll>> vvl;
typedef vector<vector<string>> vvs;
typedef vector<vector<ull>> vvul;
typedef vector<bool> vb;
const ll md = 998244353;

ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod)%mod;
}

ll mul(ll a, ll b, ll mod = md) {
    return ((a%mod) * (b%mod))%mod;
}

ll C(vl &fact, vl &invfact, ll n, ll r, ll mod = md) {
    if(r == 0) return 1;
    return mul(fact[n], mul(invfact[r], invfact[n-r], mod), mod);
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    res %= mod;
    return res;
}

void cachefact(vector<ll>& fac, vector<ll> &ifac, ll bound, ll mod = md) {
	fac[0] = 1;
	ifac[0] = power(1, mod-2)%mod;
	for(ll i = 1; i <= bound; i++) {
		fac[i] = (fac[i-1] % mod * i % mod)%mod;
		ifac[i] = power(fac[i], mod-2)%mod;
	}
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n) {  
        if (n & 1) res = (res*x);
        n = (n >> 1);
        x = (x*x);
    }  
    return res;
}

ll lg(ll b, ll e) {
	ll i, x = b;
	for(i = 0; ; i++, x *= b) {
		if(x > e) {
			break;
		}
	}
	return i;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// ll n;
	// cin >> n;
	// ll tm = lg(26, (25*n+1)/26) + 1;
	// n -= 26*((power2(26, tm - 1) - 1)/25);
	// ll cur = 1;
	// string res = "";
	// for(int i = 0; i < tm; i++) {
	// 	res += 'a';
	// }
	// int itr = 0;
	// cout << n << "\n";
	// while(n > 26) {
	// 	// ll trm = (n + 25) / 26;
	// 	// res[itr] = 'a' + trm - 1;
	// 	// cout << trm << " ";
	// 	// itr++;
	// 	// n = n - ((n-1) / 26)*26;
	// 	// cout << n << "\n";
	// 	ll cur = n, prod;
	// 	while(cur / 26 > 26) {
	// 		cur /= 26;
	// 		prod *= 26;
	// 	}
	// 	res[itr] = 'a' + cur/26;
	// 	prod *= cur / 26;
	// 	n = n - prod;
	// }
	// res[tm - 1] = 'a' + n - 1;
	// cout << res << "\n";
	ll n, sum = 0;
	cin >> n;
	vector<ll> a(n), f(5e5, 0);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		f[a[i]]++;
		sum += a[i];
	}
	ll q;
	cin >> q;
	while(q--) {
		ll b, c;
		cin >> b >> c;
		sum -= f[b]*b;
		f[c] += f[b];
		sum += f[b] * c;
		cout << sum << "\n";
		f[b] = 0;
	}
	return 0;
}

Measured memory_bytes: 7948
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){

	ll n;
	cin >> n;
	vll p(n),v(n);
	rep(i,n){
		cin >> p[i];
		v[p[i]-1] = i;
	}

	set<ll> s1,s2;
	ll ans = 0;
	// s.insert(-1);
	// s.insert(1000000);
	for(int i = n-1;i>=0;i--){
		ll a,b,c,d;
		auto itr1 = s1.lower_bound(v[i]);
		if(itr1 == s1.end()){
			d = n-v[i];b = 0;
		}else{
			auto itr2 = itr1;
			itr2++;
			d = *itr1 - v[i];
			if(itr2 == s1.end())b = n - *itr1;
			else b = *itr2 - *itr1;
		}
		itr1 = s2.lower_bound(-v[i]);
		if(itr1 == s2.end()){
			a = v[i]+1;c = 0;
		}else{
			auto itr2 = itr1;
			itr2++;
			a = *itr1 + v[i];
			if(itr2 == s2.end())c = 1 - *itr1;
			else c = *itr2 - *itr1;
		}
		ans += (a*b + c*d)*(i+1);
		s1.insert(v[i]);
		s2.insert(-v[i]);
		cerr << i << endl;
		// for(auto x:s1)cerr << x << " ";cerr << endl;
		// for(auto x:s2)cerr << x << " ";cerr << endl;
		// cerr << a << " " << b << " " << c << " " << d << endl << endl;
	}
	cout << ans << endl;


	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc140.contest.atcoder.jp/tasks/abc140_a

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

struct UnionFind
{
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}

  int root(int x)
  {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }

  bool merge(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x)
  {
    return -par[root(x)];
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  for (auto &it : p)
  {
    cin >> it;
    it--;
  }
  UnionFind uf(N);
  for (int i = 0; i < M; i++)
  {
    int x, y;
    cin >> x >> y;
    x--, y--;
    uf.merge(x, y);
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (uf.isSame(i, p[i]))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let minimum = List.fold_left min max_int as_ in
  let maximum = List.fold_left max min_int as_ in
  let minimums = List.length (List.filter (( = ) minimum) as_) in
  let maximums = List.length (List.filter (( = ) maximum) as_) in
  print_endline begin
    if maximum = minimum && (maximum = n - 1 || 2 * maximum <= n)
    || minimum + 1 = maximum && minimums < maximum && 2 * (maximum - minimums) <= maximums then "Yes"
    else "No" end

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, s, e) for (int i = s; i < e; i++)
using namespace std;

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] = -1;
    }

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

    int size(int x)
    {
        return -par[root(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の根が同じ(=同じ木にある)時はそのまま
        if (size(rx) < size(ry))
        {
            swap(rx, ry);
        }
        par[rx] += par[ry];
        par[ry] = rx;
    }

    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, M;
    cin >> N >> M;
    UnionFind A(N);
    rep(i, 0, M)
    {
        int a, b;
        cin >> a >> b;
        A.unite(a, b);
    }
    int res = 0;
    rep(i, 0, N)
    {
        res = max(res, A.size(i));
    }
    cout << res << endl;
}


Measured memory_bytes: 4048
from math import sqrt

def fact(n):
    F_dict,F_set = {},set()
    for i in range(2,int(sqrt(n))+1):
        if n % i == 0:
            F_dict[i] = 1
            F_set.add(i)
            n //= i
            while n % i == 0:
                F_dict[i] += 1
                n //= i
        if n == 1:
            break

    if n != 1:
        F_dict[n] = 1
        F_set.add(n)

    return (F_dict,F_set)

def main_cal(F_dict,F_set):
    output = 0
    for f in F_set:
        num = 1
        while F_dict[f] > 0:
            if F_dict[f] >= num:
                F_dict[f] -= num
                num += 1
            else:
                break
        output += (num-1)
    return output

def main():
    N = int(input())

    fa = fact(N)
    print(main_cal(fa[0],fa[1]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9236
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
#include  <sstream>
#include  <bitset>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int k;

bool dfs(int m, int a, int b, int c)
{	
	
	if (m == k) {
		//cout << a << " " << b << " " << c << endl;
		if (a < b && b < c) return true;
		else return false;
	}
	bool res = false;
	if (dfs(m + 1, 2 * a, b, c) || dfs(m + 1, a, 2 * b, c) || dfs(m + 1, a, b, 2 * c)) res = true;
	return res;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cin >> k;
	
	if (dfs(0, a, b, c)) cout << "Yes" << endl;
	else  cout << "No" << endl;
	
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int a;
  cin >>a;
  
  cout << "ABC" << a << endl;  
  
}
      
     

Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <climits>
#include <set>
#define endl '\n'
#define ll long long

using namespace std;

ll dp[100001][2];

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> h(N, 0);
    for(int i = 1; i <= N; i++) cin >> h[i];
    
    for(int i = 1; i <= N; i++)
    {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + abs(h[i] - h[i-1]);
        if(i == 2)
        {
            dp[i][1] = dp[i][0];
        }
        else if(i - 2 >= 0)
        {
            dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + abs(h[i] - h[i-2]);
        }
    }
    cout << min(dp[N][0], dp[N][1]) << endl;
    return 0;
}


Measured memory_bytes: 2560
module Main where

import           Control.Monad
import           Data.List
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector.Unboxed           as V
import           Text.Printf

main :: IO ()
main = do
  [x, y, z, k] <- map read . words <$> getLine
  [as, bs, cs] <- replicateM 3 $ map read . words <$> getLine
  let ab  = take k . sortBy (flip compare) $ [ a + b | a <- as, b <- bs ]
      abc = take k . sortBy (flip compare) $ [ a + c | a <- ab, c <- cs ]
  mapM_ print abc


Measured memory_bytes: 423292
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Line | diff Line.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Line.cpp && ./a.out

/*
 
 3/28/2020
 
 5:12-5:57 give up
 8:24-
 
 */

const int MAX_N=1e4+1;
int N,X,Y;

VI G[MAX_N];
const int Inf=1e7;
int mx[MAX_N][MAX_N];
void solve() {
  REP(i,N)REP(j,N) mx[i][j]=i==j?0:Inf;
  queue<II> Q;
  REP(i,N) Q.emplace(i,i);
  while(SZ(Q)) {
    int s,u; tie(s,u)=Q.front(),Q.pop();
    FORR(v,G[u]) {
      if(mx[s][v]>mx[s][u]+1) {
        mx[s][v]=mx[s][u]+1;
        Q.emplace(s,v);
      }
    }
  }
  VI res(N);
  REP(j,N)REP(i,j) res[mx[i][j]]++;
  FORE(k,1,N-1) cout<<res[k]<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>X>>Y;
  --X,--Y;
  REP(i,N-1) G[i].push_back(i+1),G[i+1].push_back(i);
  G[X].push_back(Y),G[Y].push_back(X);
  
  solve();
  
  return 0;
}


Measured memory_bytes: 79104